Debian Codegraph @

netcon/lanclient/lanclient.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/lanclient/lanclient.cpp $
21 * $Revision: 1.3 $
22 * $Date: 2004/02/25 00:04:06 $
23 * $Author: ryan $
24 *
25 * LAN Client DLL
26 *
27 * $Log: lanclient.cpp,v $
28 * Revision 1.3 2004/02/25 00:04:06 ryan
29 * Removed loki_utils dependency and ported to MacOS X (runs, but incomplete).
30 *
31 * Revision 1.2 2000/05/29 05:30:46 icculus
32 * support for static linking into main executable.
33 *
34 * Revision 1.1.1.1 2000/04/18 00:00:38 icculus
35 * initial checkin
36 *
37 *
38 * 75 10/21/99 9:27p Jeff
39 * B.A. Macintosh code merge
40 *
41 * 74 8/24/99 5:47p Kevin
42 * Macintosh crap
43 *
44 * 73 5/23/99 2:38a Kevin
45 * fixed text overlapping thingy
46 *
47 * 72 5/20/99 9:18p Kevin
48 * removed invisible hotspot
49 *
50 * 71 5/04/99 5:39p Kevin
51 * connection dll & pxo game tracking improvements (added server type to
52 * list)
53 *
54 * 70 5/01/99 3:16p Kevin
55 *
56 * 69 4/29/99 11:49a Kevin
57 * enabled the 'i' key in the game list
58 *
59 * 68 4/28/99 6:39p Kevin
60 * Build 182 fixes
61 *
62 * 67 4/25/99 5:20p Kevin
63 * fixed a bug where the last item would never dissapear
64 *
65 * 66 4/25/99 5:02p Kevin
66 * Bunches of multiplayer UI improvements
67 *
68 * 65 4/22/99 3:43p Kevin
69 * Training missions show controls on screen
70 *
71 * 64 4/18/99 3:12p Jeff
72 * got working for linux
73 *
74 * 63 4/17/99 3:44p Kevin
75 * Demo2 changes & fixes
76 *
77 * 62 4/14/99 1:22a Jeff
78 * fixed case mismatched #includes
79 *
80 * 61 4/03/99 9:26p Jeff
81 * changed dialogs that weren't using UID_OK and UID_CANCEL to use and
82 * handle them properly
83 *
84 * 60 3/17/99 4:08p Kevin
85 * Changed the way games appear and timeout in the game list.
86 *
87 * 59 2/19/99 5:21p Kevin
88 * Fixed some connection DLLs and a Direct Sound bug with threads.
89 *
90 * 58 2/08/99 11:44p Kevin
91 * Fixed a bug with entering addresses
92 *
93 * 57 2/03/99 4:20p Kevin
94 * Got multiplayer working with .mn3 files, and setup autodownloading
95 *
96 * 56 1/23/99 3:19p Kevin
97 * Made gamelist boxes not sort
98 *
99 * 55 1/07/99 11:51a Kevin
100 * Added support for joining servers on alternate ports and hosting behind
101 * a proxy/firewall
102 *
103 * 54 12/30/98 12:16p Kevin
104 * Auto Mission Download system
105 *
106 * 53 12/14/98 10:53a Jason
107 * added bright player ships option
108 *
109 * 52 12/04/98 4:37p Kevin
110 * Fixed selection being reset in game lists...
111 *
112 * 51 12/01/98 12:47p Jason
113 * got rid of NF_DROPMISORDERED and added NF_USE_SMOOTHING
114 *
115 * 50 11/18/98 3:26p Kevin
116 * Put multiplayer options into con_dll.h
117 *
118 * 49 10/19/98 2:48p Kevin
119 * Added accurate weapon thingy for Chris
120 *
121 * 48 10/17/98 2:32p Kevin
122 * FIxed problem with banned users getting stuck on the ban message
123 * screen.
124 *
125 * 47 10/15/98 12:08p Kevin
126 * Changed game list to line up differently
127 *
128 * 46 10/13/98 3:41p Kevin
129 * bug fixes
130 *
131 * 45 10/12/98 8:39p Kevin
132 * removed mprintf's and fixed some smallish bugs
133 *
134 * 44 10/08/98 3:37p Jeff
135 * removed time_left from Netgame
136 *
137 * 43 10/01/98 11:37a Kevin
138 * UI fixes and stuff
139 *
140 * 42 9/29/98 2:23p Kevin
141 * More UI tweaks
142 *
143 * 41 9/28/98 4:21p Kevin
144 * Redesigned game list menus
145 *
146 * 40 9/28/98 11:25a Kevin
147 *
148 * 39 9/28/98 11:24a Kevin
149 * More UI improvements
150 *
151 * 38 9/28/98 11:02a Kevin
152 * added Networking defer, and fixed some UI issues
153 *
154 * 37 9/28/98 9:53a Kevin
155 * Fixing misc UI problems, and fixed some bugs that VC 6 found
156 *
157 * 36 9/25/98 11:07a Kevin
158 * fixed columns to line up and cleaned up some PXO bugs
159 *
160 * 35 9/24/98 12:50p Kevin
161 * Added UI for rotational velocity and drop out of order packets in net
162 * games
163 *
164 * 34 9/23/98 6:33p Kevin
165 * Fixed load settings
166 *
167 * 33 9/23/98 2:55p Kevin
168 * Saved multi config and changed UI to conform
169 *
170 * 32 9/22/98 3:55p Kevin
171 * Removed obsolete function
172 *
173 * 31 9/22/98 2:29p Kevin
174 * moved ships allowed code out of dll and into main app. Also added
175 * powerup exclusions
176 *
177 * 30 9/21/98 11:19a Kevin
178 * check protocol before entering multiplayer screens
179 *
180 * 29 9/15/98 12:42p Jason
181 * got dedicated server actually working
182 *
183 * 28 9/14/98 2:36p Kevin
184 * fixed some UI issues
185 *
186 * 27 9/09/98 12:41p Kevin
187 * Fixed up some UI issues
188 *
189 * 26 9/04/98 3:46p Kevin
190 * Added ping_time to Netplayers struct. It's updated in peer-peer and
191 * client server
192 *
193 * 25 8/27/98 5:03p Kevin
194 * Prettied up multiplayer screens and fixed some bugs.
195 *
196 * 24 8/24/98 5:04p Kevin
197 * Made msn files have the option to not be playable in multiplayer
198 *
199 * 23 8/24/98 12:37p Kevin
200 * added background bmp things
201 *
202 * 22 8/19/98 11:49a Kevin
203 * Got DirectPlay IPX working, and localized connection DLLs
204 *
205 * 21 8/17/98 11:00a Kevin
206 * Moved DLLs into subdirectories
207 *
208 * 20 8/07/98 12:39p Jeff
209 * added "allowed ships" to multiplayer options
210 *
211 * 19 8/04/98 10:26a Kevin
212 * Custom sound and bmp exchange system
213 *
214 * 18 7/21/98 1:49p Kevin
215 * IPX support and peer-peer option for multi
216 *
217 * 17 7/20/98 6:20p Kevin
218 * peer-peer stuff
219 *
220 * 16 7/20/98 2:34p Kevin
221 * Re-wrote the DLL wrapper, to allow for better expandability
222 *
223 * 13 7/02/98 4:52p Kevin
224 * direct ip list fixes
225 *
226 * 12 7/02/98 12:19p Kevin
227 * misc network fixes
228 *
229 * 11 6/30/98 3:20p Kevin
230 * fixed ping time
231 *
232 * 10 6/25/98 10:03a Kevin
233 * Minor chat fixes in PXO
234 *
235 * 9 6/24/98 6:40p Kevin
236 * Added help to main dll menu
237 *
238 * 8 6/24/98 5:12p Kevin
239 * Fixed bug with main menu crashing
240 *
241 * 7 6/24/98 3:24p Kevin
242 * Updated PXO screens with chat, etc.
243 *
244 * 6 6/18/98 4:49p Kevin
245 * Updated multiplayer menus
246 *
247 * 5 6/11/98 1:56p Jeff
248 * looks for d3m files instead of dll
249 *
250 * 4 6/05/98 2:58p Jeff
251 * changes made for new module library
252 *
253 * 3 6/01/98 3:52p Kevin
254 * changed listbox item to be white
255 *
256 * 2 6/01/98 10:10a Kevin
257 * Added DLL connection interface and auto update DLL
258 *
259 * 1 5/28/98 12:14p Kevin
260 *
261 * 1 5/18/98 12:47p Kevin
262 *
263 * $NoKeywords: $
264 */
265
266 #include "ui.h"
267 #include "newui.h"
268 #include "grdefs.h"
269 #include "player.h"
270 #include "game.h"
271 #include "pilot.h"
272 #include "module.h"
273 #include "ddio_common.h"
274
275 #include "inetgetfile.h"
276
277 #ifdef __STATIC_NETWORK_CLIENTS
278 #define DLLMultiCall DLLMultiCall_LAN
279 #define DLLMultiInit DLLMultiInit_LAN
280 #define DLLMultiClose DLLMultiClose_LAN
281 #define MainMultiplayerMenu MainMultiplayerMenu_LAN
282 #define AutoLoginAndJoinGame AutoLoginAndJoinGame_LAN
283 #endif
284
285 #define TXT_DLL_SAVESETTINGS TXT(27)
286 #define TXT_DLL_LOADSETTINGS TXT(28)
287
288 ///////////////////////////////////////////////
289 // localization header
290 #include "lanstrings.h"
291
292 #define TXT_GEN_MPLYROPTIONS TXT_LC_MPLYROPTIONS
293 #define TXT_GEN_TIMELIMIT TXT_LC_TIMELIMIT
294 #define TXT_GEN_KILLGOAL TXT_LC_KILLGOAL
295 #define TXT_GEN_PPS TXT_LC_PPS
296 #define TXT_GEN_RESPAWNRATE TXT_LC_RESPAWNRATE
297 #define TXT_GEN_MAXPLAYERS TXT_LC_MAXPLAYERS
298 #define TXT_GEN_PREVMENU TXT_LC_PREVMENU
299 #define TXT_GEN_CANCEL TXT_LC_CANCEL
300 #define TXT_GEN_CFGALLOWEDSHIP TXT_LC_CFGALLOWEDSHIP
301 #define TXT_GEN_USEROTVEL TXT_LC_USEROTVEL
302 #define TXT_GEN_USEROTVEL TXT_LC_USEROTVEL
303 #define TXT_GEN_USESMOOTHING TXT_LC_USESMOOTHING
304 #define TXT_GEN_CLIENTSERVER TXT_LC_CLIENTSERVER
305 #define TXT_GEN_PEERPEER TXT_LC_PEERPEER
306 #define TXT_GEN_ACC_WEAP_COLL TXT_LC_ACC_WEAP_COLL
307 #define TXT_GEN_BRIGHT_PLAYERS TXT_LC_BRIGHT_PLAYERS
308
309 #define MULTI_USE_ALL_OPTIONS 1
310
311 #include "lanclient.h"
312 #include "DLLUiItems.h"
313
314 using namespace lanclient;
315
316 // int DLLUIClass_CurrID = 0xD0;
317
318 #define MAX_NET_GAMES 100
319 #define JEFF_RED GR_RGB(255, 40, 40)
320 #define JEFF_BLUE GR_RGB(40, 40, 255)
321 #define JEFF_GREEN GR_RGB(40, 255, 40)
322 #define NETPOLLINTERVAL 10.0
323
324 extern int MTAVersionCheck(uint32_t oldver, char *URL);
325 /////////////////////////////
326 // Defines
327
328 // These next two function prototypes MUST appear in the extern "C" block if called
329 // from a CPP file.
330 extern "C" {
331 DLLEXPORT void DLLFUNCCALL DLLMultiInit(int *api_func);
332 DLLEXPORT void DLLFUNCCALL DLLMultiCall(int eventnum);
333 DLLEXPORT void DLLFUNCCALL DLLMultiClose();
334 }
335
336 static bool All_ok = true;
337 // Initializes the game function pointers
338 void DLLFUNCCALL DLLMultiInit(int *api_func) {
339 Use_netgame_flags = 1;
340 #include "mdllinit.h"
341 DLLCreateStringTable("lanclient.str", &StringTable, &StringTableSize);
342 DLLmprintf(0, "%d strings loaded from string table\n", StringTableSize);
343 if (!StringTableSize) {
344 All_ok = false;
345 return;
346 }
347 *DLLUse_DirectPlay = false;
348 }
349
350 // Called when the DLL is shutdown
351 void DLLFUNCCALL DLLMultiClose() { DLLDestroyStringTable(StringTable, StringTableSize); }
352
353 // The main entry point where the game calls the dll
354 void DLLFUNCCALL DLLMultiCall(int eventnum) {
355
356 switch (eventnum) {
357 case MT_EVT_GET_HELP:
358 strcpy(DLLHelpText1, TXT_LC_HELP1);
359 strcpy(DLLHelpText2, TXT_LC_HELP2);
360 strcpy(DLLHelpText3, TXT_LC_HELP3);
361 strcpy(DLLHelpText4, TXT_LC_HELP4);
362 break;
363 case MT_AUTO_START:
364 if (!All_ok)
365 *DLLMultiGameStarting = 0;
366 else
367 *DLLMultiGameStarting = 1;
368 break;
369 case MT_RETURN_TO_GAME_LIST:
370 case MT_EVT_LOGIN:
371 if (!DLLTCP_active) {
372 DLLDoMessageBox(TXT_LC_ERROR, TXT_LC_NO_TCPIP, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
373 *DLLMultiGameStarting = 0;
374 break;
375 }
376 if (!All_ok)
377 *DLLMultiGameStarting = 0;
378 else
379 *DLLMultiGameStarting = MainMultiplayerMenu();
380 break;
381 case MT_EVT_FRAME:
382
383 break;
384 case MT_EVT_FIRST_FRAME:
385
386 break;
387 case MT_EVT_GAME_OVER:
388 break;
389 case MT_AUTO_LOGIN:
390 if (!DLLTCP_active) {
391 DLLDoMessageBox(TXT_LC_ERROR, TXT_LC_NO_TCPIP, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
392 *DLLMultiGameStarting = 0;
393 break;
394 }
395 if (All_ok)
396 AutoLoginAndJoinGame();
397 break;
398 }
399 }
400
401 namespace lanclient {
402 #define GET_INFO_ID 50
403 // The first multiplayer menu that the user will see...all multiplayer stuff is
404 // reached from this menu
405 // Returns true if we're starting a multiplayer game
406 int MainMultiplayerMenu() {
407
408 char selgame[200] = "";
409 void *join_LC_text = DLLCreateNewUITextItem(TXT_LC_RETURNMAIN, GR_BLACK); // return_menu
410 void *list_head_txt = DLLCreateNewUITextItem(TXT_LC_GAMELISTHDR, UICOL_TEXT_NORMAL);
411 void *exit_on_text = DLLCreateNewUITextItem(TXT_LC_EXIT, UICOL_HOTSPOT_HI);
412 void *exit_off_text = DLLCreateNewUITextItem(TXT_LC_EXIT, UICOL_HOTSPOT_LO);
413 void *join_on_text = DLLCreateNewUITextItem(TXT_LC_JOINSEL, UICOL_HOTSPOT_HI);
414 void *join_off_text = DLLCreateNewUITextItem(TXT_LC_JOINSEL, UICOL_HOTSPOT_LO);
415 void *start_on_text = DLLCreateNewUITextItem(TXT_LC_STARTNEW, UICOL_HOTSPOT_HI);
416 void *start_off_text = DLLCreateNewUITextItem(TXT_LC_STARTNEW, UICOL_HOTSPOT_LO);
417 void *srch_on_text = DLLCreateNewUITextItem(TXT_LC_SRCHADDR, UICOL_HOTSPOT_HI);
418 void *srch_off_text = DLLCreateNewUITextItem(TXT_LC_SRCHADDR, UICOL_HOTSPOT_LO);
419 void *scan_on_text = DLLCreateNewUITextItem(TXT_LC_SCANLOCAL, UICOL_HOTSPOT_HI);
420 void *scan_off_text = DLLCreateNewUITextItem(TXT_LC_SCANLOCAL, UICOL_HOTSPOT_LO);
421 void *game_hdr_text = DLLCreateNewUITextItem(TXT_LC_GAMEHEADER, UICOL_WINDOW_TITLE, DLL_BIG_BRIEFING_FONT);
422
423 int exit_menu = 0;
424 void *net_game_txt_items[MAX_NET_GAMES];
425 int a;
426 for (a = 0; a < MAX_NET_GAMES; a++)
427 net_game_txt_items[a] = NULL;
428 int ret = 0;
429 uint8_t oldalpha = *DLLNewUIWindow_alpha;
430 int cury = 40;
431
432 DLLSetScreenMode(SM_MENU);
433 *DLLNewUIWindow_alpha = 255;
434
435 void *main_wnd = DLLNewUIWindowCreate(0, 0, 640, 480, UIF_PROCESS_ALL);
436
437 void *info_on_text = DLLCreateNewUITextItem("", UICOL_HOTSPOT_HI);
438 void *info_hs = DLLHotSpotCreate(main_wnd, GET_INFO_ID, KEY_I, info_on_text, info_on_text, 1, 1, 1, 1, 0);
439
440 void *screen_header = DLLTextCreate(main_wnd, game_hdr_text, 45, cury, UIF_CENTER);
441 cury += 35;
442 void *start_hs = DLLHotSpotCreate(main_wnd, 7, KEY_S, start_off_text, start_on_text, 320, cury, 150, 15, UIF_CENTER);
443 cury += 25;
444 void *srch_hs = DLLHotSpotCreate(main_wnd, 9, KEY_A, srch_off_text, srch_on_text, 320, cury, 250, 15, UIF_CENTER);
445 cury += 25;
446 void *edit_box = DLLEditCreate(main_wnd, 9, 10, cury, 300, 15, UIF_CENTER);
447 cury += 35;
448 void *scan_hs = DLLHotSpotCreate(main_wnd, 8, KEY_L, scan_off_text, scan_on_text, 320, cury, 200, 15, UIF_CENTER);
449 cury += 50;
450 void *list_header = DLLTextCreate(main_wnd, list_head_txt, 45, cury, 0);
451 cury += 13;
452 void *main_list = DLLListCreate(main_wnd, UID_OK, 10, cury, 600, 170, UIF_CENTER | UILB_NOSORT);
453 cury += 200;
454 void *join_hs = DLLHotSpotCreate(main_wnd, UID_OK, KEY_ENTER, join_off_text, join_on_text, 100, cury, 130, 15, 0);
455 void *exit_hs = DLLHotSpotCreate(main_wnd, UID_CANCEL, KEY_ESC, exit_off_text, exit_on_text, 400, cury, 70, 15, 0);
456 char szdip[30] = "";
457 int diplen = 29;
458 DLLDatabaseRead("DirectIP", szdip, &diplen);
459 DLLEditSetText(edit_box, szdip);
460
461 DLLNewUIWindowLoadBackgroundImage(main_wnd, "multimain.ogf");
462 DLLNewUIWindowOpen(main_wnd);
463 *DLLNum_network_games_known = 0;
464 int lastgamesfound = 0;
465 int itemp;
466 int looklocal = 1;
467 void *selti = NULL;
468
469 float lastpoll = DLLtimer_GetTime();
470 DLLSearchForLocalGamesTCP(0xffffffffl, htons(DEFAULT_GAME_PORT));
471 // Menu loop
472 while (!exit_menu) {
473 int res;
474 int selno;
475 DLLUpdateAndPackGameList();
476
477 if (((itemp = DLLSearchForLocalGamesTCP(0, 0)) != 0) || (*DLLMulti_Gamelist_changed)) {
478 // if(itemp != lastgamesfound)
479 if (*DLLMulti_Gamelist_changed) {
480 // We found a new game!
481 *DLLMulti_Gamelist_changed = false;
482 selti = NULL;
483 lastgamesfound = itemp;
484 // Get the currently selected item
485 // char * psel = DLLListGetItem(main_list,DLLListGetSelectedIndex(main_list)) ;
486 // selno = DLLListGetSelectedIndex(main_list);
487 // strcpy(selgame,DLLNetwork_games[selno].name);
488 DLLmprintf(0, "Selected item = %s\n", selgame);
489 selti = NULL;
490 DLLListRemoveAll(main_list);
491 for (int k = 0; k < *DLLNum_network_games_known; k++) {
492 char fmtline[200];
493 char server_mode[20];
494
495 if (DLLNetwork_games[k].flags & NF_PEER_PEER) {
496 strcpy(server_mode, "PP");
497 } else if (DLLNetwork_games[k].flags & NF_PERMISSABLE) {
498 strcpy(server_mode, "PS");
499 } else {
500 strcpy(server_mode, "CS");
501 }
502
503 if (DLLNetwork_games[k].flags & NF_ALLOW_MLOOK) {
504 strcat(server_mode, "-ML");
505 }
506
507 DLLmprintf(0, "Found game: %s\n", DLLNetwork_games[k].name);
508 snprintf(fmtline, sizeof(fmtline), "%.20s\t\x02\x02b%s %.10s\x02\x45%.15s\x02\x63%d\x02\x6d%d/%d\x02\x7e%.3f",
509 DLLNetwork_games[k].name, server_mode, DLLNetwork_games[k].scriptname,
510 DLLNetwork_games[k].mission_name, DLLNetwork_games[k].level_num,
511 DLLNetwork_games[k].curr_num_players, DLLNetwork_games[k].max_num_players,
512 DLLNetwork_games[k].server_response_time);
513
514 if (DLLNetwork_games[k].dedicated_server) {
515 net_game_txt_items[k] = DLLCreateNewUITextItem(fmtline, GR_WHITE);
516 } else {
517 net_game_txt_items[k] = DLLCreateNewUITextItem(fmtline, GR_LIGHTGRAY);
518 }
519
520 selgame[20] = '\0';
521 if (strncmp(selgame, DLLNetwork_games[k].name, 19) == 0) {
522 selti = net_game_txt_items[k];
523 DLLmprintf(0, "Found previously selected game in list, reselecting...\n");
524 }
525 DLLListAddItem(main_list, net_game_txt_items[k]);
526 }
527 if (selti) {
528 DLLListSelectItem(main_list, selti);
529 }
530 }
531 }
532 if ((looklocal) && ((DLLtimer_GetTime() - lastpoll) > NETPOLLINTERVAL)) {
533 DLLSearchForLocalGamesTCP(0xffffffffl, htons(DEFAULT_GAME_PORT));
534 //*DLLNum_network_games_known = 0;
535 // DLLListRemoveAll(main_list);
536 lastgamesfound = 0;
537 lastpoll = DLLtimer_GetTime();
538 selno = DLLListGetSelectedIndex(main_list);
539 if (selno >= 0)
540 strcpy(selgame, DLLNetwork_games[selno].name);
541 else
542 selgame[0] = '\0';
543 }
544 res = DLLPollUI();
545
546 if (res == -1) {
547 continue;
548 }
549 // handle all UI results.
550 switch (res) {
551
552 case UID_CANCEL:
553 DLLNewUIWindowClose(main_wnd);
554 exit_menu = 1;
555 break;
556 case UID_OK:
557 // Double click on listbox, or join selected hit.
558 if (*DLLNum_network_games_known) {
559 // Get the appropriate game address
560 int gameno;
561 gameno = DLLListGetSelectedIndex(main_list);
562 DLLmprintf(0, "Selected item is %d\n", gameno);
563 network_address s_address;
564 memcpy(&s_address, &DLLNetwork_games[gameno].addr, sizeof(network_address));
565 s_address.connection_type = NP_TCP;
566 // s_address.port=&DLLNetwork_games[gameno].addr.port;//DEFAULT_GAME_PORT;
567 *DLLGame_is_master_tracker_game = 0;
568 DLLMultiStartClient(NULL);
569 if (DLLDoPlayerMouselookCheck(DLLNetwork_games[gameno].flags)) {
570 if (DLLmsn_CheckGetMission(&s_address, DLLNetwork_games[gameno].mission)) {
571 if ((DLLTryToJoinServer(&s_address))) {
572 DLLmprintf(0, "Menu: Game joined!\n");
573 DLLNewUIWindowClose(main_wnd);
574 exit_menu = 1;
575 ret = 1;
576 } else {
577 DLLNewUIWindowClose(main_wnd);
578 DLLNewUIWindowOpen(main_wnd);
579 }
580 }
581 }
582 } else {
583 DLLDoMessageBox(TXT_LC_ERROR, TXT_LC_NO_GAMES, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
584 }
585 break;
586 case 7:
587 // Start a new game
588 // Start a netgame
589 DLLNewUIWindowClose(main_wnd);
590 *DLLGame_is_master_tracker_game = 0;
591 if (StartMultiplayerGameMenu()) {
592 exit_menu = 1;
593 ret = 1;
594 } else {
595 DLLNewUIWindowOpen(main_wnd);
596 }
597 break;
598 case 8:
599 // Scan for local games
600 *DLLMulti_Gamelist_changed = true;
601 *DLLNum_network_games_known = 0;
602 looklocal = 1;
603 lastgamesfound = 0;
604 selno = DLLListGetSelectedIndex(main_list);
605 if (selno >= 0)
606 strcpy(selgame, DLLNetwork_games[selno].name);
607 else
608 selgame[0] = '\0';
609
610 DLLSearchForLocalGamesTCP(0xffffffffl, htons(DEFAULT_GAME_PORT));
611 DLLListRemoveAll(main_list);
612 for (a = 0; a < MAX_NET_GAMES; a++)
613 if (net_game_txt_items[a])
614 DLLRemoveUITextItem(net_game_txt_items[a]);
615 for (a = 0; a < MAX_NET_GAMES; a++)
616 net_game_txt_items[a] = NULL;
617 break;
618 case 9: {
619 // Scan a specific IP
620 uint16_t iport = DEFAULT_GAME_PORT;
621 looklocal = 0;
622 uint32_t iaddr;
623 lastgamesfound = 0;
624 DLLEditGetText(edit_box, szdip, 25);
625 // Make this IP the default
626 DLLDatabaseWrite("DirectIP", szdip, strlen(szdip) + 1);
627
628 char *pport = strchr(szdip, ':');
629 if (pport) {
630 *pport = '\0';
631 pport++;
632 iport = atoi(pport);
633 }
634
635 iaddr = inet_addr(szdip);
636 DLLmprintf(0, "Local inet_addr %x\n", iaddr);
637 if (iaddr && (INADDR_NONE != iaddr))
638 DLLSearchForLocalGamesTCP(iaddr, htons(iport));
639 else
640 DLLmprintf(0, "Invalid IP for local search\n");
641 DLLListRemoveAll(main_list);
642 for (a = 0; a < MAX_NET_GAMES; a++)
643 if (net_game_txt_items[a])
644 DLLRemoveUITextItem(net_game_txt_items[a]);
645 for (a = 0; a < MAX_NET_GAMES; a++)
646 net_game_txt_items[a] = NULL;
647 } break;
648 case GET_INFO_ID: {
649 if (*DLLNum_network_games_known) {
650 int gameno;
651 gameno = DLLListGetSelectedIndex(main_list);
652 DLLShowNetgameInfo(&DLLNetwork_games[gameno]);
653 }
654 } break;
655 }
656 }
657 DLLNewUIWindowDestroy(main_wnd);
658
659 *DLLNewUIWindow_alpha = oldalpha;
660 for (a = 0; a < MAX_NET_GAMES; a++)
661 if (net_game_txt_items[a])
662 DLLRemoveUITextItem(net_game_txt_items[a]);
663 // Cleanup
664 DLLDeleteUIItem(screen_header);
665 DLLDeleteUIItem(main_wnd);
666 DLLDeleteUIItem(main_list);
667 DLLDeleteUIItem(list_header);
668 DLLDeleteUIItem(exit_hs);
669 DLLDeleteUIItem(join_hs);
670 DLLDeleteUIItem(start_hs);
671 DLLDeleteUIItem(srch_hs);
672 DLLDeleteUIItem(scan_hs);
673 DLLDeleteUIItem(edit_box);
674
675 DLLDeleteUIItem(info_hs);
676 DLLRemoveUITextItem(info_on_text);
677 DLLRemoveUITextItem(game_hdr_text);
678 DLLRemoveUITextItem(join_LC_text);
679 DLLRemoveUITextItem(list_head_txt);
680 DLLRemoveUITextItem(exit_on_text);
681 DLLRemoveUITextItem(exit_off_text);
682 DLLRemoveUITextItem(join_on_text);
683 DLLRemoveUITextItem(join_off_text);
684 DLLRemoveUITextItem(start_on_text);
685 DLLRemoveUITextItem(start_off_text);
686 DLLRemoveUITextItem(srch_on_text);
687 DLLRemoveUITextItem(srch_off_text);
688 DLLRemoveUITextItem(scan_on_text);
689 DLLRemoveUITextItem(scan_off_text);
690 return ret;
691 }
692
693 // MTS: only used in this file
694 void AutoLoginAndJoinGame(void) {
695 uint16_t port;
696 uint32_t iaddr;
697
698 *DLLMultiGameStarting = 0;
699
700 if (!*DLLAuto_login_addr) {
701 DLLmprintf(0, "Can't autostart because no IP address was specified!!\n");
702 return;
703 }
704 if (*DLLAuto_login_port) {
705 port = atoi(DLLAuto_login_port);
706 } else {
707 port = DEFAULT_GAME_PORT;
708 }
709
710 // Now actually connect to the server!
711
712 network_address s_address;
713 iaddr = inet_addr(DLLAuto_login_addr);
714 memcpy(&s_address.address, &iaddr, sizeof(uint32_t));
715 s_address.port = port;
716 s_address.connection_type = NP_TCP;
717 *DLLGame_is_master_tracker_game = 0;
718 DLLMultiStartClient(NULL);
719
720 if ((DLLTryToJoinServer(&s_address))) {
721 DLLmprintf(0, "Menu: Game joined!\n");
722 *DLLMultiGameStarting = 1;
723 }
724 }
725
726 } // namespace lanclient