Debian Codegraph @

netcon/mtclient/mtclient.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/mtclient/mtclient.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:58:40 $
23 * $Author: kevinb $
24 *
25 * Mastertracker Client DLL
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 127 10/03/01 12:44a Kevin
30 * Smaller version of pxo packets
31 *
32 * 126 3/26/00 10:30p Kevin
33 * MOD Downloader for 1.4 patch.
34 *
35 * 125 3/20/00 12:29p Matt
36 * Merge of Duane's post-1.3 changes.
37 * Deleted Mac-only stricmp() function.
38 *
39 * 124 2/18/00 11:33p Kevin
40 * Fixed crash when sorting ping list bug, and clear the game list when
41 * joining a private lobby.
42 *
43 * 123 9/07/99 2:21p Kevin
44 * more CR/LF issues for the mac
45 *
46 * 122 9/07/99 10:24a Kevin
47 * Macintosh fixes!
48 *
49 * 121 9/02/99 3:16p Kevin
50 * Macintosh byte ordering fixes
51 *
52 * 120 8/24/99 5:47p Kevin
53 * Macintosh crap
54 *
55 * 119 8/24/99 10:39a Kevin
56 * Hopefully fixed the PXO return to chat bug
57 *
58 * 118 8/17/99 3:35p Kevin
59 * inverse sorts wouldn't show the last item! Doh!
60 *
61 * 117 8/17/99 1:52p Kevin
62 * fixed potential crash bugs as well as formatting for "CS Team Anarchy"
63 *
64 * 116 8/12/99 10:15a Kevin
65 * debugging stuff
66 *
67 * 115 8/10/99 12:53p Kevin
68 * fixed bug with return to chat & sorted gamelist
69 *
70 * 114 7/30/99 1:20p Kevin
71 * Fixed problems with sorted game list
72 *
73 * 113 7/26/99 11:45a Kevin
74 * possible return to chat crash fix
75 *
76 * 112 7/21/99 9:11a Kevin
77 * bandwidth reduction act #1
78 *
79 * 111 7/12/99 4:15p Kevin
80 * Changed the way we determine if we should report stats or not in PXO
81 *
82 * 110 7/07/99 3:38p Kevin
83 * Sorting in PXO gamelist!
84 *
85 * 109 7/06/99 5:52p Kevin
86 * PXO & multiplayer fixes for the patch
87 *
88 * 108 5/23/99 3:04a Jason
89 * fixed bug with player rankings not being updated correctly
90 *
91 * 107 5/23/99 2:38a Kevin
92 * fixed text overlapping thingy
93 *
94 * 106 5/20/99 9:17p Kevin
95 * removed invisible hotspot
96 *
97 * 105 5/17/99 5:19p Samir
98 * added ability for edit box to autoselect when hitting the max number of
99 * characters typable.
100 *
101 * 104 5/08/99 11:32a Kevin
102 * increased the gamelist update interval from pxo
103 *
104 * 103 5/05/99 5:23p Kevin
105 * fixed some bugs on the gamelist
106 *
107 * 102 5/05/99 11:04a Kevin
108 * added defer call to game over (previously it was only happening while
109 * writing stats
110 *
111 * 101 5/04/99 10:16p Kevin
112 * Fixed problem with 'set default screen'
113 *
114 * 100 5/04/99 5:39p Kevin
115 * connection dll & pxo game tracking improvements (added server type to
116 * list)
117 *
118 * 99 4/28/99 6:39p Kevin
119 * Build 182 fixes
120 *
121 * 98 4/27/99 1:54p Kevin
122 * Added pilot name to stats dialog
123 *
124 * 97 4/27/99 10:23a Kevin
125 * nifty titles for dialogs
126 *
127 * 96 4/25/99 5:02p Kevin
128 * Bunches of multiplayer UI improvements
129 *
130 * 95 4/24/99 11:59p Kevin
131 * game info dialog stuff
132 *
133 * 94 4/23/99 11:49p Kevin
134 *
135 * 93 4/22/99 3:43p Kevin
136 * Training missions show controls on screen
137 *
138 * 92 4/20/99 8:57p Jeff
139 * compile for Linux
140 *
141 * 91 4/19/99 7:56p Kevin
142 * ifdef'd out some win32 specific stuff
143 *
144 * 90 4/18/99 1:18p Kevin
145 * Demo2 build changes
146 *
147 * 89 4/17/99 3:44p Kevin
148 * Demo2 changes & fixes
149 *
150 * 88 4/16/99 6:00p Kevin
151 * Bunches of Demo stuff
152 *
153 * 87 4/14/99 1:37a Jeff
154 * fixed case mismatched #includes
155 *
156 * 86 4/02/99 12:19p Kevin
157 * Fixed chat server failed to connect
158 *
159 * 85 3/25/99 3:26p Kevin
160 * Made PXO games be based on your chat channel
161 *
162 * 84 3/17/99 4:08p Kevin
163 * Changed the way games appear and timeout in the game list.
164 *
165 * 83 3/05/99 11:35a Kevin
166 * new screens
167 *
168 * 82 3/04/99 12:07p Kevin
169 * Fixed stupid bug if you cancel out of connecting.
170 *
171 * 81 3/02/99 5:50p Kevin
172 * Ouch. Duplicate structures existed and were conflicting.
173 *
174 * 80 2/19/99 5:21p Kevin
175 * Fixed some connection DLLs and a Direct Sound bug with threads.
176 *
177 * 79 2/15/99 7:47p Jeff
178 * new pilot file class and read/write system checked in...should be more
179 * robust than old
180 *
181 * 78 2/03/99 4:20p Kevin
182 * Got multiplayer working with .mn3 files, and setup autodownloading
183 *
184 * 77 2/02/99 7:06p Jason
185 * added ranking system
186 *
187 * 76 1/23/99 3:20p Kevin
188 * Made gamelist boxes not sort
189 *
190 * 75 1/11/99 12:29p Jeff
191 * changes made not to call the module library directly
192 *
193 * 74 1/07/99 11:51a Kevin
194 * Added support for joining servers on alternate ports and hosting behind
195 * a proxy/firewall
196 *
197 * 73 1/04/99 5:43p Kevin
198 * new command line args
199 *
200 * 72 12/30/98 5:24p Kevin
201 * Added +name to specify a default pilot (for gamespy) fixed a gamespy
202 * bug, and improved the pxo dll game list screen
203 *
204 * 71 12/30/98 12:16p Kevin
205 * Auto Mission Download system
206 *
207 * 70 12/23/98 6:38p Kevin
208 * All UDP data (except gamespy) now uses one (registered) port number
209 *
210 * 69 12/14/98 10:53a Jason
211 * added bright player ships option
212 *
213 * 68 12/04/98 4:37p Kevin
214 * Fixed selection being reset in game lists...
215 *
216 * 67 12/01/98 12:47p Jason
217 * got rid of NF_DROPMISORDERED and added NF_USE_SMOOTHING
218 *
219 * 66 11/18/98 3:26p Kevin
220 * Put multiplayer options into con_dll.h
221 *
222 * 65 11/03/98 9:27a Kevin
223 * Added PXO message of the day
224 *
225 * 64 10/30/98 11:25a Kevin
226 * Message of the day for PXO
227 *
228 * 63 10/23/98 10:12a Kevin
229 * fixed bug when you hit cancel in the login screen
230 *
231 * 62 10/22/98 10:14a Kevin
232 * Made Stats dialog bigger
233 *
234 * 61 10/20/98 5:46p Kevin
235 * Gunboy and other fixes
236 *
237 * 60 10/20/98 2:07p Kevin
238 * changed tab order of login dialog, and changed strings
239 *
240 * 59 10/19/98 11:07p Kevin
241 * fixed bug
242 *
243 * 58 10/19/98 2:48p Kevin
244 * Added accurate weapon thingy for Chris
245 *
246 * 57 10/19/98 11:24a Kevin
247 * Fixed problem with help
248 *
249 * 56 10/17/98 2:32p Kevin
250 * FIxed problem with banned users getting stuck on the ban message
251 * screen.
252 *
253 * 55 10/17/98 12:46p Kevin
254 * Beta 4 fixes
255 *
256 * 54 10/15/98 3:29p Kevin
257 * Fixed dlls to not require runtime debug libraries in release builds
258 *
259 * 53 10/15/98 12:08p Kevin
260 * Changed game list to line up differently
261 *
262 * 52 10/13/98 3:42p Kevin
263 * bug fixes
264 *
265 * 51 10/12/98 8:39p Kevin
266 * removed mprintf's and fixed some smallish bugs
267 *
268 * 50 10/12/98 11:02a Kevin
269 * Changed directory of mtav file
270 *
271 * 49 10/09/98 2:56p Kevin
272 * Changed IP addresses for PXO demo
273 *
274 * 48 10/08/98 3:37p Jeff
275 * removed time_left from Netgame
276 *
277 * 47 10/05/98 11:00a Kevin
278 * Fixed bug with uninitialized variable
279 *
280 * 46 10/01/98 11:37a Kevin
281 * UI fixes and stuff
282 *
283 * 45 9/30/98 12:33p Kevin
284 * Added web launching support
285 *
286 * 44 9/29/98 2:23p Kevin
287 * More UI tweaks
288 *
289 * 43 9/28/98 4:55p Kevin
290 *
291 * 42 9/28/98 4:21p Kevin
292 * Redesigned game list menus
293 *
294 * 41 9/28/98 11:10a Kevin
295 * fuxed returning onf uninitialized variable
296 *
297 * 40 9/28/98 9:53a Kevin
298 * Fixing misc UI problems, and fixed some bugs that VC 6 found
299 *
300 * 39 9/25/98 11:07a Kevin
301 * fixed columns to line up and cleaned up some PXO bugs
302 *
303 * 38 9/24/98 12:50p Kevin
304 * Added UI for rotational velocity and drop out of order packets in net
305 * games
306 *
307 * 37 9/23/98 6:33p Kevin
308 * Fixed load settings
309 *
310 * 36 9/23/98 2:55p Kevin
311 * Saved multi config and changed UI to conform
312 *
313 * 35 9/22/98 3:55p Kevin
314 * Removed obsolete function
315 *
316 * 34 9/22/98 2:29p Kevin
317 * moved ships allowed code out of dll and into main app. Also added
318 * powerup exclusions
319 *
320 * 33 9/21/98 11:19a Kevin
321 * check protocol before entering multiplayer screens
322 *
323 * 32 9/16/98 8:06p Jason
324 * got mastertracker working with the dedicated server
325 *
326 * 31 9/14/98 12:34p Kevin
327 * Fixed problems with using strtok and grtext functions.
328 *
329 * 30 9/09/98 12:41p Kevin
330 * Fixed up some UI issues
331 *
332 * 29 9/04/98 1:51p Kevin
333 * implemented asyncronous gethostbyname
334 *
335 * 28 9/02/98 6:54p Kevin
336 * Fixed general directplay support up, and got modem-modem working
337 *
338 * 27 8/31/98 10:14a Kevin
339 * Misc. multi-UI fixes
340 *
341 * 26 8/27/98 5:03p Kevin
342 * Prettied up multiplayer screens and fixed some bugs.
343 *
344 * 25 8/26/98 3:28p Samir
345 * put focus thing back in
346 *
347 * 24 8/25/98 6:33p Kevin
348 * PXO screens
349 *
350 * 23 8/24/98 5:04p Kevin
351 * Made msn files have the option to not be playable in multiplayer
352 *
353 * 22 8/24/98 10:42a Kevin
354 * Updated DLL for directplay and PXO background
355 *
356 * 21 8/19/98 11:50a Kevin
357 * Got DirectPlay IPX working, and localized connection DLLs
358 *
359 * 20 8/17/98 2:26p Kevin
360 * fixed auto update dll directory
361 *
362 * 19 8/17/98 11:00a Kevin
363 * Moved DLLs into subdirectories
364 *
365 * 18 8/07/98 12:39p Jeff
366 * added "allowed ships" to multiplayer options
367 *
368 * 17 7/27/98 5:31p Kevin
369 * Sound/Bitmap exchange system
370 *
371 * 16 7/22/98 4:34p Kevin
372 * fixed bug in MT gamelist with >10 games
373 *
374 * 15 7/21/98 1:49p Kevin
375 * IPX support and peer-peer option for multi
376 *
377 * 14 7/20/98 2:34p Kevin
378 * Re-wrote the DLL wrapper, to allow for better expandability
379 *
380 * 11 6/30/98 3:20p Kevin
381 * fixed ping time
382 *
383 * 10 6/25/98 10:03a Kevin
384 * Minor chat fixes in PXO
385 *
386 * 9 6/24/98 6:40p Kevin
387 * Added help to main dll menu
388 *
389 * 8 6/24/98 3:24p Kevin
390 * Updated PXO screens with chat, etc.
391 *
392 * 7 6/18/98 4:49p Kevin
393 * Updated multiplayer menus
394 *
395 * 6 6/11/98 1:56p Jeff
396 * looks for d3m files instead of dll
397 *
398 * 5 6/05/98 2:16p Jeff
399 * Changes made so Dynamic loading of DLLs done through module library
400 *
401 * 4 6/05/98 12:40p Kevin
402 *
403 * 3 6/01/98 3:52p Kevin
404 * changed listbox item to be white
405 *
406 * 2 6/01/98 10:10a Kevin
407 * Added DLL connection interface and auto update DLL
408 *
409 * 1 5/18/98 12:47p Kevin
410 *
411 * $NoKeywords: $
412 */
413
414 #include "ui.h"
415 #include "newui.h"
416 #include "grdefs.h"
417 #include "player.h"
418 #include "game.h"
419 #include "pilot.h"
420 #include "ddio_common.h"
421 #include "mt_net.h"
422 #include "mtgametrack.h"
423 #include "module.h"
424 #include "inetgetfile.h"
425 #include "chat_api.h"
426 #include "mtstrings.h"
427
428 #define TXT_DLL_SAVESETTINGS TXT(79)
429 #define TXT_DLL_LOADSETTINGS TXT(80)
430
431 #define TXT_GEN_MPLYROPTIONS TXT_PXO_MPLYROPTIONS
432 #define TXT_GEN_TIMELIMIT TXT_PXO_TIMELIMIT
433 #define TXT_GEN_KILLGOAL TXT_PXO_KILLGOAL
434 #define TXT_GEN_PPS TXT_PXO_PPS
435 #define TXT_GEN_RESPAWNRATE TXT_PXO_RESPAWNRATE
436 #define TXT_GEN_MAXPLAYERS TXT_PXO_MAXPLAYERS
437 #define TXT_GEN_PREVMENU TXT_PXO_PREVMENU
438 #define TXT_GEN_CANCEL TXT_PXO_CANCEL
439 #define TXT_GEN_CFGALLOWEDSHIP TXT_PXO_CFGALLOWEDSHIP
440 #define TXT_GEN_USEROTVEL TXT_PXO_USEROTVEL
441 #define TXT_GEN_USEROTVEL TXT_PXO_USEROTVEL
442 #define TXT_GEN_USESMOOTHING TXT_PXO_USESMOOTHING
443 #define TXT_GEN_CLIENTSERVER TXT_PXO_CLIENTSERVER
444 #define TXT_GEN_PEERPEER TXT_PXO_PEERPEER
445 #define TXT_GEN_ACC_WEAP_COLL TXT_PXO_ACC_WEAP_COLL
446 #define TXT_GEN_BRIGHT_PLAYERS TXT_PXO_BRIGHT_PLAYERS
447
448 #define MULTI_USE_ALL_OPTIONS 1
449
450 #include "mtclient.h"
451 #include "mtpilottrack.h"
452
453 #include "DLLUiItems.h"
454
455 char Ourlobby[50] = "";
456 bool Login_aborted = false;
457 bool Auto_start = false;
458 int Bypass_chat = 0;
459 int ChatStarted = 0;
460 extern int Motd_version;
461
462 d3_net_game_data_tiny DLLD3_tracker_info;
463
464 #define MTADDNEWURL TXT_PXO_REGURL
465
466 #define MAX_GAMELIST_ITEMS 300
467
468 pxo_game_list PXOGamelist[MAX_GAMELIST_ITEMS];
469 int NextGameItemNo = 0;
470 uint16_t DLLPXOPort = 0;
471
472 void AutoLoginAndStartGame();
473
474 int GetGameByHandle(uint32_t handle) {
475 int j;
476 for (j = 0; j < *DLLNum_network_games_known; j++) {
477 if (DLLNetwork_games[j].handle == handle) {
478 return j;
479 }
480 }
481 return -1;
482 }
483
484 int GetPXOItemByHandle(uint32_t handle) {
485 for (int i = 0; i < MAX_GAMELIST_ITEMS; i++) {
486 if (PXOGamelist[i].used) {
487 if (PXOGamelist[i].handle == handle) {
488 return i;
489 }
490 }
491 }
492 return -1;
493 }
494
495 int GetGameByLBNo(int selno) {
496 for (int i = 0; i < MAX_GAMELIST_ITEMS; i++) {
497 if (PXOGamelist[i].used) {
498 if (PXOGamelist[i].lb_no == selno) {
499 return GetGameByHandle(PXOGamelist[i].handle);
500 }
501 }
502 }
503 return -1;
504 }
505
506 void FormatServerLine(char *fmt, int servernum, int pxonum) {
507 int k = servernum;
508 char server_mode[20];
509 char server_type[200];
510
511 if (DLLNetwork_games[k].flags & NF_PEER_PEER) {
512 strcpy(server_mode, "PP");
513 } else if (DLLNetwork_games[k].flags & NF_PERMISSABLE) {
514 strcpy(server_mode, "PS");
515 } else {
516 strcpy(server_mode, "CS");
517 }
518
519 if (DLLNetwork_games[k].flags & NF_ALLOW_MLOOK) {
520 strcat(server_mode, "-ML");
521 }
522
523 snprintf(server_type, sizeof(server_type), "%s %s", server_mode, DLLNetwork_games[k].scriptname);
524
525 int game_type_pos = strlen(server_type);
526
527 #define SERVER_TYPE_MAX_LEN 100
528 while (DLLgrtext_GetTextLineWidth(server_type) > SERVER_TYPE_MAX_LEN) {
529 server_type[game_type_pos] = 0;
530 game_type_pos--;
531 }
532
533 sprintf(fmt, "%.20s\t\x02\x02b%s\x02\x45%.15s\x02\x63%d\x02\x6d%d/%d\x02\x7e%.3f", DLLNetwork_games[k].name,
534 server_type, DLLNetwork_games[k].mission_name, DLLNetwork_games[k].level_num,
535 DLLNetwork_games[k].curr_num_players, DLLNetwork_games[k].max_num_players,
536 DLLNetwork_games[k].server_response_time);
537 }
538
539 void UpdateGamelist(void *lb) {
540
541 int i, j;
542
543 // Look for items that we need to remove
544 for (i = 0; i < MAX_GAMELIST_ITEMS; i++) {
545 bool found = false;
546 if (PXOGamelist[i].used) {
547 for (j = 0; j < *DLLNum_network_games_known; j++) {
548 if (DLLNetwork_games[j].handle == PXOGamelist[i].handle) {
549 found = true;
550 }
551 }
552 if (!found) {
553 // Remove this item!
554 /*
555 int gameid = GetGameByHandle(PXOGamelist[i].handle);
556
557 if(gameid!=-1)
558 {
559 DLLmprintf(0,"Removing %s\n",DLLNetwork_games[gameid].name);
560 }
561 */
562
563 // Now we need to fix up the lb_no items because we removed this one!
564 int k = 0;
565 for (k = 0; k < MAX_GAMELIST_ITEMS; k++) {
566 if (!PXOGamelist[k].used)
567 continue;
568
569 // This is yucky, but it accounts for the shifting up of the game items in the list
570 if (PXOGamelist[i].lb_no < PXOGamelist[k].lb_no)
571 PXOGamelist[k].lb_no--;
572 }
573 NextGameItemNo--;
574 PXOGamelist[i].used = false;
575 PXOGamelist[i].handle = -1;
576 DLLListRemoveItem(lb, PXOGamelist[i].ti);
577 DLLRemoveUITextItem(PXOGamelist[i].ti);
578 }
579 }
580 }
581
582 // Look for items to add
583 for (i = 0; i < *DLLNum_network_games_known; i++) {
584 bool found = false;
585 for (j = 0; j < MAX_GAMELIST_ITEMS; j++) {
586 if (DLLNetwork_games[i].handle == PXOGamelist[j].handle) {
587 found = true;
588 }
589 }
590 if (!found) {
591 // Add this item!
592 // Update PXOGamelist[i].ti
593 for (j = 0; j < MAX_GAMELIST_ITEMS; j++) {
594 if (!PXOGamelist[j].used) {
595 // Aha! an empty slot
596 break;
597 }
598 }
599
600 int k = i;
601 if (j < MAX_GAMELIST_ITEMS) {
602 char fmtline[200];
603
604 PXOGamelist[j].lb_no = NextGameItemNo;
605 NextGameItemNo++;
606 PXOGamelist[j].handle = DLLNetwork_games[k].handle;
607 PXOGamelist[j].used = true;
608 DLLmprintf(0, "Adding %s\n", DLLNetwork_games[k].name);
609
610 // DLLmprintf(0,"Found game: %s\n",DLLNetwork_games[k].name);
611 FormatServerLine(fmtline, k, j);
612
613 if (DLLNetwork_games[k].dedicated_server) {
614 PXOGamelist[j].ti = DLLCreateNewUITextItem(fmtline, UICOL_HOTSPOT_LO);
615 } else {
616 PXOGamelist[j].ti = DLLCreateNewUITextItem(fmtline, GR_LIGHTGRAY);
617 }
618 DLLListAddItem(lb, PXOGamelist[j].ti);
619 } else {
620 // DLLInt3();
621 // Out of slots???
622 }
623 }
624 }
625
626 for (j = 0; j < MAX_GAMELIST_ITEMS; j++) {
627 if (PXOGamelist[j].used && (PXOGamelist[j].handle != -1)) {
628 int gameid = GetGameByHandle(PXOGamelist[j].handle);
629
630 if (gameid != -1) {
631 int k = gameid;
632 // DLLmprintf(0,"Updating %s\n",DLLNetwork_games[gameid].name);
633 char fmtline[200];
634 FormatServerLine(fmtline, k, j);
635 DLLSetUITextItemText(PXOGamelist[j].ti, fmtline,
636 DLLNetwork_games[k].dedicated_server ? UICOL_HOTSPOT_LO : GR_LIGHTGRAY);
637 }
638 }
639 }
640 }
641
642 #ifdef MACINTOSH
643 #pragma export on
644 #endif
645
646 // These next two function prototypes MUST appear in the extern "C" block if called
647 // from a CPP file.
648 extern "C" {
649 DLLEXPORT void DLLFUNCCALL DLLMultiInit(int *api_func);
650 DLLEXPORT void DLLFUNCCALL DLLMultiCall(int eventnum);
651 DLLEXPORT void DLLFUNCCALL DLLMultiClose();
652 }
653
654 bool All_ok = true;
655 bool MT_Sock_inited = false;
656
657 // Initializes the game function pointers
658 void DLLFUNCCALL DLLMultiInit(int *api_func) {
659 Use_netgame_flags = 1;
660 #ifdef MACINTOSH
661 InitOTSockets();
662 #endif
663 #include "mdllinit.h"
664 DLLPXOPort = (uint16_t)((size_t)API.vp[32] & 0xffff);
665 DLLmprintf(0, "Inside DLLMultiInit...\n");
666 *DLLUse_DirectPlay = false;
667 Auto_start = false;
668 DLLmprintf(0, "About to create string table...\n");
669 DLLCreateStringTable("mtclient.str", &StringTable, &StringTableSize);
670 DLLmprintf(0, "%d strings loaded from string table\n", StringTableSize);
671 if (!StringTableSize) {
672 All_ok = false;
673 return;
674 }
675
676 memset(PXOGamelist, 0, sizeof(PXOGamelist));
677 }
678
679 // Called when the DLL is shutdown
680 void DLLFUNCCALL DLLMultiClose() {
681 DLLmprintf(0, "Closing down PXO DLL\n");
682 DLLDestroyStringTable(StringTable, StringTableSize);
683 DLLnw_UnRegisterCallback(PXO_NETID_USER_TRACKER);
684 DLLnw_UnRegisterCallback(PXO_NETID_GAME_TRACKER);
685 if (MT_Sock_inited) {
686 CloseMTSockets();
687 }
688 #ifdef MACINTOSH
689 ShutdownOTSockets();
690 #endif
691 }
692
693 // The main entry point where the game calls the dll
694 void DLLFUNCCALL DLLMultiCall(int eventnum) {
695 // We don't need eventnum right now.
696
697 switch (eventnum) {
698 case MT_EVT_GET_HELP:
699 strcpy(DLLHelpText1, TXT_PXO_HELP1);
700 strcpy(DLLHelpText2, TXT_PXO_HELP2);
701 strcpy(DLLHelpText3, TXT_PXO_HELP3);
702 strcpy(DLLHelpText4, TXT_PXO_HELP4);
703 break;
704 case MT_EVT_LOGIN:
705 DLLDatabaseReadInt("BypassChat", &Bypass_chat);
706 if (!DLLTCP_active) {
707 DLLDoMessageBox(TXT_PXO_ERROR, TXT_PXO_NO_TCPIP, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
708 *DLLMultiGameStarting = 0;
709 break;
710 }
711
712 *DLLMultiGameStarting = 0;
713 if (*DLLDedicated_server) {
714 InitMTSockets();
715 } else {
716 DLLCreateSplashScreen(TXT_PXO_CONNECTING, 1);
717 InitMTSockets();
718 MT_Sock_inited = true;
719 DLLCloseSplashScreen();
720 }
721 if (!All_ok) {
722 *DLLMultiGameStarting = 0;
723 return;
724 }
725 {
726 UnvalidatedDLL = 0;
727 DLLCreateSplashScreen(TXT_PXO_CONNECTING, 1);
728 DLLPollUI();
729 if (MT_Initialized) {
730 DLLPollUI();
731 if (!MTVersionCheck()) {
732 if (Login_aborted) {
733 MT_Initialized = 0;
734 } else {
735 // If the first call fails, try again
736 DLLPollUI();
737 if (!MTVersionCheck()) {
738 DLLPollUI();
739 if (!MTVersionCheck()) {
740 // If this call fails, we have a problem, and when MT_EVT_LOGIN is called we will let the user know.
741 UnvalidatedDLL = 1;
742 }
743 }
744 }
745 }
746 }
747 DLLCloseSplashScreen();
748 if (!MT_Initialized) {
749 DLLDoMessageBox(TXT_PXO_MASTERTRACKER, TXT_PXO_CANTCONNECT, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
750 return;
751 }
752 // Start off with a login to tracker dialog
753 if (UnvalidatedDLL) {
754 DLLDoMessageBox(TXT_PXO_MASTERTRACKER, TXT_PXO_CANTAUTOVALIDATE, MSGBOX_OK, UICOL_WINDOW_TITLE,
755 UICOL_TEXT_NORMAL);
756 return;
757 }
758
759 if (LoginMasterTracker()) {
760 // menu.... start a game, or join a game
761 if (MainMultiplayerMenu()) {
762 *DLLMultiGameStarting = 1;
763 } else {
764 *DLLMultiGameStarting = 0;
765 }
766 } else {
767 DLLmprintf(0, "Login failed!\n");
768 *DLLMultiGameStarting = 0;
769 return;
770 }
771 }
772 break;
773 case MT_EVT_FRAME:
774 DoMTFrame();
775 break;
776 case MT_EVT_FIRST_FRAME:
777 MTWritingPilot = -1;
778 MTReadingPilot = -1;
779 *DLLGame_is_master_tracker_game = 1;
780 // strcpy(DLLD3_tracker_info.game_name,DLLNetgame->name);
781 // strcpy(DLLD3_tracker_info.mission_name,DLLNetgame->mission);
782 strcpy(DLLD3_tracker_info.lobby, DLLPXO_hosted_lobby_name);
783 StartTrackerGame(&DLLD3_tracker_info);
784 break;
785 case MT_EVT_GAME_OVER:
786 DoMTGameOver();
787 /*
788 if(!All_ok)
789 break;
790 //menu.... start a game, or join a game
791 if(MainMultiplayerMenu())
792 {
793 *DLLMultiGameStarting = 1;
794 }
795 else
796 {
797 *DLLMultiGameStarting = 0;
798 }
799 */
800 break;
801 case MT_AUTO_LOGIN:
802 if (!DLLTCP_active) {
803 DLLDoMessageBox(TXT_PXO_ERROR, TXT_PXO_NO_TCPIP, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
804 *DLLMultiGameStarting = 0;
805 break;
806 }
807 InitMTSockets();
808 if (!All_ok) {
809 *DLLMultiGameStarting = 0;
810 return;
811 }
812 AutoLoginAndJoinGame();
813 break;
814 case MT_AUTO_START:
815 InitMTSockets();
816 if (!All_ok) {
817 *DLLMultiGameStarting = 0;
818 return;
819 }
820 Auto_start = true;
821 AutoLoginAndStartGame();
822 break;
823 case MT_RETURN_TO_GAME_LIST:
824 Bypass_chat = 1;
825
826 // menu.... start a game, or join a game
827 if (MainMultiplayerMenu()) {
828 *DLLMultiGameStarting = 1;
829 } else {
830 *DLLMultiGameStarting = 0;
831 }
832 break;
833 }
834 }
835
836 #ifdef MACINTOSH
837 #pragma export off
838 #endif
839
840 int LoginMasterTracker() {
841
842 void *title_text = DLLCreateNewUITextItem(TXT_PXO_LOGINMASTERTRKR, UICOL_WINDOW_TITLE);
843 void *cancel_on_text = DLLCreateNewUITextItem(TXT_PXO_CANCEL, UICOL_HOTSPOT_HI);
844 void *login_on_text = DLLCreateNewUITextItem(TXT_PXO_LOGIN, UICOL_HOTSPOT_HI);
845
846 void *cancel_off_text = DLLCreateNewUITextItem(TXT_PXO_CANCEL, UICOL_HOTSPOT_LO);
847 void *login_off_text = DLLCreateNewUITextItem(TXT_PXO_LOGIN, UICOL_HOTSPOT_LO);
848
849 void *login_id_text = DLLCreateNewUITextItem(TXT_PXO_LOGINID, UICOL_TEXT_NORMAL);
850 void *tracker_id_text = DLLCreateNewUITextItem(TXT_PXO_TRACKERID, UICOL_TEXT_NORMAL);
851 void *password_text = DLLCreateNewUITextItem(TXT_PXO_PASSWORD, UICOL_TEXT_NORMAL);
852
853 void *new_prof_on_text = DLLCreateNewUITextItem(TXT_PXO_CREATENEWPROFILE, UICOL_HOTSPOT_HI);
854 void *new_prof_off_text = DLLCreateNewUITextItem(TXT_PXO_CREATENEWPROFILE, UICOL_HOTSPOT_LO);
855
856 void *blank_text = DLLCreateNewUITextItem(TXT_PXO_BLANK, GR_BLACK);
857
858 int exit_menu = 0;
859 int ret = 0;
860
861 int loginlen = LOGIN_LEN;
862 int passlen = PASSWORD_LEN;
863
864 void *main_wnd = DLLNewUIGameWindowCreate(TRACKER_MENU_X, TRACKER_MENU_Y, TRACKER_MENU_W, TRACKER_MENU_H,
865 UIF_PROCESS_ALL | UIF_CENTER | NUWF_TITLEMED);
866
867 void *title = DLLTextCreate(main_wnd, title_text, 0, 7, UIF_CENTER);
868
869 void *password = DLLTextCreate(main_wnd, password_text, 30, 130, UIF_CENTER);
870 void *login_id = DLLTextCreate(main_wnd, login_id_text, 50, 80, UIF_CENTER);
871
872 void *pass_edit = DLLEditCreate(main_wnd, UID_OK, 100, 140, 130, 15, UIF_CENTER | UIED_PASSWORD);
873
874 void *login_hs =
875 DLLHotSpotCreate(main_wnd, UID_OK, KEY_ENTER, login_off_text, login_on_text, 60, TRACKER_MENU_H - 80, 60, 20, 0);
876
877 void *cancel_hs = DLLHotSpotCreate(main_wnd, UID_CANCEL, KEY_ESC, cancel_off_text, cancel_on_text, 130,
878 TRACKER_MENU_H - 80, 60, 20, 0);
879
880 void *new_id_hs =
881 DLLHotSpotCreate(main_wnd, 4, KEY_N, new_prof_off_text, new_prof_on_text, 0, 45, 120, 20, UIF_CENTER | UIF_FIT);
882
883 void *login_edit = DLLEditCreate(main_wnd, 3, 100, 90, 130, 15, UIF_CENTER);
884
885 // Read defaults
886
887 DLLDatabaseRead("TrackerLogin", szloginid, &loginlen);
888 DLLDatabaseRead("TrackerPassword", szpassword, &passlen);
889
890 DLLEditSetText(login_edit, szloginid);
891 DLLEditSetText(pass_edit, szpassword);
892
893 DLLNewUIGameWindowOpen(main_wnd);
894
895 while (!exit_menu) {
896 int res;
897
898 res = DLLDoUI();
899
900 // handle all UI results.
901
902 switch (res) {
903 case 3:
904 DLLmprintf(0, "Got event 3!\n");
905 break;
906 case 4:
907 #ifdef WIN32
908 // TODO: reacivate for site opening
909 // ShellExecute(NULL, "open", MTADDNEWURL, NULL, NULL, SW_SHOW);
910 #endif
911 break;
912 case UID_OK: {
913 DLLEditGetText(login_edit, szloginid, LOGIN_LEN);
914 DLLEditGetText(pass_edit, szpassword, PASSWORD_LEN);
915
916 DLLDatabaseWrite("TrackerLogin", szloginid, strlen(szloginid) + 1);
917 DLLDatabaseWrite("TrackerPassword", szpassword, strlen(szpassword) + 1);
918
919 if ((!*szloginid) || (!*szpassword)) {
920 DLLDoMessageBox(TXT_PXO_MASTERTRACKER, TXT_PXO_BADLOGIN, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
921 break;
922 }
923
924 // Fill out the validate struct and send off the packet
925 validate_id_request val_user{};
926 strcpy(val_user.tracker_id, sztrackerid);
927 strcpy(val_user.login, szloginid);
928 strcpy(val_user.password, szpassword);
929
930 DLLCreateSplashScreen(TXT_PXO_CONNECTING, 1);
931
932 int valret = ValidateUser(&val_user, sztrackerid);
933
934 while (valret == 0) {
935 valret = ValidateUser(nullptr, nullptr);
936 res = DLLPollUI();
937 if (res == 99) {
938 valret = -2;
939 }
940 DLLDescentDefer();
941 }
942 DLLCloseSplashScreen();
943 if (valret == 1) {
944 // User was validated
945 DLLmprintf(0, "Mastertracker user validated!\n");
946 // Run this to make sure we properly ACK the server.
947 for (int j = 0; j < 10; j++)
948 PollPTrackNet();
949 strcpy(DLLTracker_id, sztrackerid);
950 strcpy(DLLMPlayers[DLLPlayer_num].tracker_id, sztrackerid);
951 exit_menu = 1;
952 ret = 1;
953
954 break;
955 } else if (valret == -1) {
956 // User invalid!
957 DLLmprintf(0, "Mastertracker user not validated!\n");
958 DLLDoMessageBox(TXT_PXO_MASTERTRACKER, TXT_PXO_BADLOGIN, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
959 // Run this to make sure we properly ACK the server.
960 for (int j = 0; j < 10; j++)
961 PollPTrackNet();
962 break;
963 } else {
964 // timeout waiting for tracker!
965 DLLmprintf(0, "Mastertracker timeout!\n");
966 DLLDoMessageBox(TXT_PXO_MASTERTRACKER, TXT_PXO_TIMEOUTMT, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
967 // Run this to make sure we properly ACK the server.
968 for (int j = 0; j < 10; j++)
969 PollPTrackNet();
970 break;
971 }
972 }
973 case UID_CANCEL:
974 exit_menu = 1;
975 ret = 0;
976 break;
977 }
978 }
979
980 DLLNewUIGameWindowClose(main_wnd);
981 DLLNewUIGameWindowDestroy(main_wnd);
982
983 DLLRemoveUITextItem(title_text);
984 DLLRemoveUITextItem(cancel_on_text);
985 DLLRemoveUITextItem(login_on_text);
986 DLLRemoveUITextItem(cancel_off_text);
987 DLLRemoveUITextItem(login_off_text);
988 DLLRemoveUITextItem(login_id_text);
989 DLLRemoveUITextItem(tracker_id_text);
990 DLLRemoveUITextItem(password_text);
991 DLLRemoveUITextItem(new_prof_on_text);
992 DLLRemoveUITextItem(new_prof_off_text);
993 DLLRemoveUITextItem(blank_text);
994
995 DLLDeleteUIItem(main_wnd);
996 DLLDeleteUIItem(title);
997 DLLDeleteUIItem(cancel_hs);
998 DLLDeleteUIItem(login_hs);
999 DLLDeleteUIItem(new_id_hs);
1000 DLLDeleteUIItem(login_edit);
1001 DLLDeleteUIItem(password);
1002 DLLDeleteUIItem(login_id);
1003 DLLDeleteUIItem(pass_edit);
1004
1005 return ret;
1006 }
1007
1008 // The first multiplayer menu that the user will see...all multiplayer stuff is
1009 // reached from this menu
1010 // Returns true if we're starting a multiplayer game
1011 #define CONNECT_PXO_TIMEOUT 60.0
1012 #define MAX_CHAT_SEND_LEN 200
1013 #define MAX_CHAT_CHANNELS 50
1014 #define CHAT_INFO_LEN 200
1015 #define CHAT_COUNT_LEN 10
1016 #define CHAT_MAX_USERLIST 200
1017 #define CHAT_USER_REFRESH_TIME 5
1018 #define CHAT_LIST_REFRESH_TIME 10
1019
1020 struct {
1021 char name[CHAT_INFO_LEN];
1022 char origname[CHAT_INFO_LEN];
1023 char topic[CHAT_INFO_LEN];
1024 char count[CHAT_COUNT_LEN];
1025 char games[CHAT_COUNT_LEN];
1026 } chan_info[MAX_CHAT_CHANNELS];
1027
1028 int MainMultiplayerMenu() {
1029
1030 DLLmprintf(0, "%d", DESCENT3_BLOCK_SIZE);
1031 if (!ShowMessageOfTheDay()) {
1032 return 0;
1033 }
1034
1035 DLLmprintf(0, "Inside MainMultiplayerMenu()\n");
1036 if (Bypass_chat && !ChatStarted) {
1037 int rcode1 = SearchMasterTrackerGameMenu();
1038 if (rcode1 == -1)
1039 rcode1 = 0;
1040 return rcode1;
1041 }
1042
1043 DLLToggleUICallback(0);
1044 ChatStarted = 1;
1045 void *title_text = DLLCreateNewUITextItem(TXT_PXO_CONNECTING, UICOL_WINDOW_TITLE);
1046
1047 void *cancel_on_text = DLLCreateNewUITextItem(TXT_PXO_CANCEL, UICOL_HOTSPOT_HI);
1048 void *cancel_off_text = DLLCreateNewUITextItem(TXT_PXO_CANCEL, UICOL_HOTSPOT_LO);
1049
1050 void *exit_on_text = DLLCreateNewUITextItem(TXT_PXO_EXIT, UICOL_HOTSPOT_HI);
1051 void *exit_off_text = DLLCreateNewUITextItem(TXT_PXO_EXIT, UICOL_HOTSPOT_LO);
1052
1053 void *priv_msg_on_text = DLLCreateNewUITextItem(TXT_PXO_SENDPRIV, UICOL_HOTSPOT_HI);
1054 void *priv_msg_off_text = DLLCreateNewUITextItem(TXT_PXO_SENDPRIV, UICOL_HOTSPOT_LO);
1055
1056 void *join_lobby_on_text = DLLCreateNewUITextItem(TXT_PXO_JOINPRIV, UICOL_HOTSPOT_HI);
1057 void *join_lobby_off_text = DLLCreateNewUITextItem(TXT_PXO_JOINPRIV, UICOL_HOTSPOT_LO);
1058
1059 void *join_chan_on_text = DLLCreateNewUITextItem(TXT_PXO_JOINCHAN, UICOL_HOTSPOT_HI);
1060 void *join_chan_off_text = DLLCreateNewUITextItem(TXT_PXO_JOINCHAN, UICOL_HOTSPOT_LO);
1061
1062 void *find_pilot_on_text = DLLCreateNewUITextItem(TXT_PXO_FINDPILOT, UICOL_HOTSPOT_HI);
1063 void *find_pilot_off_text = DLLCreateNewUITextItem(TXT_PXO_FINDPILOT, UICOL_HOTSPOT_LO);
1064
1065 void *get_pilot_on_text = DLLCreateNewUITextItem(TXT_PXO_GETPILOTINFO, UICOL_HOTSPOT_HI);
1066 void *get_pilot_off_text = DLLCreateNewUITextItem(TXT_PXO_GETPILOTINFO, UICOL_HOTSPOT_LO);
1067
1068 void *game_on_text = DLLCreateNewUITextItem(TXT_PXO_JOINSTARTGAME, UICOL_HOTSPOT_HI);
1069 void *game_off_text = DLLCreateNewUITextItem(TXT_PXO_JOINSTARTGAME, UICOL_HOTSPOT_LO);
1070
1071 void *send_on_text = DLLCreateNewUITextItem(TXT_PXO_SEND, UICOL_HOTSPOT_HI);
1072 void *send_off_text = DLLCreateNewUITextItem(TXT_PXO_SEND, UICOL_HOTSPOT_LO);
1073
1074 char fmtlobbytext[200];
1075 snprintf(fmtlobbytext, sizeof(fmtlobbytext), TXT_PXO_YOUAREINLOBBY, Ourlobby);
1076 void *lobby_text = DLLCreateNewUITextItem(fmtlobbytext, UICOL_TEXT_AUX);
1077
1078 void *blank_text = DLLCreateNewUITextItem(TXT_PXO_BLANK, UICOL_TEXT_AUX);
1079 char sendline[MAX_CHAT_SEND_LEN];
1080 int exit_menu = 0;
1081 int ret = 0;
1082 int res;
1083 const char *p;
1084 int i;
1085 float lastlisttime = 0;
1086 float lastchanlisttime = 0;
1087 void *chan_ti[MAX_CHAT_CHANNELS];
1088 void *user_ti[CHAT_MAX_USERLIST];
1089 char selpilot[MAX_CHAT_SEND_LEN];
1090 char oldselchan[200];
1091 for (i = 0; i < MAX_CHAT_CHANNELS; i++)
1092 chan_ti[i] = nullptr;
1093 for (i = 0; i < CHAT_MAX_USERLIST; i++)
1094 user_ti[i] = nullptr;
1095
1096 uint8_t oldalpha = *DLLNewUIWindow_alpha;
1097
1098 int colx1 = 0;
1099 int colx2 = 148;
1100 DLLSetScreenMode(SM_MENU);
1101 *DLLNewUIWindow_alpha = 255;
1102
1103 for (i = 0; i < MAX_CHAT_CHANNELS; i++) {
1104 chan_info[i].origname[0] = '\0';
1105 }
1106
1107 // Create our buttons
1108 void *main_wnd = DLLNewUIWindowCreate(0, 0, 640, 480, UIF_PROCESS_ALL);
1109
1110 // void HotSpotCreate(int item,int parentitem, int id, int key, int txtitemoff, int txtitemon, int x, int y, int w,
1111 // int h, int flags,int winnum)
1112 void *exit_hs = DLLHotSpotCreate(main_wnd, 5, KEY_ESC, exit_off_text, exit_on_text, 33, 427, 70, 15, 0);
1113
1114 void *priv_hs = DLLHotSpotCreate(main_wnd, 6, 0, priv_msg_off_text, priv_msg_on_text, 328, 403, 170, 15, 0);
1115
1116 #define JOIN_ROW 131
1117 void *join_lobby_hs =
1118 DLLHotSpotCreate(main_wnd, 7, 0, join_lobby_off_text, join_lobby_on_text, 400, JOIN_ROW, 170, 15, 0);
1119 void *join_chan_hs =
1120 DLLHotSpotCreate(main_wnd, 14, 0, join_chan_off_text, join_chan_on_text, 178, JOIN_ROW, 170, 15, 0);
1121
1122 void *find_hs = DLLHotSpotCreate(main_wnd, 9, 0, find_pilot_off_text, find_pilot_on_text, 156, 403, 140, 15, 0);
1123 void *get_pilot_hs =
1124 DLLHotSpotCreate(main_wnd, 10, 0, get_pilot_off_text, get_pilot_on_text, colx1 + 10, 372, 130, 15, 0);
1125 void *game_hs = DLLHotSpotCreate(main_wnd, 11, 0, game_off_text, game_on_text, 505, 431, 135, 15, 0);
1126
1127 void *enter_hs = DLLHotSpotCreate(main_wnd, 15, KEY_ENTER, send_off_text, send_on_text, 550, 370, 70, 15, 0);
1128
1129 // lobby_text
1130 void *lobby_txt_gadget = DLLTextCreate(main_wnd, lobby_text, 200, 450, UIF_CENTER);
1131
1132 // User list box, id #10
1133 void *user_list = DLLOldListCreate(main_wnd, 10, colx1 + 20, 100, 108, 265, 0);
1134 // Channel list box, id #14
1135 void *chan_list = DLLOldListCreate(main_wnd, 14, colx2, 25, 470, 96, 0);
1136
1137 // Edit box for typing in chat, id # 15
1138 void *send_edit = DLLOldEditCreate(main_wnd, 15, colx2 + 10, 372, 390, 20, UIED_AUTOSELECT);
1139 DLLNewUIWindowLoadBackgroundImage(main_wnd, "pxomain.ogf");
1140 DLLSetOldEditBufferLen(send_edit, 100);
1141 void *console_item = DLLUIConsoleGadgetCreate(main_wnd, 16, colx2, 165, 0, 51, 16, 0);
1142 pconsole = console_item;
1143
1144 DLLNewUIWindowOpen(main_wnd);
1145 // Menu loop
1146 // Create status window while we are connecting
1147
1148 DLLCreateSplashScreen(TXT_PXO_CONNECTING, 1);
1149 Chat_command *cmd;
1150 int gotcancel = 0;
1151 int chat_connected = 0;
1152 float chat_conn_time = 0;
1153 char oldseluser[100];
1154 char chat_whois_info[PILOT_NAME_LEN + TRACKER_ID_LEN + 4];
1155
1156 char pilot_name[PILOT_STRING_SIZE];
1157 CurrentPilotName(pilot_name);
1158
1159 snprintf(chat_whois_info, sizeof(chat_whois_info), "%s %s", sztrackerid, pilot_name);
1160 chat_conn_time = DLLtimer_GetTime();
1161 // DLLNewUIWindowSetFocusOnEditGadget(send_edit,main_wnd);
1162 DLLmprintf(0, "About to connect...\n");
1163 do {
1164 chat_connected = ConnectToChatServer(CHATTRACKERNAME, CHATPORT, pilot_name, chat_whois_info);
1165 // chat_connected = ConnectToChatServer("plasma.outrage.com:7000",pilot_name,chat_whois_info);
1166 p = GetChatText();
1167 if (p) {
1168 DLLUIConsoleGadgetputs(console_item, p);
1169 DLLUIConsoleGadgetputs(console_item, "\x0a\x0d");
1170 }
1171 if ((chat_connected == -1) || ((DLLtimer_GetTime() - chat_conn_time) > CONNECT_PXO_TIMEOUT)) {
1172 DLLDoMessageBox(TXT_PXO_MASTERTRACKER, TXT_PXO_CANTCONNECT, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
1173 // Go ahead to the game screen.
1174 // SearchMasterTrackerGameMenu();
1175 int rcode1 = SearchMasterTrackerGameMenu();
1176 if (rcode1 == -1)
1177 rcode1 = 0;
1178 ret = rcode1;
1179 exit_menu = 1;
1180 DLLCloseSplashScreen();
1181 DLLNewUIWindowClose(main_wnd);
1182 goto shutdownpxo;
1183 // gotcancel = 1;
1184 break;
1185 }
1186 res = DLLPollUI();
1187 if (res == 99) {
1188 SearchMasterTrackerGameMenu();
1189 gotcancel = 1;
1190 }
1191
1192 } while ((!gotcancel) && (chat_connected == 0));
1193 DLLCloseSplashScreen();
1194
1195 if (gotcancel) {
1196 ret = 0;
1197 exit_menu = 1;
1198 DLLNewUIWindowClose(main_wnd);
1199 goto shutdownpxo;
1200 }
1201 DLLmprintf(0, "Connected to chat server!\n");
1202 if (!JoinNewLobby("#autoselect")) {
1203 ret = 0;
1204 exit_menu = 1;
1205 }
1206 SendChatString("/list");
1207 // DLLNewUIWindowSetFocusOnEditGadget(send_edit,main_wnd);
1208 while (!exit_menu) {
1209
1210 // Handle commands...
1211 cmd = GetChatCommandFromQueue();
1212 if (cmd) {
1213 switch (cmd->command) {
1214 case CC_USER_JOINING:
1215 case CC_USER_LEAVING:
1216 case CC_KICKED:
1217 case CC_NICKCHANGED:
1218 // We will ignore all these things for now
1219 break;
1220 case CC_YOURCHANNEL: {
1221 strcpy(Ourlobby, cmd->data);
1222 char fmtlobbytext[200];
1223 char cleanlobby[50];
1224 memset(cleanlobby, 0, 29);
1225 strcpy(cleanlobby, Ourlobby + 1);
1226 for (int l = 0; l < 18; l++) {
1227 if (cleanlobby[l] == '_')
1228 cleanlobby[l] = ' ';
1229 // if(cleanlobby[l]==NULL) cleanlobby[l]= ' ';
1230 }
1231 snprintf(fmtlobbytext, sizeof(fmtlobbytext), TXT_PXO_YOUAREINLOBBY, cleanlobby);
1232
1233 DLLRemoveUITextItem(lobby_text);
1234 DLLGadgetDestroy(lobby_txt_gadget);
1235 DLLDeleteUIItem(lobby_txt_gadget);
1236 lobby_text = DLLCreateNewUITextItem(fmtlobbytext, UICOL_TEXT_AUX);
1237 lobby_txt_gadget = DLLTextCreate(main_wnd, lobby_text, 0, 450, UIF_CENTER);
1238 // Now update the text on the bottom of the screen
1239 } break;
1240 case CC_DISCONNECTED:
1241 // Display a message box letting the user know we are disconnected.
1242 DLLDoMessageBox(TXT_PXO_MASTERTRACKER, TXT_PXO_CHATDISCONNECTED, MSGBOX_OK, UICOL_WINDOW_TITLE,
1243 UICOL_TEXT_NORMAL);
1244 DLLNewUIWindowClose(main_wnd);
1245 exit_menu = 1;
1246 break;
1247 default:
1248 DLLmprintf(0, "Warning: Received an unknown chat command!\n");
1249 break;
1250 }
1251 }
1252 if (exit_menu)
1253 break;
1254 p = GetChatText();
1255 if (p) {
1256 DLLUIConsoleGadgetputs(console_item, p);
1257 DLLUIConsoleGadgetputs(console_item, "\x0a\x0d");
1258 }
1259 // refresh the userlist
1260 if ((DLLtimer_GetTime() - lastlisttime) > CHAT_USER_REFRESH_TIME) {
1261 lastlisttime = DLLtimer_GetTime();
1262 p = GetChatUserList();
1263 if (p) {
1264
1265 char *oldsel = DLLOldListGetItem(user_list, DLLOldListGetSelectedIndex(user_list));
1266 oldseluser[0] = 0;
1267 if (oldsel)
1268 strcpy(oldseluser, oldsel);
1269 void *old_ti = nullptr; // = DLLCreateNewUITextItem(TXT_PXO_JOINSTARTGAME,GR_WHITE);
1270 // int oldsel = DLLOldListGetSelectedIndex(user_list);
1271 // void * old_ti =
1272
1273 DLLOldListRemoveAll(user_list);
1274 for (i = 0; i < CHAT_MAX_USERLIST; i++) {
1275 if (user_ti[i] != nullptr)
1276 DLLRemoveUITextItem(user_ti[i]);
1277 user_ti[i] = nullptr;
1278 }
1279 char seps[] = " ";
1280 char *tokp;
1281 tokp = strtok((char *)p, seps);
1282 if (tokp) {
1283 for (i = 0; i < CHAT_MAX_USERLIST; i++) {
1284 user_ti[i] = DLLCreateNewUITextItem(tokp, GR_WHITE);
1285 DLLOldListAddItem(user_list, user_ti[i]);
1286 if (strcmp(tokp, oldseluser) == 0)
1287 old_ti = user_ti[i];
1288 tokp = strtok(nullptr, seps);
1289 if (!tokp)
1290 break;
1291 }
1292 if (old_ti)
1293 DLLOldListSelectItem(user_list, old_ti);
1294 }
1295 }
1296 }
1297 // refresh the channellist
1298 if ((DLLtimer_GetTime() - lastchanlisttime) > CHAT_LIST_REFRESH_TIME) {
1299 lastchanlisttime = DLLtimer_GetTime();
1300 SendChatString("/list");
1301 }
1302 p = GetChannelList();
1303 if (p) {
1304 char *pchanlist;
1305 pchanlist = (char *)DLLmem_malloc(strlen(p) + 1);
1306 memset(pchanlist, 0, strlen(p));
1307 strcpy(pchanlist, p);
1308 char *tokp = nullptr;
1309 char *nexttok;
1310 // tokp = strtok(pchanlist,seps);
1311 nexttok = strchr(pchanlist, '$');
1312 if (nexttok) {
1313 *nexttok = '\0';
1314 nexttok++;
1315 tokp = nexttok;
1316 if (nexttok) {
1317 nexttok = strchr(nexttok, '$');
1318 if (nexttok) {
1319 *nexttok = '\0';
1320 nexttok++;
1321 }
1322 }
1323 }
1324
1325 if (tokp) {
1326 // Remove all previous items
1327 DLLmprintf(0, "Refreshing channel list\n");
1328 // get the text of the currently selected channel.
1329 // char * oldsel = DLLOldListGetItem(chan_list,DLLOldListGetSelectedIndex(chan_list));
1330 //
1331 int selitem = DLLOldListGetSelectedIndex(chan_list);
1332 char *oldsel = nullptr;
1333 oldselchan[0] = 0;
1334
1335 if ((selitem > 0) && (selitem < MAX_CHAT_CHANNELS)) {
1336 oldsel = chan_info[selitem].origname;
1337 strcpy(oldselchan, oldsel);
1338 }
1339
1340 DLLOldListRemoveAll(chan_list);
1341 for (i = 0; i < MAX_CHAT_CHANNELS; i++) {
1342 if (chan_ti[i] != nullptr)
1343 DLLRemoveUITextItem(chan_ti[i]);
1344 chan_ti[i] = nullptr;
1345 }
1346 for (i = 0; i < MAX_CHAT_CHANNELS; i++) {
1347 char fmtchan[500];
1348 char *pcount = strchr(tokp, ' ');
1349 // if(pcount)
1350 {
1351 if (!pcount) {
1352 pcount = (char *)"";
1353 } else {
1354 // pcount++;
1355 *pcount = '\0';
1356 }
1357
1358 // 17 is the magic number we want all channel names to align with
1359 memset(chan_info[i].name, 0, 19);
1360 strcpy(chan_info[i].origname, tokp);
1361 strcpy(chan_info[i].name, tokp + 1); // skip the #
1362 for (int l = 0; l < 18; l++) {
1363 if (chan_info[i].name[l] == '_')
1364 chan_info[i].name[l] = ' ';
1365 if (chan_info[i].name[l] == '\0')
1366 chan_info[i].name[l] = ' ';
1367 }
1368 pcount++;
1369 char *ptopic = pcount;
1370 while (isdigit(*ptopic)) {
1371 ptopic++;
1372 }
1373 *ptopic = '\0';
1374 ptopic++;
1375 // count
1376 strcpy(chan_info[i].count, pcount);
1377 // topic
1378 strcpy(chan_info[i].topic, ptopic);
1379 // Now we want it formatted nicely.....
1380 char chan_name[100];
1381 memset(chan_name, ' ', 99);
1382 chan_name[99] = '\0';
1383 char count_list[10];
1384 memset(count_list, ' ', 9);
1385 count_list[9] = '\0';
1386
1387 memset(fmtchan, 0, 500);
1388
1389 int textx = 0;
1390 int charpos = 0;
1391 int endpos;
1392 #define LIST_ROW1 90
1393 #define LIST_ROW2 130
1394
1395 strcpy(chan_name, chan_info[i].name);
1396 endpos = strlen(chan_info[i].name);
1397 chan_name[endpos] = ' ';
1398
1399 strcpy(count_list, chan_info[i].count);
1400 endpos = strlen(chan_info[i].count);
1401 count_list[endpos] = ' ';
1402
1403 while (DLLgrtext_GetTextLineWidth(fmtchan) < LIST_ROW1) {
1404 endpos = strlen(fmtchan);
1405 fmtchan[endpos] = chan_name[charpos];
1406 fmtchan[endpos + 1] = NULL;
1407 charpos++;
1408 }
1409 strcat(fmtchan, "\t\0");
1410 charpos = 0;
1411 while (DLLgrtext_GetTextLineWidth(fmtchan) < LIST_ROW2) {
1412 endpos = strlen(fmtchan);
1413 fmtchan[endpos] = count_list[charpos];
1414 fmtchan[endpos + 1] = NULL;
1415 charpos++;
1416 }
1417 strcat(fmtchan, "\t\0");
1418
1419 strcat(fmtchan, chan_info[i].topic);
1420 // sprintf(fmtchan,"%.15s\t%s\t%s",chan_info[i].name,chan_info[i].count,chan_info[i].topic);
1421 chan_ti[i] = DLLCreateNewUITextItem(fmtchan, GR_WHITE);
1422 DLLOldListAddItem(chan_list, chan_ti[i]);
1423 if (strcmp(oldselchan, chan_info[i].origname) == 0) {
1424 DLLOldListSelectItem(chan_list, chan_ti[i]);
1425 }
1426 }
1427 tokp = nexttok;
1428 if (nexttok) {
1429 nexttok = strchr(nexttok, '$');
1430 if (nexttok) {
1431 *nexttok = '\0';
1432 nexttok++;
1433 }
1434 }
1435 // tokp = strtok(NULL,seps);
1436 if (!tokp)
1437 break;
1438 }
1439 }
1440 DLLmem_free(pchanlist);
1441 }
1442
1443 res = DLLPollUI();
1444 if (res != -1) {
1445 // DLLNewUIWindowSetFocusOnEditGadget(send_edit,main_wnd);
1446 }
1447 // handle all UI results.
1448 switch (res) {
1449 case -1:
1450 break;
1451 case 3:
1452 // Join Mastertracker game
1453 {
1454 DLLmprintf(0, "Sending Mastertracker game list request.\n");
1455 RequestGameList();
1456 DLLmprintf(0, "Calling SearchMasterTrackerGameMenu().\n");
1457 DLLNewUIWindowClose(main_wnd);
1458 *DLLGame_is_master_tracker_game = 1;
1459 int gamestart = SearchMasterTrackerGameMenu();
1460 if (gamestart == 1) {
1461 exit_menu = 1;
1462 ret = 1;
1463 } else if (gamestart == 0) {
1464 DLLNewUIWindowOpen(main_wnd);
1465 } else if (gamestart == -1) {
1466 exit_menu = 1;
1467 ret = 0;
1468 }
1469 break;
1470 }
1471
1472 case 4:
1473
1474 // Start Mastertracker game
1475 // Start a netgame
1476 DLLNewUIWindowClose(main_wnd);
1477 *DLLGame_is_master_tracker_game = 1;
1478 if (StartMultiplayerGameMenu()) {
1479 exit_menu = 1;
1480 ret = 1;
1481 } else {
1482 DLLNewUIWindowOpen(main_wnd);
1483 }
1484 break;
1485 case 5:
1486 DLLNewUIWindowClose(main_wnd);
1487 exit_menu = 1;
1488 ret = 0;
1489 break;
1490 case 6:
1491 // Send a private message
1492 // Create new dialog box, prompt for user and message, then send message
1493 DLLmprintf(0, "Sending private Message\n");
1494 // Get the currently selected pilot name
1495 strcpy(selpilot, DLLOldListGetItem(user_list, DLLOldListGetSelectedIndex(user_list)));
1496 SendWhisper(selpilot);
1497 break;
1498 case 7:
1499 // Join a private channel
1500 if (!JoinPrivateLobby()) {
1501 ret = 0;
1502 exit_menu = 0;
1503 }
1504 break;
1505 case 8:
1506 // Join a channel
1507 // unused
1508 break;
1509 case 9:
1510 // Find a pilot
1511 DLLmprintf(0, "Finding a pilot\n");
1512 FindPilot();
1513 break;
1514 case 10:
1515 // Get pilot stats
1516 DLLmprintf(0, "Getting pilot statistics\n");
1517 strcpy(selpilot, DLLOldListGetItem(user_list, DLLOldListGetSelectedIndex(user_list)));
1518 GetPilotStats(selpilot);
1519 break;
1520 case 11: {
1521 DLLmprintf(0, "Sending Mastertracker game list request.\n");
1522 RequestGameList();
1523 DLLmprintf(0, "Calling SearchMasterTrackerGameMenu().\n");
1524 DLLNewUIWindowClose(main_wnd);
1525 *DLLGame_is_master_tracker_game = 1;
1526 int gamestart = SearchMasterTrackerGameMenu();
1527 if (gamestart == 1) {
1528 exit_menu = 1;
1529 ret = 1;
1530 } else if (gamestart == 0) {
1531 DLLNewUIWindowOpen(main_wnd);
1532 } else if (gamestart == -1) {
1533 exit_menu = 1;
1534 ret = 0;
1535 }
1536 break;
1537 } break;
1538 case 14:
1539 // Channel list box
1540 DLLmprintf(0, "Joining new public channel\n");
1541 {
1542 int selitem = 0;
1543 DLLmprintf(0, "Joining new public channel\n");
1544 selitem = DLLOldListGetSelectedIndex(chan_list);
1545 if (!JoinNewLobby(chan_info[selitem].origname)) {
1546 ret = 0;
1547 exit_menu = 0;
1548 } else {
1549 char txtmessage[200];
1550 char cleanlobby[50];
1551 memset(cleanlobby, 0, 29);
1552 strcpy(cleanlobby, chan_info[selitem].origname + 1);
1553 for (int l = 0; l < 18; l++) {
1554 if (cleanlobby[l] == '_')
1555 cleanlobby[l] = ' ';
1556 }
1557 snprintf(txtmessage, sizeof(txtmessage), TXT_PXO_INNEWLOBBY, cleanlobby);
1558 DLLDoMessageBox(TXT_PXO_MASTERTRACKER, txtmessage, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
1559 }
1560 }
1561
1562 break;
1563 case 15:
1564 // Send a message
1565 DLLOldEditGetText(send_edit, sendline, MAX_CHAT_SEND_LEN - 1);
1566 if (*sendline == '\0') {
1567 break;
1568 }
1569 DLLOldEditSetText(send_edit, "");
1570 p = SendChatString(sendline);
1571 if (p) {
1572 DLLUIConsoleGadgetputs(console_item, p);
1573 DLLUIConsoleGadgetputs(console_item, "\x0a\x0d");
1574 }
1575 DLLNewUIWindowSetFocusOnEditGadget(send_edit, main_wnd);
1576 break;
1577 }
1578 }
1579 shutdownpxo:
1580
1581 DLLNewUIWindowDestroy(main_wnd);
1582 DLLOldListRemoveAll(chan_list);
1583 DLLOldListRemoveAll(user_list);
1584 for (i = 0; i < MAX_CHAT_CHANNELS; i++) {
1585 if (chan_ti[i] != nullptr)
1586 DLLRemoveUITextItem(chan_ti[i]);
1587 chan_ti[i] = nullptr;
1588 }
1589 for (i = 0; i < CHAT_MAX_USERLIST; i++) {
1590 if (user_ti[i] != nullptr)
1591 DLLRemoveUITextItem(user_ti[i]);
1592 user_ti[i] = nullptr;
1593 }
1594 *DLLNewUIWindow_alpha = oldalpha;
1595 DLLmprintf(0, "Disconnecting from PXO.\n");
1596 DisconnectFromChatServer();
1597 ChatStarted = 0;
1598 DLLmprintf(0, "Disconnected.\n");
1599 DLLToggleUICallback(1);
1600
1601 // Delete all those items we created
1602 DLLDeleteUIItem(main_wnd);
1603 DLLDeleteUIItem(priv_hs);
1604 DLLDeleteUIItem(join_lobby_hs);
1605 DLLDeleteUIItem(join_chan_hs);
1606 DLLDeleteUIItem(find_hs);
1607 DLLDeleteUIItem(get_pilot_hs);
1608 DLLDeleteUIItem(game_hs);
1609 DLLDeleteUIItem(enter_hs);
1610 DLLDeleteUIItem(user_list);
1611 DLLDeleteUIItem(chan_list);
1612 DLLDeleteUIItem(send_edit);
1613 DLLDeleteUIItem(console_item);
1614 DLLDeleteUIItem(lobby_txt_gadget);
1615
1616 DLLRemoveUITextItem(title_text);
1617 DLLRemoveUITextItem(lobby_text);
1618 DLLRemoveUITextItem(cancel_on_text);
1619 DLLRemoveUITextItem(cancel_off_text);
1620 DLLRemoveUITextItem(exit_on_text);
1621 DLLRemoveUITextItem(exit_off_text);
1622 DLLRemoveUITextItem(priv_msg_on_text);
1623 DLLRemoveUITextItem(priv_msg_off_text);
1624 DLLRemoveUITextItem(join_lobby_on_text);
1625 DLLRemoveUITextItem(join_lobby_off_text);
1626 DLLRemoveUITextItem(join_chan_on_text);
1627 DLLRemoveUITextItem(join_chan_off_text);
1628 DLLRemoveUITextItem(find_pilot_on_text);
1629 DLLRemoveUITextItem(find_pilot_off_text);
1630 DLLRemoveUITextItem(get_pilot_on_text);
1631 DLLRemoveUITextItem(get_pilot_off_text);
1632 DLLRemoveUITextItem(game_on_text);
1633 DLLRemoveUITextItem(game_off_text);
1634 DLLRemoveUITextItem(blank_text);
1635 DLLRemoveUITextItem(send_on_text);
1636 DLLRemoveUITextItem(send_off_text);
1637 return ret;
1638 }
1639
1640 #define SORT_GAMENAME 30
1641 #define SORT_GAMETYPE 31
1642 #define SORT_MISSION 32
1643 #define SORT_LEVEL 33
1644 #define SORT_PLAYERS 34
1645 #define SORT_PING 35
1646
1647 int sort_type;
1648
1649 bool invert_sort_gamename = true;
1650 bool invert_sort_gametype = true;
1651 bool invert_sort_mission = true;
1652 bool invert_sort_levels = true;
1653 bool invert_sort_players = true;
1654 bool invert_sort_ping = true;
1655
1656 int net_game_compare(const void *arg1, const void *arg2) {
1657
1658 network_game *net1 = (network_game *)arg1;
1659 network_game *net2 = (network_game *)arg2;
1660
1661 if ((!arg1) || (!arg2))
1662 return 0;
1663
1664 switch (sort_type) {
1665 case SORT_GAMENAME: {
1666 return stricmp(net1->name, net2->name);
1667 } break;
1668 case SORT_GAMETYPE: {
1669 return stricmp(net1->scriptname, net2->scriptname);
1670 } break;
1671 case SORT_MISSION: {
1672 return stricmp(net1->mission_name, net2->mission_name);
1673 } break;
1674 case SORT_LEVEL: {
1675 if (net1->level_num == net2->level_num)
1676 return 0;
1677 else
1678 return (net1->level_num - net2->level_num);
1679 } break;
1680 case SORT_PLAYERS: {
1681 if (net1->curr_num_players == net2->curr_num_players)
1682 return 0;
1683 else
1684 return (net1->curr_num_players - net2->curr_num_players);
1685 } break;
1686 case SORT_PING: {
1687 if (net1->server_response_time == net2->server_response_time)
1688 return 0;
1689 else
1690 return (net1->server_response_time < net2->server_response_time) ? 1 : -1;
1691 } break;
1692 }
1693 return 0;
1694 }
1695
1696 void ResortGameList(void *lb, int type, bool invert) {
1697
1698 if (!*DLLNum_network_games_known) {
1699 return;
1700 }
1701 // Make a copy of the games list
1702 network_game *net_game_copy;
1703 net_game_copy = (network_game *)DLLmem_malloc(sizeof(network_game) * (*DLLNum_network_games_known));
1704 memcpy(net_game_copy, &DLLNetwork_games[0], sizeof(network_game) * (*DLLNum_network_games_known));
1705
1706 // Set the sort type
1707 sort_type = type;
1708
1709 // Do the actual sort
1710 qsort(net_game_copy, *DLLNum_network_games_known, sizeof(network_game), net_game_compare);
1711
1712 // Now populate the list in the order sorted...
1713 NextGameItemNo = 0;
1714 DLLListRemoveAll(lb);
1715 int i;
1716 if (!invert) {
1717 for (i = 0; i < *DLLNum_network_games_known; i++) {
1718 int pxo_item = GetPXOItemByHandle(net_game_copy[i].handle);
1719 if (pxo_item != -1) {
1720 PXOGamelist[pxo_item].lb_no = NextGameItemNo;
1721 NextGameItemNo++;
1722 DLLListAddItem(lb, PXOGamelist[pxo_item].ti);
1723 }
1724 }
1725 } else {
1726 for (i = *DLLNum_network_games_known; i >= 0; i--) {
1727 int pxo_item = GetPXOItemByHandle(net_game_copy[i].handle);
1728 if (pxo_item != -1) {
1729 PXOGamelist[pxo_item].lb_no = NextGameItemNo;
1730 NextGameItemNo++;
1731 DLLListAddItem(lb, PXOGamelist[pxo_item].ti);
1732 }
1733 }
1734 }
1735
1736 DLLmem_free(net_game_copy);
1737 }
1738
1739 #define GET_MT_GAME_TIME 5
1740 #define REQ_GAME_LIST_INTERVAL 8
1741
1742 #define GET_INFO_ID 50
1743
1744 int SearchMasterTrackerGameMenu() {
1745
1746 int exit_menu = 0;
1747 int cury = 40;
1748 int ret = 0;
1749 int res;
1750
1751 game_list *games = nullptr;
1752 int i = 0;
1753 float last_req_time;
1754 char selgame[200];
1755 void *selti = nullptr;
1756 void *return_text_on = DLLCreateNewUITextItem(TXT_PXO_RETURNTOCHAT, UICOL_HOTSPOT_HI);
1757 void *return_text_off = DLLCreateNewUITextItem(TXT_PXO_RETURNTOCHAT, UICOL_HOTSPOT_LO);
1758 void *game_head_text = DLLCreateNewUITextItem(TXT_PXO_GAMELISTHDR, UICOL_TEXT_NORMAL);
1759 void *exit_on_text = DLLCreateNewUITextItem(TXT_PXO_EXIT, UICOL_HOTSPOT_HI);
1760 void *exit_off_text = DLLCreateNewUITextItem(TXT_PXO_EXIT, UICOL_HOTSPOT_LO);
1761 void *join_on_text = DLLCreateNewUITextItem(TXT_PXO_JOINSEL, UICOL_HOTSPOT_HI);
1762 void *join_off_text = DLLCreateNewUITextItem(TXT_PXO_JOINSEL, UICOL_HOTSPOT_LO);
1763 void *start_on_text = DLLCreateNewUITextItem(TXT_PXO_STARTNEW, UICOL_HOTSPOT_HI);
1764 void *start_off_text = DLLCreateNewUITextItem(TXT_PXO_STARTNEW, UICOL_HOTSPOT_LO);
1765
1766 void *gname_on_text = DLLCreateNewUITextItem(TXT_PXO_GAMENAME2, UICOL_HOTSPOT_HI);
1767 void *gname_off_text = DLLCreateNewUITextItem(TXT_PXO_GAMENAME2, UICOL_HOTSPOT_LO);
1768 void *gtype_on_text = DLLCreateNewUITextItem(TXT_PXO_GAMETYPE, UICOL_HOTSPOT_HI);
1769 void *gtype_off_text = DLLCreateNewUITextItem(TXT_PXO_GAMETYPE, UICOL_HOTSPOT_LO);
1770 void *msn_on_text = DLLCreateNewUITextItem(TXT_PXO_MISSION, UICOL_HOTSPOT_HI);
1771 void *msn_off_text = DLLCreateNewUITextItem(TXT_PXO_MISSION, UICOL_HOTSPOT_LO);
1772 void *lvl_on_text = DLLCreateNewUITextItem(TXT_PXO_LEVEL, UICOL_HOTSPOT_HI);
1773 void *lvl_off_text = DLLCreateNewUITextItem(TXT_PXO_LEVEL, UICOL_HOTSPOT_LO);
1774 void *plrs_on_text = DLLCreateNewUITextItem(TXT_PXO_PLAYERS, UICOL_HOTSPOT_HI);
1775 void *plrs_off_text = DLLCreateNewUITextItem(TXT_PXO_PLAYERS, UICOL_HOTSPOT_LO);
1776 void *ping_on_text = DLLCreateNewUITextItem(TXT_PXO_PING, UICOL_HOTSPOT_HI);
1777 void *ping_off_text = DLLCreateNewUITextItem(TXT_PXO_PING, UICOL_HOTSPOT_LO);
1778
1779 char fmt_textstr[200];
1780 snprintf(fmt_textstr, sizeof(fmt_textstr), TXT_PXO_MAKEGAMEDEFAULT, 28);
1781 void *default_on_text = DLLCreateNewUITextItem(fmt_textstr, UICOL_HOTSPOT_HI);
1782 snprintf(fmt_textstr, sizeof(fmt_textstr), TXT_PXO_MAKEGAMEDEFAULT, 28);
1783
1784 void *default_off_text = DLLCreateNewUITextItem(fmt_textstr, UICOL_HOTSPOT_LO);
1785 void *game_hdr_text = DLLCreateNewUITextItem(TXT_PXO_GAME_HDR, UICOL_WINDOW_TITLE);
1786
1787 void *info_on_text = DLLCreateNewUITextItem("", UICOL_HOTSPOT_HI);
1788 void *info_off_text = DLLCreateNewUITextItem("", UICOL_HOTSPOT_LO);
1789
1790 memset(PXOGamelist, 0, sizeof(PXOGamelist));
1791 NextGameItemNo = 0;
1792
1793 void *return_hs;
1794 void *set_dft_hs;
1795
1796 void *net_game_txt_items[MAX_NET_GAMES];
1797 int a;
1798 bool hardexit = false;
1799 for (a = 0; a < MAX_NET_GAMES; a++)
1800 net_game_txt_items[a] = nullptr;
1801 uint8_t oldalpha = *DLLNewUIWindow_alpha;
1802
1803 DLLSetScreenMode(SM_MENU);
1804 *DLLNewUIWindow_alpha = 255;
1805
1806 void *main_wnd = DLLNewUIWindowCreate(0, 0, 640, 480, UIF_PROCESS_ALL);
1807
1808 void *screen_header = DLLTextCreate(main_wnd, game_hdr_text, 5, 15, UIF_CENTER);
1809 cury += 30;
1810 void *start_hs = DLLHotSpotCreate(main_wnd, 7, KEY_S, start_off_text, start_on_text, 320, cury, 150, 15, UIF_CENTER);
1811 cury += 30; // 25;
1812
1813 int setdfty;
1814
1815 return_hs = DLLHotSpotCreate(main_wnd, 8, KEY_R, return_text_off, return_text_on, 490, cury, 250, 15, UIF_CENTER);
1816 cury += 20;
1817
1818 if (Bypass_chat) {
1819
1820 snprintf(fmt_textstr, sizeof(fmt_textstr), TXT_PXO_MAKEGAMEDEFAULT, 29);
1821 default_on_text = DLLCreateNewUITextItem(fmt_textstr, UICOL_HOTSPOT_HI);
1822 snprintf(fmt_textstr, sizeof(fmt_textstr), TXT_PXO_MAKEGAMEDEFAULT, 29);
1823 default_off_text = DLLCreateNewUITextItem(fmt_textstr, UICOL_HOTSPOT_LO);
1824 setdfty = cury;
1825 set_dft_hs = DLLHotSpotCreate(main_wnd, 9, 0, default_off_text, default_on_text, 490, cury, 300, 15, UIF_CENTER);
1826 cury += 20;
1827 } else {
1828 snprintf(fmt_textstr, sizeof(fmt_textstr), TXT_PXO_MAKEGAMEDEFAULT, 28);
1829 default_on_text = DLLCreateNewUITextItem(fmt_textstr, UICOL_HOTSPOT_HI);
1830 snprintf(fmt_textstr, sizeof(fmt_textstr), TXT_PXO_MAKEGAMEDEFAULT, 28);
1831 default_off_text = DLLCreateNewUITextItem(fmt_textstr, UICOL_HOTSPOT_LO);
1832 setdfty = cury;
1833 set_dft_hs = DLLHotSpotCreate(main_wnd, 9, 0, default_off_text, default_on_text, 490, cury, 300, 15, UIF_CENTER);
1834 cury += 30;
1835 }
1836 // void * game_head = DLLTextCreate(main_wnd,game_head_text,45,cury,0);
1837
1838 void *gname_hs = DLLHotSpotCreate(main_wnd, SORT_GAMENAME, 0, gname_off_text, gname_on_text, 44, cury,
1839 DLLgrtext_GetTextLineWidth(TXT_PXO_GAMENAME2) + 1, 15, 0);
1840 void *gtype_hs = DLLHotSpotCreate(main_wnd, SORT_GAMETYPE, 0, gtype_off_text, gtype_on_text, 215, cury,
1841 DLLgrtext_GetTextLineWidth(TXT_PXO_GAMETYPE) + 1, 15, 0);
1842 void *msn_hs = DLLHotSpotCreate(main_wnd, SORT_MISSION, 0, msn_off_text, msn_on_text, 320, cury,
1843 DLLgrtext_GetTextLineWidth(TXT_PXO_MISSION) + 1, 15, 0);
1844 void *lvl_hs = DLLHotSpotCreate(main_wnd, SORT_LEVEL, 0, lvl_off_text, lvl_on_text, 428, cury,
1845 DLLgrtext_GetTextLineWidth(TXT_PXO_LEVEL) + 1, 15, 0);
1846 void *players_hs = DLLHotSpotCreate(main_wnd, SORT_PLAYERS, 0, plrs_off_text, plrs_on_text, 479, cury,
1847 DLLgrtext_GetTextLineWidth(TXT_PXO_PLAYERS) + 1, 15, 0);
1848 void *ping_hs = DLLHotSpotCreate(main_wnd, SORT_PING, 0, ping_off_text, ping_on_text, 549, cury,
1849 DLLgrtext_GetTextLineWidth(TXT_PXO_PING) + 1, 15, 0);
1850
1851 cury += 15;
1852 void *game_list = DLLListCreate(main_wnd, 6, 10, cury, 600, 230, UIF_CENTER | UILB_NOSORT);
1853 cury += 260;
1854 void *join_hs = DLLHotSpotCreate(main_wnd, 6, KEY_ENTER, join_off_text, join_on_text, 100, cury, 130, 15, 0);
1855 void *exit_hs = DLLHotSpotCreate(main_wnd, 5, KEY_ESC, exit_off_text, exit_on_text, 400, cury, 70, 15, 0);
1856
1857 void *info_hs = DLLHotSpotCreate(main_wnd, GET_INFO_ID, KEY_I, info_off_text, info_on_text, 1, 1, 1, 1, 0);
1858
1859 DLLNewUIWindowLoadBackgroundImage(main_wnd, "pxogame.ogf");
1860 DLLNewUIWindowOpen(main_wnd);
1861 *DLLNum_network_games_known = 0;
1862 int lastgamesfound = 0;
1863 int itemp;
1864 last_req_time = DLLtimer_GetTime();
1865 RequestGameList();
1866 *DLLNum_network_games_known = 0;
1867 DLLmprintf(0, "Waiting for Mastertracker response.\n");
1868
1869 // Menu loop
1870 while (!exit_menu) {
1871 if (ChatStarted)
1872 const char *p = GetChatText();
1873
1874 DLLDescentDefer();
1875 IdleGameTracker();
1876 games = GetGameList();
1877 res = DLLPollUI();
1878 if (games) {
1879 // DLLmprintf(0,"GetGameList() returned a gamedata.\n");
1880 for (i = 0; i < (MAX_GAME_LISTS_PER_PACKET * 4); i++) {
1881 // char *gn = games->game_name[i];
1882 if (games->game_type == GT_D3TNG) {
1883 DLLSearchForGamesPXO(games->game_server[i], games->game_port[i]);
1884 } else {
1885 if (games->game_server[i] && games->game_port[i]) {
1886 DLLmprintf(0, "Bad bad bad!!!!\n");
1887 DLLSearchForGamesPXO(games->game_server[i], games->game_port[i]);
1888 }
1889 }
1890 }
1891 games = nullptr;
1892 }
1893 if ((DLLtimer_GetTime() - last_req_time) > REQ_GAME_LIST_INTERVAL) {
1894 last_req_time = DLLtimer_GetTime();
1895 RequestGameList();
1896 *DLLMulti_Gamelist_changed = true;
1897 int selno = DLLListGetSelectedIndex(game_list);
1898 if (selno >= 0) {
1899 strcpy(selgame, DLLNetwork_games[selno].name);
1900 } else {
1901 selgame[0] = '\0';
1902 }
1903 }
1904 DLLUpdateAndPackGameList();
1905
1906 if ((itemp = DLLSearchForGamesPXO(0, 0)) || *DLLMulti_Gamelist_changed) {
1907 UpdateGamelist(game_list);
1908 }
1909
1910 if (res == -1) {
1911 continue;
1912 }
1913 // handle all UI results.
1914 switch (res) {
1915
1916 case 5:
1917 // Hard exit. Don't return to chat if in bypass chat mode
1918 hardexit = true;
1919 DLLNewUIWindowClose(main_wnd);
1920 exit_menu = 1;
1921 break;
1922 case 6:
1923 // Double click on listbox, or join selected hit.
1924 if (*DLLNum_network_games_known) {
1925 // Get the appropriate game address
1926 int gameno;
1927 gameno = DLLListGetSelectedIndex(game_list);
1928
1929 int gameid = GetGameByLBNo(gameno);
1930
1931 if (gameid == -1)
1932 break;
1933 gameno = gameid;
1934
1935 DLLmprintf(0, "Selected item is %s\n", DLLNetwork_games[gameno].name);
1936
1937 network_address s_address;
1938 s_address.connection_type = NP_TCP;
1939 memcpy(&s_address.address, &DLLNetwork_games[gameno].addr, sizeof(network_address));
1940 s_address.port = DLLNetwork_games[gameno].addr.port;
1941 *DLLGame_is_master_tracker_game = 1;
1942 DLLMultiStartClient(nullptr);
1943
1944 if (DLLDoPlayerMouselookCheck(DLLNetwork_games[gameno].flags)) {
1945 char script_file[500];
1946 snprintf(script_file, sizeof(script_file), "%s.d3m", DLLNetwork_games[gameno].scriptname);
1947 if (DLLCheckGetD3M(script_file)) {
1948 // Check to see if this mission exists!
1949 if (DLLmsn_CheckGetMission(&s_address, DLLNetwork_games[gameno].mission)) {
1950 if ((DLLTryToJoinServer(&s_address))) {
1951 DLLmprintf(0, "Menu: Game joined!\n");
1952 DLLNewUIWindowClose(main_wnd);
1953 exit_menu = 1;
1954 ret = 1;
1955 } else {
1956 DLLNewUIWindowClose(main_wnd);
1957 DLLNewUIWindowOpen(main_wnd);
1958 }
1959 }
1960 }
1961 }
1962 } else {
1963 DLLListRemoveAll(game_list);
1964 last_req_time = DLLtimer_GetTime() - (REQ_GAME_LIST_INTERVAL * 2);
1965 DLLDoMessageBox(TXT_PXO_ERROR, TXT_PXO_NO_GAMES, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
1966 }
1967 break;
1968 case 7:
1969 // Start a new game
1970
1971 DLLNewUIWindowClose(main_wnd);
1972 *DLLGame_is_master_tracker_game = 1;
1973 if (StartMultiplayerGameMenu()) {
1974 exit_menu = 1;
1975 ret = 1;
1976 } else {
1977 DLLNewUIWindowOpen(main_wnd);
1978 }
1979 break;
1980 case 8:
1981 // We just want to return to chat, not totally exit PXO
1982 DLLNewUIWindowClose(main_wnd);
1983 exit_menu = 1;
1984 ret = 0;
1985 break;
1986 case 9:
1987 // Change the current selection
1988 {
1989 int bypass_chat_curr_val;
1990 DLLDatabaseReadInt("BypassChat", &bypass_chat_curr_val);
1991
1992 DLLRemoveUITextItem(default_on_text);
1993 DLLRemoveUITextItem(default_off_text);
1994 DLLGadgetDestroy(set_dft_hs);
1995 DLLDeleteUIItem(set_dft_hs);
1996 if (bypass_chat_curr_val) {
1997 bypass_chat_curr_val = 0;
1998 DLLDatabaseWriteInt("BypassChat", bypass_chat_curr_val);
1999 snprintf(fmt_textstr, sizeof(fmt_textstr), TXT_PXO_MAKEGAMEDEFAULT, 28);
2000 default_on_text = DLLCreateNewUITextItem(fmt_textstr, UICOL_HOTSPOT_HI);
2001 snprintf(fmt_textstr, sizeof(fmt_textstr), TXT_PXO_MAKEGAMEDEFAULT, 28);
2002 default_off_text = DLLCreateNewUITextItem(fmt_textstr, UICOL_HOTSPOT_LO);
2003 set_dft_hs =
2004 DLLHotSpotCreate(main_wnd, 9, 0, default_off_text, default_on_text, 490, setdfty, 300, 15, UIF_CENTER);
2005 } else {
2006 bypass_chat_curr_val = 1;
2007 DLLDatabaseWriteInt("BypassChat", bypass_chat_curr_val);
2008 snprintf(fmt_textstr, sizeof(fmt_textstr), TXT_PXO_MAKEGAMEDEFAULT, 29);
2009 default_on_text = DLLCreateNewUITextItem(fmt_textstr, UICOL_HOTSPOT_HI);
2010 snprintf(fmt_textstr, sizeof(fmt_textstr), TXT_PXO_MAKEGAMEDEFAULT, 29);
2011 default_off_text = DLLCreateNewUITextItem(fmt_textstr, UICOL_HOTSPOT_LO);
2012 set_dft_hs =
2013 DLLHotSpotCreate(main_wnd, 9, 0, default_off_text, default_on_text, 490, setdfty, 300, 15, UIF_CENTER);
2014 }
2015 }
2016 break;
2017 case GET_INFO_ID: {
2018 if (*DLLNum_network_games_known) {
2019 int gameno;
2020 gameno = DLLListGetSelectedIndex(game_list);
2021 int gameid = GetGameByLBNo(gameno);
2022 gameno = gameid;
2023 if (gameid == -1)
2024 break;
2025 DLLmprintf(0, "Selected item is %s\n", DLLNetwork_games[gameno].name);
2026 DLLShowNetgameInfo(&DLLNetwork_games[gameno]);
2027 }
2028 } break;
2029
2030 case SORT_GAMENAME: {
2031 DLLmprintf(0, "Sorting by game name.\n");
2032 invert_sort_gamename = !invert_sort_gamename;
2033 ResortGameList(game_list, res, invert_sort_gamename);
2034 } break;
2035 case SORT_GAMETYPE: {
2036 DLLmprintf(0, "Sorting by game type.\n");
2037 invert_sort_gametype = !invert_sort_gametype;
2038 ResortGameList(game_list, res, invert_sort_gametype);
2039 } break;
2040 case SORT_MISSION: {
2041 DLLmprintf(0, "Sorting by mission.\n");
2042 invert_sort_mission = !invert_sort_mission;
2043 ResortGameList(game_list, res, invert_sort_mission);
2044 } break;
2045 case SORT_LEVEL: {
2046 DLLmprintf(0, "Sorting by level.\n");
2047 invert_sort_levels = !invert_sort_levels;
2048 ResortGameList(game_list, res, invert_sort_levels);
2049 } break;
2050 case SORT_PLAYERS: {
2051 DLLmprintf(0, "Sorting by players.\n");
2052 invert_sort_players = !invert_sort_players;
2053 ResortGameList(game_list, res, invert_sort_players);
2054 } break;
2055 case SORT_PING: {
2056 DLLmprintf(0, "Sorting by ping.\n");
2057 invert_sort_ping = !invert_sort_ping;
2058 ResortGameList(game_list, res, invert_sort_ping);
2059 } break;
2060 }
2061 }
2062 DLLNewUIWindowDestroy(main_wnd);
2063
2064 *DLLNewUIWindow_alpha = oldalpha;
2065
2066 // Look for items that we need to remove
2067 for (i = 0; i < MAX_GAMELIST_ITEMS; i++) {
2068 if (PXOGamelist[i].used) {
2069 DLLRemoveUITextItem(PXOGamelist[i].ti);
2070 PXOGamelist[i].used = false;
2071 }
2072 }
2073
2074 /*
2075 for(a=0;a<MAX_NET_GAMES;a++)
2076 if(net_game_txt_items[a])
2077 DLLRemoveUITextItem(net_game_txt_items[a]);
2078 */
2079
2080 // Clean up
2081 DLLDeleteUIItem(main_wnd);
2082 DLLDeleteUIItem(game_list);
2083 // DLLDeleteUIItem(game_head);
2084 DLLDeleteUIItem(exit_hs);
2085 DLLDeleteUIItem(join_hs);
2086 DLLDeleteUIItem(start_hs);
2087 DLLDeleteUIItem(screen_header);
2088 DLLDeleteUIItem(set_dft_hs);
2089 DLLDeleteUIItem(return_hs);
2090 DLLDeleteUIItem(info_hs);
2091 DLLDeleteUIItem(gname_hs);
2092 DLLDeleteUIItem(gtype_hs);
2093 DLLDeleteUIItem(msn_hs);
2094 DLLDeleteUIItem(lvl_hs);
2095 DLLDeleteUIItem(players_hs);
2096 DLLDeleteUIItem(ping_hs);
2097
2098 DLLRemoveUITextItem(info_on_text);
2099 DLLRemoveUITextItem(info_off_text);
2100 DLLRemoveUITextItem(game_hdr_text);
2101 DLLRemoveUITextItem(return_text_on);
2102 DLLRemoveUITextItem(return_text_off);
2103 DLLRemoveUITextItem(game_head_text);
2104 DLLRemoveUITextItem(exit_on_text);
2105 DLLRemoveUITextItem(exit_off_text);
2106 DLLRemoveUITextItem(join_on_text);
2107 DLLRemoveUITextItem(join_off_text);
2108 DLLRemoveUITextItem(start_on_text);
2109 DLLRemoveUITextItem(start_off_text);
2110 DLLRemoveUITextItem(default_on_text);
2111 DLLRemoveUITextItem(default_off_text);
2112
2113 DLLRemoveUITextItem(gname_on_text);
2114 DLLRemoveUITextItem(gname_off_text);
2115 DLLRemoveUITextItem(gtype_on_text);
2116 DLLRemoveUITextItem(gtype_off_text);
2117 DLLRemoveUITextItem(msn_on_text);
2118 DLLRemoveUITextItem(msn_off_text);
2119 DLLRemoveUITextItem(lvl_on_text);
2120 DLLRemoveUITextItem(lvl_off_text);
2121 DLLRemoveUITextItem(plrs_on_text);
2122 DLLRemoveUITextItem(plrs_off_text);
2123 DLLRemoveUITextItem(ping_on_text);
2124 DLLRemoveUITextItem(ping_off_text);
2125
2126 if (hardexit)
2127 return -1;
2128
2129 if (!ret && !ChatStarted && Bypass_chat) {
2130 ChatStarted = 1;
2131 ret = MainMultiplayerMenu();
2132 }
2133 return ret;
2134 }
2135
2136 // This is just a function that does some debugging
2137 void CheckPXOForAnomalies() {
2138 int i, j;
2139 for (i = 0; i < MAX_NET_PLAYERS; i++) {
2140 if (!(DLLMNetPlayers[i].flags & NPF_CONNECTED))
2141 continue;
2142 for (j = 0; j < MAX_NET_PLAYERS; j++) {
2143 if (!(DLLMNetPlayers[j].flags & NPF_CONNECTED))
2144 continue;
2145 if (i == j)
2146 continue;
2147 if (stricmp(DLLMPlayers[i].tracker_id, DLLMPlayers[j].tracker_id) == 0) {
2148 // Ok, what we have here is multiple users with the same tracker ID.
2149 // This is bad. It could be user error, but it could be something worse.
2150 FILE *errfile;
2151 char errfilepath[_MAX_PATH];
2152 DLLddio_MakePath(errfilepath, DLLLocalD3Dir, "pxo.err", NULL);
2153 errfile = fopen(errfilepath, "at");
2154 if (errfile) {
2155 fprintf(errfile, "Dup TID: %s & %s / %s\n", DLLMPlayers[j].callsign, DLLMPlayers[i].callsign,
2156 DLLMPlayers[i].tracker_id);
2157 fclose(errfile);
2158 }
2159 }
2160 }
2161 }
2162 }
2163
2164 #define MT_DATA_UPDATE_INTERVAL 10 // 30 seconds
2165 void DoMTFrame() {
2166 int i;
2167 int rcode;
2168 IdleGameTracker();
2169 PollPTrackNet();
2170 // Periodically update the master tracker's info.
2171 if ((DLLtimer_GetTime() - LastTrackerDataUpdate) > MT_DATA_UPDATE_INTERVAL) {
2172 UpdateGameData(&DLLD3_tracker_info);
2173 LastTrackerDataUpdate = DLLtimer_GetTime();
2174 }
2175
2176 if (DLLNetgame->flags & NF_TRACK_RANK) {
2177 // Loop through all DLLMNetPlayers looking to see if we need to send or receive
2178 if (MTWritingPilot != -1) {
2179 // We are already sending a pilot
2180 rcode = SendD3PilotData(nullptr);
2181 if (rcode != 0) {
2182 if (rcode == 1) {
2183 // Copy data from the DLLMTPilotinfo[MTReadingPilot] struct here
2184 DLLMNetPlayers[MTWritingPilot].flags &= ~NPF_MT_WRITING_PILOT;
2185 DLLmprintf(0, "Pilot data wrote to the Mastertracker for Player[%d] %s (tid=%s).\n", MTWritingPilot,
2186 DLLMTPilotinfo[MTWritingPilot].pilot_name, DLLMTPilotinfo[MTWritingPilot].tracker_id);
2187 MTWritingPilot = -1;
2188
2189 } else {
2190 DLLMNetPlayers[MTWritingPilot].flags &= ~NPF_MT_WRITING_PILOT;
2191 DLLmprintf(0, "Pilot write to the mastertracker failed. Error code %d.\n", rcode);
2192 MTWritingPilot = -1;
2193 }
2194 }
2195 } else {
2196 // See if se need to look for another
2197 for (i = 0; i < MAX_NET_PLAYERS; i++) {
2198
2199 if (DLLMNetPlayers[i].flags & NPF_MT_WRITING_PILOT) {
2200 if ((!(DLLMNetPlayers[i].flags & NPF_MT_READING_PILOT)) &&
2201 (DLLMNetPlayers[i].flags & NPF_MT_HAS_PILOT_DATA)) {
2202 strcpy(DLLMTPilotinfo[i].tracker_id, DLLMPlayers[i].tracker_id);
2203 strcpy(DLLMTPilotinfo[i].pilot_name, DLLMPlayers[i].callsign);
2204 DLLMTPilotinfo[i].kills = DLLMPlayers[i].kills;
2205 DLLMTPilotinfo[i].deaths = DLLMPlayers[i].deaths;
2206 DLLMTPilotinfo[i].suicides = DLLMPlayers[i].suicides;
2207 DLLMTPilotinfo[i].rank = (DLLMPlayers[i].rank * 65536.0);
2208 DLLmprintf(0, "Sending pilot %d rank of %f\n", i, DLLMTPilotinfo[i].rank / 65536.0);
2209
2210 DLLMTPilotinfo[i].lateral_thrust = DLLMPlayers[i].lateral_thrust;
2211 DLLMTPilotinfo[i].rotational_thrust = DLLMPlayers[i].rotational_thrust;
2212 DLLMTPilotinfo[i].online_time += DLLtimer_GetTime() - DLLMPlayers[i].time_in_game;
2213 DLLMTPilotinfo[i].sliding_pct = 0; // FIXME
2214 DLLMPlayers[i].time_in_game = DLLtimer_GetTime(); // when we write this data multiple times we need this
2215
2216 DLLmprintf(0, "Sending User info to the Mastertracker for Player[%d] %s (tid=%s).\n", i,
2217 DLLMTPilotinfo[i].pilot_name, DLLMTPilotinfo[i].tracker_id);
2218 SendD3PilotData(&DLLMTPilotinfo[i]);
2219
2220 MTWritingPilot = i;
2221 i = MAX_NET_PLAYERS + 1;
2222 break;
2223 } else {
2224 // If we never read this pilot's stats, we really don't care what they were.
2225 DLLMNetPlayers[i].flags &= ~NPF_MT_READING_PILOT;
2226 DLLMNetPlayers[i].flags &= ~NPF_MT_WRITING_PILOT;
2227 DLLmprintf(0, "Didn't write Mastertracker stats for %s because we never received any from the tracker!\n",
2228 DLLMPlayers[i].callsign);
2229 }
2230 }
2231 }
2232 }
2233 // Don't want to read and write at the same time at this point
2234 if (MTWritingPilot == -1) {
2235 if (MTReadingPilot != -1) {
2236 // We are already waiting on a pilot
2237 rcode = GetD3PilotData(nullptr, nullptr, nullptr);
2238 if (rcode != 0) {
2239 if (rcode == 1) {
2240 DLLMNetPlayers[MTReadingPilot].flags &= ~NPF_MT_READING_PILOT;
2241 // Copy data into the DLLMTPilotinfo[MTReadingPilot] struct here
2242 DLLMPlayers[MTReadingPilot].kills = DLLMTPilotinfo[MTReadingPilot].kills;
2243 DLLMPlayers[MTReadingPilot].deaths = DLLMTPilotinfo[MTReadingPilot].deaths;
2244 DLLMPlayers[MTReadingPilot].suicides = DLLMTPilotinfo[MTReadingPilot].suicides;
2245 DLLMPlayers[MTReadingPilot].rank = DLLMTPilotinfo[MTReadingPilot].rank / 65536.0;
2246 DLLmprintf(0, "Read pilot %s rank of %f\n", DLLMPlayers[MTReadingPilot].callsign,
2247 DLLMPlayers[MTReadingPilot].rank);
2248 DLLMPlayers[MTReadingPilot].lateral_thrust = DLLMTPilotinfo[MTReadingPilot].lateral_thrust;
2249 DLLMPlayers[MTReadingPilot].rotational_thrust = DLLMTPilotinfo[MTReadingPilot].rotational_thrust;
2250 // DLLMPlayers[MTReadingPilot].time_in_game = DLLMTPilotinfo[MTReadingPilot].online_time;
2251 // Something = DLLMTPilotinfo[i].sliding_pct;//FIXME
2252
2253 DLLMNetPlayers[MTReadingPilot].flags |= NPF_MT_HAS_PILOT_DATA;
2254 DLLmprintf(0, "Pilot data received from the Mastertracker for Player[%d] %s (tid=%s).\n", MTReadingPilot,
2255 DLLMTPilotinfo[MTReadingPilot].pilot_name, DLLMTPilotinfo[MTReadingPilot].tracker_id);
2256 MTReadingPilot = -1;
2257 } else {
2258 // DLLMNetPlayers[MTReadingPilot].flags &= ~NPF_MT_READING_PILOT;
2259 DLLmprintf(0, "Pilot read from mastertracker failed. Error code %d.\n", rcode);
2260 MTReadingPilot = -1;
2261 }
2262 }
2263 } else {
2264 // See if se need to look for another
2265 for (i = 0; i < MAX_NET_PLAYERS; i++) {
2266 if (DLLMNetPlayers[i].flags & NPF_MT_READING_PILOT) {
2267 MTReadingPilot = i;
2268 DLLmprintf(0, "Requesting User info from the Mastertracker for Player[%d] %s (tid=%s).\n", i,
2269 DLLMTPilotinfo[i].pilot_name, DLLMTPilotinfo[i].tracker_id);
2270 GetD3PilotData(&DLLMTPilotinfo[i], DLLMPlayers[i].callsign, DLLMPlayers[i].tracker_id);
2271 CheckPXOForAnomalies();
2272 break;
2273 }
2274 }
2275 }
2276 }
2277 }
2278 }
2279
2280 void DoMTGameOver(void) {
2281 int i;
2282
2283 DLLShowProgressScreen(TXT_PXO_WRITINGGAMESTATS, nullptr);
2284
2285 if (DLLNetgame->local_role != LR_SERVER) {
2286 return;
2287 }
2288 // Send all player info to the mastertracker
2289 for (i = 0; i < MAX_NET_PLAYERS; i++) {
2290 if ((DLLMNetPlayers[i].flags & NPF_CONNECTED) || (DLLMNetPlayers[i].flags & NPF_MT_WRITING_PILOT)) {
2291 if (!(DLLMNetPlayers[i].flags & NPF_MT_READING_PILOT)) {
2292 if (DLLMNetPlayers[i].flags & NPF_MT_HAS_PILOT_DATA) // Security will do this for us
2293 {
2294 strcpy(DLLMTPilotinfo[i].tracker_id, DLLMPlayers[i].tracker_id);
2295 strcpy(DLLMTPilotinfo[i].pilot_name, DLLMPlayers[i].callsign);
2296 DLLMTPilotinfo[i].kills = DLLMPlayers[i].kills;
2297 DLLMTPilotinfo[i].deaths = DLLMPlayers[i].deaths;
2298 DLLMTPilotinfo[i].suicides = DLLMPlayers[i].suicides;
2299 DLLMTPilotinfo[i].rank = DLLMPlayers[i].rank * 65536.0;
2300 DLLMTPilotinfo[i].lateral_thrust = DLLMPlayers[i].lateral_thrust;
2301 DLLMTPilotinfo[i].rotational_thrust = DLLMPlayers[i].rotational_thrust;
2302 DLLMTPilotinfo[i].online_time += DLLtimer_GetTime() - DLLMPlayers[i].time_in_game;
2303 DLLMTPilotinfo[i].sliding_pct = 0; // FIXME
2304 DLLmprintf(0, "Sending User info to the Mastertracker for Player[%d] %s (tid=%s).\n", i,
2305 DLLMTPilotinfo[i].pilot_name, DLLMTPilotinfo[i].tracker_id);
2306 DLLmprintf(0, "Sending pilot %d rank of %f\n", i, DLLMTPilotinfo[i].rank / 65536.0);
2307 SendD3PilotData(&DLLMTPilotinfo[i]);
2308 while (SendD3PilotData(nullptr) == 0) {
2309 DLLDescentDefer();
2310 }
2311 }
2312 }
2313 }
2314 }
2315 DLLShowProgressScreen(TXT_PXO_SENDINGGAMEOVER, nullptr);
2316 while (!SendGameOver())
2317 DLLDescentDefer();
2318 }
2319
2320 int MTVersionCheck() {
2321 #ifdef WIN32
2322 int rcode;
2323 InetGetFile *inetfile;
2324 char sznewdll[_MAX_PATH], szolddll[_MAX_PATH], szbakdll[_MAX_PATH];
2325 char fulldllpath[_MAX_PATH * 2];
2326 // char dllpath[_MAX_PATH];
2327 DLLAVInit = NULL;
2328 DLLAVCall = NULL;
2329 DLLAVClose = NULL;
2330 DLLAVGetVersion = NULL;
2331 DLLRunCheck = NULL;
2332 // Start by getting the current MT version and see if a newer is needed
2333 // Load the DLL and get it's version
2334
2335 // Specify the correct path
2336 DLLddio_MakePath(fulldllpath, DLLLocalD3Dir, "mtav.dll", NULL);
2337 if (!DLLmod_LoadModule(&MTAVDLLHandle, fulldllpath, MODF_LAZY)) {
2338 DLLmprintf(0, "Unable to load Mastertracker Auto version update DLL (mtav.dll)\n");
2339 // Try restoring a backup of the DLL
2340 DLLddio_MakePath(szolddll, DLLLocalD3Dir, "mtav.dll", NULL);
2341 DLLddio_MakePath(szbakdll, DLLLocalD3Dir, "mtav.bak", NULL);
2342 CopyFile(szbakdll, szolddll, FALSE);
2343 return 0;
2344 }
2345 DLLAVInit = (DLLAVInit_fp *)DLLmod_GetSymbol(&MTAVDLLHandle, "DLLAVInit", 4);
2346 if (!DLLAVInit) {
2347 DLLmprintf(0, "Unable to Find DLLAVInit() function in mtav.dll\n");
2348 DLLmod_FreeModule(&MTAVDLLHandle);
2349 // Try restoring a backup of the DLL
2350 DLLddio_MakePath(szolddll, DLLLocalD3Dir, "mtav.dll", NULL);
2351 DLLddio_MakePath(szbakdll, DLLLocalD3Dir, "mtav.bak", NULL);
2352 CopyFile(szbakdll, szolddll, FALSE);
2353 return 0;
2354 }
2355 DLLAVGetVersion = (DLLAVGetVersion_fp *)DLLmod_GetSymbol(&MTAVDLLHandle, "DLLAVGetVersion", 4);
2356 if (!DLLAVGetVersion) {
2357 DLLmprintf(0, "Unable to Find DLLAVGetVersion() function in mtav.dll\n");
2358 DLLmod_FreeModule(&MTAVDLLHandle);
2359 // Try restoring a backup of the DLL
2360 DLLddio_MakePath(szolddll, DLLLocalD3Dir, "mtav.dll", NULL);
2361 DLLddio_MakePath(szbakdll, DLLLocalD3Dir, "mtav.bak", NULL);
2362 CopyFile(szbakdll, szolddll, FALSE);
2363 return 0;
2364 }
2365 DLLRunCheck = (DLLRunCheck_fp *)DLLmod_GetSymbol(&MTAVDLLHandle, "DLLRunCheck", 4);
2366 if (!DLLRunCheck) {
2367 DLLmprintf(0, "Unable to Find DLLRunCheck() function in mtav.dll\n");
2368 DLLmod_FreeModule(&MTAVDLLHandle);
2369 // Try restoring a backup of the DLL
2370 DLLddio_MakePath(szolddll, DLLLocalD3Dir, "mtav.dll", NULL);
2371 DLLddio_MakePath(szbakdll, DLLLocalD3Dir, "mtav.bak", NULL);
2372 CopyFile(szbakdll, szolddll, FALSE);
2373 return 0;
2374 }
2375 uint32_t mtver;
2376 DLLAVGetVersion((int *)&mtver);
2377 if (MTAVersionCheck(mtver, MTUpdateURL)) {
2378 DLLmprintf(0, "VersionCheck() returned an unexpected return code!\n");
2379 DLLmod_FreeModule(&MTAVDLLHandle);
2380 return 0;
2381 }
2382 DLLmprintf(0, "Getting Version # from Mastertracker.\n");
2383 do {
2384 //
2385 rcode = MTAVersionCheck(0, NULL);
2386 } while (rcode == 0);
2387
2388 if (rcode == -2) {
2389 // Don't try anymore... it timed out.
2390 Login_aborted = true;
2391 }
2392 if (rcode == 1) {
2393 if (MTUpdateURL[0]) {
2394 // We need to get a new DLL
2395 DLLmprintf(0, "Mastertracker says we need a new version, which is at %s.\n", MTUpdateURL);
2396 sprintf(sznewdll, "%s\\newmtav.dll", DLLLocalD3Dir);
2397 DLLddio_MakePath(sznewdll, DLLLocalD3Dir, "newmtav.dll", NULL);
2398 inetfile = new InetGetFile(MTUpdateURL, sznewdll);
2399 while (1) {
2400 DLLPollUI();
2401 if (inetfile->IsFileError()) {
2402 // Error here
2403 DLLmprintf(0, "Mastertracker update DLL not received. Error code: %d.\n", inetfile->GetErrorCode());
2404 DLLmod_FreeModule(&MTAVDLLHandle);
2405 return 0;
2406 }
2407 if (inetfile->IsFileReceived()) {
2408 DLLmprintf(0, "Mastertracker update DLL received.\n");
2409 DLLmod_FreeModule(&MTAVDLLHandle);
2410 DLLddio_MakePath(szolddll, DLLLocalD3Dir, "mtav.dll", NULL);
2411 DLLddio_MakePath(szbakdll, DLLLocalD3Dir, "mtav.bak", NULL);
2412
2413 // We have the file, now backup & copy it and try to reload.
2414 CopyFile(szolddll, szbakdll, FALSE);
2415 CopyFile(sznewdll, szolddll, FALSE);
2416 return 0;
2417 }
2418 };
2419 } else {
2420 DLLmprintf(0, "Mastertracker says we are up to date\n");
2421 // Here is where we call into the DLL so it can do it's magic
2422 DLLAVInit(0);
2423 DLLmod_FreeModule(&MTAVDLLHandle);
2424 return 1;
2425 }
2426 } else {
2427 DLLmprintf(0, "Mastertracker timeout while getting version\n");
2428 DLLmod_FreeModule(&MTAVDLLHandle);
2429 return 0;
2430 }
2431 #endif
2432 return 1;
2433 }
2434
2435 int JoinNewLobby(const char *lobby) {
2436 int rcode;
2437 const char *p;
2438 DLLmprintf(0, "Entering new lobby");
2439 void *title_text = DLLCreateNewUITextItem(TXT_PXO_ENTERINGLOBBY, UICOL_WINDOW_TITLE);
2440
2441 void *cancel_on_text = DLLCreateNewUITextItem(TXT_PXO_CANCEL, UICOL_HOTSPOT_HI);
2442 void *cancel_off_text = DLLCreateNewUITextItem(TXT_PXO_CANCEL, UICOL_HOTSPOT_LO);
2443
2444 void *main_wnd = DLLNewUIGameWindowCreate(0, 256, 128, 128, UIF_CENTER | UIF_PROCESS_ALL | NUWF_TITLEMED);
2445 void *title = DLLTextCreate(main_wnd, title_text, 0, 7, UIF_CENTER);
2446 void *cancel_hs =
2447 DLLHotSpotCreate(main_wnd, 5, KEY_ESC, cancel_off_text, cancel_on_text, 20, 100, 70, 15, UIF_CENTER);
2448 DLLNewUIGameWindowOpen(main_wnd);
2449 do {
2450 rcode = SetNewChatChannel(lobby);
2451 p = GetChatText();
2452 if (p && pconsole) {
2453 DLLUIConsoleGadgetputs(pconsole, p);
2454 DLLUIConsoleGadgetputs(pconsole, "\x0a\x0d");
2455 }
2456 } while (rcode == 0);
2457
2458 DLLNewUIGameWindowClose(main_wnd);
2459 DLLNewUIGameWindowDestroy(main_wnd);
2460
2461 if (rcode == 1) {
2462 strcpy(DLLPXO_hosted_lobby_name, lobby);
2463 return 1;
2464 } else {
2465 DLLmprintf(0, "Unable to join lobby: %d\n", rcode);
2466 char txtmessage[200];
2467 char cleanlobby[50];
2468 memset(cleanlobby, 0, 29);
2469 strcpy(cleanlobby, lobby + 1);
2470 for (int l = 0; l < 18; l++) {
2471 if (cleanlobby[l] == '_')
2472 cleanlobby[l] = ' ';
2473 }
2474 snprintf(txtmessage, sizeof(txtmessage), TXT_PXO_CANTJOINLOBBY, cleanlobby);
2475 DLLDoMessageBox(TXT_PXO_MASTERTRACKER, txtmessage, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
2476 return 0;
2477 }
2478
2479 DLLDeleteUIItem(main_wnd);
2480 DLLDeleteUIItem(title);
2481 DLLDeleteUIItem(cancel_hs);
2482
2483 DLLRemoveUITextItem(title_text);
2484 DLLRemoveUITextItem(cancel_on_text);
2485 DLLRemoveUITextItem(cancel_off_text);
2486 }
2487
2488 const char *SendWhisper(const char *name) {
2489
2490 int exit_menu = 0;
2491 const char *p;
2492 char message[MAX_CHAT_SEND_LEN];
2493 char pilot_name[MAX_CHAT_SEND_LEN];
2494 static char fmt_msg[MAX_CHAT_SEND_LEN * 2];
2495 void *title_text = DLLCreateNewUITextItem(TXT_PXO_PRIVATEMESSAGE, UICOL_WINDOW_TITLE);
2496
2497 void *cancel_on_text = DLLCreateNewUITextItem(TXT_PXO_CANCEL, UICOL_HOTSPOT_HI);
2498 void *cancel_off_text = DLLCreateNewUITextItem(TXT_PXO_CANCEL, UICOL_HOTSPOT_LO);
2499 void *send_on_text = DLLCreateNewUITextItem(TXT_PXO_SEND, UICOL_HOTSPOT_HI);
2500 void *send_off_text = DLLCreateNewUITextItem(TXT_PXO_SEND, UICOL_HOTSPOT_LO);
2501
2502 void *pilot_text = DLLCreateNewUITextItem(TXT_PXO_PILOTNAME, UICOL_TEXT_NORMAL);
2503 void *message_text = DLLCreateNewUITextItem(TXT_PXO_MESSAGE, UICOL_TEXT_NORMAL);
2504
2505 void *main_wnd = DLLNewUIGameWindowCreate(0, 0, 384, 256, UIF_PROCESS_ALL | UIF_CENTER | NUWF_TITLEMED);
2506
2507 void *title = DLLTextCreate(main_wnd, title_text, 0, 7, UIF_CENTER);
2508 void *pilot = DLLTextCreate(main_wnd, pilot_text, 50, 55, 0);
2509 void *message_t = DLLTextCreate(main_wnd, message_text, 50, 110, 0);
2510 void *user_edit = DLLEditCreate(main_wnd, 10, 50, 75, 130, 15, 0);
2511 void *msg_edit = DLLEditCreate(main_wnd, 3, 50, 130, 200, 15, 0);
2512
2513 // HotSpotCreate(int item,int parentitem, int id, int key, int txtitemoff, int txtitemon, int x, int y, int w, int h,
2514 // int flags,int winnum)
2515 void *cancel_hs =
2516 DLLHotSpotCreate(main_wnd, UID_CANCEL, KEY_ESC, cancel_on_text, cancel_off_text, 130, 256 - 80, 60, 20, 0);
2517 void *send_hs = DLLHotSpotCreate(main_wnd, UID_OK, KEY_ENTER, send_on_text, send_off_text, 60, 256 - 80, 60, 20, 0);
2518 DLLNewUIGameWindowOpen(main_wnd);
2519 // DLLNewUIWindowSetFocusOnEditGadget(msg_edit,main_wnd);
2520 DLLEditSetText(user_edit, name);
2521 while (!exit_menu) {
2522 int res;
2523
2524 res = DLLDoUI();
2525
2526 // handle all UI results.
2527
2528 switch (res) {
2529
2530 case 3:
2531 case UID_OK:
2532 DLLEditGetText(user_edit, pilot_name, MAX_CHAT_SEND_LEN);
2533 DLLEditGetText(msg_edit, message, MAX_CHAT_SEND_LEN);
2534 snprintf(fmt_msg, sizeof(fmt_msg), "/msg %s %s", pilot_name, message);
2535 p = SendChatString(fmt_msg);
2536 if (p && pconsole) {
2537 DLLUIConsoleGadgetputs(pconsole, p);
2538 DLLUIConsoleGadgetputs(pconsole, "\x0a\x0d");
2539 }
2540 exit_menu = 1;
2541 break;
2542 case UID_CANCEL:
2543 exit_menu = 1;
2544 break;
2545 }
2546 }
2547
2548 DLLNewUIGameWindowClose(main_wnd);
2549 DLLNewUIGameWindowDestroy(main_wnd);
2550
2551 // Clean up
2552 DLLRemoveUITextItem(title_text);
2553 DLLRemoveUITextItem(cancel_on_text);
2554 DLLRemoveUITextItem(cancel_off_text);
2555 DLLRemoveUITextItem(send_on_text);
2556 DLLRemoveUITextItem(send_off_text);
2557 DLLRemoveUITextItem(pilot_text);
2558 DLLRemoveUITextItem(message_text);
2559
2560 DLLDeleteUIItem(main_wnd);
2561 DLLDeleteUIItem(title);
2562 DLLDeleteUIItem(pilot);
2563 DLLDeleteUIItem(message_t);
2564 DLLDeleteUIItem(user_edit);
2565 DLLDeleteUIItem(msg_edit);
2566 DLLDeleteUIItem(cancel_hs);
2567 DLLDeleteUIItem(send_hs);
2568
2569 return "";
2570 }
2571
2572 int JoinPrivateLobby() {
2573 int exit_menu = 0;
2574 int ret = 0;
2575 char message[MAX_CHAT_SEND_LEN];
2576 char priv_channel[MAX_CHAT_SEND_LEN];
2577
2578 void *title_text = DLLCreateNewUITextItem(TXT_PXO_JOINPRIV, UICOL_WINDOW_TITLE);
2579
2580 void *cancel_on_text = DLLCreateNewUITextItem(TXT_PXO_CANCEL, UICOL_HOTSPOT_HI);
2581 void *cancel_off_text = DLLCreateNewUITextItem(TXT_PXO_CANCEL, UICOL_HOTSPOT_LO);
2582 void *join_on_text = DLLCreateNewUITextItem(TXT_PXO_JOIN, UICOL_HOTSPOT_HI);
2583 void *join_off_text = DLLCreateNewUITextItem(TXT_PXO_JOIN, UICOL_HOTSPOT_LO);
2584
2585 void *channel_text = DLLCreateNewUITextItem(TXT_PXO_CHANNELNAME, UICOL_TEXT_NORMAL);
2586
2587 void *main_wnd = DLLNewUIGameWindowCreate(0, 0, 256, 256, UIF_PROCESS_ALL | UIF_CENTER | NUWF_TITLELARGE);
2588
2589 void *title = DLLTextCreate(main_wnd, title_text, 0, 7, UIF_CENTER);
2590 void *channel_t = DLLTextCreate(main_wnd, channel_text, 50, 95, UIF_CENTER);
2591 void *chan_edit = DLLEditCreate(main_wnd, 3, 50, 115, 130, 15, UIF_CENTER);
2592
2593 // DLLNewUIWindowSetFocusOnEditGadget(chan_edit,main_wnd);
2594 // HotSpotCreate(int item,int parentitem, int id, int key, int txtitemoff, int txtitemon, int x, int y, int w, int h,
2595 // int flags,int winnum)
2596 void *cancel_hs =
2597 DLLHotSpotCreate(main_wnd, UID_CANCEL, KEY_ESC, cancel_on_text, cancel_off_text, 130, 256 - 80, 60, 20, 0);
2598 void *join_hs = DLLHotSpotCreate(main_wnd, UID_OK, KEY_ENTER, join_on_text, join_off_text, 60, 256 - 80, 60, 20, 0);
2599 DLLNewUIGameWindowOpen(main_wnd);
2600 while (!exit_menu) {
2601 int res;
2602
2603 res = DLLDoUI();
2604
2605 // handle all UI results.
2606
2607 switch (res) {
2608 case 3:
2609 case UID_OK: {
2610 DLLEditGetText(chan_edit, priv_channel, MAX_CHAT_SEND_LEN);
2611 for (uint32_t i = 0; i < strlen(priv_channel); i++) {
2612 if (priv_channel[i] == ' ') {
2613 priv_channel[i] = '_';
2614 }
2615 }
2616 snprintf(message, sizeof(message), "+%s", priv_channel);
2617 ret = JoinNewLobby(message);
2618 exit_menu = 1;
2619 if (ret) {
2620 char txtmessage[200];
2621 char cleanlobby[50];
2622 memset(cleanlobby, 0, 29);
2623 strcpy(cleanlobby, message + 1);
2624 for (int l = 0; l < 18; l++) {
2625 if (cleanlobby[l] == '_')
2626 cleanlobby[l] = ' ';
2627 }
2628 snprintf(txtmessage, sizeof(txtmessage), TXT_PXO_INNEWLOBBY, cleanlobby);
2629 DLLDoMessageBox(TXT_PXO_MASTERTRACKER, txtmessage, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
2630 *DLLNum_network_games_known = 0;
2631 }
2632 } break;
2633 case UID_CANCEL:
2634 exit_menu = 1;
2635 break;
2636 }
2637 }
2638
2639 DLLNewUIGameWindowClose(main_wnd);
2640 DLLNewUIGameWindowDestroy(main_wnd);
2641
2642 DLLRemoveUITextItem(title_text);
2643 DLLRemoveUITextItem(cancel_on_text);
2644 DLLRemoveUITextItem(cancel_off_text);
2645 DLLRemoveUITextItem(join_on_text);
2646 DLLRemoveUITextItem(join_off_text);
2647 DLLRemoveUITextItem(channel_text);
2648
2649 DLLDeleteUIItem(main_wnd);
2650 DLLDeleteUIItem(title);
2651 DLLDeleteUIItem(channel_t);
2652 DLLDeleteUIItem(chan_edit);
2653 DLLDeleteUIItem(cancel_hs);
2654 DLLDeleteUIItem(join_hs);
2655 return ret;
2656 }
2657
2658 int FindPilot() {
2659
2660 int exit_menu = 0;
2661 const char *p;
2662 char message[MAX_CHAT_SEND_LEN];
2663 char pilot_name[MAX_CHAT_SEND_LEN];
2664 static char fmt_msg[MAX_CHAT_SEND_LEN * 2];
2665 void *title_text = DLLCreateNewUITextItem(TXT_PXO_FINDPILOT, UICOL_WINDOW_TITLE);
2666
2667 void *cancel_on_text = DLLCreateNewUITextItem(TXT_PXO_CANCEL, UICOL_HOTSPOT_HI);
2668 void *cancel_off_text = DLLCreateNewUITextItem(TXT_PXO_CANCEL, UICOL_HOTSPOT_LO);
2669 void *search_on_text = DLLCreateNewUITextItem(TXT_PXO_SEARCH, UICOL_HOTSPOT_HI);
2670 void *search_off_text = DLLCreateNewUITextItem(TXT_PXO_SEARCH, UICOL_HOTSPOT_LO);
2671
2672 void *pilot_text = DLLCreateNewUITextItem(TXT_PXO_PILOTNAME, UICOL_TEXT_NORMAL);
2673
2674 void *main_wnd = DLLNewUIGameWindowCreate(0, 0, 256, 256, UIF_PROCESS_ALL | UIF_CENTER | NUWF_TITLEMED);
2675
2676 void *title_t = DLLTextCreate(main_wnd, title_text, 0, 7, UIF_CENTER);
2677 void *pilot_t = DLLTextCreate(main_wnd, pilot_text, 50, 95, UIF_CENTER);
2678 void *pilot_edit = DLLEditCreate(main_wnd, 3, 50, 115, 130, 15, UIF_CENTER);
2679
2680 // DLLNewUIWindowSetFocusOnEditGadget(pilot_edit,main_wnd);
2681 // HotSpotCreate(int item,int parentitem, int id, int key, int txtitemoff, int txtitemon, int x, int y, int w, int h,
2682 // int flags,int winnum)
2683 void *cancel_hs =
2684 DLLHotSpotCreate(main_wnd, UID_CANCEL, KEY_ESC, cancel_on_text, cancel_off_text, 130, 256 - 80, 60, 20, 0);
2685 void *search_hs =
2686 DLLHotSpotCreate(main_wnd, UID_OK, KEY_ENTER, search_on_text, search_off_text, 60, 256 - 80, 60, 20, 0);
2687 DLLNewUIGameWindowOpen(main_wnd);
2688 while (!exit_menu) {
2689 int res;
2690
2691 res = DLLDoUI();
2692
2693 // handle all UI results.
2694
2695 switch (res) {
2696 case 3:
2697 case UID_OK: {
2698 DLLEditGetText(pilot_edit, pilot_name, MAX_CHAT_SEND_LEN);
2699 DLLCreateSplashScreen(TXT_PXO_SEARCHINGPILOT, 1);
2700 p = GetChannelByUser(pilot_name);
2701 while (p == nullptr) {
2702 int sres = DLLPollUI();
2703 // Detect if cancel is hit
2704 if (sres == 99) {
2705 p = nullptr;
2706 // Cancel the lookup
2707 GetChannelByUser((char *)-1);
2708 break;
2709 }
2710 DLLDescentDefer();
2711 p = GetChatText();
2712 if (p && pconsole) {
2713 DLLUIConsoleGadgetputs(pconsole, p);
2714 DLLUIConsoleGadgetputs(pconsole, "\x0a\x0d");
2715 }
2716 p = GetChannelByUser(pilot_name);
2717 }
2718 if ((p == nullptr) || (p == (char *)-1)) {
2719 exit_menu = 1;
2720 DLLCloseSplashScreen();
2721 break;
2722 }
2723 strcpy(message, p + 1);
2724 for (uint32_t i = 0; i < strlen(message); i++)
2725 if (message[i] == '_')
2726 message[i] = ' ';
2727 snprintf(fmt_msg, sizeof(fmt_msg), TXT_PXO_CANBEFOUNDIN, pilot_name, message);
2728 if (pconsole) {
2729 DLLUIConsoleGadgetputs(pconsole, fmt_msg);
2730 DLLUIConsoleGadgetputs(pconsole, "\x0a\x0d");
2731 }
2732 exit_menu = 1;
2733 DLLCloseSplashScreen();
2734 break;
2735 }
2736 case UID_CANCEL:
2737 exit_menu = 1;
2738 break;
2739 }
2740 }
2741
2742 DLLNewUIGameWindowClose(main_wnd);
2743 DLLNewUIGameWindowDestroy(main_wnd);
2744
2745 DLLRemoveUITextItem(title_text);
2746 DLLRemoveUITextItem(cancel_on_text);
2747 DLLRemoveUITextItem(cancel_off_text);
2748 DLLRemoveUITextItem(search_on_text);
2749 DLLRemoveUITextItem(search_off_text);
2750 DLLRemoveUITextItem(pilot_text);
2751
2752 DLLDeleteUIItem(main_wnd);
2753 DLLDeleteUIItem(title_t);
2754 DLLDeleteUIItem(pilot_t);
2755 DLLDeleteUIItem(pilot_edit);
2756 DLLDeleteUIItem(cancel_hs);
2757 DLLDeleteUIItem(search_hs);
2758
2759 return 1;
2760 }
2761
2762 const char *GetRankString(float ranking) {
2763 int val = 0;
2764
2765 if (ranking >= 0 && ranking < 600)
2766 val = 0;
2767 else if (ranking >= 600 && ranking < 900)
2768 val = 1;
2769 else if (ranking >= 900 && ranking < 1200)
2770 val = 2;
2771 else if (ranking >= 1200 && ranking < 1500)
2772 val = 3;
2773 else if (ranking >= 1500 && ranking < 1800)
2774 val = 4;
2775 else if (ranking >= 1800 && ranking < 2100)
2776 val = 5;
2777 else if (ranking >= 2100 && ranking < 2400)
2778 val = 6;
2779 else if (ranking >= 2400 && ranking < 2600)
2780 val = 7;
2781 else if (ranking >= 2600 && ranking < 3000)
2782 val = 8;
2783 else if (ranking >= 3000)
2784 val = 9;
2785 return TXT(TXT_RANKING0 + val);
2786 }
2787
2788 int GetNextRank(float ranking) {
2789 int val = 0;
2790
2791 if (ranking >= 0 && ranking < 600)
2792 val = 600;
2793 else if (ranking >= 600 && ranking < 900)
2794 val = 900;
2795 else if (ranking >= 900 && ranking < 1200)
2796 val = 1200;
2797 else if (ranking >= 1200 && ranking < 1500)
2798 val = 1500;
2799 else if (ranking >= 1500 && ranking < 1800)
2800 val = 1800;
2801 else if (ranking >= 1800 && ranking < 2100)
2802 val = 2100;
2803 else if (ranking >= 2100 && ranking < 2400)
2804 val = 2400;
2805 else if (ranking >= 2400 && ranking < 2600)
2806 val = 2600;
2807 else if (ranking >= 2600 && ranking < 3000)
2808 val = 3000;
2809 else if (ranking >= 3000)
2810 val = 3000;
2811 return val;
2812 }
2813
2814 int GetPilotStats(const char *pilot) {
2815 int res;
2816 const char *p;
2817 char *tokp;
2818 char tid[MAX_CHAT_SEND_LEN];
2819 char real_pilot[MAX_CHAT_SEND_LEN];
2820 char tmp_text[MAX_CHAT_SEND_LEN];
2821 vmt_descent3_struct d3_pilot_info;
2822
2823 void *eff_text;
2824 void *time_text;
2825 void *main_wnd;
2826 void *title_t;
2827 void *kill_t;
2828 void *death_t;
2829 void *suicide_t;
2830 void *eff_t;
2831 void *time_in_game_t;
2832 void *pilot_t;
2833 void *rank_t;
2834
2835 void *title_text;
2836 void *pilot_name_text;
2837 void *close_on_text;
2838 void *close_off_text;
2839 void *kills_text;
2840 void *deaths_text;
2841 void *suicide_text;
2842 void *rank_text;
2843
2844 DLLCreateSplashScreen(TXT_PXO_GETTINGPILOTSTAT, 1);
2845 // Cancel previously active lookups
2846 // GetD3PilotData((vmt_descent3_struct *)-1, NULL, NULL);
2847 GetD3PilotDataCancel();
2848 GetTrackerIdByUser((char *)-1);
2849 p = GetTrackerIdByUser(pilot);
2850 while (p == NULL) {
2851 res = DLLPollUI();
2852 DLLDescentDefer();
2853 p = GetChatText();
2854 if (p && pconsole) {
2855 DLLUIConsoleGadgetputs(pconsole, p);
2856 DLLUIConsoleGadgetputs(pconsole, "\x0a\x0d");
2857 }
2858 p = GetTrackerIdByUser(pilot);
2859 if (res == 99) {
2860 // cancel was hit
2861 // Cancel the look
2862 GetTrackerIdByUser((char *)-1);
2863 DLLCloseSplashScreen();
2864 }
2865 }
2866 if (p == (char *)-1) {
2867 DLLmprintf(0, "Timeout looking for user\n");
2868 DLLDoMessageBox(TXT_PXO_MASTERTRACKER, TXT_PXO_TIMEOUTMT, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
2869 DLLCloseSplashScreen();
2870 return 0;
2871 }
2872 tokp = strchr((char *)p, ' ');
2873 if (tokp) {
2874 *tokp = '\0';
2875 tokp++;
2876 strcpy(tid, p);
2877 strcpy(real_pilot, tokp);
2878 DLLmprintf(0, "Requesting pilot info for %s %s\n", tid, real_pilot);
2879 memset(&d3_pilot_info, 0, sizeof(vmt_descent3_struct));
2880 GetD3PilotData(&d3_pilot_info, real_pilot, tid);
2881 int iresult = 0;
2882 while (iresult == 0) {
2883 iresult = GetD3PilotData(nullptr, nullptr, nullptr);
2884 res = DLLPollUI();
2885 if (res == 99) {
2886 // cancel was hit
2887 // GetD3PilotData((vmt_descent3_struct *)-1, NULL, NULL);
2888 GetD3PilotDataCancel();
2889 iresult = -1;
2890 }
2891 DLLDescentDefer();
2892 p = GetChatText();
2893 if (p && pconsole) {
2894 DLLUIConsoleGadgetputs(pconsole, p);
2895 DLLUIConsoleGadgetputs(pconsole, "\x0a\x0d");
2896 }
2897 }
2898 if (iresult == 1) {
2899 DLLmprintf(0, "Got pilot info for %s %s\n", tid, real_pilot);
2900
2901 // Do rank thingy here.
2902 snprintf(tmp_text, sizeof(tmp_text), "Rank: %s (%d) Next Advance at %d",
2903 GetRankString(d3_pilot_info.rank / 65536), d3_pilot_info.rank / 65536,
2904 GetNextRank(d3_pilot_info.rank / 65536));
2905 rank_text = DLLCreateNewUITextItem(tmp_text, UICOL_TEXT_NORMAL);
2906
2907 title_text = DLLCreateNewUITextItem(TXT_PXO_PILOTSTATS, UICOL_WINDOW_TITLE);
2908
2909 pilot_name_text = DLLCreateNewUITextItem(real_pilot, UICOL_WINDOW_TITLE, DLL_BIG_BRIEFING_FONT);
2910
2911 close_on_text = DLLCreateNewUITextItem(TXT_PXO_CLOSE, UICOL_HOTSPOT_HI);
2912 close_off_text = DLLCreateNewUITextItem(TXT_PXO_CLOSE, UICOL_HOTSPOT_LO);
2913
2914 snprintf(tmp_text, sizeof(tmp_text), TXT_PXO_TOTALKILLS, d3_pilot_info.kills);
2915 kills_text = DLLCreateNewUITextItem(tmp_text, UICOL_TEXT_NORMAL);
2916
2917 snprintf(tmp_text, sizeof(tmp_text), TXT_PXO_TOTALDEATHS, d3_pilot_info.deaths);
2918 deaths_text = DLLCreateNewUITextItem(tmp_text, UICOL_TEXT_NORMAL);
2919
2920 snprintf(tmp_text, sizeof(tmp_text), TXT_PXO_SUICIDES, d3_pilot_info.suicides);
2921 suicide_text = DLLCreateNewUITextItem(tmp_text, UICOL_TEXT_NORMAL);
2922
2923 int leff = 0;
2924 int cury;
2925 if (d3_pilot_info.kills && d3_pilot_info.deaths) {
2926 // leff = d3_pilot_info.kills/d3_pilot_info.deaths+d3_pilot_info.suicides+d3_pilot_info.kills;
2927 leff = (int)((float)((float)d3_pilot_info.kills / ((float)d3_pilot_info.deaths + (float)d3_pilot_info.kills +
2928 (float)d3_pilot_info.suicides)) *
2929 100.0);
2930 }
2931
2932 snprintf(tmp_text, sizeof(tmp_text), TXT_PXO_EFFECIENCY, leff);
2933 eff_text = DLLCreateNewUITextItem(tmp_text, UICOL_TEXT_NORMAL);
2934 snprintf(tmp_text, sizeof(tmp_text), TXT_PXO_TIMEINGAME, d3_pilot_info.online_time / 60);
2935 time_text = DLLCreateNewUITextItem(tmp_text, UICOL_TEXT_NORMAL);
2936
2937 main_wnd = DLLNewUIGameWindowCreate(0, 0, 384, 256, UIF_PROCESS_ALL | UIF_CENTER | NUWF_TITLEMED);
2938
2939 title_t = DLLTextCreate(main_wnd, title_text, 0, 7, UIF_CENTER);
2940 cury = 30;
2941 pilot_t = DLLTextCreate(main_wnd, pilot_name_text, 0, cury, UIF_CENTER);
2942 cury += 30;
2943
2944 rank_t = DLLTextCreate(main_wnd, rank_text, 0, cury, UIF_CENTER);
2945 cury += 20;
2946 kill_t = DLLTextCreate(main_wnd, kills_text, 0, cury, UIF_CENTER);
2947 cury += 20;
2948 death_t = DLLTextCreate(main_wnd, deaths_text, 0, cury, UIF_CENTER);
2949 cury += 20;
2950 suicide_t = DLLTextCreate(main_wnd, suicide_text, 0, cury, UIF_CENTER);
2951 cury += 20;
2952 eff_t = DLLTextCreate(main_wnd, eff_text, 0, cury, UIF_CENTER);
2953 cury += 20;
2954 time_in_game_t = DLLTextCreate(main_wnd, time_text, 0, cury, UIF_CENTER);
2955 cury += 30;
2956
2957 // HotSpotCreate(int item,int parentitem, int id, int key, int txtitemoff, int txtitemon, int x, int y, int w, int
2958 // h, int flags,int winnum)
2959 DLLHotSpotCreate(main_wnd, UID_CANCEL, KEY_ESC, close_on_text, close_off_text, 130, cury, 60, 20, UIF_CENTER);
2960 DLLNewUIGameWindowOpen(main_wnd);
2961 int exit_menu = 0;
2962 while (!exit_menu) {
2963 int res;
2964
2965 res = DLLDoUI();
2966 if (res == UID_CANCEL) {
2967 exit_menu = 1;
2968 }
2969 }
2970 DLLNewUIGameWindowClose(main_wnd);
2971 DLLNewUIGameWindowDestroy(main_wnd);
2972 // Cleanup
2973 DLLRemoveUITextItem(rank_text);
2974 DLLRemoveUITextItem(title_text);
2975 DLLRemoveUITextItem(close_on_text);
2976 DLLRemoveUITextItem(close_off_text);
2977 DLLRemoveUITextItem(kills_text);
2978 DLLRemoveUITextItem(deaths_text);
2979 DLLRemoveUITextItem(suicide_text);
2980 DLLRemoveUITextItem(eff_text);
2981 DLLRemoveUITextItem(time_text);
2982 DLLRemoveUITextItem(pilot_name_text);
2983
2984 DLLDeleteUIItem(pilot_t);
2985 DLLDeleteUIItem(main_wnd);
2986 DLLDeleteUIItem(title_t);
2987 DLLDeleteUIItem(kill_t);
2988 DLLDeleteUIItem(death_t);
2989 DLLDeleteUIItem(suicide_t);
2990 DLLDeleteUIItem(eff_t);
2991 DLLDeleteUIItem(rank_t);
2992 DLLDeleteUIItem(time_in_game_t);
2993 }
2994 }
2995 DLLCloseSplashScreen();
2996
2997 return 1;
2998 }
2999
3000 void AutoLoginAndJoinGame() {
3001
3002 int loginlen = LOGIN_LEN;
3003 int passlen = PASSWORD_LEN;
3004 int valret;
3005 uint16_t port;
3006 uint32_t iaddr;
3007
3008 *DLLMultiGameStarting = 0;
3009 DLLCreateSplashScreen(TXT_PXO_CONNECTING, 0);
3010 DLLDatabaseRead("TrackerLogin", szloginid, &loginlen);
3011 DLLDatabaseRead("TrackerPassword", szpassword, &passlen);
3012 if (!*DLLAuto_login_addr) {
3013 DLLmprintf(0, "Can't autostart because no IP address was specified!!\n");
3014 *DLLMultiGameStarting = 0;
3015 goto failed_login;
3016 }
3017 if (*DLLAuto_login_port) {
3018 port = atoi(DLLAuto_login_port);
3019 } else {
3020 port = DEFAULT_GAME_PORT;
3021 }
3022 if (!*szloginid || !*szpassword) {
3023 if (LoginMasterTracker()) {
3024 // Uh... now connect to the server
3025 } else {
3026 goto failed_login;
3027 }
3028 }
3029
3030 // Fill out the validate struct and send off the packet
3031 validate_id_request val_user;
3032 strcpy(val_user.tracker_id, sztrackerid);
3033 strcpy(val_user.login, szloginid);
3034 strcpy(val_user.password, szpassword);
3035
3036 valret = ValidateUser(&val_user, sztrackerid);
3037 while (valret == 0) {
3038 valret = ValidateUser(nullptr, nullptr);
3039 DLLDescentDefer();
3040 }
3041 if (valret == 1) {
3042 // User was validated
3043 DLLmprintf(0, "Mastertracker user validated!\n");
3044 strcpy(DLLTracker_id, sztrackerid);
3045 strcpy(DLLMPlayers[DLLPlayer_num].tracker_id, sztrackerid);
3046
3047 } else if (valret == -1) {
3048 // User invalid!
3049 DLLmprintf(0, "Mastertracker user not validated!\n");
3050 DLLDoMessageBox(TXT_PXO_MASTERTRACKER, TXT_PXO_BADLOGIN, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
3051 goto failed_login;
3052 } else {
3053 // timeout waiting for tracker!
3054 DLLmprintf(0, "Mastertracker timeout!\n");
3055 DLLDoMessageBox(TXT_PXO_MASTERTRACKER, TXT_PXO_TIMEOUTMT, MSGBOX_OK, UICOL_WINDOW_TITLE, UICOL_TEXT_NORMAL);
3056 goto failed_login;
3057 }
3058
3059 // Now actually connect to the server!
3060
3061 network_address s_address;
3062 iaddr = inet_addr(DLLAuto_login_addr);
3063 memcpy(&s_address.address, &iaddr, sizeof(uint32_t));
3064 s_address.port = port;
3065 s_address.connection_type = NP_TCP;
3066 *DLLGame_is_master_tracker_game = 1;
3067 DLLMultiStartClient(nullptr);
3068
3069 if ((DLLTryToJoinServer(&s_address))) {
3070 DLLmprintf(0, "Menu: Game joined!\n");
3071 *DLLMultiGameStarting = 1;
3072 }
3073
3074 failed_login:
3075 // Run this to make sure we properly ACK the server.
3076 for (int j = 0; j < 10; j++)
3077 PollPTrackNet();
3078 DLLCloseSplashScreen();
3079 }
3080
3081 void AutoLoginAndStartGame() {
3082 int loginlen = LOGIN_LEN;
3083 int passlen = PASSWORD_LEN;
3084 int valret;
3085
3086 *DLLMultiGameStarting = 0;
3087
3088 DLLDatabaseRead("TrackerLogin", szloginid, &loginlen);
3089 DLLDatabaseRead("TrackerPassword", szpassword, &passlen);
3090
3091 if (!*szloginid || !*szpassword) {
3092 if (LoginMasterTracker()) {
3093 // Uh... now connect to the server
3094 } else {
3095 goto failed_login;
3096 }
3097 }
3098
3099 // Fill out the validate struct and send off the packet
3100 validate_id_request val_user;
3101 strcpy(val_user.tracker_id, sztrackerid);
3102 strcpy(val_user.login, szloginid);
3103 strcpy(val_user.password, szpassword);
3104
3105 valret = ValidateUser(&val_user, sztrackerid);
3106 while (valret == 0) {
3107 valret = ValidateUser(nullptr, nullptr);
3108 DLLDescentDefer();
3109 }
3110 if (valret == 1) {
3111 // User was validated
3112 DLLmprintf(0, "Mastertracker user validated!\n");
3113 DLLPrintDedicatedMessage("Mastertracker user validated.\n");
3114 strcpy(DLLTracker_id, sztrackerid);
3115 strcpy(DLLMPlayers[DLLPlayer_num].tracker_id, sztrackerid);
3116
3117 } else if (valret == -1) {
3118 // User invalid!
3119 DLLmprintf(0, "Mastertracker user not validated!\n");
3120 DLLPrintDedicatedMessage("Mastertracker user not validated!\n");
3121 goto failed_login;
3122 } else {
3123 // timeout waiting for tracker!
3124 DLLmprintf(0, "Mastertracker timeout!\n");
3125 DLLPrintDedicatedMessage("Mastertracker timeout!\n");
3126 goto failed_login;
3127 }
3128
3129 *DLLMultiGameStarting = 1;
3130 *DLLGame_is_master_tracker_game = 1;
3131 // strcpy(DLLD3_tracker_info.game_name,DLLNetgame->name);
3132 // strcpy(DLLD3_tracker_info.mission_name,DLLNetgame->mission);
3133 strcpy(DLLD3_tracker_info.lobby, DLLPXO_hosted_lobby_name);
3134
3135 failed_login:
3136 // Run this to make sure we properly ACK the server.
3137 for (int j = 0; j < 10; j++)
3138 PollPTrackNet();
3139 }
3140
3141 #define MAX_MOTD_LEN 400
3142 #define NUM_MOTD_LINES 6
3143 #define MOTD_WIDTH 384
3144 #define MOTD_HEIGHT 256
3145
3146 int ShowMessageOfTheDay(void) {
3147 static char szlastmotd[MAX_MOTD_LEN];
3148 static char sznewmotd[MAX_MOTD_LEN];
3149 int motdlen = MAX_MOTD_LEN;
3150 int res;
3151 int rval = 0;
3152 static void *main_wnd;
3153 void *close_hs;
3154
3155 int last_motd_version = 0;
3156
3157 DLLDatabaseReadInt("MOTDVersion", &last_motd_version);
3158
3159 if (Motd_version == last_motd_version) {
3160 // MOTD is old....
3161 DLLmprintf(0, "MOTD is old, skipping\n");
3162 return 1;
3163 }
3164
3165 DLLDatabaseWriteInt("MOTDVersion", Motd_version);
3166
3167 void *close_on_text = DLLCreateNewUITextItem(TXT_PXO_CLOSE, UICOL_HOTSPOT_HI);
3168 void *close_off_text = DLLCreateNewUITextItem(TXT_PXO_CLOSE, UICOL_HOTSPOT_LO);
3169 void *motd_text = DLLCreateNewUITextItem("PXO Message of the day", UICOL_WINDOW_TITLE);
3170
3171 main_wnd = DLLNewUIGameWindowCreate(0, 0, MOTD_WIDTH, MOTD_HEIGHT, UIF_PROCESS_ALL | UIF_CENTER | NUWF_TITLELARGE);
3172
3173 void *console_item = DLLUIConsoleGadgetCreate(main_wnd, 15, 20, 30, 0, 40, 20, 0);
3174 void *title = DLLTextCreate(main_wnd, motd_text, 0, 7, UIF_CENTER);
3175
3176 close_hs = DLLHotSpotCreate(main_wnd, UID_OK, KEY_ENTER, close_off_text, close_on_text, 60, MOTD_HEIGHT - 60, 60, 20,
3177 UIF_CENTER);
3178
3179 DLLDatabaseRead("LastMOTD", szlastmotd, &motdlen);
3180
3181 DLLmprintf(0, "Getting message of the day...\n");
3182 DLLCreateSplashScreen(TXT_PXO_CONNECTING, 1);
3183 int mcode = GetD3MOTD(sznewmotd, MAX_MOTD_LEN);
3184 do {
3185 mcode = GetD3MOTD(nullptr, 0);
3186 res = DLLPollUI();
3187 if (res == 99) {
3188 GetD3MOTDCancel();
3189 DLLCloseSplashScreen();
3190 goto close_motd;
3191 }
3192 DLLDescentDefer();
3193 } while (mcode == 0);
3194
3195 DLLCloseSplashScreen();
3196
3197 if (mcode == 1) {
3198 DLLmprintf(0, "Message of the day: %s\n", sznewmotd);
3199 if (strcmp(szlastmotd, sznewmotd) != 0) {
3200 DLLNewUIGameWindowOpen(main_wnd);
3201 DLLUIConsoleGadgetputs(console_item, sznewmotd);
3202 DLLDatabaseWrite("LastMOTD", sznewmotd, strlen(sznewmotd) + 1);
3203 do {
3204 res = DLLPollUI();
3205 DLLDescentDefer();
3206 } while (res != UID_OK);
3207 DLLNewUIGameWindowClose(main_wnd);
3208 rval = 1;
3209 goto close_motd;
3210 } else {
3211 DLLmprintf(0, "Message of the day is old, ignoring!\n");
3212 rval = 1;
3213 goto close_motd;
3214 }
3215 } else {
3216 DLLmprintf(0, "Get message of the day failed (%d)!\n", mcode);
3217 goto close_motd;
3218 }
3219
3220 close_motd:
3221 DLLmprintf(0, "Ending motd\n");
3222 DLLNewUIGameWindowDestroy(main_wnd);
3223 DLLRemoveUITextItem(motd_text);
3224 DLLRemoveUITextItem(close_on_text);
3225 DLLRemoveUITextItem(close_off_text);
3226
3227 DLLDeleteUIItem(console_item);
3228 DLLDeleteUIItem(title);
3229 DLLDeleteUIItem(close_hs);
3230 DLLDeleteUIItem(main_wnd);
3231 return rval;
3232 }