showMacroWin(void) { int num = macrocnt + 5; if (!macroWin) { if (maclevel == 0) { lineno = 0; filldist(0); num = lineno + 5; } /* we'll use GWINSIDE since it is (probably) less than or equal to * * TWINSIDE. The smaller the better. */ macroWin = W_MakeTextWindow("macrow", GWINSIDE + BORDER, BORDER, 80, num, NULL, BORDER); W_ResizeTextWindow(macroWin, 80, num); W_DefineTrekCursor(macroWin); W_SetWindowExposeHandler(macroWin, fillmacro); W_SetWindowButtonHandler(macroWin, switchmacros); W_MapWindow(macroWin); } else if (W_IsMapped(macroWin)) W_UnmapWindow(macroWin); else W_MapWindow(macroWin); }
void metawindow() /* Show the meta server menu window */ { int i, height; char *header; static int lastHeight = 0; if (!metaWin) { height = 250 + metaHeight * (W_Textheight + 8) + 4 * (metaHeight - 1); metaWin = W_MakeWindow("Netrek Server List", 0, 0, 716, height, NULL, 2, foreColor); W_SetBackgroundImage(metaWin, "Misc/map_back.png"); logo = W_ReadImage(metaWin, "netrek-green-white-300px.png"); metaList = W_MakeMenu("metalist", 50, 200, LINE, metaHeight, metaWin, 1); lastHeight = metaHeight; make_help(); } else { if (metaHeight > lastHeight) { W_ReinitMenu(metaList, LINE, metaHeight); W_ResizeMenu(metaList, LINE, metaHeight); lastHeight = metaHeight; } // FIXME: handle metaList growing beyond metaWin } header = "Server Status Type Age"; W_WriteText(metaList, 0, 0, W_Cyan, header, -1, 0); for (i = 0; i < metaHeight; i++) redraw(i); /* Give the window the right name */ W_RenameWindow(metaWin, metaWindowName); /* Add additional options */ W_WriteText(metaList, 0, metaHeight-B_REFRESH, W_Yellow, "Refresh (r)", -1, 0); add_redraw(); W_WriteText(metaList, 0, metaHeight-B_HELP, W_Yellow, "Help & Tips (h)", -1, 0); W_WriteText(metaList, 0, metaHeight-B_QUIT, W_Yellow, "Quit (q)", -1, 0); /* Map window */ W_MapWindow(metaList); W_MapWindow(metaWin); }
void warwindow(void) { W_MapWindow(war); newhostile = me->p_hostile; warrefresh(); }
nswindow(void) { register int i; for (i = 0; i < NETSTAT_NUMFIELDS; i++) nsrefresh(i); /* Map window */ W_MapWindow(netstatWin); }
void spwindow(void) { register int i; for (i = 0; i < SPK_NUMFIELDS; i++) sprefresh(i); /* Map window */ W_MapWindow(spWin); }
void soundwindow(void) { #if defined(HAVE_SDL) char *buf="All or nothing with SDL sound. Sorry"; W_WriteText(soundWin, 0, 0, textColor, buf, strlen(buf), 0); #else int i; for (i=0; i <= SOUND_DONE; i++) soundrefresh(i); #endif /* Map window */ W_MapWindow(soundWin); }
void switchmacros(void) { int num = macrocnt + 5; if (!macroWin) return; /* paranoia? */ maclevel = abs(maclevel - 1); if (maclevel == 0) { lineno = 0; filldist(0); num = lineno + 5; } W_ResizeTextWindow(macroWin, 80, num); W_SetWindowExposeHandler(macroWin, fillmacro); W_SetWindowButtonHandler(macroWin, switchmacros); W_MapWindow(macroWin); }
/* Set up the option menus and window. */ optionwindow(void) { register int i; /* Init not done flag */ notdone = 1; *newkeys = '\0'; if (FirstMenu == NULL) { MaxOptions = InitOptionMenus(); if (MaxOptions < 0) { fprintf(stderr, "InitOptionMenus() error %s!\n", MaxOptions); notdone = 0; return; } } /* Create window big enough to hold option windows */ if (optionWin == NULL) { optionWin = W_MakeMenu("option", TWINSIDE + 10, -BORDER + 10, OPTIONLEN, MaxOptions, baseWin, OPTIONBORDER); W_SetWindowKeyDownHandler(optionWin, optionaction); W_SetWindowButtonHandler(optionWin, optionaction); W_DefineArrowCursor(optionWin); CurrentMenu = FirstMenu; RefreshOptions(); } /* Map window */ W_MapWindow(optionWin); }
/* deal with events sent to the option window */ void optionaction(W_Event * data) { register struct option *op; int i; register char *cp; if (data->y >= CurrentMenu->numopt) { W_Beep(); return; } if (notdone == 0) return; op = &(CurrentMenu->menu[data->y]); /* Update string; don't claim keystrokes for non-string options */ /* deal with options with string input first */ if (op->op_string == 0) { if (data->type == W_EV_KEY) return; } else { if (data->type == W_EV_BUTTON) return; switch (data->key) { case '\b': /* delete character */ case '\177': cp = op->op_string; i = strlen(cp); if (i > 0) { cp += i - 1; *cp = '\0'; } break; case '\027': /* word erase */ cp = op->op_string; i = strlen(cp); /* back up over blanks */ while (--i >= 0 && isspace(cp[i])) ; i++; /* back up over non-blanks */ while (--i >= 0 && !isspace(cp[i])) ; i++; cp[i] = '\0'; break; case '\025': /* kill line */ case '\030': op->op_string[0] = '\0'; break; default: /* add character to the list * */ if (data->key < 32 || data->key > 127) break; cp = op->op_string; i = strlen(cp); if (i < (op->op_size - 1) && !iscntrl(data->key)) { cp += i; cp[1] = '\0'; cp[0] = data->key; } else W_Beep(); break; } } /* Toggle int, if it exists */ if (op->op_array) { if (data->key == W_RBUTTON) { (*op->op_option)++; if (*(op->op_array)[*op->op_option] == '\0') { *op->op_option = 0; } } else if (data->key == W_MBUTTON) { /* set option number to zero on the middle key to ease shutoff */ *op->op_option = 0; } else if (data->key == W_LBUTTON) { /* if left button, decrease option */ (*op->op_option)--; /* if decreased too far, set to top option */ if (*(op->op_option) < 0) { *op->op_option = 0; while (*(op->op_array)[*op->op_option] != '\0') { (*op->op_option)++; } (*op->op_option)--; } } /* Actions to be taken when certain options are selected. (Yes, this is * * * a hack). */ if (op->op_option == &plistStyle) { if (plistCustomLayout == 0 && plistStyle == 0) plistStyle = (data->key == W_LBUTTON) ? PLISTLASTSTYLE : 1; RedrawPlayerList(); } else if (op->op_option == &showgalactic) { redrawall = 1; } #ifdef ROTATERACE else if (rotate != old_rotate) { register i; register struct planet *l; register struct player *j; redrawall = 1; reinitPlanets = 1; for (i = 0, l = planets; i < MAXPLANETS; i++, l++) { if (rotate) { rotate_deg = -old_rotate_deg + rotate * 64; rotate_coord(&l->pl_x, &l->pl_y, rotate_deg, GWIDTH / 2, GWIDTH / 2); rotate_deg = rotate * 64; } else { rotate_deg = -old_rotate_deg; rotate_coord(&l->pl_x, &l->pl_y, rotate_deg, GWIDTH / 2, GWIDTH / 2); rotate_deg = 0; } } /* we could wait for the server to do this but looks better if we * * * * do it now. */ for (i = 0, j = players; i < MAXPLAYER; i++, j++) { if (j->p_status != PALIVE) continue; if (rotate) { rotate_deg = -old_rotate_deg + rotate * 64; rotate_coord(&j->p_x, &j->p_y, rotate_deg, GWIDTH / 2, GWIDTH / 2); rotate_dir(&j->p_dir, rotate_deg); rotate_deg = rotate * 64; } else { rotate_deg = -old_rotate_deg; rotate_coord(&j->p_x, &j->p_y, rotate_deg, GWIDTH / 2, GWIDTH / 2); rotate_dir(&j->p_dir, rotate_deg); rotate_deg = 0; } } /* phasers/torps/etc .. wait for server */ old_rotate = rotate; old_rotate_deg = rotate_deg; } #endif } /* Does the button have a range of values? */ else if (op->op_range) { if (data->key == W_RBUTTON) { (*op->op_option) += op->op_range->increment; } else if (data->key == W_MBUTTON) { (*op->op_option) = op->op_range->min_value; } else if (data->key == W_LBUTTON) { (*op->op_option) -= op->op_range->increment; } /* wrap value around within option range */ if (*(op->op_option) > op->op_range->max_value) *(op->op_option) = op->op_range->min_value; if (*(op->op_option) < op->op_range->min_value) *(op->op_option) = op->op_range->max_value; } /* Is the option a toggle? */ #ifdef HAVE_XPM /* Bitwise Toggle */ else if ((op->op_option) && (op->op_size)) { if (!(pixMissing & op->op_size)) { *op->op_option ^= op->op_size; if (op->op_size & (NO_MAP_PIX | NO_BG_PIX | NO_HALOS)) redrawall = 1; } } #endif else if (op->op_option) { *op->op_option = !*op->op_option; /* Actions to be taken when certain options are selected. * (Yes, this * * is a hack). */ if (op->op_option == &showPlanetOwner) redrawall = 1; else if (op->op_option == &partitionPlist) RedrawPlayerList(); else if (op->op_option == &sortPlayers) RedrawPlayerList(); else if (op->op_option == &sortMyTeamFirst) RedrawPlayerList(); } /* Map/unmap window, if it exists */ if (op->op_targetwin) { if (W_IsMapped(*op->op_targetwin)) W_UnmapWindow(*op->op_targetwin); else { W_MapWindow(*op->op_targetwin); if (*op->op_targetwin == udpWin) udpwindow(); if (*op->op_targetwin == pStats) redrawPStats(); if (*op->op_targetwin == netstatWin) nswindow(); if (*op->op_targetwin == spWin) spwindow(); #ifdef XTREKRC_HELP if (defWin && *op->op_targetwin == defWin) showdef(); #endif #ifdef SOUND if (*op->op_targetwin == soundWin) soundwindow(); #endif #ifdef DOC_WIN if (docwin && *op->op_targetwin == docwin) showdocs(0); if (xtrekrcwin && *op->op_targetwin == xtrekrcwin) showxtrekrc(0); #endif } } /* deal with possible menu change */ if (MenuPage != CurrentMenu->page_num) { SetMenuPage(MenuPage); RefreshOptions(); } else if (notdone) optionrefresh(op); else { optionrefresh(op); optiondone(); } return; }
int main(int argc, char **argv) { int team, s_type; char *dpyname = NULL; int usage = 0; int err = 0; char *name, *ptr, *cp; struct passwd *pwent; int passive = 0; int xpmopt = 1; int useORopt = 0; int useCookieOpt = 0; int dontUseCookieOpt = 0; /* char *defaultsFile=NULL;*/ pseudo[0] = defpasswd[0] = '\0'; name = *argv++; argc--; if ((ptr = strrchr(name, '/')) != NULL) name = ptr + 1; while (*argv) { if (**argv != '-') { serverName = *argv; /* don't abort argument processing */ argv++; argc--; } else { ++*argv; argc--; ptr = *argv++; while (*ptr) { switch (*ptr) { case 'C': /* character name */ (void) strncpy(pseudo, *argv, sizeof(pseudo)); argv++; argc--; break; case 'P': /* authorization password */ (void) strncpy(defpasswd, *argv, sizeof(defpasswd)); { int i; for (i = 0; (*argv)[i]; i++) (*argv)[i] = 0; } argv++; argc--; break; case 'u': usage++; break; case 's': if (*argv) { xtrekPort = atoi(*argv); passive = 1; argv++; argc--; } break; case 'p': if (*argv) { xtrekPort = atoi(*argv); argv++; argc--; } break; case 'd': dpyname = *argv; argc--; argv++; break; case 'm': usemeta = 1; break; case 'h': serverName = *argv; argc--; argv++; break; case 't': title = *argv; argc--; argv++; break; case 'r': defaultsFile = *argv; argv++; argc--; break; #ifdef AUTHORIZE case 'o': RSA_Client = -1; break; case 'R': RSA_Client = -2; break; #else case 'o': case 'R': printf("This client does not have binary authorization.\n"); break; #endif case 'e': #ifdef AUTHORIZE checkExpire(1); #else printf("This client does not RSA verify and will not expire.\n"); #endif exit(0); break; case 'f': /* list ftp sites */ fprintf(stderr, "\n\ The newest version of the Paradise client can be found at:\n\ ftp.netrek.org in /pub/netrek/paradise/bin/\n"); exit(0); case 'G': if (*argv) { ghoststart++; ghost_pno = atoi(*argv); printf("Emergency restart being attempted...\n"); argv++; argc--; } break; case '2': /* force paradise */ paradise = 1; break; case 'F': /* File playback */ if (*argv) { playFile = strdup(*argv); playback = 1; argv++; argc--; } break; case 'x': xpmopt = 0; break; case 'k': /* cookie mode [BDyess] */ useCookieOpt = 1; break; case 'K': /* no-cookies :( [BDyess] */ dontUseCookieOpt = 1; break; case 'v': verbose_image_loading = 1; break; case 'O': /* turn on GXor image drawing [BDyess]*/ useORopt = 1; break; case 'c': /* dump .paradiserc defaults [BDyess] */ dump_defaults = 1; break; default: fprintf(stderr, "%s: unknown option '%c'\n", name, *ptr); err++; break; } ptr++; } } } inittrigtables(); initStars(); /* moved from redraw.c at KAO\'s suggestion */ if (usage || err) { printUsage(name); #ifdef AUTHORIZE checkExpire(1); #endif exit(0); /* exit(err); Exits from checkExpire */ } defaultsFile = initDefaults(defaultsFile); if(xpmopt) xpm = 1; else xpm = booleanDefault("xpm",xpm); if(xpm) printf("XPM mode enabled.\n"); /* command line option overrides .paradiserc value [BDyess] */ if(useORopt) useOR = 1; else useOR = booleanDefault("useOR",useOR); if(useOR) printf("OR mode enabled.\n"); if(useOR || !xpm) cookie = 0; /* default no-cookies unless in XPM mode w/out OR [BDyess] */ /* note: need a milk mode :) */ if(useCookieOpt) cookie = 1; else if(dontUseCookieOpt) cookie = 0; else cookie = booleanDefault("cookie",cookie); if(cookie) printf("Cookie mode enabled.\n"); #ifdef AUTHORIZE if (RSA_Client != -1) checkExpire(0); #endif /* compatability */ if (argc > 0) serverName = argv[0]; srandom(getpid() + time((long *) 0)); if(playback || booleanDefault("playback",0)) { defNickName = "playback"; usemeta=0; serverName = "playback"; } else { if (serverName) { char temp[80], *s; sprintf(temp, "server.%s", serverName); if ((s = stringDefault(temp,NULL))) { printf("Using nickname \"%s\" for server %s\n", serverName, s); defNickName = serverName; serverName = s; defFlavor = stringDefault("flavor",NULL); } } if (!serverName) { serverName = stringDefault("server",NULL); } if (!serverName && !passive) { serverName = DEFAULT_SERVER; usemeta = 1; /* no server specified, show the menu */ } if (passive) serverName = "passive"; /* newwin gets a wrong title otherwise */ if (xtrekPort < 0) xtrekPort = intDefault("port", -1); if (xtrekPort < 0) xtrekPort = DEFAULT_PORT; } /* playback */ build_default_configuration(); metaserverAddress = stringDefault("metaserver", "metaserver.netrek.org"); if (usemeta) openmeta(); W_Initialize(dpyname); metaFork = booleanDefault("metaFork", metaFork); /* do the metawindow thang */ if (usemeta) { metawindow(); metainput(); if (metaFork) W_Initialize(dpyname); newwin(dpyname, name); } else /* this creates the necessary x windows for the game */ newwin(dpyname, name); /* open memory...? */ openmem(); if (!startPlayback()) { if (!passive) { serverName = callServer(xtrekPort, serverName); } else { connectToServer(xtrekPort); } } sendFeature("FEATURE_PACKETS", 'S', 1, 0, 0); timeStart = time(NULL); findslot(); /* sets all the settings from defaults file (.xtrekrc probably) */ resetDefaults(); #ifdef UNIX_SOUND init_sound(); play_sound(SND_PARADISE); #endif mapAll(); /* signal(SIGINT, SIG_IGN);*/ signal(SIGCHLD, reaper); /* Get login name */ if ((pwent = getpwuid(getuid())) != NULL) (void) strncpy(login, pwent->pw_name, sizeof(login)); else (void) strncpy(login, "Bozo", sizeof(login)); login[sizeof(login) - 1] = '\0'; if (pseudo[0] == '\0') { char *freeme; strncpy(pseudo, freeme = stringDefault("name",login), sizeof(pseudo)); free(freeme); } pseudo[sizeof(pseudo) - 1] = '\0'; if (defpasswd[0] == '\0') { char buf[100]; /* added password by character name -JR */ sprintf(buf,"password.%s",pseudo); if((cp = stringDefault(buf,NULL)) || (cp = stringDefault("password",NULL))) (void) strncpy(defpasswd, cp, sizeof(defpasswd)); } defpasswd[sizeof(defpasswd) - 1] = '\0'; /* sendLoginReq("Gray Lensman", "hh", "sfd", 0); loginAccept = -1; while (loginAccept == -1) { socketPause(1,0); readFromServer(); } */ getname(pseudo, defpasswd); loggedIn = 1; /* Set p_hostile to hostile, so if keeppeace is on, the guy starts off hating everyone (like a good fighter should) */ me->p_hostile = (1 << number_of_teams) - 1; redrawTstats(); me->p_planets = 0; me->p_genoplanets = 0; me->p_armsbomb = 0; me->p_genoarmsbomb = 0; /* Set up a reasonable default */ me->p_whydead = KNOREASON; me->p_teami = -1; s_type = defaultShip(CRUISER); /* from rlb7h 11/15/91 TC */ if (booleanDefault("netStats", 1)) startPing(); /* tell the server that we support pings */ /* hack to make galaxy class ships work. This could be more elegant, but the configuration code would have to be modified quite a bit, since the client doesn't know if it's on a paradise server until after it connects, and it needs the configuration info before it connects. */ init_galaxy_class(); initkeymap(-1); /* needs to have ship types initialized -JR */ setjmp(env); /* Reentry point of game */ if (ghoststart) { int i; ghoststart = 0; for (i = -1; i < 5; i++) if (teaminfo[i].letter == me->p_mapchars[0]) break; me->p_teami = i; if (me->p_damage > me->p_ship->s_maxdamage) { me->p_status = POUTFIT; } else me->p_status = PALIVE; } else me->p_status = POUTFIT; while (1) { switch (me->p_status) { case POUTFIT: case PTQUEUE: /* give the player the motd and find out which team he wants */ new_entrywindow(&team, &s_type); allowPlayerlist = 1; if (W_IsMapped(playerw)) playerlist(); if (!playback) if (team == -1) { W_DestroyWindow(w); sendByeReq(); sleep(1); printf("OK, bye!\n"); EXIT(0); } sendVersion(); myship = getship(myship->s_type); currentship = myship->s_type; /* sendOptionsPacket(); this would totally blast any flags you had on the server */ redrawall = 1; enter(); calibrate_stats(); W_ClearWindow(w); /* for (i = 0; i < NSIG; i++) { signal(i, SIG_IGN); } */ me->p_status = PALIVE; /* Put player in game */ #ifdef UNIX_SOUND kill_sound (); #endif hockeyInit(); if (showStats) /* Default showstats are on. */ W_MapWindow(statwin); if (showNewStats) /* default showNewStats are off. [BDyess] */ W_MapWindow(newstatwin); if (tryUdp && commMode != COMM_UDP) { sendUdpReq(COMM_UDP); } if (tryShort) { sendShortReq(SPK_VON); tryShort = 0; /* only try it once */ } /* Send request for a full update */ if (askforUpdate) { if(recv_short) sendShortReq(SPK_SALL); else sendUdpReq(COMM_UPDATE); } sendUpdatePacket(1000000 / updateSpeed); W_Deiconify(baseWin); break; case PALIVE: case PEXPLODE: case PDEAD: case POBSERVE: /* Get input until the player quits or dies */ input(); W_ClearWindow(mapw); break; default: printf("client has p_status=%d. how strange\n", me->p_status); me->p_status = POUTFIT; } } /* NOTREACHED */ }
static void show_help() { W_MapWindow(metaHelpWin); }
void new_entrywindow(int *team, int *s_type) { int i; int lastplayercount[4]; /* number of players on each team */ int okayMask, lastOkayMask; /* teams you're allowed to choose */ char buf[100]; /* OUTFIT timeout stuff */ long startTime = -1; long lasttime = -1; int spareTime = 0; if (fastQuit) { *team = -1; return; } lastOkayMask = okayMask = tournMask; /* erase packet lights to make Bob happy [BDyess] */ light_erase(); /* map all team selection windows, and stripe out those that are unchoosable */ for (i = 0; i < number_of_teams; i++) { W_MapWindow(teamWin[i]); lastplayercount[i] = -1; } W_MapWindow(qwin); /* no team selected yet */ *team = -1; /* set to team index (0..n-1) to choose a team. set to n if you want to quit */ /* I don't know why this restriction is in place - RF */ if (me->p_whydead != KWINNER && me->p_whydead != KGENOCIDE) { showMotd(w); W_ClearWindow(mapw); showValues(mapw); redraw_death_messages(); } do { /* set team to n if you want to quit */ while (!W_EventsPending() && (me->p_status == POUTFIT || me->p_status == PTQUEUE)) { /* no window events, just process socket stuff */ fd_set mask; light_erase(); readFromServer(); if (me->p_status == POUTFIT || me->p_status == PTQUEUE) { /* wait up to a half-second for input from the window system */ struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 500000; FD_ZERO(&mask); FD_SET(W_Socket(), &mask); select(W_Socket() + 1, &mask, 0, 0, &tv); } #if SHOW_MAP_AT_MOTD_DATA_ITEM_IMPLEMENTED if(showMapAtMotd) { map(); } #endif redraw_death_messages(); if (me->p_status == PTQUEUE) startTime = -1; if (me->p_status == POUTFIT) { /* time only elapses in OUTFIT mode */ if (startTime == -1) { /* we were on the tqueue */ /* I hate this [BDyess] */ W_Deiconify(baseWin); /* we changed status. alert the user */ startTime = time(0); spareTime = 480; /* Allow them extra time, as long */ /* as they are active */ } elapsed = time(0) - startTime; if (elapsed > autoQuit) { printf("Auto-Quit.\n"); *team = number_of_teams; break; } } if (lasttime != time(0)) { if (W_IsMapped(playerw)) playerlist2(); if (newMotdStuff) { showMotd(w); showValues(mapw); redraw_death_messages(); } if (me->p_status == POUTFIT) { showTimeLeft(elapsed, autoQuit); } lasttime = time(0); } okayMask = tournMask; /* redraw those windows whose choosable status has changed */ for (i = 0; i < number_of_teams; i++) { if ((okayMask ^ lastOkayMask) & (1 << i)) { lastplayercount[i] = -1; /* force update */ } redrawTeam(teamWin[i], i, &lastplayercount[i]); } lastOkayMask = okayMask; } if (playback) /* silly. Shouldn't even be mapping team windows. */ break; /* they quit or ran out of time */ if (*team == number_of_teams) { me->p_status = PFREE; /* exit outer while loop */ break; } /* this makes them eventually run out of time no matter how awake they are. Only affects the OUTFIT screen. */ if (me->p_status == POUTFIT && startTime != -1) { if (time(0) - startTime <= spareTime) { spareTime -= time(0) - startTime; startTime = time(0); } else { startTime += spareTime; spareTime = 0; } } if (!W_EventsPending()) continue; /* ok, there's a window event pending */ /* thiswill set p_status to PFREE if they decide to quit */ get_N_dispatch_outfit_event(team, s_type, lastplayercount); } while ((me->p_status == POUTFIT || me->p_status == PTQUEUE) && (!pb_update) ); if (*team >= 0) { strcpy(buf, "Welcome aboard "); if (paradise) strcat(buf, ranks2[me->p_stats2.st_rank].name); else strcat(buf, ranks[me->p_stats.st_rank].name); sprintf(buf, "Welcome aboard %s!", get_players_rank_name(me)); warning(buf); } if (playback) { extern int lastTeamReq; *team = me->p_teami = lastTeamReq; } else /* if they quit or ran out of time */ if (me->p_status == PFREE) *team = -1; else if (me->p_status == PALIVE || me->p_status == POBSERVE) if (*team == -1) *team = me->p_teami; else me->p_teami = *team; for (i = 0; i < number_of_teams; i++) W_UnmapWindow(teamWin[i]); W_UnmapWindow(qwin); }
void get_N_dispatch_outfit_event(int *team, int *s_type, int *lastplayercount) { W_Event event; int validshipletter = 0; static int resetting = 0; int oldresetting; int i; oldresetting = resetting; W_NextEvent(&event); switch ((int) event.type) { case W_EV_KEY: { struct shiplist *shipscan; validshipletter = 0; shipscan = shiptypes; while (shipscan) { if (shipscan->ship->s_letter == event.key) { *s_type = shipscan->ship->s_type; validshipletter = 1; break; } shipscan = shipscan->next; } } if (me->p_status == PTQUEUE) { for (i = 0; i < WNUM; i++) { if (event.Window == messWin[i].window) { messageWinEvent(&event); break; } } if (i != WNUM) break; if (event.Window == messagew || event.Window == tstatw || event.Window == warnw) smessage(event.key); } if (event.Window == motdWin) { motdWinEvent(&event); break; } else if (event.Window == playerw || event.Window == infow) { /* allow 'i' 'I' and '^i' in playerw [BDyess] */ playerwEvent(&event); break; } else if (event.Window == w || event.Window == mapw) { switch (event.key) { #ifdef Q_OUTFITTING case 'q': *team = number_of_teams; me->p_status = PFREE; break; #endif /* Q_OUTFITTING */ case 'R': warning("Are you sure you want to reset your stats?"); resetting = 1; break; case 'y': if (resetting) { sendResetStatsReq('Y'); warning("OK, your stats have been reset."); resetting = 0; } break; case 'n': if (resetting) { warning("I didn't think so."); resetting = 0; } break; case 'f': /* Scroll motd forward */ if (currpage == NULL) currpage = motddata; if (currpage == NULL || currpage->next == NULL) break; currpage->next->prev = currpage; currpage = currpage->next; showMotd(w); resetting = 0; break; case 'b': /* Scroll motd backward */ if (currpage == NULL || currpage->prev == NULL) break; currpage = currpage->prev; showMotd(w); resetting = 0; break; /* ok, let's have some info windows available on the TQ */ default: /* hmm, something that doesn't have to do with the MOTD, maybe it's an info window request */ switch (doKeymap(&event)) { case 'U': /* U = Rank list */ if (W_IsMapped(rankw)) { W_UnmapWindow(rankw); } else { W_MapWindow(rankw); } break; case 'P': /* P = Planet list */ if (W_IsMapped(planetw)) { W_UnmapWindow(planetw); W_UnmapWindow(planetw2); } else { W_MapWindow(planetw); W_MapWindow(planetw2); } break; case 'h': /* h = Map help window */ if (W_IsMapped(helpWin)) { W_UnmapWindow(helpWin); } else { W_MapWindow(helpWin); } if (optionWin) optionredrawtarget(helpWin); break; case 'O': /* O = options Window */ if (optionWin != NULL && W_IsMapped(optionWin)) optiondone(); else optionwindow(); break; case 'w': /* w = map war stuff */ if (W_IsMapped(war)) W_UnmapWindow(war); else warwindow(); break; case '&': if (defaultsFile) { char buf[150]; sprintf(buf, "Reading defaults from %s", defaultsFile); warning(buf); freeDefaults(); defaultsFile = initDefaults(defaultsFile); resetDefaults(); } else { warning("No defaults file to read from!"); } } break; } break; /* switch event type */ } if (event.Window == qwin) return; /* normal keypresses can't make you quit */ if (event.Window == optionWin) { optionaction(&event); return; } if (!validshipletter) break; /* it wasn't the main window, see if they hit the key in a team window to choose their ship... falling through */ case W_EV_BUTTON: for (i = 0; i < number_of_teams; i++) if (event.Window == teamWin[i]) { *team = i; break; } if (event.Window == qwin) { *team = number_of_teams; me->p_status = PFREE; break; } /* allow message scrollback [BDyess] */ for (i = 0; i < WNUM; i++) { if (event.Window == messWin[i].window) { messageWinEvent(&event); break; } } /* allow bozo selection in playerw [BDyess] */ if (event.Window == playerw) { playerwEvent(&event); break; } else if (event.Window == war) waraction(&event); else if (event.Window == optionWin) optionaction(&event); else if (event.Window == motdWin) motdWinEvent(&event); else if (event.Window == w) { W_Window tmp = motdWin; motdWin = w; motdWinEvent(&event); motdWin = tmp; } if (*team != -1 && !teamRequest(*team, *s_type)) { *team = -1; } break; case W_EV_EXPOSE: for (i = 0; i < number_of_teams; i++) if (event.Window == teamWin[i]) { lastplayercount[i] = -1; /* force update */ redrawTeam(teamWin[i], i, &lastplayercount[i]); break; } if (event.Window == qwin) redrawQuit(); else if (event.Window == w) showMotd(w); else if (event.Window == mapw) { showValues(mapw); redraw_death_messages(); } else /* let the normal expose handler figure out who to redraw */ dispatch_W_expose_event(&event); break; case W_EV_KILL_WINDOW: /* WM_DESTROY_WINDOW support [BDyess] */ if(event.Window == baseWin) exit(0); else W_UnmapWindow(event.Window); break; } if (oldresetting && resetting) { resetting = 0; warning("Resetting of stats cancelled"); } }
void mapAll(void) { initinput(); W_MapWindow(mapw); W_MapWindow(tstatw); W_MapWindow(warnw); W_MapWindow(messagew); W_MapWindow(w); W_MapWindow(baseWin); /* since we aren't mapping windows that have root as parent in x11window.c (since that messes up the TransientFor feature) we have to map them here. (If already mapped, W_MapWindow returns) */ if (checkMapped("planet")) W_MapWindow(planetw); if (checkMapped("planet2")) W_MapWindow(planetw2); if (checkMapped("rank")) W_MapWindow(rankw); if (checkMapped("help")) W_MapWindow(helpWin); if (checkMapped("Motd")) W_MapWindow(motdWin); if (checkMapped("review_all")) W_MapWindow(messWin[WALL].window); if (checkMapped("review_team")) W_MapWindow(messWin[WTEAM].window); if (checkMapped("review_your")) W_MapWindow(messWin[WINDIV].window); if (checkMapped("review_kill")) W_MapWindow(messWin[WKILL].window); if (checkMapped("review_phaser")) W_MapWindow(messWin[WPHASER].window); if (booleanDefault("player.mapped", 1)) W_MapWindow(playerw); if (booleanDefault("review.mapped", 1)) W_MapWindow(messWin[WREVIEW].window); if (checkMapped("UDP")) udpwindow(); }
void showdef(void) { register i, j, x = 0, y = 0, xo = 0, yo = 0, max_desc = 0, height = 1, width = 1; register struct def *d; char *val; name = getdefault("name"); keymap = getdefault("keymap"); ckeymap = getdefault("ckeymap"); plist = getdefault("playerlist"); cloak_chars = cloakChars; bmap = getdefault("buttonmap"); if (!defWin) defWin = W_MakeTextWindow("xtrekrc_help", 1, 100, 174, 41, NULL, BORDER); for (i = 0, d = def_messages; i < DEFMESSAGES; i++, d++) { x = xo; y = yo; W_WriteText(defWin, x, y, W_Yellow, d->name, strlen(d->name), W_BoldFont); x += NAME_WIDTH; W_WriteText(defWin, x, y, textColor, d->desc, strlen(d->desc), W_RegularFont); if (strlen(d->desc) > max_desc) { max_desc = strlen(d->desc); width = MAX(width, x + max_desc); } y++; x = xo + INDENT; if (d->type != STR_DEF) { if (!d->values[0].desc && d->variable) { if (d->type == SINT_DEF) val = itos(*d->variable); else val = itos(d->values[0].i_value); W_WriteText(defWin, x, y, W_Green, val, strlen(val), W_RegularFont); y++; } for (j = 0; d->values[j].desc; j++) { switch (d->type) { case INT_DEF: val = itos(d->values[j].i_value); if (d->values[j].i_value == *d->variable) { W_WriteText(defWin, x, y, W_Green, val, strlen(val), W_BoldFont); if (W_Mono()) { W_WriteText(defWin, x + 1, y, W_Green, "*", 1, W_RegularFont); } } else W_WriteText(defWin, x, y, textColor, val, strlen(val), W_RegularFont); x = xo + NAME_WIDTH; W_WriteText(defWin, x, y, textColor, d->values[j].desc, strlen(d->values[j].desc), W_RegularFont); y++; x = xo + INDENT; break; case BOOL_DEF: val = btoa(*d->variable); W_WriteText(defWin, x, y, W_Green, val, strlen(val), W_RegularFont); y++; x = xo + INDENT; break; default: fprintf(stderr, "Unknown type.\n"); break; } } } else if (d->variable && *d->variable) { W_WriteText(defWin, x, y, W_Green, *((char **) d->variable), strlen(*((char **) d->variable)), W_RegularFont); y++; } height = MAX(height, y); if (y > MAX_VLINES) { yo = 0; xo += NAME_WIDTH + max_desc + 2; max_desc = 0; } else { yo = y + 1; } } W_ResizeTextWindow(defWin, width, height); W_MapWindow(defWin); }
findslot(void) { int oldcount = -1; W_Window waitWin, qwin, countWin, motdButtonWin; W_Window motdWin; extern int MaxMotdLine; int WaitMotdLine = 0; int mapMotd = booleanDefault("showMotd", 1); W_Event event; /* Wait for some kind of indication about in/not in */ while (queuePos == -1) { socketPause(); if (isServerDead()) { #if defined(SOUND) && !defined(HAVE_SDL) Exit_Sound(); #endif printf("Shit! Ghostbusted!\n"); terminate(0); } readFromServer(NULL); if (me != NULL) { /* We are in! */ ANNOUNCESOCKET; return (me->p_no); } } /* We have to wait. Make appropriate windows, etc... */ waitWin = W_MakeWindow("wait", 0, 0, WAITWIDTH, WAITHEIGHT, NULL, 2, foreColor); countWin = W_MakeWindow("count", WAITWIDTH / 3, WAITTITLE, WAITWIDTH / 3, WAITHEIGHT - WAITTITLE, waitWin, 1, foreColor); qwin = W_MakeWindow("waitquit", 0, WAITTITLE, WAITWIDTH / 3, WAITHEIGHT - WAITTITLE, waitWin, 1, foreColor); motdButtonWin = W_MakeWindow("motdbutton", 2 * WAITWIDTH / 3, WAITTITLE, WAITWIDTH / 3, WAITHEIGHT - WAITTITLE, waitWin, 1, foreColor); W_MapWindow(waitWin); W_MapWindow(countWin); W_MapWindow(motdButtonWin); W_MapWindow(qwin); if (mapMotd) { motdWin = W_MakeWindow("waitmotd", 1, WAITWIDTH + 1, TWINSIDE, TWINSIDE, 0, 2, foreColor); W_MapWindow(motdWin); showMotd(motdWin, WaitMotdLine); } for (;;) { socketPause(); readFromServer(NULL); if (isServerDead()) { #if defined(SOUND) && !defined(HAVE_SDL) Exit_Sound(); #endif printf("Damn, We've been ghostbusted!\n"); terminate(0); } while (W_EventsPending()) { W_NextEvent(&event); switch ((int) event.type) { case W_EV_BUTTON: case W_EV_KEY: if (mapMotd && event.Window == motdWin) { if (event.key == ' ' || event.key == 'q') { W_DestroyWindow(motdWin); mapMotd = !mapMotd; } else { if (event.key == 'b') { WaitMotdLine -= 28; WaitMotdLine = MAX(WaitMotdLine, 0); } else { WaitMotdLine += 28; /* scroll to start if it goes over */ if (WaitMotdLine > MaxMotdLine) WaitMotdLine = 0; } W_ClearWindow(motdWin); showMotd(motdWin, WaitMotdLine); break; } } else if (event.Window == motdButtonWin) { if (mapMotd) { W_DestroyWindow(motdWin); } else { motdWin = W_MakeWindow("waitmotd", 1, WAITWIDTH + 1, TWINSIDE, TWINSIDE, 0, 2, foreColor); W_MapWindow(motdWin); showMotd(motdWin, WaitMotdLine); } mapMotd = !mapMotd; } else if (event.Window == qwin) { #if defined(SOUND) && !defined(HAVE_SDL) Exit_Sound(); #endif printf("OK, bye!\n"); terminate(0); } break; case W_EV_EXPOSE: if (event.Window == waitWin) { mapWaitWin(waitWin); } else if (event.Window == motdWin) { showMotd(motdWin, WaitMotdLine); } else if (event.Window == qwin) { mapWaitQuit(qwin); } else if (event.Window == countWin) { mapWaitCount(waitWin, countWin, queuePos); } else if (event.Window == motdButtonWin) { mapWaitMotdButton(motdButtonWin); } break; default: break; } } if (queuePos != oldcount) { mapWaitCount(waitWin, countWin, queuePos); oldcount = queuePos; } if (me != NULL) { W_DestroyWindow(waitWin); if (mapMotd) { W_DestroyWindow(motdWin); } ANNOUNCESOCKET; W_Beep(); W_Beep(); return (me->p_no); } } }
showxtrekrc(int atline) { FILE *fptr; int i, length, top, center; struct list *data; int count; char buf[128]; W_Font font; if (!xtrekrcwin) xtrekrcwin = W_MakeWindow("xtrekrcWin", 0, 200, 500, 500, 0, 2, foreColor); W_ClearWindow(xtrekrcwin); if (!W_IsMapped(xtrekrcwin)) W_MapWindow(xtrekrcwin); sprintf(buf, "--- %s ---", (char *) query_cowid()); length = strlen(buf); center = GWINSIDE / 2 - (length * W_Textwidth) / 2; W_WriteText(xtrekrcwin, center, W_Textheight, textColor, buf, length, W_BoldFont); sprintf(buf, cbugs); length = strlen(buf); center = GWINSIDE / 2 - (length * W_Textwidth) / 2; W_WriteText(xtrekrcwin, center, 3 * W_Textheight, textColor, buf, length, W_RegularFont); if (!xtrekrcdata) loadxtrekrc(); top = 10; if (atline > maxxtrekrclines) atline = maxxtrekrclines - 28; data = xtrekrcdata; for (i = 0; i < atline; i++) { if (data == NULL) { atline = 0; data = xtrekrcdata; break; } data = data->next; } count = 28; /* Magical # of lines to * * * display */ for (i = top; i < 50; i++) { if (data == NULL) break; if (data->data == NULL) continue; switch (data->face) { case BOLD: font = W_BoldFont; break; case ITALIC: font = W_UnderlineFont; break; case NORMAL: font = W_RegularFont; break; } W_WriteText(xtrekrcwin, 20, i * W_Textheight, textColor, data->data, strlen(data->data), font); data = data->next; count--; if (count <= 0) break; } }
showdocs(int atline) { FILE *fptr; int i, length, top, center; struct list *data; int count; char buf[128]; W_Font font; if (!docwin) docwin = W_MakeWindow("DocWin", 0, 181, 500, 500, 0, 2, foreColor); W_ClearWindow(docwin); if (!W_IsMapped(docwin)) W_MapWindow(docwin); sprintf(buf, "--- %s ---", (char *) query_cowid()); length = strlen(buf); /* using GWINSIDE instead of TWINSIDE because with SMALL_SCREEN defined it * * makes more sense to use the smaller width in the interest of saving * * screen real estate */ center = GWINSIDE / 2 - (length * W_Textwidth) / 2; W_WriteText(docwin, center, W_Textheight, textColor, buf, length, W_BoldFont); sprintf(buf, cbugs); length = strlen(buf); center = GWINSIDE / 2 - (length * W_Textwidth) / 2; W_WriteText(docwin, center, 3 * W_Textheight, textColor, buf, length, W_RegularFont); if (!docdata) loaddocs(); top = 10; if (atline > maxdoclines) atline = maxdoclines - 28; data = docdata; for (i = 0; i < atline; i++) { if (data == NULL) { atline = 0; data = docdata; break; } data = data->next; } count = 28; /* Magical # of lines to * * * display */ for (i = top; i < 50; i++) { if (data == NULL) break; if (data->data == NULL) continue; switch (data->face) { case BOLD: font = W_BoldFont; break; case ITALIC: font = W_UnderlineFont; break; case NORMAL: font = W_RegularFont; break; } W_WriteText(docwin, 20, i * W_Textheight, textColor, data->data, strlen(data->data), font); data = data->next; count--; if (count <= 0) break; } }