Debian Codegraph @

Descent3/multi_connect.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/multi_connect.cpp $
21 * $Revision: 82 $
22 * $Date: 10/10/01 11:33a $
23 * $Author: Matt $
24 *
25 *
26 *
27 * $Log: /DescentIII/Main/multi_connect.cpp $
28 *
29 * 82 10/10/01 11:33a Matt
30 * Do checksums on all ships, not just the client's ship. (This fixes a
31 * problem where the server could cheat because his ship was never
32 * checked.)
33 *
34 * 81 10/08/01 3:08p Matt
35 * Added physics flags & model radius to ship checksum.
36 *
37 * 80 8/29/01 2:51p Matt
38 * Improved ship weapon checksum calculation to fix cheating by modifiying
39 * weapon values.
40 *
41 * 79 2/01/00 3:47a Jason
42 * made usesmoothing be a client side option only
43 *
44 * 78 10/21/99 4:56p Matt
45 * Mac merge
46 *
47 * 77 5/23/99 4:17a Jason
48 * fixed potential ranking bug
49 *
50 * 76 5/23/99 3:05a Jason
51 * fixed bug with player rankings not being updated correctly
52 *
53 * 75 5/21/99 7:08p Jason
54 * fixed some weird multiplayer rejoin anomalies
55 *
56 * 74 5/21/99 11:38a Jason
57 * fixed bug with server heartbeats
58 *
59 * 73 5/20/99 4:55p Jason
60 * added heartbeats to server
61 *
62 * 72 5/20/99 4:10p Jason
63 * added heartbeat to multiplayer so clients wouldn't time out, also
64 * various multiplayer fixes
65 *
66 * 71 5/13/99 6:53p Jason
67 * upped retry time for clients connecting to servers
68 *
69 * 70 5/10/99 10:22p Ardussi
70 * changes to compile on Mac
71 *
72 * 69 5/09/99 1:34p Kevin
73 * Added diffuculty level system to multiplayer
74 *
75 * 68 5/07/99 3:16p Jason
76 * fixed crash bug with Player_object being null
77 *
78 * 67 5/07/99 2:50p Jason
79 * fixed a bunch of endlevel multiplayer issues
80 *
81 * 66 5/05/99 5:41p Jason
82 * fixed various multiplayer issues, including sequencing bugs and cheat
83 * prevention
84 *
85 * 65 5/05/99 12:24p Jason
86 * fixed some problems with ending levels
87 *
88 * 64 5/03/99 3:35p Kevin
89 * bug fixes
90 *
91 * 63 4/29/99 7:50p Jason
92 * fixed level ending problems
93 *
94 * 62 4/26/99 4:16p Jason
95 * added check for cheaters
96 *
97 * 61 4/16/99 11:56a Matt
98 * Changed directplay code to be "ifdef _WIN32" instead of "ifndef
99 * __LINUX__" so it will work on the Mac.
100 *
101 * 60 4/15/99 1:41a Jeff
102 * changes for linux compile
103 *
104 * 59 4/14/99 2:51a Jeff
105 * fixed some case mismatched #includes
106 *
107 * 58 3/22/99 6:21p Jeff
108 * added 2 more audio taunts. a mulitplayer event when someone plays an
109 * audio taunt. option to disable audio taunts.
110 *
111 * 57 3/17/99 4:08p Kevin
112 * Changed the way games appear and timeout in the game list.
113 *
114 * 56 2/15/99 7:49p Jeff
115 * new pilot file class and read/write system checked in...should be more
116 * robust than old
117 *
118 * 55 2/01/99 4:17p Jason
119 * more changes for multisafe
120 *
121 * 54 1/29/99 5:22p Jeff
122 * localization
123 *
124 * 53 1/27/99 5:47p Jeff
125 * audio taunts implemented!
126 *
127 * 52 1/07/99 11:51a Kevin
128 * Added support for joining servers on alternate ports and hosting behind
129 * a proxy/firewall
130 *
131 * 51 11/19/98 11:27a Jason
132 * added Multi_accept_state for Jeff
133 *
134 * 50 11/10/98 11:16a Jason
135 * fixed some multiplayer bugs with powerups disappearing
136 *
137 *
138 * 49 11/02/98 6:53p Jason
139 * made different game versions not show up in game list
140 *
141 * 48 10/28/98 5:07p Jason
142 * more changes for cleaner multiplayer
143 *
144 * 47 10/28/98 11:51a Jason
145 * fixed some multiplayer problems, plus redid coop a bit to make it
146 * cleaner
147 *
148 * 46 10/08/98 7:30p Samir
149 * game sequencing changes.
150 *
151 * 45 10/07/98 11:34a Kevin
152 * Added connecting progress screen
153 *
154 * 44 10/05/98 5:44p Jason
155 * added netgame flags to connection accepted packet
156 *
157 * 43 9/28/98 12:56p Jason
158 * multiplayer bug fixes
159 *
160 * 42 9/02/98 6:54p Kevin
161 * Fixed general directplay support up, and got modem-modem working
162 *
163 * 41 8/27/98 5:03p Kevin
164 * Prettied up multiplayer screens and fixed some bugs.
165 *
166 * 40 8/19/98 11:49a Kevin
167 * Got DirectPlay IPX working, and localized connection DLLs
168 *
169 * 39 8/14/98 4:54p Kevin
170 * More directplay stuff
171 *
172 * 38 8/05/98 2:25p Kevin
173 * improved network address reporting
174 *
175 * 37 8/04/98 6:21p Jeff
176 * send over Game name on connect
177 *
178 * 36 8/04/98 10:26a Kevin
179 * Custom sound and bmp exchange system
180 *
181 * 35 7/29/98 5:39p Kevin
182 * sound/bitmap exchange
183 *
184 * 34 7/27/98 5:31p Kevin
185 * Sound/Bitmap exchange system
186 *
187 * 33 7/21/98 1:49p Kevin
188 * IPX support and peer-peer option for multi
189 *
190 * 32 7/20/98 6:20p Kevin
191 * peer-peer stuff
192 *
193 * 31 7/17/98 1:22p Kevin
194 * Dynamic retransmission of reliable packets and stuff
195 *
196 * 30 7/13/98 11:52a Kevin
197 * Added Callscriptwithparms
198 *
199 * 29 6/30/98 3:22p Kevin
200 * Improved game ping time
201 *
202 * 28 6/25/98 5:22p Kevin
203 * Req/Send gametime to clients
204 *
205 * 27 6/24/98 3:24p Kevin
206 * Updated PXO screens with chat, etc.
207 *
208 * 26 6/18/98 4:49p Kevin
209 * Updated multiplayer menus
210 *
211 * 25 6/16/98 10:54a Jeff
212 *
213 * 24 6/01/98 10:09a Kevin
214 * Added DLL connection interface and auto update DLL
215 *
216 * 23 5/14/98 5:27p Jason
217 * fixed some more sequencing bugs
218 *
219 * 22 5/14/98 3:18p Jason
220 * finished multiplayer sequencing issues
221 *
222 * 21 5/14/98 11:07a Kevin
223 * Made gameover packet to the tracker reliable
224 *
225 * 20 5/12/98 12:33p Jason
226 * got level sequencing working in multiplayer
227 *
228 * 19 5/11/98 4:40p Chris
229 * AI info is now a malloc'ed pointer
230 *
231 * 18 5/01/98 5:34p Jason
232 * added debug mprintf
233 *
234 * 17 4/30/98 3:50p Kevin
235 * Mastertracker pilot stats
236 *
237 * 16 4/24/98 3:50p Kevin
238 * Added mastertracker game tracking support
239 *
240 * 15 4/24/98 11:06a Kevin
241 * Fixed problem where Ok_to_join was set to -1 when the user tried to
242 * join a server that wasn't running.
243 *
244 * 14 4/20/98 12:46p Jason
245 * added level checksumming for multiplayer games
246 *
247 * 13 4/15/98 8:38p Jason
248 * fixed some multiplayer issues
249 *
250 * 12 4/14/98 7:56p Matt
251 * Moved MSN_NAMELEN from mission.h to descent,h, so multi.h didn't need
252 * to include mission.h.
253 *
254 */
255
256 #include "multi.h"cxx . . $ `<file>/Descent3/multi.h`/
257 #include "multi_server.h"cxx . . $ `<file>/Descent3/multi_server.h`/
258 #include "player.h"cxx . . $ `<file>/Descent3/player.h`/
259 #include "game.h"cxx . . $ `<file>/Descent3/game.h`/
260 #include "ddio.h"cxx . . $ `<file>/ddio/ddio.h`/
261 #include "Mission.h"cxx . . $ `<file>/Descent3/Mission.h`/
262 // #include "gametrack.h"
263 #include "stringtable.h"cxx . . $ `<file>/Descent3/stringtable.h`/
264 #include "pilot.h"cxx . . $ `<file>/Descent3/pilot.h`/
265 #include "ship.h"cxx . . $ `<file>/Descent3/ship.h`/
266 #include "args.h"cxx . . $ `<file>/Descent3/args.h`/
267
268 #include "ui.h"cxx . . $ `<file>/ui/ui.h`/
269 #include "newui.h"cxx . . $ `<file>/Descent3/newui.h`/
270 #include "multi_dll_mgr.h"cxx . . $ `<file>/Descent3/multi_dll_mgr.h`/
271
272 #include "LoadLevel.h"cxx . . $ `<file>/Descent3/LoadLevel.h`/
273 // #define USE_DIRECTPLAY
274
275 #ifdef USE_DIRECTPLAY
276 #include "directplay.h"
277 #endif
278
279 SOCKETcxx . . $ `lib/networking.h:217:9`! ReliableSocketcxx . . $ ReliableSocket.;
280 int Ok_to_joincxx . . $ Ok_to_join. = -1;
281
282 int Got_level_infocxx . . $ Got_level_info. = 0;
283
284 // Whether or not the server will answer
285 bool Multi_accept_statecxx . . $ Multi_accept_state. = true;
286
287 // Points the server_address variable at a new location
288 void MultiSetServerAddresscxx . . $ MultiSetServerAddress(f2758234d0c8cb80).(network_addresscxx . . $ network_address# *addr) { memcpy(&Netgamecxx . . $ Netgame..server_addresscxx . . $ netgame_info#server_address., addr, sizeof(network_addresscxx . . $ network_address#)); }
289
290 // How often to inquire about joining a game
291 #define ASK_POLL_TIMEcxx . . $ `Descent3/multi_connect.cpp:291:9`! 2
292
293 // Returns true if the server says we can join
294 int AskToJoincxx . . $ AskToJoin(974bd2fc5f961852).(network_addresscxx . . $ network_address# *addr) {
295 int count = 0;
296 int size;
297 int tries = 0;
298 uint8_tcxx . . $ uint8_t# data[MAX_GAME_DATA_SIZEcxx . . $ `Descent3/multi_external.h:134:9`!];
299 float start_time;
300 network_addresscxx . . $ network_address# from_addr;
301
302 size = START_DATAcxx . . $ START_DATA(8c36ee1faa9e0a0b).(MP_ASK_TO_JOINcxx . . $ `Descent3/multi.h:534:9`!, data, &count);
303 END_DATAcxx . . $ END_DATA(dde21517a502ab05).(count, data, size);
304
305 Ok_to_joincxx . . $ Ok_to_join. = -1;
306
307 while (tries < 5 && Ok_to_joincxx . . $ Ok_to_join. == -1) {
308 // Send of our question and then wait!
309 ASSERTcxx . . $ `misc/pserror.h:246:9`!(size > 0);
310 nw_Sendcxx . . $ nw_Send(102d2f582237fe86).(addr, data, count, 0);
311 tries++;
312
313 start_time = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
314 while ((timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - start_time < ASK_POLL_TIMEcxx . . $ `Descent3/multi_connect.cpp:291:9`!) && Ok_to_joincxx . . $ Ok_to_join. == -1) {
315 int packsize;
316 while (((packsize = nw_Receivecxx . . $ nw_Receive(4faaf8d0141e84f4).(Multi_receive_buffercxx . . $ Multi_receive_buffer., &from_addr)) > 0) && Ok_to_joincxx . . $ Ok_to_join. == -1) {
317 MultiProcessBigDatacxx . . $ MultiProcessBigData(c3263a6d42f31e8c).(Multi_receive_buffercxx . . $ Multi_receive_buffer., packsize, &from_addr);
318 }
319 }
320 }
321
322 if (tries >= 5 || Ok_to_joincxx . . $ Ok_to_join. != JOIN_ANSWER_OKcxx . . $ `Descent3/multi_server.h:42:9`!)
323 return 0;
324
325 // Ok to join!
326 return 1;
327 }
328
329 // Trys to join this client with the server address passed in
330 // Returns 1 on success, 0 on fail
331 // Client only
332 // For DirectPlay games, use the addr pointer as a pointer to the DPSESSIONDESC2
333 int TryToJoinServercxx . . $ TryToJoinServer(974bd2fc5f961852).(network_addresscxx . . $ network_address# *addr) {
334 SOCKETcxx . . $ `lib/networking.h:217:9`! sock;
335
336 ShowProgressScreencxx . . $ ShowProgressScreen(8d00172ec7558ddf).(TXT_MULTI_CONNECTINGcxx . . $ `Descent3/stringtable.h:613:9`!);
337 // Store the server's address in the netplayer struct
338 memcpy(&NetPlayerscxx . . $ NetPlayers.[0].addrcxx . . $ netplayer#addr., addr, sizeof(network_addresscxx . . $ network_address#));
339
340 for (int i = 0; i < MAX_NET_PLAYERScxx . . $ `Descent3/multi_external.h:132:9`!; i++) {
341 NetPlayerscxx . . $ NetPlayers.[i].file_xfer_flagscxx . . $ netplayer#file_xfer_flags. = NETFILE_NONEcxx . . $ `Descent3/multi.h:683:9`!;
342 NetPlayerscxx . . $ NetPlayers.[i].ship_logocxx . . $ netplayer#ship_logo.[0] = 0;
343 NetPlayerscxx . . $ NetPlayers.[i].voice_taunt1cxx . . $ netplayer#voice_taunt1.[0] = 0;
344 NetPlayerscxx . . $ NetPlayers.[i].voice_taunt2cxx . . $ netplayer#voice_taunt2.[0] = 0;
345 NetPlayerscxx . . $ NetPlayers.[i].voice_taunt3cxx . . $ netplayer#voice_taunt3.[0] = 0;
346 NetPlayerscxx . . $ NetPlayers.[i].voice_taunt4cxx . . $ netplayer#voice_taunt4.[0] = 0;
347 NetPlayerscxx . . $ NetPlayers.[i].custom_file_seqcxx . . $ netplayer#custom_file_seq. = NETFILE_ID_NOFILEcxx . . $ `Descent3/multi.h:688:9`!;
348 // Set all custom textures to NULL
349 PlayerSetCustomTexturecxx . . $ PlayerSetCustomTexture(3c8082c546dd2ea0).(i, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
350 }
351 Current_pilotcxx . . $ Current_pilot..get_multiplayer_datacxx . . $ pilot#get_multiplayer_data(ea6e7aa10f4b80f5).(NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].ship_logocxx . . $ netplayer#ship_logo., NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].voice_taunt1cxx . . $ netplayer#voice_taunt1.,
352 NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].voice_taunt2cxx . . $ netplayer#voice_taunt2., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].voice_taunt3cxx . . $ netplayer#voice_taunt3.,
353 NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].voice_taunt4cxx . . $ netplayer#voice_taunt4.);
354 if (NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].ship_logocxx . . $ netplayer#ship_logo.[0])
355 PlayerSetCustomTexturecxx . . $ PlayerSetCustomTexture(3c8082c546dd2ea0).(Player_numcxx . . $ Player_num., NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].ship_logocxx . . $ netplayer#ship_logo.);
356
357 bool connected = false;
358 #ifdef USE_DIRECTPLAY
359 if (Use_DirectPlay) {
360 LPDPSESSIONDESC2 session = (LPDPSESSIONDESC2)addr;
361 DPID server_id = DPID_SERVERPLAYER;
362 Netgame.server_address.connection_type = NP_DIRECTPLAY;
363 memcpy(&Netgame.server_address.address, &server_id, sizeof(DPID));
364 if (dp_DirectPlayJoinGame(session)) {
365 connected = true;
366 NetPlayers[Player_num].reliable_socket = DPID_SERVERPLAYER;
367 } else {
368 mprintf(0, "Unable to join DirectPlay session!\n");
369 }
370 } else
371 #endif
372 {
373 if (!AskToJoincxx . . $ AskToJoin(974bd2fc5f961852).(addr)) {
374 if (Ok_to_joincxx . . $ Ok_to_join. != -1) {
375 char str[255];
376 snprintf(str, sizeof(str), "%s", TXTcxx . . $ `Descent3/stringtable.h:24:9`!(Join_response_strings[Ok_to_join]));
377 ShowProgressScreencxx . . $ ShowProgressScreen(8d00172ec7558ddf).(str);
378 Sleepcxx . . $ Sleep(d4f767463ce0a6b3).(2000);
379 } else {
380 ShowProgressScreencxx . . $ ShowProgressScreen(8d00172ec7558ddf).(TXT_MLTNORESPONSEcxx . . $ `Descent3/stringtable.h:184:9`!);
381 Sleepcxx . . $ Sleep(d4f767463ce0a6b3).(2000);
382 }
383 return 0;
384 } else
385 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Server says its ok to join!\n");
386
387 nw_ConnectToServercxx . . $ nw_ConnectToServer(cabc7cbaf24da8c).(&sock, addr);
388 if (sock != INVALID_SOCKETcxx . . $ `lib/networking.h:221:9`! && sock != 0) {
389 connected = true;
390 NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].reliable_socketcxx . . $ netplayer#reliable_socket. = sock;
391 }
392 }
393 if (connected) {
394 #ifdef USE_DIRECTPLAY
395 if (!Use_DirectPlay)
396 #endif
397 {
398 MultiSetServerAddresscxx . . $ MultiSetServerAddress(f2758234d0c8cb80).(addr);
399 }
400 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Client mode set! Polling...\n");
401
402 MultiPollForConnectionAcceptedcxx . . $ MultiPollForConnectionAccepted(49f6e7a06ebc5aa8).();
403
404 if (NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].flagscxx . . $ netplayer#flags. & NPF_CONNECTEDcxx . . $ `Descent3/multi_external.h:165:9`!)
405 return 1;
406 else {
407 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Couldn't join game for some reason!\n");
408 #ifdef USE_DIRECTPLAY
409 if (!Use_DirectPlay)
410 #endif
411 {
412 nw_CloseSocketcxx . . $ nw_CloseSocket(11b0e290e57a7e53).(&sock);
413 }
414 }
415 } else {
416 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "nw_ConnectToServer says it can't find a good socket!\n");
417 }
418
419 return 0;
420 }
421
422 // The server says we can join!
423 // Client only
424 void MultiDoConnectionAcceptedcxx . . $ MultiDoConnectionAccepted(f25546b61a629de7).(uint8_tcxx . . $ uint8_t# *data) {
425 int count = 0;
426 uint16_tcxx . . $ uint16_t# server_version;
427
428 // Skip header
429 SKIP_HEADERcxx . . $ SKIP_HEADER(849dbebf9185c2d3).(data, &count);
430
431 server_version = MultiGetShortcxx . . $ MultiGetShort(82c3ad32bc1210f5).(data, &count);
432
433 if (server_version != MULTI_VERSIONcxx . . $ `Descent3/multi.h:517:9`!) {
434 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Client and server code versions don't match. Do an update!\n");
435 return;
436 } else {
437 // Versions match, get info about the game and then connect!
438 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Client/server versions match.\n");
439
440 // Check if we have the mission needed
441 uint8_tcxx . . $ uint8_t# len = MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count);
442 memcpy(Netgamecxx . . $ Netgame..missioncxx . . $ netgame_info#mission., &data[count], len);
443 count += len;
444
445 if (!LoadMissioncxx . . $ LoadMission(c5f7da30cbc0f4e9).(Netgamecxx . . $ Netgame..missioncxx . . $ netgame_info#mission.)) {
446 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "We don't have this mission: %s!\n", Netgame.mission);
447 } else
448 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Using mission %s...\n", Netgame.mission);
449
450 len = MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count);
451 memcpy(Netgamecxx . . $ Netgame..namecxx . . $ netgame_info#name., &data[count], len);
452 count += len;
453
454 // Do script name stuff
455 len = MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count);
456 memcpy(Netgamecxx . . $ Netgame..scriptnamecxx . . $ netgame_info#scriptname., &data[count], len);
457 count += len;
458
459 SetGamemodeScriptcxx . . $ SetGamemodeScript(34d26762b42c433a).(Netgamecxx . . $ Netgame..scriptnamecxx . . $ netgame_info#scriptname.);
460
461 // Get my player num and copy my name over
462 uint8_tcxx . . $ uint8_t# player_num = MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count);
463 char name[CALLSIGN_LENcxx . . $ `Descent3/player_external_struct.h:89:9`!];
464 netplayercxx . . $ netplayer# tempplayer;
465 strcpy(name, Playerscxx . . $ Players.[Player_numcxx . . $ Player_num.].callsigncxx . . $ player#callsign.);
466 memcpy(&tempplayer, &NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.], sizeof(netplayercxx . . $ netplayer#));
467
468 Player_numcxx . . $ Player_num. = player_num;
469 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Server tells me that my player num is %d!\n", Player_num);
470 strcpy(Playerscxx . . $ Players.[Player_numcxx . . $ Player_num.].callsigncxx . . $ player#callsign., name);
471 memcpy(&NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.], &tempplayer, sizeof(netplayercxx . . $ netplayer#));
472 NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].flagscxx . . $ netplayer#flags. = NPF_CONNECTEDcxx . . $ `Descent3/multi_external.h:165:9`!; // Hurray! We're connected
473
474 // Get packets per second
475 Netgamecxx . . $ Netgame..packets_per_secondcxx . . $ netgame_info#packets_per_second. = MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count);
476 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Server is sending %d packets per second\n", Netgame.packets_per_second);
477
478 // Get the secret code we will use to identify ourselves to the server
479 uint32_tcxx . . $ uint32_t# secret_code = MultiGetUintcxx . . $ MultiGetUint(3599f90e4cb334dc).(data, &count);
480
481 // Get the peer-peer flag
482 int flags = MultiGetIntcxx . . $ MultiGetInt(7337501fe74387bd).(data, &count);
483 if (flags & NF_PEER_PEERcxx . . $ `Descent3/multi_external.h:230:9`!)
484 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Using Peer/Peer model\n");
485 else
486 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Using Client/Server model\n");
487
488 Netgamecxx . . $ Netgame..flagscxx . . $ netgame_info#flags. = flags;
489
490 // Do Client smoothing hack
491 if (FindArgcxx . . $ FindArg(5c4306d8553b3696).("-usesmoothing"))
492 Netgamecxx . . $ Netgame..flagscxx . . $ netgame_info#flags. |= NF_USE_SMOOTHINGcxx . . $ `Descent3/multi_external.h:237:9`!;
493
494 MultiSendGreetingscxx . . $ MultiSendGreetings(cb2f890c2fdad230).(secret_code);
495 }
496 }
497
498 #define JOIN_POLL_TIMEcxx . . $ `Descent3/multi_connect.cpp:498:9`! 10 // Wait 4 seconds before bailing
499 // Polls for a connection message so we can finally join this game
500 // Client only
501 void MultiPollForConnectionAcceptedcxx . . $ MultiPollForConnectionAccepted(49f6e7a06ebc5aa8).() {
502 float start_time;
503 int connected = 0;
504 uint8_tcxx . . $ uint8_t# data[MAX_RECEIVE_SIZEcxx . . $ `Descent3/multi.h:677:9`!];
505
506 start_time = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
507
508 while ((timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - start_time < JOIN_POLL_TIMEcxx . . $ `Descent3/multi_connect.cpp:498:9`!) && !connected) {
509 int size;
510 while ((size = nw_ReceiveReliablecxx . . $ nw_ReceiveReliable(ef9024b465536c23).(NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].reliable_socketcxx . . $ netplayer#reliable_socket., data, MAX_RECEIVE_SIZEcxx . . $ `Descent3/multi.h:677:9`!)) > 0) {
511 MultiProcessBigDatacxx . . $ MultiProcessBigData(c3263a6d42f31e8c).(data, size, &Netgamecxx . . $ Netgame..server_addresscxx . . $ netgame_info#server_address.);
512
513 if (NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].flagscxx . . $ netplayer#flags. & NPF_CONNECTEDcxx . . $ `Descent3/multi_external.h:165:9`!) {
514 connected = 1;
515 }
516 }
517 }
518
519 if (!connected) {
520 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Couldn't get a connection_accepted packet for some reason!\n");
521 }
522 }
523
524 // Gets a new connection to a new client set up
525 // This does not mean the client will enter the game, just that the server
526 // is successfully talking to the client
527 // Server only
528 void MultiSendConnectionAcceptedcxx . . $ MultiSendConnectionAccepted(151c8734e58a666a).(int slotnum, SOCKETcxx . . $ `lib/networking.h:217:9`! sock, network_addresscxx . . $ network_address# *addr) {
529 uint8_tcxx . . $ uint8_t# data[MAX_GAME_DATA_SIZEcxx . . $ `Descent3/multi_external.h:134:9`!];
530 int count = 0;
531 int size_offset;
532
533 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Sending connection accepted packet to slot %d!\n", slotnum);
534
535 NetPlayerscxx . . $ NetPlayers.[slotnum].reliable_socketcxx . . $ netplayer#reliable_socket. = sock;
536 memcpy(&NetPlayerscxx . . $ NetPlayers.[slotnum].addrcxx . . $ netplayer#addr., addr, sizeof(network_addresscxx . . $ network_address#));
537 NetPlayerscxx . . $ NetPlayers.[slotnum].flagscxx . . $ netplayer#flags. = NPF_CONNECTEDcxx . . $ `Descent3/multi_external.h:165:9`!;
538 NetPlayerscxx . . $ NetPlayers.[slotnum].sequencecxx . . $ netplayer#sequence. = NETSEQ_WAITING_FOR_LEVELcxx . . $ `Descent3/multi_external.h:149:9`!;
539 Playerscxx . . $ Players.[slotnum].flagscxx . . $ player#flags. = 0;
540 Playerscxx . . $ Players.[slotnum].rankcxx . . $ player#rank. = -1;
541
542 // Adjust port
543 NetPlayerscxx . . $ NetPlayers.[slotnum].addrcxx . . $ netplayer#addr..portcxx . . $ network_address#port.--;
544
545 NetPlayerscxx . . $ NetPlayers.[slotnum].last_packet_timecxx . . $ netplayer#last_packet_time. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
546
547 // Tell the new guy about the game in progress
548 size_offset = START_DATAcxx . . $ START_DATA(8c36ee1faa9e0a0b).(MP_CONNECTION_ACCEPTEDcxx . . $ `Descent3/multi.h:523:9`!, data, &count);
549
550 // Send server version
551 MultiAddShortcxx . . $ MultiAddShort(25946db777347f55).(Netgamecxx . . $ Netgame..server_versioncxx . . $ netgame_info#server_version., data, &count);
552
553 // Do mission name
554 int len = strlen(Netgamecxx . . $ Netgame..missioncxx . . $ netgame_info#mission.) + 1;
555 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(len, data, &count);
556 memcpy(&data[count], Netgamecxx . . $ Netgame..missioncxx . . $ netgame_info#mission., len);
557 count += len;
558
559 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Sending netgame mission %s with length of %d!\n", Netgame.mission, len);
560
561 len = strlen(Netgamecxx . . $ Netgame..namecxx . . $ netgame_info#name.) + 1;
562 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(len, data, &count);
563 memcpy(&data[count], Netgamecxx . . $ Netgame..namecxx . . $ netgame_info#name., len);
564 count += len;
565
566 // Do script name
567 len = strlen(Netgamecxx . . $ Netgame..scriptnamecxx . . $ netgame_info#scriptname.) + 1;
568 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(len, data, &count);
569 memcpy(&data[count], Netgamecxx . . $ Netgame..scriptnamecxx . . $ netgame_info#scriptname., len);
570 count += len;
571
572 // Set Player number
573 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(slotnum, data, &count);
574
575 // Send packets per second
576 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(Netgamecxx . . $ Netgame..packets_per_secondcxx . . $ netgame_info#packets_per_second., data, &count);
577
578 // Send secret code which the client will use to send a non reliable packet
579 NetPlayerscxx . . $ NetPlayers.[slotnum].secret_net_idcxx . . $ netplayer#secret_net_id. = Secret_net_idcxx . . $ Secret_net_id.++;
580 MultiAddUintcxx . . $ MultiAddUint(c51d06dbd74b8495).(NetPlayerscxx . . $ NetPlayers.[slotnum].secret_net_idcxx . . $ netplayer#secret_net_id., data, &count);
581
582 // Send netplayer flags (obsoletes the above line of code, left for a while for compatability)
583 MultiAddIntcxx . . $ MultiAddInt(49f79918a3afee3).(Netgamecxx . . $ Netgame..flagscxx . . $ netgame_info#flags., data, &count);
584
585 END_DATAcxx . . $ END_DATA(dde21517a502ab05).(count, data, size_offset);
586
587 // Send it back to the player
588 nw_SendReliablecxx . . $ nw_SendReliable(f6b56715d3e5e15a).(sock, data, count);
589
590 ASSERTcxx . . $ `misc/pserror.h:246:9`!(count < MAX_GAME_DATA_SIZEcxx . . $ `Descent3/multi_external.h:134:9`!);
591 }
592
593 #define LEVEL_POLL_TIMEcxx . . $ `Descent3/multi_connect.cpp:593:9`! 60
594 // Polls for a connection message so we can finally join this game
595 // Returns true if we got the level info
596 // Client only
597
598 int MultiPollForLevelInfocxx . . $ MultiPollForLevelInfo(b126dc7c1de90089).() {
599 float start_time, ask_time, initial_start_time;
600 int connected = 0;
601 uint8_tcxx . . $ uint8_t# data[MAX_RECEIVE_SIZEcxx . . $ `Descent3/multi.h:677:9`!];
602 network_addresscxx . . $ network_address# from_addr;
603
604 ShowProgressScreencxx . . $ ShowProgressScreen(8d00172ec7558ddf).(TXT_MLTWAITSERVERcxx . . $ `Descent3/stringtable.h:185:9`!);
605
606 NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].sequencecxx . . $ netplayer#sequence. = NETSEQ_WAITING_FOR_LEVELcxx . . $ `Descent3/multi_external.h:149:9`!;
607 Got_level_infocxx . . $ Got_level_info. = 0;
608 Got_heartbeatcxx . . $ Got_heartbeat. = false;
609
610 MultiSendReadyForLevelcxx . . $ MultiSendReadyForLevel(49f6e7a06ebc5aa8).();
611
612 start_time = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
613 ask_time = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
614 initial_start_time = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
615
616 // Go through this waiting period until the server times out or we get level info
617 while ((timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - start_time < LEVEL_POLL_TIMEcxx . . $ `Descent3/multi_connect.cpp:593:9`!) && !Got_level_infocxx . . $ Got_level_info. &&
618 (timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - initial_start_time < (LEVEL_POLL_TIMEcxx . . $ `Descent3/multi_connect.cpp:593:9`! * 5))) {
619 if (timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - ask_time > 5.0) {
620 ask_time = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
621 MultiSendReadyForLevelcxx . . $ MultiSendReadyForLevel(49f6e7a06ebc5aa8).();
622 }
623
624 int size;
625 while ((size = nw_ReceiveReliablecxx . . $ nw_ReceiveReliable(ef9024b465536c23).(NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].reliable_socketcxx . . $ netplayer#reliable_socket., data, MAX_RECEIVE_SIZEcxx . . $ `Descent3/multi.h:677:9`!)) > 0) {
626 MultiProcessBigDatacxx . . $ MultiProcessBigData(c3263a6d42f31e8c).(data, size, &Netgamecxx . . $ Netgame..server_addresscxx . . $ netgame_info#server_address.);
627 }
628
629 while ((size = nw_Receivecxx . . $ nw_Receive(4faaf8d0141e84f4).(data, &from_addr)) > 0) {
630 if (data[0] == MP_HEARTBEATcxx . . $ `Descent3/multi.h:644:9`!) {
631 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Got a heart beat from the server.\n");
632 Got_heartbeatcxx . . $ Got_heartbeat. = true;
633 }
634 }
635
636 if (Got_heartbeatcxx . . $ Got_heartbeat.) {
637 // Reset timer because we got a heartbeat
638 start_time = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
639 Got_heartbeatcxx . . $ Got_heartbeat. = false;
640 }
641 }
642
643 if (!Got_level_infocxx . . $ Got_level_info.) {
644 ShowProgressScreencxx . . $ ShowProgressScreen(8d00172ec7558ddf).(TXT_MLTNOLEVELINFOcxx . . $ `Descent3/stringtable.h:186:9`!);
645 MultiLeaveGamecxx . . $ MultiLeaveGame(49f6e7a06ebc5aa8).();
646 Sleepcxx . . $ Sleep(d4f767463ce0a6b3).(2000);
647 } else if (Got_level_infocxx . . $ Got_level_info. < 0) {
648 ShowProgressScreencxx . . $ ShowProgressScreen(8d00172ec7558ddf).(TXTcxx . . $ `Descent3/stringtable.h:24:9`!(Join_response_strings[-Got_level_info]));
649 MultiLeaveGamecxx . . $ MultiLeaveGame(49f6e7a06ebc5aa8).();
650 Sleepcxx . . $ Sleep(d4f767463ce0a6b3).(2000);
651 } else {
652 Got_level_infocxx . . $ Got_level_info. = 0;
653 return 1;
654 }
655
656 return 0;
657 }
658
659 #include "polymodel.h"cxx . . $ `<file>/model/polymodel.h`/
660
661 // Returns a unique value for this ship
662 int MultiGetShipChecksumcxx . . $ MultiGetShipChecksum(7864480464b09eea).(int ship_index) {
663 shipcxx . . $ ship# *s = &Shipscxx . . $ Ships.[ship_index];
664
665 int num = 0;
666
667 AppendToLevelChecksumcxx . . $ AppendToLevelChecksum(9364e6e7bff7660).(s->phys_infocxx . . $ ship#phys_info..full_thrustcxx . . $ physics_info#$anonymous_type_3#full_thrust.);
668 AppendToLevelChecksumcxx . . $ AppendToLevelChecksum(9364e6e7bff7660).(s->phys_infocxx . . $ ship#phys_info..full_rotthrustcxx . . $ physics_info#$anonymous_type_4#full_rotthrust.);
669
670 AppendToLevelChecksumcxx . . $ AppendToLevelChecksum(9364e6e7bff7660).(s->phys_infocxx . . $ ship#phys_info..masscxx . . $ physics_info#mass.);
671 AppendToLevelChecksumcxx . . $ AppendToLevelChecksum(9364e6e7bff7660).(s->phys_infocxx . . $ ship#phys_info..dragcxx . . $ physics_info#drag.);
672 AppendToLevelChecksumcxx . . $ AppendToLevelChecksum(9364e6e7bff7660).(s->phys_infocxx . . $ ship#phys_info..rotdragcxx . . $ physics_info#rotdrag.);
673
674 AppendToLevelChecksumcxx . . $ AppendToLevelChecksum(cb2f890c2fdad230).(s->phys_infocxx . . $ ship#phys_info..flagscxx . . $ physics_info#flags.);
675 poly_modelcxx . . $ poly_model# *pm = GetPolymodelPointercxx . . $ GetPolymodelPointer(ac85e77c73ebf794).(s->model_handlecxx . . $ ship#model_handle.);
676 AppendToLevelChecksumcxx . . $ AppendToLevelChecksum(9364e6e7bff7660).(pm->radcxx . . $ poly_model#rad.);
677
678 for (int w = 0; w < MAX_PLAYER_WEAPONScxx . . $ `Descent3/player_external_struct.h:91:9`!; w++) {
679
680 for (int i = 0; i < MAX_WB_FIRING_MASKScxx . . $ `lib/robotfirestruct_external.h:23:9`!; i++) {
681 AppendToLevelChecksumcxx . . $ AppendToLevelChecksum(9364e6e7bff7660).(s->static_wbcxx . . $ ship#static_wb.[w].gp_fire_waitcxx . . $ otype_wb_info#gp_fire_wait.[i]);
682 AppendToLevelChecksumcxx . . $ AppendToLevelChecksum(ac50b47256ae7414).(s->static_wbcxx . . $ ship#static_wb.[w].gp_fire_maskscxx . . $ otype_wb_info#gp_fire_masks.[i]);
683 }
684
685 AppendToLevelChecksumcxx . . $ AppendToLevelChecksum(9364e6e7bff7660).(s->static_wbcxx . . $ ship#static_wb.[w].energy_usagecxx . . $ otype_wb_info#energy_usage.);
686 AppendToLevelChecksumcxx . . $ AppendToLevelChecksum(9364e6e7bff7660).(s->static_wbcxx . . $ ship#static_wb.[w].ammo_usagecxx . . $ otype_wb_info#ammo_usage.);
687 AppendToLevelChecksumcxx . . $ AppendToLevelChecksum(ac50b47256ae7414).(s->fire_flagscxx . . $ ship#fire_flags.[w]);
688 }
689 return num;
690 }
691
692 // Returns a unique value for this ship
693 void MultiProcessShipChecksumcxx . . $ MultiProcessShipChecksum(54a9d97b34104f61).(MD5cxx . . $ MD5# *md5, int ship_index) {
694 shipcxx . . $ ship# *s = &Shipscxx . . $ Ships.[ship_index];
695
696 md5->updatecxx . . $ MD5#update(75096ca55fa6cf9c).(s->phys_infocxx . . $ ship#phys_info..full_thrustcxx . . $ physics_info#$anonymous_type_3#full_thrust.);
697 md5->updatecxx . . $ MD5#update(75096ca55fa6cf9c).(s->phys_infocxx . . $ ship#phys_info..full_rotthrustcxx . . $ physics_info#$anonymous_type_4#full_rotthrust.);
698
699 md5->updatecxx . . $ MD5#update(75096ca55fa6cf9c).(s->phys_infocxx . . $ ship#phys_info..masscxx . . $ physics_info#mass.);
700 md5->updatecxx . . $ MD5#update(75096ca55fa6cf9c).(s->phys_infocxx . . $ ship#phys_info..dragcxx . . $ physics_info#drag.);
701 md5->updatecxx . . $ MD5#update(75096ca55fa6cf9c).(s->phys_infocxx . . $ ship#phys_info..rotdragcxx . . $ physics_info#rotdrag.);
702
703 md5->updatecxx . . $ MD5#update(6bab9b75950d6f3).(s->phys_infocxx . . $ ship#phys_info..flagscxx . . $ physics_info#flags.);
704 poly_modelcxx . . $ poly_model# *pm = GetPolymodelPointercxx . . $ GetPolymodelPointer(ac85e77c73ebf794).(s->model_handlecxx . . $ ship#model_handle.);
705 md5->updatecxx . . $ MD5#update(75096ca55fa6cf9c).(pm->radcxx . . $ poly_model#rad.);
706
707 for (int w = 0; w < MAX_PLAYER_WEAPONScxx . . $ `Descent3/player_external_struct.h:91:9`!; w++) {
708
709 for (int i = 0; i < MAX_WB_FIRING_MASKScxx . . $ `lib/robotfirestruct_external.h:23:9`!; i++) {
710 md5->updatecxx . . $ MD5#update(75096ca55fa6cf9c).(s->static_wbcxx . . $ ship#static_wb.[w].gp_fire_waitcxx . . $ otype_wb_info#gp_fire_wait.[i]);
711 md5->updatecxx . . $ MD5#update(2008a3f7800ba735).(s->static_wbcxx . . $ ship#static_wb.[w].gp_fire_maskscxx . . $ otype_wb_info#gp_fire_masks.[i]);
712 }
713
714 md5->updatecxx . . $ MD5#update(75096ca55fa6cf9c).(s->static_wbcxx . . $ ship#static_wb.[w].energy_usagecxx . . $ otype_wb_info#energy_usage.);
715 md5->updatecxx . . $ MD5#update(75096ca55fa6cf9c).(s->static_wbcxx . . $ ship#static_wb.[w].ammo_usagecxx . . $ otype_wb_info#ammo_usage.);
716 md5->updatecxx . . $ MD5#update(2008a3f7800ba735).(s->fire_flagscxx . . $ ship#fire_flags.[w]);
717 }
718 }
719
720 // Server is telling us about the level
721 void MultiDoLevelInfocxx . . $ MultiDoLevelInfo(f25546b61a629de7).(uint8_tcxx . . $ uint8_t# *data) {
722 int count = 0;
723 char pshipmodel[PAGENAME_LENcxx . . $ `lib/manage_external.h:49:9`!];
724 Current_pilotcxx . . $ Current_pilot..get_shipcxx . . $ pilot#get_ship(fda57c8427c60377).(pshipmodel);
725
726 int ship_index = FindShipNamecxx . . $ FindShipName(5c4306d8553b3696).(pshipmodel);
727 if (ship_index < 0)
728 ship_index = 0;
729
730 // Skip header stuff
731 SKIP_HEADERcxx . . $ SKIP_HEADER(849dbebf9185c2d3).(data, &count);
732
733 int join_response = MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count);
734
735 // Get level number
736 Current_missioncxx . . $ Current_mission..cur_levelcxx . . $ tMission#cur_level. = MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count);
737
738 Netgamecxx . . $ Netgame..difficultycxx . . $ netgame_info#difficulty. = MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count);
739
740 if ((Netgamecxx . . $ Netgame..difficultycxx . . $ netgame_info#difficulty. > 4) || (Netgamecxx . . $ Netgame..difficultycxx . . $ netgame_info#difficulty. < 0))
741 Netgamecxx . . $ Netgame..difficultycxx . . $ netgame_info#difficulty. = 2;
742
743 if (join_response != JOIN_ANSWER_OKcxx . . $ `Descent3/multi_server.h:42:9`!)
744 Got_level_infocxx . . $ Got_level_info. = -join_response;
745 else
746 Got_level_infocxx . . $ Got_level_info. = 1;
747 }
748
749 // Server is telling the client about the level currently playing
750 // Server only
751 void MultiSendLevelInfocxx . . $ MultiSendLevelInfo(d4f767463ce0a6b3).(int slot) {
752 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Netgame.local_role == LR_SERVERcxx . . $ `Descent3/multi_external.h:129:9`!);
753 uint8_tcxx . . $ uint8_t# data[MAX_GAME_DATA_SIZEcxx . . $ `Descent3/multi_external.h:134:9`!];
754 int count = 0;
755 int size_offset;
756
757 size_offset = START_DATAcxx . . $ START_DATA(8c36ee1faa9e0a0b).(MP_LEVEL_INFOcxx . . $ `Descent3/multi.h:562:9`!, data, &count);
758
759 if (Netgamecxx . . $ Netgame..local_rolecxx . . $ netgame_info#local_role. == LR_SERVERcxx . . $ `Descent3/multi_external.h:129:9`!) {
760 if (Playerscxx . . $ Players.[slot].start_roomnumcxx . . $ player#start_roomnum. != -1)
761 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(JOIN_ANSWER_OKcxx . . $ `Descent3/multi_server.h:42:9`!, data, &count);
762 else
763 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(JOIN_ANSWER_NO_ROOMcxx . . $ `Descent3/multi_server.h:45:9`!, data, &count);
764 } else
765 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(JOIN_ANSWER_NOT_SERVERcxx . . $ `Descent3/multi_server.h:43:9`!, data, &count);
766
767 // Do level number (of the mission)
768 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Sending current mission level %d!\n", Current_mission.cur_level);
769 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(Current_missioncxx . . $ Current_mission..cur_levelcxx . . $ tMission#cur_level., data, &count);
770
771 // Send the difficulty
772 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(Netgamecxx . . $ Netgame..difficultycxx . . $ netgame_info#difficulty., data, &count);
773
774 END_DATAcxx . . $ END_DATA(dde21517a502ab05).(count, data, size_offset);
775
776 // Send it out
777 nw_SendReliablecxx . . $ nw_SendReliable(f6b56715d3e5e15a).(NetPlayerscxx . . $ NetPlayers.[slot].reliable_socketcxx . . $ netplayer#reliable_socket., data, count);
778 }
779
780 // Clients says he's ready for level info
781 // so send it to him
782 void MultiDoReadyForLevelcxx . . $ MultiDoReadyForLevel(f25546b61a629de7).(uint8_tcxx . . $ uint8_t# *data) {
783 int count = 0;
784 uint8_tcxx . . $ uint8_t# slot;
785 char ship_name[PAGENAME_LENcxx . . $ `lib/manage_external.h:49:9`!];
786
787 // Skip header stuff
788 SKIP_HEADERcxx . . $ SKIP_HEADER(849dbebf9185c2d3).(data, &count);
789
790 // Get slot number
791 slot = MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count);
792
793 // Copy the ship name out
794 int len = MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count);
795 memcpy(ship_name, &data[count], len);
796 count += len;
797
798 int ship_index = FindShipNamecxx . . $ FindShipName(5c4306d8553b3696).(ship_name);
799 if (ship_index < 0)
800 ship_index = 0;
801
802 PlayerChangeShipcxx . . $ PlayerChangeShip(3e454b8ccf442868).(slot, ship_index);
803
804 MultiSendLevelInfocxx . . $ MultiSendLevelInfo(d4f767463ce0a6b3).(slot);
805 NetPlayerscxx . . $ NetPlayers.[slot].sequencecxx . . $ netplayer#sequence. = NETSEQ_LEVEL_STARTcxx . . $ `Descent3/multi_external.h:150:9`!;
806 }
807
808 // Client is telling the server that he is ready for a level
809 // Client only
810 void MultiSendReadyForLevelcxx . . $ MultiSendReadyForLevel(49f6e7a06ebc5aa8).() {
811 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Netgame.local_role != LR_SERVERcxx . . $ `Descent3/multi_external.h:129:9`!);
812
813 uint8_tcxx . . $ uint8_t# data[MAX_GAME_DATA_SIZEcxx . . $ `Descent3/multi_external.h:134:9`!];
814 int count = 0;
815 int size_offset;
816
817 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Sending ready for level!\n");
818
819 char pshipmodel[PAGENAME_LENcxx . . $ `lib/manage_external.h:49:9`!];
820 Current_pilotcxx . . $ Current_pilot..get_shipcxx . . $ pilot#get_ship(fda57c8427c60377).(pshipmodel);
821
822 int ship_index = FindShipNamecxx . . $ FindShipName(5c4306d8553b3696).(pshipmodel);
823 if (ship_index < 0)
824 ship_index = 0;
825
826 size_offset = START_DATAcxx . . $ START_DATA(8c36ee1faa9e0a0b).(MP_READY_FOR_LEVELcxx . . $ `Descent3/multi.h:561:9`!, data, &count);
827
828 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(Player_numcxx . . $ Player_num., data, &count);
829
830 // Send ship for anti-cheating purposes (CHEAP and EASILY HACKABLE!)
831 int len = strlen(Shipscxx . . $ Ships.[ship_index].namecxx . . $ ship#name.) + 1;
832 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(len, data, &count);
833 memcpy(&data[count], Shipscxx . . $ Ships.[ship_index].namecxx . . $ ship#name., len);
834 count += len;
835
836 END_DATAcxx . . $ END_DATA(dde21517a502ab05).(count, data, size_offset);
837
838 // Send it out
839 nw_SendReliablecxx . . $ nw_SendReliable(f6b56715d3e5e15a).(NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].reliable_socketcxx . . $ netplayer#reliable_socket., data, count);
840 }
841
842 extern int Multi_packet_trackingcxx . . $ Multi_packet_tracking.[];
843 // Clears all connections
844 // Server and Client
845 void MultiCloseGamecxx . . $ MultiCloseGame(49f6e7a06ebc5aa8).() {
846 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Multi close game!\n");
847
848 if (!(Game_modecxx . . $ Game_mode. & GM_NETWORKcxx . . $ `Descent3/game.h:281:9`!)) {
849 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Not network game!\n");
850 return;
851 }
852
853 #if !defined(RELEASE)
854 // Write our packet tracking
855 CFILEcxx . . $ CFILE# *outfile;
856 outfile = cfopencxx . . $ cfopen(7c7b94e455f1ae56).("PacketTracking"cxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "wt");
857 if (!outfile) {
858 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Couldn't open packet tracking file!\n");
859 } else {
860 for (int i = 0; i < 255; i++) {
861 cfprintfcxx . . $ cfprintf(4762586383887345).(outfile, "Packet %d = %d\n", i, Multi_packet_trackingcxx . . $ Multi_packet_tracking.[i]);
862 }
863 cfclosecxx . . $ cfclose(3639e799710acb68).(outfile);
864 }
865 #endif
866
867 Sleepcxx . . $ Sleep(d4f767463ce0a6b3).(1000); // Sleep for one second
868
869 if (Netgamecxx . . $ Netgame..local_rolecxx . . $ netgame_info#local_role. == LR_SERVERcxx . . $ `Descent3/multi_external.h:129:9`!) {
870 int i;
871
872 for (i = 0; i < MAX_NET_PLAYERScxx . . $ `Descent3/multi_external.h:132:9`!; i++) {
873 if (i == Player_numcxx . . $ Player_num.)
874 continue;
875
876 if (NetPlayerscxx . . $ NetPlayers.[i].flagscxx . . $ netplayer#flags. & NPF_CONNECTEDcxx . . $ `Descent3/multi_external.h:165:9`!) {
877 MultiDisconnectPlayercxx . . $ MultiDisconnectPlayer(d4f767463ce0a6b3).(i);
878 }
879 }
880
881 for (i = 0; i < 100; i++) {
882 nw_DoNetworkIdlecxx . . $ nw_DoNetworkIdle(49f6e7a06ebc5aa8).();
883 Sleepcxx . . $ Sleep(d4f767463ce0a6b3).(10);
884 }
885
886 NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].flagscxx . . $ netplayer#flags. &= ~NPF_CONNECTEDcxx . . $ `Descent3/multi_external.h:165:9`!;
887 MultiFlushAllIncomingBufferscxx . . $ MultiFlushAllIncomingBuffers(49f6e7a06ebc5aa8).();
888 } else {
889 if (NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].flagscxx . . $ netplayer#flags. & NPF_CONNECTEDcxx . . $ `Descent3/multi_external.h:165:9`!) {
890 MultiFlushAllIncomingBufferscxx . . $ MultiFlushAllIncomingBuffers(49f6e7a06ebc5aa8).();
891 nw_CloseSocketcxx . . $ nw_CloseSocket(11b0e290e57a7e53).(&NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].reliable_socketcxx . . $ netplayer#reliable_socket.);
892 NetPlayerscxx . . $ NetPlayers.[Player_numcxx . . $ Player_num.].flagscxx . . $ netplayer#flags. &= ~NPF_CONNECTEDcxx . . $ `Descent3/multi_external.h:165:9`!;
893 }
894 }
895
896 Game_modecxx . . $ Game_mode. &= ~GM_MULTIcxx . . $ `Descent3/game.h:288:9`!;
897 if (Player_numcxx . . $ Player_num. != 0 && Player_objectcxx . . $ Player_object.)
898 SetObjectControlTypecxx . . $ SetObjectControlType(766a1b7183ffa4b4).(Player_objectcxx . . $ Player_object., CT_NONEcxx . . $ `Descent3/object_external.h:216:9`!);
899 Player_numcxx . . $ Player_num. = 0;
900 Player_objectcxx . . $ Player_object. = Viewer_objectcxx . . $ Viewer_object. = &Objectscxx . . $ Objects.[Playerscxx . . $ Players.[0].objnumcxx . . $ player#objnum.];
901 }
902
903 #define GET_GAME_INFO_TIMEcxx . . $ `Descent3/multi_connect.cpp:903:9`! 2
904 // Fills in the passed in buffers with the info of the games that are on this subnet
905 int SearchForLocalGamesTCPcxx . . $ SearchForLocalGamesTCP(10dfdad8c5442a70).(uint32_tcxx . . $ uint32_t# ask, uint16_tcxx . . $ uint16_t# port) {
906 int count = 0;
907 int size;
908 int tries = 0;
909 uint8_tcxx . . $ uint8_t# data[MAX_GAME_DATA_SIZEcxx . . $ `Descent3/multi_external.h:134:9`!];
910 network_addresscxx . . $ network_address# check_addr, from_addr;
911 check_addr.connection_typecxx . . $ network_address#connection_type. = NP_TCPcxx . . $ NP_TCP.;
912 if (ask) {
913 memcpy(&check_addr.addresscxx . . $ network_address#address., &ask, 4);
914 check_addr.portcxx . . $ network_address#port. = htons(port);
915
916 size = START_DATAcxx . . $ START_DATA(8c36ee1faa9e0a0b).(MP_GET_GAME_INFOcxx . . $ `Descent3/multi.h:552:9`!, data, &count);
917 MultiAddFloatcxx . . $ MultiAddFloat(a76b0cec949d1afe).(timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(), data, &count);
918 MultiAddIntcxx . . $ MultiAddInt(49f79918a3afee3).(MULTI_VERSIONcxx . . $ `Descent3/multi.h:517:9`!, data, &count);
919 END_DATAcxx . . $ END_DATA(dde21517a502ab05).(count, data, size);
920
921 nw_Sendcxx . . $ nw_Send(102d2f582237fe86).(&check_addr, data, count, 0);
922
923 // Num_network_games_known=0;
924 }
925
926 int packsize;
927 while (((packsize = nw_Receivecxx . . $ nw_Receive(4faaf8d0141e84f4).(Multi_receive_buffercxx . . $ Multi_receive_buffer., &from_addr)) > 0)) {
928 MultiProcessBigDatacxx . . $ MultiProcessBigData(c3263a6d42f31e8c).(Multi_receive_buffercxx . . $ Multi_receive_buffer., packsize, &from_addr);
929 }
930 return Num_network_games_knowncxx . . $ Num_network_games_known.;
931 }
932
933 // Fills in the passed in buffers with the info of the games that are on this subnet
934 int SearchForGamesPXOcxx . . $ SearchForGamesPXO(10dfdad8c5442a70).(uint32_tcxx . . $ uint32_t# ask, uint16_tcxx . . $ uint16_t# port) {
935 int count = 0;
936 int size;
937 int tries = 0;
938 uint8_tcxx . . $ uint8_t# data[MAX_GAME_DATA_SIZEcxx . . $ `Descent3/multi_external.h:134:9`!];
939 network_addresscxx . . $ network_address# check_addr, from_addr;
940 check_addr.connection_typecxx . . $ network_address#connection_type. = NP_TCPcxx . . $ NP_TCP.;
941 if (ask) {
942 memcpy(&check_addr.addresscxx . . $ network_address#address., &ask, 4);
943 check_addr.portcxx . . $ network_address#port. = htons(port);
944
945 size = START_DATAcxx . . $ START_DATA(8c36ee1faa9e0a0b).(MP_GET_PXO_GAME_INFOcxx . . $ `Descent3/multi.h:563:9`!, data, &count);
946 MultiAddFloatcxx . . $ MultiAddFloat(a76b0cec949d1afe).(timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(), data, &count);
947 MultiAddIntcxx . . $ MultiAddInt(49f79918a3afee3).(MULTI_VERSIONcxx . . $ `Descent3/multi.h:517:9`!, data, &count);
948 END_DATAcxx . . $ END_DATA(dde21517a502ab05).(count, data, size);
949
950 nw_Sendcxx . . $ nw_Send(102d2f582237fe86).(&check_addr, data, count, 0);
951
952 // Num_network_games_known=0;
953 }
954
955 int packsize;
956 while (((packsize = nw_Receivecxx . . $ nw_Receive(4faaf8d0141e84f4).(Multi_receive_buffercxx . . $ Multi_receive_buffer., &from_addr)) > 0)) {
957 MultiProcessBigDatacxx . . $ MultiProcessBigData(c3263a6d42f31e8c).(Multi_receive_buffercxx . . $ Multi_receive_buffer., packsize, &from_addr);
958 }
959 return Num_network_games_knowncxx . . $ Num_network_games_known.;
960 }
961
962 #define MULTI_SERVER_TIMEOUT_TIMEcxx . . $ `Descent3/multi_connect.cpp:962:9`! 40
963 extern bool Multi_Gamelist_changedcxx . . $ Multi_Gamelist_changed.;
964
965 void UpdateAndPackGameListcxx . . $ UpdateAndPackGameList(49f6e7a06ebc5aa8).(void) {
966 float curtime = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!();
967 for (int i = 0; i < Num_network_games_knowncxx . . $ Num_network_games_known.; i++) {
968 // Network_games[i]
969 if ((curtime - Network_gamescxx . . $ Network_games.[i].last_updatecxx . . $ network_game#last_update.) > MULTI_SERVER_TIMEOUT_TIMEcxx . . $ `Descent3/multi_connect.cpp:962:9`!) {
970 memcpy(&Network_gamescxx . . $ Network_games.[i], &Network_gamescxx . . $ Network_games.[Num_network_games_knowncxx . . $ Num_network_games_known.], sizeof(network_gamecxx . . $ network_game#));
971 Num_network_games_knowncxx . . $ Num_network_games_known.--;
972 i = 0;
973 Multi_Gamelist_changedcxx . . $ Multi_Gamelist_changed. = true;
974 }
975 }
976 }
977
978 // Sets whether or not the server answsers to a connection request
979 void MultiSetAcceptStatecxx . . $ MultiSetAcceptState(b45ddcbc8423892c).(bool state) {
980 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Setting multi_accept_state to %s.\n", state ? "true" : "false");
981 Multi_accept_statecxx . . $ Multi_accept_state. = state;
982 }