Debian Codegraph @

src/network.c

raw symbols SCIP
1 /*
2 * OpenTyrian: A modern cross-platform port of Tyrian
3 * Copyright (C) 2007-2009 The OpenTyrian Development Team
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (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, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 #include "network.h"cxx . . $ `<file>/src/network.h`/
20
21 #include "episodes.h"cxx . . $ `<file>/src/episodes.h`/
22 #include "fonthand.h"cxx . . $ `<file>/src/fonthand.h`/
23 #include "helptext.h"cxx . . $ `<file>/src/helptext.h`/
24 #include "joystick.h"cxx . . $ `<file>/src/joystick.h`/
25 #include "keyboard.h"cxx . . $ `<file>/src/keyboard.h`/
26 #include "mainint.h"cxx . . $ `<file>/src/mainint.h`/
27 #include "nortvars.h"cxx . . $ `<file>/src/nortvars.h`/
28 #include "opentyr.h"cxx . . $ `<file>/src/opentyr.h`/
29 #include "picload.h"cxx . . $ `<file>/src/picload.h`/
30 #include "sprite.h"cxx . . $ `<file>/src/sprite.h`/
31 #include "varz.h"cxx . . $ `<file>/src/varz.h`/
32 #include "video.h"cxx . . $ `<file>/src/video.h`/
33
34 #include <assert.h>
35
36 /* HERE BE DRAGONS!
37 *
38 * When I wrote this code I thought it was wonderful... that thought was very
39 * wrong. It works, but good luck understanding how... I don't anymore.
40 *
41 * Hopefully it'll be rewritten some day.
42 */
43
44 #define NET_VERSIONcxx . . $ `src/network.c:44:9`! 2 // increment whenever networking changes might create incompatibility
45 #define NET_PORTcxx . . $ `src/network.c:45:9`! 1333 // UDP
46
47 #define NET_PACKET_SIZEcxx . . $ `src/network.c:47:9`! 256
48 #define NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`! 16
49
50 #define NET_RETRYcxx . . $ `src/network.c:50:9`! 640 // ticks to wait for packet acknowledgment before resending
51 #define NET_RESENDcxx . . $ `src/network.c:51:9`! 320 // ticks to wait before requesting unreceived game packet
52 #define NET_KEEP_ALIVEcxx . . $ `src/network.c:52:9`! 1600 // ticks to wait between keep-alive packets
53 #define NET_TIME_OUTcxx . . $ `src/network.c:53:9`! 16000 // ticks to wait before considering connection dead
54
55 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! isNetworkGamecxx . . $ isNetworkGame. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
56 int network_delaycxx . . $ network_delay. = 1 + 1; // minimum is 1 + 0
57
58 char *network_opponent_hostcxx . . $ network_opponent_host. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
59
60 Uint16cxx . . $ Uint16# network_player_portcxx . . $ network_player_port. = NET_PORTcxx . . $ `src/network.c:45:9`!,
61 network_opponent_portcxx . . $ network_opponent_port. = NET_PORTcxx . . $ `src/network.c:45:9`!;
62
63 static char empty_stringcxx . . $ empty_string.[] = "";
64 char *network_player_namecxx . . $ network_player_name. = empty_stringcxx . . $ empty_string.,
65 *network_opponent_namecxx . . $ network_opponent_name. = empty_stringcxx . . $ empty_string.;
66
67 #ifdef WITH_NETWORKcxx . . $ `<built-in>:413:9`!
68 static UDPsocketcxx . . $ UDPsocket# socketcxx . . $ socket.;
69 static IPaddresscxx . . $ IPaddress# ipcxx . . $ ip.;
70
71 UDPpacketcxx . . $ UDPpacket# *packet_out_tempcxx . . $ packet_out_temp.;
72 static UDPpacketcxx . . $ UDPpacket# *packet_tempcxx . . $ packet_temp.;
73
74 UDPpacketcxx . . $ UDPpacket# *packet_incxx . . $ packet_in.[NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!] = { NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! },
75 *packet_outcxx . . $ packet_out.[NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!] = { NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! };
76
77 static Uint16cxx . . $ Uint16# last_out_synccxx . . $ last_out_sync. = 0, queue_in_synccxx . . $ queue_in_sync. = 0, queue_out_synccxx . . $ queue_out_sync. = 0, last_ack_synccxx . . $ last_ack_sync. = 0;
78 static Uint32cxx . . $ Uint32# last_in_tickcxx . . $ last_in_tick. = 0, last_out_tickcxx . . $ last_out_tick. = 0;
79
80 UDPpacketcxx . . $ UDPpacket# *packet_state_incxx . . $ packet_state_in.[NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!] = { NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! };
81 static UDPpacketcxx . . $ UDPpacket# *packet_state_in_xorcxx . . $ packet_state_in_xor.[NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!] = { NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! };
82 UDPpacketcxx . . $ UDPpacket# *packet_state_outcxx . . $ packet_state_out.[NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!] = { NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! };
83
84 static Uint16cxx . . $ Uint16# last_state_in_synccxx . . $ last_state_in_sync. = 0, last_state_out_synccxx . . $ last_state_out_sync. = 0;
85 static Uint32cxx . . $ Uint32# last_state_in_tickcxx . . $ last_state_in_tick. = 0;
86
87 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! net_initializedcxx . . $ net_initialized. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
88 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! connectedcxx . . $ connected. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!, quitcxx . . $ quit. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
89 #endif
90
91 uintcxx . . $ uint# thisPlayerNumcxx . . $ thisPlayerNum. = 0; /* Player number on this PC (1 or 2) */
92
93 JE_booleancxx . . $ JE_boolean# haltGamecxx . . $ haltGame. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
94
95 JE_booleancxx . . $ JE_boolean# moveOkcxx . . $ moveOk.;
96
97 /* Special Requests */
98 JE_booleancxx . . $ JE_boolean# pauseRequestcxx . . $ pauseRequest., skipLevelRequestcxx . . $ skipLevelRequest., helpRequestcxx . . $ helpRequest., nortShipRequestcxx . . $ nortShipRequest.;
99 JE_booleancxx . . $ JE_boolean# yourInGameMenuRequestcxx . . $ yourInGameMenuRequest., inGameMenuRequestcxx . . $ inGameMenuRequest.;
100
101 #ifdef WITH_NETWORKcxx . . $ `<built-in>:413:9`!
102 static void packet_copycxx . . $ packet_copy(6d1a42db56636b51).(UDPpacketcxx . . $ UDPpacket# *dst, UDPpacketcxx . . $ UDPpacket# *src)
103 {
104 void *temp = dst->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data.;
105 memcpycxx . . $ memcpy(cc817cb175f282d).(dst, src, sizeof(*dst));
106 dst->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data. = temp;
107 memcpycxx . . $ memcpy(cc817cb175f282d).(dst->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data., src->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data., src->lencxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#len.);
108 }
109
110 static void packets_shift_upcxx . . $ packets_shift_up(5226cbd459a4ad92).(UDPpacketcxx . . $ UDPpacket# **packet, int max_packets)
111 {
112 if (packet[0])
113 {
114 SDLNet_FreePacketcxx . . $ SDLNet_FreePacket(3284117369f78e1f).(packet[0]);
115 }
116 for (int i = 0; i < max_packets - 1; i++)
117 {
118 packet[i] = packet[i + 1];
119 }
120 packet[max_packets - 1] = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
121 }
122
123 static void packets_shift_downcxx . . $ packets_shift_down(5226cbd459a4ad92).(UDPpacketcxx . . $ UDPpacket# **packet, int max_packets)
124 {
125 if (packet[max_packets - 1])
126 {
127 SDLNet_FreePacketcxx . . $ SDLNet_FreePacket(3284117369f78e1f).(packet[max_packets - 1]);
128 }
129 for (int i = max_packets - 1; i > 0; i--)
130 {
131 packet[i] = packet[i - 1];
132 }
133 packet[0] = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
134 }
135
136 // prepare new packet for sending
137 void network_preparecxx . . $ network_prepare(ed53e3bbd3fa2f69).(Uint16cxx . . $ Uint16# type)
138 {
139 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(type, &packet_out_temp->data[0]);
140 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(last_out_sync, &packet_out_temp->data[2]);
141 }
142
143 // send packet but don't expect acknowledgment of delivery
144 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! network_send_no_ackcxx . . $ network_send_no_ack(83c267b20bac841a).(int len)
145 {
146 packet_out_tempcxx . . $ packet_out_temp.->lencxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#len. = len;
147
148 if (!SDLNet_UDP_Sendcxx . . $ SDLNet_UDP_Send(5c2cf9425bb6832a).(socketcxx . . $ socket., 0, packet_out_tempcxx . . $ packet_out_temp.))
149 {
150 printfcxx . . $ printf(581fddd72a8db8fc).("SDLNet_UDP_Send: %s\n", SDL_GetErrorcxx . . $ SDL_GetError(33a1f659e94feb42).());
151 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
152 }
153
154 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
155 }
156
157 // send packet and place it in queue to be acknowledged
158 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! network_sendcxx . . $ network_send(83c267b20bac841a).(int len)
159 {
160 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! temp = network_send_no_ackcxx . . $ network_send_no_ack(83c267b20bac841a).(len);
161
162 Uint16cxx . . $ Uint16# i = last_out_synccxx . . $ last_out_sync. - queue_out_synccxx . . $ queue_out_sync.;
163 if (i < NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!)
164 {
165 packet_outcxx . . $ packet_out.[i] = SDLNet_AllocPacketcxx . . $ SDLNet_AllocPacket(a0a449a22b795c56).(NET_PACKET_SIZEcxx . . $ `src/network.c:47:9`!);
166 packet_copycxx . . $ packet_copy(6d1a42db56636b51).(packet_outcxx . . $ packet_out.[i], packet_out_tempcxx . . $ packet_out_temp.);
167 }
168 else
169 {
170 // connection is probably bad now
171 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "warning: outbound packet queue overflow\n");
172 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
173 }
174
175 last_out_synccxx . . $ last_out_sync.++;
176
177 if (network_is_synccxx . . $ network_is_sync(c9857a73d68e59ba).())
178 last_out_tickcxx . . $ last_out_tick. = SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).();
179
180 return temp;
181 }
182
183 // send acknowledgment packet
184 static int network_acknowledgecxx . . $ network_acknowledge(377f6a3136964dac).(Uint16cxx . . $ Uint16# sync)
185 {
186 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(PACKET_ACKNOWLEDGEcxx . . $ `src/network.h:29:9`!, &packet_out_temp->data[0]);
187 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(sync, &packet_out_temp->data[2]);
188 network_send_no_ackcxx . . $ network_send_no_ack(83c267b20bac841a).(4);
189
190 return 0;
191 }
192
193 // activity lately?
194 static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! network_is_alivecxx . . $ network_is_alive(c9857a73d68e59ba).(void)
195 {
196 return (SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).() - last_in_tickcxx . . $ last_in_tick. < NET_TIME_OUTcxx . . $ `src/network.c:53:9`! || SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).() - last_state_in_tickcxx . . $ last_state_in_tick. < NET_TIME_OUTcxx . . $ `src/network.c:53:9`!);
197 }
198
199 // poll for new packets received, check that connection is alive, resend queued packets if necessary
200 int network_checkcxx . . $ network_check(b126dc7c1de90089).(void)
201 {
202 if (!net_initializedcxx . . $ net_initialized.)
203 return -1;
204
205 if (connectedcxx . . $ connected.)
206 {
207 // timeout
208 if (!network_is_alivecxx . . $ network_is_alive(c9857a73d68e59ba).())
209 {
210 if (!quitcxx . . $ quit.)
211 network_tyrian_haltcxx . . $ network_tyrian_halt(ee2069353d7cc01f).(2, falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
212 }
213
214 // keep-alive
215 static Uint32cxx . . $ Uint32# keep_alive_tick = 0;
216 if (SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).() - keep_alive_tick > NET_KEEP_ALIVEcxx . . $ `src/network.c:52:9`!)
217 {
218 network_preparecxx . . $ network_prepare(ed53e3bbd3fa2f69).(PACKET_KEEP_ALIVEcxx . . $ `src/network.h:30:9`!);
219 network_send_no_ackcxx . . $ network_send_no_ack(83c267b20bac841a).(4);
220
221 keep_alive_tick = SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).();
222 }
223 }
224
225 // retry
226 if (packet_outcxx . . $ packet_out.[0] && SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).() - last_out_tickcxx . . $ last_out_tick. > NET_RETRYcxx . . $ `src/network.c:50:9`!)
227 {
228 if (!SDLNet_UDP_Sendcxx . . $ SDLNet_UDP_Send(5c2cf9425bb6832a).(socketcxx . . $ socket., 0, packet_outcxx . . $ packet_out.[0]))
229 {
230 printfcxx . . $ printf(581fddd72a8db8fc).("SDLNet_UDP_Send: %s\n", SDL_GetErrorcxx . . $ SDL_GetError(33a1f659e94feb42).());
231 return -1;
232 }
233
234 last_out_tickcxx . . $ last_out_tick. = SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).();
235 }
236
237 switch (SDLNet_UDP_Recvcxx . . $ SDLNet_UDP_Recv(fe1b9cd2cbe9dbea).(socketcxx . . $ socket., packet_tempcxx . . $ packet_temp.))
238 {
239 case -1:
240 printfcxx . . $ printf(581fddd72a8db8fc).("SDLNet_UDP_Recv: %s\n", SDL_GetErrorcxx . . $ SDL_GetError(33a1f659e94feb42).());
241 return -1;
242 break;
243 case 0:
244 break;
245 default:
246 if (packet_tempcxx . . $ packet_temp.->channelcxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#channel. == 0 && packet_tempcxx . . $ packet_temp.->lencxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#len. >= 4)
247 {
248 switch (SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_temp->data[0]))
249 {
250 case PACKET_ACKNOWLEDGEcxx . . $ `src/network.h:29:9`!:
251 if ((Uint16cxx . . $ Uint16#)(SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_temp->data[2]) - last_ack_synccxx . . $ last_ack_sync.) < NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!)
252 {
253 last_ack_synccxx . . $ last_ack_sync. = SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_temp->data[2]);
254 }
255
256 {
257 Uint16cxx . . $ Uint16# i = SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_temp->data[2]) - queue_out_synccxx . . $ queue_out_sync.;
258 if (i < NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!)
259 {
260 if (packet_outcxx . . $ packet_out.[i])
261 {
262 SDLNet_FreePacketcxx . . $ SDLNet_FreePacket(3284117369f78e1f).(packet_outcxx . . $ packet_out.[i]);
263 packet_outcxx . . $ packet_out.[i] = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
264 }
265 }
266 }
267
268 // remove acknowledged packets from queue
269 while (packet_outcxx . . $ packet_out.[0] == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! && (Uint16cxx . . $ Uint16#)(last_ack_synccxx . . $ last_ack_sync. - queue_out_synccxx . . $ queue_out_sync.) < NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!)
270 {
271 packets_shift_upcxx . . $ packets_shift_up(5226cbd459a4ad92).(packet_outcxx . . $ packet_out., NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!);
272
273 queue_out_synccxx . . $ queue_out_sync.++;
274 }
275
276 last_in_tickcxx . . $ last_in_tick. = SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).();
277 break;
278
279 case PACKET_CONNECTcxx . . $ `src/network.h:32:9`!:
280 queue_in_synccxx . . $ queue_in_sync. = SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_temp->data[2]);
281
282 for (int i = 0; i < NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!; i++)
283 {
284 if (packet_incxx . . $ packet_in.[i])
285 {
286 SDLNet_FreePacketcxx . . $ SDLNet_FreePacket(3284117369f78e1f).(packet_incxx . . $ packet_in.[i]);
287 packet_incxx . . $ packet_in.[i] = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
288 }
289 }
290 // fall through
291
292 case PACKET_DETAILScxx . . $ `src/network.h:33:9`!:
293 case PACKET_WAITINGcxx . . $ `src/network.h:36:9`!:
294 case PACKET_BUSYcxx . . $ `src/network.h:37:9`!:
295 case PACKET_GAME_QUITcxx . . $ `src/network.h:39:9`!:
296 case PACKET_GAME_PAUSEcxx . . $ `src/network.h:40:9`!:
297 case PACKET_GAME_MENUcxx . . $ `src/network.h:41:9`!:
298 {
299 Uint16cxx . . $ Uint16# i = SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_temp->data[2]) - queue_in_synccxx . . $ queue_in_sync.;
300 if (i < NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!)
301 {
302 if (packet_incxx . . $ packet_in.[i] == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
303 packet_incxx . . $ packet_in.[i] = SDLNet_AllocPacketcxx . . $ SDLNet_AllocPacket(a0a449a22b795c56).(NET_PACKET_SIZEcxx . . $ `src/network.c:47:9`!);
304 packet_copycxx . . $ packet_copy(6d1a42db56636b51).(packet_incxx . . $ packet_in.[i], packet_tempcxx . . $ packet_temp.);
305 }
306 else
307 {
308 // inbound packet queue overflow/underflow
309 // under normal circumstances, this is okay
310 }
311 }
312
313 network_acknowledgecxx . . $ network_acknowledge(377f6a3136964dac).(SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_temp->data[2]));
314 // fall through
315
316 case PACKET_KEEP_ALIVEcxx . . $ `src/network.h:30:9`!:
317 last_in_tickcxx . . $ last_in_tick. = SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).();
318 break;
319
320 case PACKET_QUITcxx . . $ `src/network.h:35:9`!:
321 if (!quitcxx . . $ quit.)
322 {
323 network_preparecxx . . $ network_prepare(ed53e3bbd3fa2f69).(PACKET_QUITcxx . . $ `src/network.h:35:9`!);
324 network_sendcxx . . $ network_send(83c267b20bac841a).(4); // PACKET_QUIT
325 }
326
327 network_acknowledgecxx . . $ network_acknowledge(377f6a3136964dac).(SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_temp->data[2]));
328
329 if (!quitcxx . . $ quit.)
330 network_tyrian_haltcxx . . $ network_tyrian_halt(ee2069353d7cc01f).(1, truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
331 break;
332
333 case PACKET_STATEcxx . . $ `src/network.h:44:9`!:
334 // place packet in queue if within limits
335 {
336 Uint16cxx . . $ Uint16# i = SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_temp->data[2]) - last_state_in_synccxx . . $ last_state_in_sync. + 1;
337 if (i < NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!)
338 {
339 if (packet_state_incxx . . $ packet_state_in.[i] == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
340 packet_state_incxx . . $ packet_state_in.[i] = SDLNet_AllocPacketcxx . . $ SDLNet_AllocPacket(a0a449a22b795c56).(NET_PACKET_SIZEcxx . . $ `src/network.c:47:9`!);
341 packet_copycxx . . $ packet_copy(6d1a42db56636b51).(packet_state_incxx . . $ packet_state_in.[i], packet_tempcxx . . $ packet_temp.);
342 }
343 }
344 break;
345
346 case PACKET_STATE_XORcxx . . $ `src/network.h:45:9`!:
347 // place packet in queue if within limits
348 {
349 Uint16cxx . . $ Uint16# i = SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_temp->data[2]) - last_state_in_synccxx . . $ last_state_in_sync. + 1;
350 if (i < NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!)
351 {
352 if (packet_state_in_xorcxx . . $ packet_state_in_xor.[i] == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
353 {
354 packet_state_in_xorcxx . . $ packet_state_in_xor.[i] = SDLNet_AllocPacketcxx . . $ SDLNet_AllocPacket(a0a449a22b795c56).(NET_PACKET_SIZEcxx . . $ `src/network.c:47:9`!);
355 packet_copycxx . . $ packet_copy(6d1a42db56636b51).(packet_state_in_xorcxx . . $ packet_state_in_xor.[i], packet_tempcxx . . $ packet_temp.);
356 }
357 else if (SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_state_in_xor[i]->data[0]) != PACKET_STATE_XORcxx . . $ `src/network.h:45:9`!)
358 {
359 for (int j = 4; j < packet_state_in_xorcxx . . $ packet_state_in_xor.[i]->lencxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#len.; j++)
360 packet_state_in_xorcxx . . $ packet_state_in_xor.[i]->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data.[j] ^= packet_tempcxx . . $ packet_temp.->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data.[j];
361 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(PACKET_STATE_XORcxx . . $ `src/network.h:45:9`!, &packet_state_in_xor[i]->data[0]);
362 }
363 }
364 }
365 break;
366
367 case PACKET_STATE_RESENDcxx . . $ `src/network.h:43:9`!:
368 // resend requested state packet if still available
369 {
370 Uint16cxx . . $ Uint16# i = last_state_out_synccxx . . $ last_state_out_sync. - SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_temp->data[2]);
371 if (i > 0 && i < NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!)
372 {
373 if (packet_state_outcxx . . $ packet_state_out.[i])
374 {
375 if (!SDLNet_UDP_Sendcxx . . $ SDLNet_UDP_Send(5c2cf9425bb6832a).(socketcxx . . $ socket., 0, packet_state_outcxx . . $ packet_state_out.[i]))
376 {
377 printfcxx . . $ printf(581fddd72a8db8fc).("SDLNet_UDP_Send: %s\n", SDL_GetErrorcxx . . $ SDL_GetError(33a1f659e94feb42).());
378 return -1;
379 }
380 }
381 }
382 }
383 break;
384
385 default:
386 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "warning: bad packet %d received\n", SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_temp->data[0]));
387 return 0;
388 break;
389 }
390
391 return 1;
392 }
393 break;
394 }
395
396 return 0;
397 }
398
399 // discard working packet, now processing next packet in queue
400 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! network_updatecxx . . $ network_update(c9857a73d68e59ba).(void)
401 {
402 if (packet_incxx . . $ packet_in.[0])
403 {
404 packets_shift_upcxx . . $ packets_shift_up(5226cbd459a4ad92).(packet_incxx . . $ packet_in., NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!);
405
406 queue_in_synccxx . . $ queue_in_sync.++;
407
408 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
409 }
410
411 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
412 }
413
414 // has opponent gotten all the packets we've sent?
415 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! network_is_synccxx . . $ network_is_sync(c9857a73d68e59ba).(void)
416 {
417 return (queue_out_synccxx . . $ queue_out_sync. - last_ack_synccxx . . $ last_ack_sync. == 1);
418 }
419
420 // prepare new state for sending
421 void network_state_preparecxx . . $ network_state_prepare(49f6e7a06ebc5aa8).(void)
422 {
423 if (packet_state_outcxx . . $ packet_state_out.[0])
424 {
425 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "warning: state packet overwritten (previous packet remains unsent)\n");
426 }
427 else
428 {
429 packet_state_outcxx . . $ packet_state_out.[0] = SDLNet_AllocPacketcxx . . $ SDLNet_AllocPacket(a0a449a22b795c56).(NET_PACKET_SIZEcxx . . $ `src/network.c:47:9`!);
430 packet_state_outcxx . . $ packet_state_out.[0]->lencxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#len. = 28;
431 }
432
433 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(PACKET_STATEcxx . . $ `src/network.h:44:9`!, &packet_state_out[0]->data[0]);
434 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(last_state_out_sync, &packet_state_out[0]->data[2]);
435 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&packet_state_outcxx . . $ packet_state_out.[0]->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data.[4], 0, 28 - 4);
436 }
437
438 // send state packet, xor packet if applicable
439 int network_state_sendcxx . . $ network_state_send(b126dc7c1de90089).(void)
440 {
441 if (!SDLNet_UDP_Sendcxx . . $ SDLNet_UDP_Send(5c2cf9425bb6832a).(socketcxx . . $ socket., 0, packet_state_outcxx . . $ packet_state_out.[0]))
442 {
443 printfcxx . . $ printf(581fddd72a8db8fc).("SDLNet_UDP_Send: %s\n", SDL_GetErrorcxx . . $ SDL_GetError(33a1f659e94feb42).());
444 return -1;
445 }
446
447 // send xor of last network_delay packets
448 if (network_delaycxx . . $ network_delay. > 1 && (last_state_out_synccxx . . $ last_state_out_sync. + 1) % network_delaycxx . . $ network_delay. == 0 && packet_state_outcxx . . $ packet_state_out.[network_delaycxx . . $ network_delay. - 1] != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
449 {
450 packet_copycxx . . $ packet_copy(6d1a42db56636b51).(packet_tempcxx . . $ packet_temp., packet_state_outcxx . . $ packet_state_out.[0]);
451 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(PACKET_STATE_XORcxx . . $ `src/network.h:45:9`!, &packet_temp->data[0]);
452 for (int i = 1; i < network_delaycxx . . $ network_delay.; i++)
453 for (int j = 4; j < packet_tempcxx . . $ packet_temp.->lencxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#len.; j++)
454 packet_tempcxx . . $ packet_temp.->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data.[j] ^= packet_state_outcxx . . $ packet_state_out.[i]->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data.[j];
455
456 if (!SDLNet_UDP_Sendcxx . . $ SDLNet_UDP_Send(5c2cf9425bb6832a).(socketcxx . . $ socket., 0, packet_tempcxx . . $ packet_temp.))
457 {
458 printfcxx . . $ printf(581fddd72a8db8fc).("SDLNet_UDP_Send: %s\n", SDL_GetErrorcxx . . $ SDL_GetError(33a1f659e94feb42).());
459 return -1;
460 }
461 }
462
463 packets_shift_downcxx . . $ packets_shift_down(5226cbd459a4ad92).(packet_state_outcxx . . $ packet_state_out., NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!);
464
465 last_state_out_synccxx . . $ last_state_out_sync.++;
466
467 return 0;
468 }
469
470 // receive state packet, wait until received
471 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! network_state_updatecxx . . $ network_state_update(c9857a73d68e59ba).(void)
472 {
473 if (network_state_is_resetcxx . . $ network_state_is_reset(c9857a73d68e59ba).())
474 {
475 return 0;
476 }
477 else
478 {
479 packets_shift_upcxx . . $ packets_shift_up(5226cbd459a4ad92).(packet_state_incxx . . $ packet_state_in., NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!);
480
481 packets_shift_upcxx . . $ packets_shift_up(5226cbd459a4ad92).(packet_state_in_xorcxx . . $ packet_state_in_xor., NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!);
482
483 last_state_in_synccxx . . $ last_state_in_sync.++;
484
485 // current xor packet index
486 int x = network_delaycxx . . $ network_delay. - (last_state_in_synccxx . . $ last_state_in_sync. - 1) % network_delaycxx . . $ network_delay. - 1;
487
488 // loop until needed packet is available
489 while (!packet_state_incxx . . $ packet_state_in.[0])
490 {
491 // xor the packet from thin air, if possible
492 if (packet_state_in_xorcxx . . $ packet_state_in_xor.[x] && SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_state_in_xor[x]->data[0]) == PACKET_STATE_XORcxx . . $ `src/network.h:45:9`!)
493 {
494 // check for all other required packets
495 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! okay = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
496 for (int i = 1; i <= x; i++)
497 {
498 if (packet_state_incxx . . $ packet_state_in.[i] == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
499 {
500 okay = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
501 break;
502 }
503 }
504 if (okay)
505 {
506 packet_state_incxx . . $ packet_state_in.[0] = SDLNet_AllocPacketcxx . . $ SDLNet_AllocPacket(a0a449a22b795c56).(NET_PACKET_SIZEcxx . . $ `src/network.c:47:9`!);
507 packet_copycxx . . $ packet_copy(6d1a42db56636b51).(packet_state_incxx . . $ packet_state_in.[0], packet_state_in_xorcxx . . $ packet_state_in_xor.[x]);
508 for (int i = 1; i <= x; i++)
509 for (int j = 4; j < packet_state_incxx . . $ packet_state_in.[0]->lencxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#len.; j++)
510 packet_state_incxx . . $ packet_state_in.[0]->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data.[j] ^= packet_state_incxx . . $ packet_state_in.[i]->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data.[j];
511 break;
512 }
513 }
514
515 static Uint32cxx . . $ Uint32# resend_tick = 0;
516 if (SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).() - last_state_in_tickcxx . . $ last_state_in_tick. > NET_RESENDcxx . . $ `src/network.c:51:9`! && SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).() - resend_tick > NET_RESENDcxx . . $ `src/network.c:51:9`!)
517 {
518 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(PACKET_STATE_RESENDcxx . . $ `src/network.h:43:9`!, &packet_out_temp->data[0]);
519 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(last_state_in_sync - 1, &packet_out_temp->data[2]);
520 network_send_no_ackcxx . . $ network_send_no_ack(83c267b20bac841a).(4); // PACKET_RESEND
521
522 resend_tick = SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).();
523 }
524
525 if (network_checkcxx . . $ network_check(b126dc7c1de90089).() == 0)
526 SDL_Delaycxx . . $ SDL_Delay(cb2f890c2fdad230).(1);
527 }
528
529 if (network_delaycxx . . $ network_delay. > 1)
530 {
531 // process the current in packet against the xor queue
532 if (packet_state_in_xorcxx . . $ packet_state_in_xor.[x] == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!)
533 {
534 packet_state_in_xorcxx . . $ packet_state_in_xor.[x] = SDLNet_AllocPacketcxx . . $ SDLNet_AllocPacket(a0a449a22b795c56).(NET_PACKET_SIZEcxx . . $ `src/network.c:47:9`!);
535 packet_copycxx . . $ packet_copy(6d1a42db56636b51).(packet_state_in_xorcxx . . $ packet_state_in_xor.[x], packet_state_incxx . . $ packet_state_in.[0]);
536 packet_state_in_xorcxx . . $ packet_state_in_xor.[x]->statuscxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#status. = 0;
537 }
538 else
539 {
540 for (int j = 4; j < packet_state_in_xorcxx . . $ packet_state_in_xor.[x]->lencxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#len.; j++)
541 packet_state_in_xorcxx . . $ packet_state_in_xor.[x]->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data.[j] ^= packet_state_incxx . . $ packet_state_in.[0]->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data.[j];
542 }
543 }
544
545 last_state_in_tickcxx . . $ last_state_in_tick. = SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).();
546 }
547
548 return 1;
549 }
550
551 // ignore first network_delay states of level
552 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! network_state_is_resetcxx . . $ network_state_is_reset(c9857a73d68e59ba).(void)
553 {
554 return (last_state_out_synccxx . . $ last_state_out_sync. < network_delaycxx . . $ network_delay.);
555 }
556
557 // reset queues for new level
558 void network_state_resetcxx . . $ network_state_reset(49f6e7a06ebc5aa8).(void)
559 {
560 last_state_in_synccxx . . $ last_state_in_sync. = last_state_out_synccxx . . $ last_state_out_sync. = 0;
561
562 for (int i = 0; i < NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!; i++)
563 {
564 if (packet_state_incxx . . $ packet_state_in.[i])
565 {
566 SDLNet_FreePacketcxx . . $ SDLNet_FreePacket(3284117369f78e1f).(packet_state_incxx . . $ packet_state_in.[i]);
567 packet_state_incxx . . $ packet_state_in.[i] = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
568 }
569 }
570 for (int i = 0; i < NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!; i++)
571 {
572 if (packet_state_in_xorcxx . . $ packet_state_in_xor.[i])
573 {
574 SDLNet_FreePacketcxx . . $ SDLNet_FreePacket(3284117369f78e1f).(packet_state_in_xorcxx . . $ packet_state_in_xor.[i]);
575 packet_state_in_xorcxx . . $ packet_state_in_xor.[i] = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
576 }
577 }
578 for (int i = 0; i < NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`!; i++)
579 {
580 if (packet_state_outcxx . . $ packet_state_out.[i])
581 {
582 SDLNet_FreePacketcxx . . $ SDLNet_FreePacket(3284117369f78e1f).(packet_state_outcxx . . $ packet_state_out.[i]);
583 packet_state_outcxx . . $ packet_state_out.[i] = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
584 }
585 }
586
587 last_state_in_tickcxx . . $ last_state_in_tick. = SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).();
588 }
589
590 // attempt to punch through firewall by firing off UDP packets at the opponent
591 // exchange game information
592 int network_connectcxx . . $ network_connect(b126dc7c1de90089).(void)
593 {
594 SDLNet_ResolveHostcxx . . $ SDLNet_ResolveHost(927602347635cbd8).(&ipcxx . . $ ip., network_opponent_hostcxx . . $ network_opponent_host., network_opponent_portcxx . . $ network_opponent_port.);
595
596 SDLNet_UDP_Bindcxx . . $ SDLNet_UDP_Bind(8037f5156948035b).(socketcxx . . $ socket., 0, &ipcxx . . $ ip.);
597
598 Uint16cxx . . $ Uint16# episodes = 0, episodes_local = 0;
599 assertcxx . . $ `/usr/include/assert.h:50:10`!(EPISODE_MAX <= 16);
600 for (int i = EPISODE_MAXcxx . . $ `src/episodes.h:29:9`! - 1; i >= 0; i--)
601 {
602 episodes <<= 1;
603 episodes |= (episodeAvailcxx . . $ episodeAvail.[i] != 0);
604 }
605 episodes_local = episodes;
606
607 assertcxx . . $ `/usr/include/assert.h:50:10`!(NET_PACKET_SIZE - 12 >= 20 + 1);
608 if (strlencxx . . $ strlen(751346f8406fd082).(network_player_namecxx . . $ network_player_name.) > 20)
609 network_player_namecxx . . $ network_player_name.[20] = '\0';
610
611 connect_reset:
612 network_preparecxx . . $ network_prepare(ed53e3bbd3fa2f69).(PACKET_CONNECTcxx . . $ `src/network.h:32:9`!);
613 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(NET_VERSIONcxx . . $ `src/network.c:44:9`!, &packet_out_temp->data[4]);
614 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(network_delay, &packet_out_temp->data[6]);
615 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(episodes_local, &packet_out_temp->data[8]);
616 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(thisPlayerNum, &packet_out_temp->data[10]);
617 strcpycxx . . $ strcpy(b7b3a83273496486).((char *)&packet_out_tempcxx . . $ packet_out_temp.->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data.[12], network_player_namecxx . . $ network_player_name.);
618 network_sendcxx . . $ network_send(83c267b20bac841a).(12 + strlencxx . . $ strlen(751346f8406fd082).(network_player_namecxx . . $ network_player_name.) + 1); // PACKET_CONNECT
619
620 // until opponent sends connect packet
621 while (truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!)
622 {
623 push_joysticks_as_keyboardcxx . . $ push_joysticks_as_keyboard(49f6e7a06ebc5aa8).();
624 service_SDL_eventscxx . . $ service_SDL_events(b45ddcbc8423892c).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
625
626 if (newkeycxx . . $ newkey. && lastkey_scancxx . . $ lastkey_scan. == SDL_SCANCODE_ESCAPEcxx . . $ SDL_SCANCODE_ESCAPE.)
627 network_tyrian_haltcxx . . $ network_tyrian_halt(ee2069353d7cc01f).(0, falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
628
629 // never timeout
630 last_in_tickcxx . . $ last_in_tick. = SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).();
631
632 if (packet_incxx . . $ packet_in.[0] && SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_in[0]->data[0]) == PACKET_CONNECTcxx . . $ `src/network.h:32:9`!)
633 break;
634
635 network_updatecxx . . $ network_update(c9857a73d68e59ba).();
636 network_checkcxx . . $ network_check(b126dc7c1de90089).();
637
638 SDL_Delaycxx . . $ SDL_Delay(cb2f890c2fdad230).(16);
639 }
640
641 connect_again:
642 if (SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_in[0]->data[4]) != NET_VERSIONcxx . . $ `src/network.c:44:9`!)
643 {
644 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: network version did not match opponent's\n");
645 network_tyrian_haltcxx . . $ network_tyrian_halt(ee2069353d7cc01f).(4, truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
646 }
647 if (SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_in[0]->data[6]) != network_delaycxx . . $ network_delay.)
648 {
649 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: network delay did not match opponent's\n");
650 network_tyrian_haltcxx . . $ network_tyrian_halt(ee2069353d7cc01f).(5, truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
651 }
652 if (SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_in[0]->data[10]) == thisPlayerNumcxx . . $ thisPlayerNum.)
653 {
654 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: player number conflicts with opponent's\n");
655 network_tyrian_haltcxx . . $ network_tyrian_halt(ee2069353d7cc01f).(6, truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
656 }
657
658 episodes = SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_in[0]->data[8]);
659 for (int i = 0; i < EPISODE_MAXcxx . . $ `src/episodes.h:29:9`!; i++) {
660 episodeAvailcxx . . $ episodeAvail.[i] &= (episodes & 1);
661 episodes >>= 1;
662 }
663
664 network_opponent_namecxx . . $ network_opponent_name. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(packet_incxx . . $ packet_in.[0]->lencxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#len. - 12 + 1);
665 strcpycxx . . $ strcpy(b7b3a83273496486).(network_opponent_namecxx . . $ network_opponent_name., (char *)&packet_incxx . . $ packet_in.[0]->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data.[12]);
666
667 network_updatecxx . . $ network_update(c9857a73d68e59ba).();
668
669 // until opponent has acknowledged
670 while (!network_is_synccxx . . $ network_is_sync(c9857a73d68e59ba).())
671 {
672 service_SDL_eventscxx . . $ service_SDL_events(b45ddcbc8423892c).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
673
674 // got a duplicate packet; process it again (but why?)
675 if (packet_incxx . . $ packet_in.[0] && SDLNet_Read16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1019:9`!(&packet_in[0]->data[0]) == PACKET_CONNECTcxx . . $ `src/network.h:32:9`!)
676 goto connect_again;
677
678 network_checkcxx . . $ network_check(b126dc7c1de90089).();
679
680 // maybe opponent didn't get our packet
681 if (SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).() - last_out_tickcxx . . $ last_out_tick. > NET_RETRYcxx . . $ `src/network.c:50:9`!)
682 goto connect_reset;
683
684 SDL_Delaycxx . . $ SDL_Delay(cb2f890c2fdad230).(16);
685 }
686
687 // send another packet since sometimes the network syncs without both connect packets exchanged
688 // there should be a better way to handle this
689 network_preparecxx . . $ network_prepare(ed53e3bbd3fa2f69).(PACKET_CONNECTcxx . . $ `src/network.h:32:9`!);
690 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(NET_VERSIONcxx . . $ `src/network.c:44:9`!, &packet_out_temp->data[4]);
691 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(network_delay, &packet_out_temp->data[6]);
692 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(episodes_local, &packet_out_temp->data[8]);
693 SDLNet_Write16cxx . . $ `<external>/5426831044093305371/SDL_net.h:1015:9`!(thisPlayerNum, &packet_out_temp->data[10]);
694 strcpycxx . . $ strcpy(b7b3a83273496486).((char *)&packet_out_tempcxx . . $ packet_out_temp.->datacxx . . $ $anonymous_type_a4798dfb0a5ccc04_1#data.[12], network_player_namecxx . . $ network_player_name.);
695 network_sendcxx . . $ network_send(83c267b20bac841a).(12 + strlencxx . . $ strlen(751346f8406fd082).(network_player_namecxx . . $ network_player_name.) + 1); // PACKET_CONNECT
696
697 connectedcxx . . $ connected. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
698
699 return 0;
700 }
701
702 // something has gone wrong :(
703 void network_tyrian_haltcxx . . $ network_tyrian_halt(ee2069353d7cc01f).(unsigned int err, boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! attempt_sync)
704 {
705 const char *const err_msg[] = {
706 "Quitting...",
707 "Other player quit the game.",
708 "Network connection was lost.",
709 "Network connection failed.",
710 "Network version mismatch.",
711 "Network delay mismatch.",
712 "Network player number conflict.",
713 };
714
715 quitcxx . . $ quit. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
716
717 if (err >= COUNTOFcxx . . $ `src/opentyr.h:27:9`!(err_msg))
718 err = 0;
719
720 fade_blackcxx . . $ fade_black(d4f767463ce0a6b3).(10);
721
722 VGAScreencxx . . $ VGAScreen. = VGAScreenSegcxx . . $ VGAScreenSeg.;
723
724 JE_loadPiccxx . . $ JE_loadPic(4846ed2ea5b0a844).(VGAScreencxx . . $ VGAScreen., 2, falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
725 JE_dStringcxx . . $ JE_dString(19e4cd32eb7ad4fc).(VGAScreencxx . . $ VGAScreen., JE_fontCentercxx . . $ JE_fontCenter(1df18506ef0a631b).(err_msg[err], SMALL_FONT_SHAPEScxx . . $ `src/sprite.h:30:9`!), 140, err_msg[err], SMALL_FONT_SHAPEScxx . . $ `src/sprite.h:30:9`!);
726
727 JE_showVGAcxx . . $ JE_showVGA(49f6e7a06ebc5aa8).();
728 fade_palettecxx . . $ fade_palette(59ab901998e00635).(colorscxx . . $ colors., 10, 0, 255);
729
730 if (attempt_sync)
731 {
732 while (!network_is_synccxx . . $ network_is_sync(c9857a73d68e59ba).() && network_is_alivecxx . . $ network_is_alive(c9857a73d68e59ba).())
733 {
734 service_SDL_eventscxx . . $ service_SDL_events(b45ddcbc8423892c).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!);
735
736 network_checkcxx . . $ network_check(b126dc7c1de90089).();
737 SDL_Delaycxx . . $ SDL_Delay(cb2f890c2fdad230).(16);
738 }
739 }
740
741 if (err)
742 {
743 while (!JE_anyButtoncxx . . $ JE_anyButton(c9857a73d68e59ba).())
744 SDL_Delaycxx . . $ SDL_Delay(cb2f890c2fdad230).(16);
745 }
746
747 fade_blackcxx . . $ fade_black(d4f767463ce0a6b3).(10);
748
749 SDLNet_Quitcxx . . $ SDLNet_Quit(49f6e7a06ebc5aa8).();
750
751 JE_tyrianHaltcxx . . $ JE_tyrianHalt(ac50b47256ae7414).(5);
752 }
753
754 int network_initcxx . . $ network_init(b126dc7c1de90089).(void)
755 {
756 printfcxx . . $ printf(581fddd72a8db8fc).("Initializing network...\n");
757
758 if (network_delaycxx . . $ network_delay. * 2 > NET_PACKET_QUEUEcxx . . $ `src/network.c:48:9`! - 2)
759 {
760 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: network delay would overflow packet queue\n");
761 return -4;
762 }
763
764 if (SDLNet_Initcxx . . $ SDLNet_Init(b126dc7c1de90089).() == -1)
765 {
766 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: SDLNet_Init: %s\n", SDLNet_GetErrorcxx . . $ SDLNet_GetError(33a1f659e94feb42).());
767 return -1;
768 }
769
770 socketcxx . . $ socket. = SDLNet_UDP_Opencxx . . $ SDLNet_UDP_Open(76134ac515f35592).(network_player_portcxx . . $ network_player_port.);
771 if (!socketcxx . . $ socket.)
772 {
773 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: SDLNet_UDP_Open: %s\n", SDLNet_GetErrorcxx . . $ SDLNet_GetError(33a1f659e94feb42).());
774 return -2;
775 }
776
777 packet_tempcxx . . $ packet_temp. = SDLNet_AllocPacketcxx . . $ SDLNet_AllocPacket(a0a449a22b795c56).(NET_PACKET_SIZEcxx . . $ `src/network.c:47:9`!);
778 packet_out_tempcxx . . $ packet_out_temp. = SDLNet_AllocPacketcxx . . $ SDLNet_AllocPacket(a0a449a22b795c56).(NET_PACKET_SIZEcxx . . $ `src/network.c:47:9`!);
779
780 if (!packet_tempcxx . . $ packet_temp. || !packet_out_tempcxx . . $ packet_out_temp.)
781 {
782 printfcxx . . $ printf(581fddd72a8db8fc).("SDLNet_AllocPacket: %s\n", SDLNet_GetErrorcxx . . $ SDLNet_GetError(33a1f659e94feb42).());
783 return -3;
784 }
785
786 net_initializedcxx . . $ net_initialized. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
787
788 return 0;
789 }
790
791 #endif
792
793 void JE_clearSpecialRequestscxx . . $ JE_clearSpecialRequests(49f6e7a06ebc5aa8).(void)
794 {
795 pauseRequestcxx . . $ pauseRequest. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
796 inGameMenuRequestcxx . . $ inGameMenuRequest. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
797 skipLevelRequestcxx . . $ skipLevelRequest. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
798 helpRequestcxx . . $ helpRequest. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
799 nortShipRequestcxx . . $ nortShipRequest. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
800 }