Debian Codegraph @

netgames/dmfc/dmfcprecord.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/Dmfc/dmfcprecord.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003/08/26 03:57:21 $
23 * $Author: kevinb $
24 *
25 * DMFC Player record functions
26 *
27 * $Log: dmfcprecord.cpp,v $
28 * Revision 1.1.1.1 2003/08/26 03:57:21 kevinb
29 * initial 1.5 import
30 *
31 *
32 * 18 10/21/99 9:28p Jeff
33 * B.A. Macintosh code merge
34 *
35 * 17 7/09/99 2:54p Jeff
36 * handle gametime better (pause it when needed) if the server is 'waiting
37 * for players'
38 *
39 * 16 5/21/99 10:44p Jeff
40 * fix PXO crash due to bytes being out of line when joining a game
41 *
42 * 15 5/13/99 4:55p Ardussi
43 * changes for compiling on the Mac
44 *
45 * 14 5/12/99 11:05p Jeff
46 * dmfc and multiplayer games now have endian friendly packets (*whew*)
47 *
48 * 13 3/17/99 12:25p Jeff
49 * converted DMFC to be COM interface
50 *
51 * 12 2/11/99 12:51a Jeff
52 * changed names of exported variables
53 *
54 * 11 12/08/98 4:47p Jeff
55 * umm, various changes, fixed pilot pics so that they work for everyone
56 * now
57 *
58 * 10 11/11/98 7:19p Jeff
59 * changes made so that a dedicated server's team is always -1 (team game
60 * or not)
61 *
62 * 9 10/18/98 7:59p Jeff
63 * functions added to dmfc for client->server objnum matching. Banning
64 * now uses tracker id when available.
65 *
66 * 8 10/17/98 7:30p Jeff
67 * network_address compares don't compare port on somethings
68 *
69 * 7 9/30/98 3:50p Jeff
70 * general improvements (many)
71 *
72 * 6 9/29/98 3:04p Jeff
73 * added time in game and start_time support
74 *
75 * 5 9/22/98 5:20p Jason
76 * fixed some player bugs
77 *
78 * 4 9/21/98 7:11p Jeff
79 * made InputCommand interface API and moved existing input commands to
80 * the interface. Changed mprintf/ASSERT so they are valid in DMFC
81 *
82 * $NoKeywords: $
83 */
84
85 #include "gamedll_header.h"cxx . . $ `<file>/netgames/includes/gamedll_header.h`/
86 #include "DMFC.h"cxx . . $ `<file>/netgames/includes/DMFC.h`/
87 #include "dmfcinternal.h"cxx . . $ `<file>/netgames/dmfc/dmfcinternal.h`/
88 #include <stdlib.h>
89 #include <string.h>
90
91 extern DMFCBasecxx . . $ DMFCBase# *basethiscxx . . $ basethis.;
92 player_recordcxx . . $ player_record# Player_recordscxx . . $ Player_records.[MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!];
93 int Pnum_to_PReccxx . . $ Pnum_to_PRec.[DLLMAX_PLAYERScxx . . $ `netgames/includes/DMFC.h:425:9`!];
94
95 // callback pointers for packet packing and unpacking
96 int (*Player_record_pack_cbcxx . . $ Player_record_pack_cb.)(void *user_info, uint8_tcxx . . $ uint8_t# *data);
97 int (*Player_record_unpack_cbcxx . . $ Player_record_unpack_cb.)(void *user_info, uint8_tcxx . . $ uint8_t# *data);
98
99 // Initializes the Player records
100 void PRec_Initcxx . . $ PRec_Init(49f6e7a06ebc5aa8).(void) {
101 int i;
102
103 for (i = 0; i < MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!; i++) {
104 memset(&Player_recordscxx . . $ Player_records.[i], 0, sizeof(player_recordcxx . . $ player_record#));
105 Player_recordscxx . . $ Player_records.[i].statecxx . . $ player_record#state. = STATE_EMPTYcxx . . $ STATE_EMPTY.;
106 Player_recordscxx . . $ Player_records.[i].user_infocxx . . $ player_record#user_info. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
107 Player_recordscxx . . $ Player_records.[i].pinfocxx . . $ player_record#pinfo. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
108 Player_recordscxx . . $ Player_records.[i].tracker_idcxx . . $ player_record#tracker_id. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
109 Player_recordscxx . . $ Player_records.[i].user_info_sizecxx . . $ player_record#user_info_size. = 0;
110 Player_recordscxx . . $ Player_records.[i].total_time_in_gamecxx . . $ player_record#total_time_in_game. = 0;
111 }
112 for (i = 0; i < DLLMAX_PLAYERScxx . . $ `netgames/includes/DMFC.h:425:9`!; i++)
113 Pnum_to_PReccxx . . $ Pnum_to_PRec.[i] = -1;
114
115 Player_record_pack_cbcxx . . $ Player_record_pack_cb. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
116 Player_record_unpack_cbcxx . . $ Player_record_unpack_cb. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
117 }
118
119 // Frees up and closes the Player records
120 void PRec_Closecxx . . $ PRec_Close(49f6e7a06ebc5aa8).(void) {
121 for (int i = 0; i < MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!; i++) {
122 if (Player_recordscxx . . $ Player_records.[i].user_infocxx . . $ player_record#user_info.)
123 free(Player_recordscxx . . $ Player_records.[i].user_infocxx . . $ player_record#user_info.);
124
125 if (Player_recordscxx . . $ Player_records.[i].tracker_idcxx . . $ player_record#tracker_id.)
126 free(Player_recordscxx . . $ Player_records.[i].tracker_idcxx . . $ player_record#tracker_id.);
127
128 if (Player_recordscxx . . $ Player_records.[i].pinfocxx . . $ player_record#pinfo.) {
129 delete Player_recordscxx . . $ Player_records.[i].pinfocxx . . $ player_record#pinfo.;
130 Player_recordscxx . . $ Player_records.[i].pinfocxx . . $ player_record#pinfo. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
131 }
132 }
133 Player_record_pack_cbcxx . . $ Player_record_pack_cb. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
134 Player_record_unpack_cbcxx . . $ Player_record_unpack_cb. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
135 }
136
137 // Sets up the Player records so they can be used for Multiplayer user defined stats
138 // sizeof_user_stats : size of the struct for each player's stats
139 // pack_callback : callback function called when data from the struct needs to be packed
140 // into a packet. It is SUPER important that this function packs the data
141 // in little endian format. This function gets a pointer to the struct that
142 // needs to be packed (user_info), and a buffer in which to pack it to. This
143 // function is to return the number of bytes it has packed.
144 // unpack_callback : callback function called when data from the struct needs to be unpacket
145 // from a packet. This data will be in little endian format. Returns the number of
146 // bytes unpacked.
147 // returns: 1 if size given was <=0 (if so all previous user stats will be removed)
148 // 0 all went ok
149 // -1 out of memory (all user stats memory will be freed)
150 // -2 invalid callbacks
151 int PRec_SetupUserPReccxx . . $ PRec_SetupUserPRec(7df49e8a00e47932).(int sizeof_user_stats, int (*pack_callback)(void *user_info, uint8_tcxx . . $ uint8_t# *data),
152 int (*unpack_callback)(void *user_info, uint8_tcxx . . $ uint8_t# *data)) {
153 ASSERTcxx . . $ `netgames/includes/DMFC.h:370:9`!(pack_callback != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
154 ASSERTcxx . . $ `netgames/includes/DMFC.h:370:9`!(unpack_callback != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
155 if (!pack_callback || !unpack_callback)
156 return -2;
157
158 int i;
159
160 // calculate to make sure they don't specify too much
161 int size = MAX_GAME_DATA_SIZEcxx . . $ `Descent3/multi_external.h:134:9`! - (104 + 5 * MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!);
162 if (sizeof_user_stats > size) {
163 // the user mod specified too big of a size
164 mprintfcxx . . $ `netgames/dmfc/dmfcinternal.h:275:9`!(0, "DMFC Warning: In PRec_SetupUserPRec(), the size given is too large for a packet\n");
165 Int3cxx . . $ `netgames/includes/DMFC.h:378:9`!();
166 goto user_stats_err;
167 }
168
169 // check the first item to see whats set for it
170 if (Player_recordscxx . . $ Player_records.[0].user_infocxx . . $ player_record#user_info.) {
171 // we need to free up all the user_info's
172 for (i = 0; i < MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!; i++) {
173 if (Player_recordscxx . . $ Player_records.[i].user_infocxx . . $ player_record#user_info.) {
174 free(Player_recordscxx . . $ Player_records.[i].user_infocxx . . $ player_record#user_info.);
175 Player_recordscxx . . $ Player_records.[i].user_infocxx . . $ player_record#user_info. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
176 }
177 Player_recordscxx . . $ Player_records.[i].user_info_sizecxx . . $ player_record#user_info_size. = 0;
178 }
179 }
180
181 if (sizeof_user_stats <= 0)
182 return 1;
183
184 for (i = 0; i < MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!; i++) {
185 Player_recordscxx . . $ Player_records.[i].user_infocxx . . $ player_record#user_info. = malloc(sizeof_user_stats);
186 if (!Player_recordscxx . . $ Player_records.[i].user_infocxx . . $ player_record#user_info.)
187 goto user_stats_err;
188 Player_recordscxx . . $ Player_records.[i].user_info_sizecxx . . $ player_record#user_info_size. = sizeof_user_stats;
189 memset(Player_recordscxx . . $ Player_records.[i].user_infocxx . . $ player_record#user_info., 0, sizeof_user_stats);
190 }
191
192 Player_record_pack_cbcxx . . $ Player_record_pack_cb. = pack_callback;
193 Player_record_unpack_cbcxx . . $ Player_record_unpack_cb. = unpack_callback;
194
195 return 0;
196
197 user_stats_err:
198 for (i = 0; i < MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!; i++) {
199 if (Player_recordscxx . . $ Player_records.[i].user_infocxx . . $ player_record#user_info.) {
200 free(Player_recordscxx . . $ Player_records.[i].user_infocxx . . $ player_record#user_info.);
201 Player_recordscxx . . $ Player_records.[i].user_infocxx . . $ player_record#user_info. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
202 }
203 Player_recordscxx . . $ Player_records.[i].user_info_sizecxx . . $ player_record#user_info_size. = 0;
204 }
205 return -1;
206 }
207
208 // Given a pnum it will return the PRec slot of that player, or -1 if it's not a valid player
209 int PRec_GetPlayerSlotcxx . . $ PRec_GetPlayerSlot(7864480464b09eea).(int pnum) {
210 if ((pnum < 0) || (pnum >= DLLMAX_PLAYERScxx . . $ `netgames/includes/DMFC.h:425:9`!))
211 return -1;
212 return Pnum_to_PReccxx . . $ Pnum_to_PRec.[pnum];
213 }
214
215 // Given a PRec slot, it returns a pointer to the user stats struct, NULL if error, or PRec_SetupUserPRec
216 // hasn't been called yet
217 void *PRec_GetUserStatscxx . . $ PRec_GetUserStats(d1680a912d714170).(int slot) {
218 if ((slot < 0) || (slot >= MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!))
219 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
220 return Player_recordscxx . . $ Player_records.[slot].user_infocxx . . $ player_record#user_info.;
221 }
222
223 // Returns a pointer to a player_record for the requested slot, NULL if error
224 player_recordcxx . . $ player_record# *PRec_GetPRecordcxx . . $ PRec_GetPRecord(6359c6f28dd028ae).(int slot) {
225 if ((slot < 0) || (slot >= MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!))
226 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
227 return &Player_recordscxx . . $ Player_records.[slot];
228 }
229
230 // Returns a pointer to a player_record of a player, NULL if error
231 player_recordcxx . . $ player_record# *PRec_GetPRecordByPnumcxx . . $ PRec_GetPRecordByPnum(6359c6f28dd028ae).(int pnum) {
232 int slot = PRec_GetPlayerSlotcxx . . $ PRec_GetPlayerSlot(7864480464b09eea).(pnum);
233 return PRec_GetPRecordcxx . . $ PRec_GetPRecord(6359c6f28dd028ae).(slot);
234 }
235
236 // Sets a disconnect time for a player
237 void PRec_SetDisconnectTimecxx . . $ PRec_SetDisconnectTime(43c79ee2f1b9aefe).(int slot, float time) {
238 if ((slot < 0) || (slot >= MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!))
239 return;
240 Player_recordscxx . . $ Player_records.[slot].disconnect_timecxx . . $ player_record#$anonymous_type_0#disconnect_time. = time;
241 }
242
243 // Returns the PRec slot of a player who matches the given info, -1 if none
244 // addr = network address (can be NULL)
245 // tracker_id = Mastertracker ID (can be NULL)
246 int PRec_FindPlayercxx . . $ PRec_FindPlayer(4f784f6a1e751a10).(const char *callsign, network_addresscxx . . $ network_address# *addr, const char *tracker_id) {
247 if (!callsign)
248 return -1;
249
250 bool good_to_use;
251
252 for (int i = 0; i < MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!; i++) {
253 // check if the slot isn't empty
254 if (Player_recordscxx . . $ Player_records.[i].statecxx . . $ player_record#state. == STATE_DISCONNECTEDcxx . . $ STATE_DISCONNECTED.) {
255
256 if (!strcmp(Player_recordscxx . . $ Player_records.[i].callsigncxx . . $ player_record#callsign., callsign)) {
257 // we have a possible match, the callsign matches
258
259 good_to_use = true;
260
261 if (addr) {
262 // we need to check the network address
263 if (!basethiscxx . . $ basethis.->CompareNetworkAddresscxx . . $ DMFCBase#CompareNetworkAddress(3c6f311cdf2181f2).(&Player_recordscxx . . $ Player_records.[i].net_addrcxx . . $ player_record#net_addr., addr, false))
264 good_to_use = false; // the network address doesn't match
265 }
266
267 if (tracker_id && good_to_use) {
268 // we need to check the master tracker_id
269 if (Player_recordscxx . . $ Player_records.[i].tracker_idcxx . . $ player_record#tracker_id.) {
270 if (strcmp(Player_recordscxx . . $ Player_records.[i].tracker_idcxx . . $ player_record#tracker_id., tracker_id)) {
271 good_to_use = false; // the tracker_id doesn't match
272 }
273 } else {
274 good_to_use = false;
275 }
276 }
277
278 if (good_to_use) {
279 // we found the player based on the information passed in
280 return i;
281 }
282 }
283 }
284 }
285 return -1; // no matches
286 }
287
288 // Gets the first available free slot (STATE_EMPTY), if none are available it clears and returns
289 // the oldest disconnected player (STATE_DISCONNECTED)
290 int PRec_GetFreeSlotcxx . . $ PRec_GetFreeSlot(b126dc7c1de90089).(void) {
291 int i, old_player = -1;
292 float old_time = 9999999.0f;
293 for (i = 0; i < MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!; i++) {
294 if (Player_recordscxx . . $ Player_records.[i].statecxx . . $ player_record#state. == STATE_EMPTYcxx . . $ STATE_EMPTY.)
295 return i; // we found a free slot
296 if (Player_recordscxx . . $ Player_records.[i].statecxx . . $ player_record#state. == STATE_DISCONNECTEDcxx . . $ STATE_DISCONNECTED.) {
297 if (old_player == -1) {
298 // we found our first, so make sure we mark it
299 old_player = i;
300 old_time = Player_recordscxx . . $ Player_records.[i].disconnect_timecxx . . $ player_record#$anonymous_type_0#disconnect_time.;
301 }
302 // check to see if this player has been disconnected longer than any others
303 if (Player_recordscxx . . $ Player_records.[i].disconnect_timecxx . . $ player_record#$anonymous_type_0#disconnect_time. < old_time) {
304 // he has
305 old_time = Player_recordscxx . . $ Player_records.[i].disconnect_timecxx . . $ player_record#$anonymous_type_0#disconnect_time.;
306 old_player = i;
307 }
308 }
309 }
310
311 ASSERTcxx . . $ `netgames/includes/DMFC.h:370:9`!(old_player != -1);
312
313 if (old_player != -1) {
314 // go through all the records and remove this guy as a victim
315 for (int p = 0; p < MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!; p++) {
316 if ((p != old_player) && (Player_recordscxx . . $ Player_records.[p].pinfocxx . . $ player_record#pinfo.)) {
317 Player_recordscxx . . $ Player_records.[p].pinfocxx . . $ player_record#pinfo.->RemoveKillercxx . . $ PInfo#RemoveKiller(d4f767463ce0a6b3).(old_player);
318 }
319 }
320
321 // clear out this player
322 if (Player_recordscxx . . $ Player_records.[old_player].tracker_idcxx . . $ player_record#tracker_id.)
323 free(Player_recordscxx . . $ Player_records.[old_player].tracker_idcxx . . $ player_record#tracker_id.);
324 void *save_ptr = Player_recordscxx . . $ Player_records.[old_player].user_infocxx . . $ player_record#user_info.;
325 int size = Player_recordscxx . . $ Player_records.[old_player].user_info_sizecxx . . $ player_record#user_info_size.;
326 if (Player_recordscxx . . $ Player_records.[old_player].pinfocxx . . $ player_record#pinfo.) {
327 delete Player_recordscxx . . $ Player_records.[old_player].pinfocxx . . $ player_record#pinfo.;
328 Player_recordscxx . . $ Player_records.[old_player].pinfocxx . . $ player_record#pinfo. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
329 }
330 memset(&Player_recordscxx . . $ Player_records.[old_player], 0, sizeof(player_recordcxx . . $ player_record#));
331 Player_recordscxx . . $ Player_records.[old_player].statecxx . . $ player_record#state. = STATE_EMPTYcxx . . $ STATE_EMPTY.;
332 Player_recordscxx . . $ Player_records.[old_player].user_infocxx . . $ player_record#user_info. = save_ptr;
333 Player_recordscxx . . $ Player_records.[old_player].user_info_sizecxx . . $ player_record#user_info_size. = size;
334 Player_recordscxx . . $ Player_records.[old_player].total_time_in_gamecxx . . $ player_record#total_time_in_game. = 0;
335 }
336 return old_player;
337 }
338
339 // Assigns a player to a specified slot (fills in the info, and prepares the slot for action)
340 // Do Not use this for a reconnecting player
341 bool PRec_AssignPlayerToSlotcxx . . $ PRec_AssignPlayerToSlot(a983d75b38abae39).(int pnum, int slot, playercxx . . $ player# *players_array, netplayercxx . . $ netplayer# *netplayers_array) {
342 if ((slot < 0) || (slot >= MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!))
343 return false;
344 if ((pnum < 0) || (pnum >= DLLMAX_PLAYERScxx . . $ `netgames/includes/DMFC.h:425:9`!))
345 return false;
346 if (!players_array)
347 return false;
348 if (!netplayers_array)
349 return false;
350 if (Player_recordscxx . . $ Player_records.[slot].statecxx . . $ player_record#state. != STATE_EMPTYcxx . . $ STATE_EMPTY.)
351 return false;
352
353 Pnum_to_PReccxx . . $ Pnum_to_PRec.[pnum] = slot;
354 Player_recordscxx . . $ Player_records.[slot].statecxx . . $ player_record#state. = STATE_INGAMEcxx . . $ STATE_INGAME.;
355 strcpy(Player_recordscxx . . $ Player_records.[slot].callsigncxx . . $ player_record#callsign., players_array[pnum].callsigncxx . . $ player#callsign.);
356 memcpy(&Player_recordscxx . . $ Player_records.[slot].net_addrcxx . . $ player_record#net_addr., &netplayers_array[pnum].addrcxx . . $ netplayer#addr., sizeof(network_addresscxx . . $ network_address#));
357 Player_recordscxx . . $ Player_records.[slot].pnumcxx . . $ player_record#pnum. = pnum;
358 Player_recordscxx . . $ Player_records.[slot].start_timecxx . . $ player_record#$anonymous_type_0#start_time. = basethiscxx . . $ basethis.->GetRealGametimecxx . . $ DMFCBase#GetRealGametime(a493af64c7bc6d09).();
359 Player_recordscxx . . $ Player_records.[slot].total_time_in_gamecxx . . $ player_record#total_time_in_game. = 0;
360 Player_recordscxx . . $ Player_records.[slot].teamcxx . . $ player_record#team. = players_array[pnum].teamcxx . . $ player#team.;
361
362 if (basethiscxx . . $ basethis.->IsMasterTrackerGamecxx . . $ DMFCBase#IsMasterTrackerGame(c9857a73d68e59ba).() && (basethiscxx . . $ basethis.->Playerscxx . . $ DMFCBase#Players.[pnum].tracker_idcxx . . $ player#tracker_id.)) {
363 // we are in a master tracker game, so save the tracker ID
364 mprintfcxx . . $ `netgames/dmfc/dmfcinternal.h:275:9`!(0, "PREC: Got a PXO Player ID of %s\n", basethis->Players[pnum].tracker_id);
365 Player_recordscxx . . $ Player_records.[slot].tracker_idcxx . . $ player_record#tracker_id. = strdup(basethiscxx . . $ basethis.->Playerscxx . . $ DMFCBase#Players.[pnum].tracker_idcxx . . $ player#tracker_id.);
366 } else {
367 // either it's not a tracker game or the tracker_id member of players is void
368 Player_recordscxx . . $ Player_records.[slot].tracker_idcxx . . $ player_record#tracker_id. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
369 }
370
371 memset(&Player_recordscxx . . $ Player_records.[slot].dstatscxx . . $ player_record#dstats., 0, sizeof(t_dstatcxx . . $ t_dstat#));
372 if (Player_recordscxx . . $ Player_records.[slot].pinfocxx . . $ player_record#pinfo.) {
373 delete Player_recordscxx . . $ Player_records.[slot].pinfocxx . . $ player_record#pinfo.;
374 Player_recordscxx . . $ Player_records.[slot].pinfocxx . . $ player_record#pinfo. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
375 }
376 Player_recordscxx . . $ Player_records.[slot].pinfocxx . . $ player_record#pinfo. = new PInfocxx . . $ PInfo#PInfo(d4f767463ce0a6b3).(slot);
377 return true;
378 }
379
380 // Reconnects a player to a STATE_DISCONNECTED slot
381 bool PRec_ReconnectPlayerToSlotcxx . . $ PRec_ReconnectPlayerToSlot(a983d75b38abae39).(int pnum, int slot, playercxx . . $ player# *players_array, netplayercxx . . $ netplayer# *netplayers_array) {
382 if ((slot < 0) || (slot >= MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!))
383 return false;
384 if ((pnum < 0) || (pnum >= DLLMAX_PLAYERScxx . . $ `netgames/includes/DMFC.h:425:9`!))
385 return false;
386 if (!players_array)
387 return false;
388 if (!netplayers_array)
389 return false;
390 if (Player_recordscxx . . $ Player_records.[slot].statecxx . . $ player_record#state. != STATE_DISCONNECTEDcxx . . $ STATE_DISCONNECTED.)
391 return false;
392
393 Pnum_to_PReccxx . . $ Pnum_to_PRec.[pnum] = slot;
394 Player_recordscxx . . $ Player_records.[slot].statecxx . . $ player_record#state. = STATE_INGAMEcxx . . $ STATE_INGAME.;
395 strcpy(Player_recordscxx . . $ Player_records.[slot].callsigncxx . . $ player_record#callsign., players_array[pnum].callsigncxx . . $ player#callsign.);
396 memcpy(&Player_recordscxx . . $ Player_records.[slot].net_addrcxx . . $ player_record#net_addr., &netplayers_array[pnum].addrcxx . . $ netplayer#addr., sizeof(network_addresscxx . . $ network_address#));
397 Player_recordscxx . . $ Player_records.[slot].pnumcxx . . $ player_record#pnum. = pnum;
398 Player_recordscxx . . $ Player_records.[slot].start_timecxx . . $ player_record#$anonymous_type_0#start_time. = basethiscxx . . $ basethis.->GetRealGametimecxx . . $ DMFCBase#GetRealGametime(a493af64c7bc6d09).();
399
400 if (!Player_recordscxx . . $ Player_records.[slot].pinfocxx . . $ player_record#pinfo.) {
401 // try to create the pinfo now
402 Player_recordscxx . . $ Player_records.[slot].pinfocxx . . $ player_record#pinfo. = new PInfocxx . . $ PInfo#PInfo(d4f767463ce0a6b3).(slot);
403 }
404 return true;
405 }
406
407 // Disconnects a player from the Player records
408 bool PRec_DisconnectPlayercxx . . $ PRec_DisconnectPlayer(83c267b20bac841a).(int pnum) {
409 if ((pnum < 0) || (pnum >= DLLMAX_PLAYERScxx . . $ `netgames/includes/DMFC.h:425:9`!))
410 return false;
411
412 int slot = Pnum_to_PReccxx . . $ Pnum_to_PRec.[pnum];
413 if (slot == -1)
414 return false; // player was never connected
415
416 Pnum_to_PReccxx . . $ Pnum_to_PRec.[pnum] = -1;
417 Player_recordscxx . . $ Player_records.[slot].statecxx . . $ player_record#state. = STATE_DISCONNECTEDcxx . . $ STATE_DISCONNECTED.;
418 Player_recordscxx . . $ Player_records.[slot].pnumcxx . . $ player_record#pnum. = -1;
419
420 float curr_time = basethiscxx . . $ basethis.->GetRealGametimecxx . . $ DMFCBase#GetRealGametime(a493af64c7bc6d09).();
421 float time_in = curr_time - Player_recordscxx . . $ Player_records.[slot].start_timecxx . . $ player_record#$anonymous_type_0#start_time.;
422 if (time_in > 0) {
423 Player_recordscxx . . $ Player_records.[slot].total_time_in_gamecxx . . $ player_record#total_time_in_game. += time_in;
424 }
425
426 PRec_SetDisconnectTimecxx . . $ PRec_SetDisconnectTime(43c79ee2f1b9aefe).(slot, curr_time);
427 return true;
428 }
429
430 // Clear all the level volatile (things that reset with the change of levels) things
431 void PRec_LevelResetcxx . . $ PRec_LevelReset(49f6e7a06ebc5aa8).(void) {
432 t_dstatcxx . . $ t_dstat# *stat;
433 for (int i = 0; i < MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!; i++) {
434 stat = &Player_recordscxx . . $ Player_records.[i].dstatscxx . . $ player_record#dstats.;
435 stat->killscxx . . $ t_dstat#kills.[DSTAT_LEVELcxx . . $ `netgames/includes/DMFC.h:527:9`!] = 0;
436 stat->deathscxx . . $ t_dstat#deaths.[DSTAT_LEVELcxx . . $ `netgames/includes/DMFC.h:527:9`!] = 0;
437 stat->suicidescxx . . $ t_dstat#suicides.[DSTAT_LEVELcxx . . $ `netgames/includes/DMFC.h:527:9`!] = 0;
438 if (Player_recordscxx . . $ Player_records.[i].pinfocxx . . $ player_record#pinfo.)
439 Player_recordscxx . . $ Player_records.[i].pinfocxx . . $ player_record#pinfo.->ResetAllcxx . . $ PInfo#ResetAll(49f6e7a06ebc5aa8).();
440 }
441 }
442
443 // Gets the team of a player given the pnum
444 int PRec_GetPlayerTeamcxx . . $ PRec_GetPlayerTeam(7864480464b09eea).(int pnum) {
445 int slot = PRec_GetPlayerSlotcxx . . $ PRec_GetPlayerSlot(7864480464b09eea).(pnum);
446 if (slot == -1)
447 return 0;
448 return Player_recordscxx . . $ Player_records.[slot].teamcxx . . $ player_record#team.;
449 }
450
451 // Sets the team of a player given the pnum
452 void PRec_SetPlayerTeamcxx . . $ PRec_SetPlayerTeam(3e454b8ccf442868).(int pnum, int team) {
453 int slot = PRec_GetPlayerSlotcxx . . $ PRec_GetPlayerSlot(7864480464b09eea).(pnum);
454 if (slot == -1)
455 return;
456 Player_recordscxx . . $ Player_records.[slot].teamcxx . . $ player_record#team. = team;
457 }
458
459 void MultiPackNetworkAddresscxx . . $ MultiPackNetworkAddress(ebc41e8502ef59a3).(network_addresscxx . . $ network_address# *addr, uint8_tcxx . . $ uint8_t# *data, int *count) {
460 memcpy(&data[*count], addr->addresscxx . . $ network_address#address., 6);
461 (*count) += 6;
462 MultiAddUshortcxx . . $ MultiAddUshort(309f537dbae2306e).(addr->portcxx . . $ network_address#port., data, count);
463 memcpy(&data[*count], addr->net_idcxx . . $ network_address#net_id., 4);
464 (*count) += 4;
465 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(addr->connection_typecxx . . $ network_address#connection_type., data, count);
466 }
467
468 void MultiUnpackNetworkAddresscxx . . $ MultiUnpackNetworkAddress(ebc41e8502ef59a3).(network_addresscxx . . $ network_address# *addr, uint8_tcxx . . $ uint8_t# *data, int *count) {
469 memcpy(addr->addresscxx . . $ network_address#address., &data[*count], 6);
470 (*count) += 6;
471 addr->portcxx . . $ network_address#port. = MultiGetUshortcxx . . $ MultiGetUshort(4574463662eb5370).(data, count);
472 memcpy(addr->net_idcxx . . $ network_address#net_id., &data[*count], 4);
473 (*count) += 4;
474 addr->connection_typecxx . . $ network_address#connection_type. = (network_protocolcxx . . $ network_protocol#)MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, count);
475 }
476
477 void MultiPackDStatscxx . . $ MultiPackDStats(add99152bad3d636).(t_dstatcxx . . $ t_dstat# *stat, uint8_tcxx . . $ uint8_t# *data, int *count) {
478 MultiAddIntcxx . . $ MultiAddInt(49f79918a3afee3).(stat->killscxx . . $ t_dstat#kills.[0], data, count);
479 MultiAddIntcxx . . $ MultiAddInt(49f79918a3afee3).(stat->killscxx . . $ t_dstat#kills.[1], data, count);
480 MultiAddIntcxx . . $ MultiAddInt(49f79918a3afee3).(stat->deathscxx . . $ t_dstat#deaths.[0], data, count);
481 MultiAddIntcxx . . $ MultiAddInt(49f79918a3afee3).(stat->deathscxx . . $ t_dstat#deaths.[1], data, count);
482 MultiAddIntcxx . . $ MultiAddInt(49f79918a3afee3).(stat->suicidescxx . . $ t_dstat#suicides.[0], data, count);
483 MultiAddIntcxx . . $ MultiAddInt(49f79918a3afee3).(stat->suicidescxx . . $ t_dstat#suicides.[1], data, count);
484 }
485
486 void MultiUnpackDStatscxx . . $ MultiUnpackDStats(add99152bad3d636).(t_dstatcxx . . $ t_dstat# *stat, uint8_tcxx . . $ uint8_t# *data, int *count) {
487 stat->killscxx . . $ t_dstat#kills.[0] = MultiGetIntcxx . . $ MultiGetInt(7337501fe74387bd).(data, count);
488 stat->killscxx . . $ t_dstat#kills.[1] = MultiGetIntcxx . . $ MultiGetInt(7337501fe74387bd).(data, count);
489 stat->deathscxx . . $ t_dstat#deaths.[0] = MultiGetIntcxx . . $ MultiGetInt(7337501fe74387bd).(data, count);
490 stat->deathscxx . . $ t_dstat#deaths.[1] = MultiGetIntcxx . . $ MultiGetInt(7337501fe74387bd).(data, count);
491 stat->suicidescxx . . $ t_dstat#suicides.[0] = MultiGetIntcxx . . $ MultiGetInt(7337501fe74387bd).(data, count);
492 stat->suicidescxx . . $ t_dstat#suicides.[1] = MultiGetIntcxx . . $ MultiGetInt(7337501fe74387bd).(data, count);
493 }
494
495 // Sends the Player records info to the given client
496 void PRec_SendPRecToPlayercxx . . $ PRec_SendPRecToPlayer(d4f767463ce0a6b3).(int pnum) {
497 if (basethiscxx . . $ basethis.->GetLocalRolecxx . . $ DMFCBase#GetLocalRole(b126dc7c1de90089).() != LR_SERVERcxx . . $ `Descent3/multi_external.h:129:9`!)
498 return;
499
500 uint8_tcxx . . $ uint8_t# data[MAX_GAME_DATA_SIZEcxx . . $ `Descent3/multi_external.h:134:9`!];
501 int callsignlen, totalsize, totalcount;
502 totalsize = totalcount = 0;
503 int pinfo_size, count;
504
505 for (int i = 0; i < MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!; i++) {
506 if (Player_recordscxx . . $ Player_records.[i].statecxx . . $ player_record#state. != STATE_EMPTYcxx . . $ STATE_EMPTY.) {
507 callsignlen = strlen(Player_recordscxx . . $ Player_records.[i].callsigncxx . . $ player_record#callsign.);
508
509 if (Player_recordscxx . . $ Player_records.[i].pinfocxx . . $ player_record#pinfo.)
510 pinfo_size = Player_recordscxx . . $ Player_records.[i].pinfocxx . . $ player_record#pinfo.->GetSizeOfDatacxx . . $ PInfo#GetSizeOfData(b126dc7c1de90089).();
511 else
512 pinfo_size = 0;
513
514 uint8_tcxx . . $ uint8_t# tracker_len = 0;
515
516 if (Player_recordscxx . . $ Player_records.[i].tracker_idcxx . . $ player_record#tracker_id.) {
517 tracker_len = strlen(Player_recordscxx . . $ Player_records.[i].tracker_idcxx . . $ player_record#tracker_id.);
518 }
519
520 count = 0;
521 basethiscxx . . $ basethis.->StartPacketcxx . . $ DMFCBase#StartPacket(261852a8f74abaa0).(data, SPID_PRECORDcxx . . $ `netgames/dmfc/dmfcinternal.h:2765:9`!, &count);
522
523 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(i, data, &count); // pack byte (record num)
524 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(Player_recordscxx . . $ Player_records.[i].statecxx . . $ player_record#state., data, &count); // pack byte (state)
525 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(callsignlen, data, &count); // pack byte (strlen(callsign))
526 memcpy(&data[count], Player_recordscxx . . $ Player_records.[i].callsigncxx . . $ player_record#callsign., callsignlen);
527 count += callsignlen; // pack bytes (callsign)
528 MultiPackNetworkAddresscxx . . $ MultiPackNetworkAddress(ebc41e8502ef59a3).(&Player_recordscxx . . $ Player_records.[i].net_addrcxx . . $ player_record#net_addr., data, &count); // pack bytes (network_address)
529 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(Player_recordscxx . . $ Player_records.[i].pnumcxx . . $ player_record#pnum., data, &count); // pack byte (pnum)
530 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).((Player_recordscxx . . $ Player_records.[i].teamcxx . . $ player_record#team. == -1) ? 255 : Player_recordscxx . . $ Player_records.[i].teamcxx . . $ player_record#team., data, &count); // pack byte (team)
531
532 if (basethiscxx . . $ basethis.->IsMasterTrackerGamecxx . . $ DMFCBase#IsMasterTrackerGame(c9857a73d68e59ba).()) {
533 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(1, data, &count);
534 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(tracker_len, data, &count); // pack byte (tracker len)
535 if (tracker_len) {
536 memcpy(&data[count], Player_recordscxx . . $ Player_records.[i].tracker_idcxx . . $ player_record#tracker_id., tracker_len);
537 count += tracker_len; // pack bytes (tracker_id)
538 }
539 } else {
540 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).(0, data, &count);
541 }
542
543 MultiAddFloatcxx . . $ MultiAddFloat(a76b0cec949d1afe).(Player_recordscxx . . $ Player_records.[i].disconnect_timecxx . . $ player_record#$anonymous_type_0#disconnect_time., data, &count); // pack float (disconnect_time/start_time)
544 MultiAddFloatcxx . . $ MultiAddFloat(a76b0cec949d1afe).(Player_recordscxx . . $ Player_records.[i].total_time_in_gamecxx . . $ player_record#total_time_in_game., data, &count); // pack float (total time in game)
545
546 MultiPackDStatscxx . . $ MultiPackDStats(add99152bad3d636).(&Player_recordscxx . . $ Player_records.[i].dstatscxx . . $ player_record#dstats., data, &count); // pack bytes (dstats)
547
548 MultiAddBytecxx . . $ MultiAddByte(3bbe8835367eaa4e).((Player_recordscxx . . $ Player_records.[i].user_info_sizecxx . . $ player_record#user_info_size. > 0) ? 1 : 0, data, &count); // pack byte (there is user info)
549 if (Player_recordscxx . . $ Player_records.[i].user_info_sizecxx . . $ player_record#user_info_size. > 0) // if(user_info_size>0)
550 {
551 if (Player_record_pack_cbcxx . . $ Player_record_pack_cb.) {
552 count += (*Player_record_pack_cbcxx . . $ Player_record_pack_cb.)(Player_recordscxx . . $ Player_records.[i].user_infocxx . . $ player_record#user_info., &data[count]);
553 } else {
554 Int3cxx . . $ `netgames/includes/DMFC.h:378:9`!();
555 count += Player_recordscxx . . $ Player_records.[i].user_info_sizecxx . . $ player_record#user_info_size.; // attempt to recover
556 }
557 }
558
559 // PInfo stuff
560 MultiAddIntcxx . . $ MultiAddInt(49f79918a3afee3).(pinfo_size, data, &count);
561 if (pinfo_size > 0) {
562 Player_recordscxx . . $ Player_records.[i].pinfocxx . . $ player_record#pinfo.->PackDatacxx . . $ PInfo#PackData(f25546b61a629de7).(&data[count]);
563 count += pinfo_size;
564 }
565
566 totalsize += count;
567 totalcount++;
568 basethiscxx . . $ basethis.->SendPacketcxx . . $ DMFCBase#SendPacket(49a5bbab55ea8abc).(data, count, pnum);
569 }
570 }
571
572 mprintfcxx . . $ `netgames/dmfc/dmfcinternal.h:275:9`!(0, "*Player Record: Send out %d packets of total %d bytes to %s\n",
573 totalcount,
574 totalsize,
575 basethis->Players[pnum].callsign);
576 }
577
578 // Receives the Player records info from the server
579 void PRec_ReceivePRecFromServercxx . . $ PRec_ReceivePRecFromServer(f25546b61a629de7).(uint8_tcxx . . $ uint8_t# *data) {
580 int count = 0;
581 int callsignlen;
582 int slot = MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count); // unpack byte (record num)
583 int pinfo_size;
584 player_recordcxx . . $ player_record# *pr;
585 ASSERTcxx . . $ `netgames/includes/DMFC.h:370:9`!((slot >= 0) && (slot < MAX_PLAYER_RECORDScxx . . $ `netgames/includes/DMFC.h:526:9`!));
586 pr = &Player_recordscxx . . $ Player_records.[slot];
587
588 pr->statecxx . . $ player_record#state. = (slot_statecxx . . $ slot_state#)MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count); // unpack byte (state)
589 callsignlen = MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count); // unpack byte (callsign length)
590 memcpy(pr->callsigncxx . . $ player_record#callsign., &data[count], callsignlen);
591 count += callsignlen; // unpack bytes (callsign)
592 pr->callsigncxx . . $ player_record#callsign.[callsignlen] = '\0';
593 MultiUnpackNetworkAddresscxx . . $ MultiUnpackNetworkAddress(ebc41e8502ef59a3).(&pr->net_addrcxx . . $ player_record#net_addr., data, &count); // unpack bytes (network address)
594 pr->pnumcxx . . $ player_record#pnum. = MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count); // unpack byte (pnum)
595 pr->teamcxx . . $ player_record#team. = MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count);
596 if (pr->teamcxx . . $ player_record#team. == 255) // unpack byte (team)
597 pr->teamcxx . . $ player_record#team. = -1;
598
599 if (MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count)) {
600 ASSERTcxx . . $ `netgames/includes/DMFC.h:370:9`!(basethis->IsMasterTrackerGame() != 0);
601 // there is tracker_id data coming in
602 uint8_tcxx . . $ uint8_t# len = MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count);
603 pr->tracker_idcxx . . $ player_record#tracker_id. = (char *)malloc(len + 1);
604
605 if (pr->tracker_idcxx . . $ player_record#tracker_id.) {
606 memcpy(pr->tracker_idcxx . . $ player_record#tracker_id., &data[count], len);
607 pr->tracker_idcxx . . $ player_record#tracker_id.[len] = '\0';
608 } else {
609 mprintfcxx . . $ `netgames/dmfc/dmfcinternal.h:275:9`!(0, "PREC: UH OH!!! OUT OF MEMORY\n");
610 }
611 count += len;
612 } else {
613 ASSERTcxx . . $ `netgames/includes/DMFC.h:370:9`!(basethis->IsMasterTrackerGame() == 0);
614 }
615
616 pr->disconnect_timecxx . . $ player_record#$anonymous_type_0#disconnect_time. = MultiGetFloatcxx . . $ MultiGetFloat(fe244d2c191680c4).(data, &count); // unpack float (disconnect time/start time)
617 pr->total_time_in_gamecxx . . $ player_record#total_time_in_game. = MultiGetFloatcxx . . $ MultiGetFloat(fe244d2c191680c4).(data, &count); // unpack float (total time in game)
618 MultiUnpackDStatscxx . . $ MultiUnpackDStats(add99152bad3d636).(&pr->dstatscxx . . $ player_record#dstats., data, &count); // unpack bytes (dstats)
619
620 if (MultiGetBytecxx . . $ MultiGetByte(96e36f15bd3e0281).(data, &count)) {
621 ASSERTcxx . . $ `netgames/includes/DMFC.h:370:9`!(pr->user_info != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
622 if (Player_record_unpack_cbcxx . . $ Player_record_unpack_cb.) {
623 count += (*Player_record_unpack_cbcxx . . $ Player_record_unpack_cb.)(pr->user_infocxx . . $ player_record#user_info., &data[count]);
624 } else {
625 Int3cxx . . $ `netgames/includes/DMFC.h:378:9`!();
626 count += pr->user_info_sizecxx . . $ player_record#user_info_size.; // attempt to recover
627 }
628 } else {
629 ASSERTcxx . . $ `netgames/includes/DMFC.h:370:9`!(pr->user_info == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
630 }
631
632 if (pr->pinfocxx . . $ player_record#pinfo.) {
633 delete pr->pinfocxx . . $ player_record#pinfo.;
634 }
635 pr->pinfocxx . . $ player_record#pinfo. = new PInfocxx . . $ PInfo#PInfo(d4f767463ce0a6b3).(slot);
636
637 // PInfo stuff
638 pinfo_size = MultiGetIntcxx . . $ MultiGetInt(7337501fe74387bd).(data, &count);
639 if (pinfo_size > 0) {
640 if (pr->pinfocxx . . $ player_record#pinfo.)
641 pr->pinfocxx . . $ player_record#pinfo.->UnpackDatacxx . . $ PInfo#UnpackData(6a46171b248bf29b).(&data[count], pinfo_size);
642 count += pinfo_size;
643 } else {
644 if (pr->pinfocxx . . $ player_record#pinfo.)
645 pr->pinfocxx . . $ player_record#pinfo.->ResetAllcxx . . $ PInfo#ResetAll(49f6e7a06ebc5aa8).();
646 }
647
648 if (pr->pnumcxx . . $ player_record#pnum. != 255) {
649 Pnum_to_PReccxx . . $ Pnum_to_PRec.[pr->pnumcxx . . $ player_record#pnum.] = slot;
650 }
651 }