| 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/networking/networking.cpp $ |
| 21 |
* $Revision: 1.7 $ |
| 22 |
* $Date: 2004/12/05 04:38:23 $ |
| 23 |
* $Author: ryan $ |
| 24 |
* |
| 25 |
* |
| 26 |
* |
| 27 |
* $Log: networking.cpp,v $ |
| 28 |
* Revision 1.7 2004/12/05 04:38:23 ryan |
| 29 |
* Disable IPX support. |
| 30 |
* |
| 31 |
* Revision 1.6 2004/12/05 04:00:20 ryan |
| 32 |
* MacOS X patches. |
| 33 |
* |
| 34 |
* Revision 1.5 2004/02/25 00:04:06 ryan |
| 35 |
* Removed loki_utils dependency and ported to MacOS X (runs, but incomplete). |
| 36 |
* |
| 37 |
* Revision 1.4 2001/01/13 21:48:46 icculus |
| 38 |
* patched to (re)compile on win32. |
| 39 |
* |
| 40 |
* Revision 1.3 2000/06/29 06:41:24 icculus |
| 41 |
* mad commits. |
| 42 |
* |
| 43 |
* Revision 1.2 2000/06/24 01:15:15 icculus |
| 44 |
* patched to compile. |
| 45 |
* |
| 46 |
* Revision 1.1.1.1 2000/04/18 00:00:41 icculus |
| 47 |
* initial checkin |
| 48 |
* |
| 49 |
* |
| 50 |
* 116 1/30/00 3:33p Jason |
| 51 |
* Expanded network receive buffer |
| 52 |
* |
| 53 |
* 115 10/21/99 3:01p Kevin |
| 54 |
* Macintosh willdial fixes |
| 55 |
* |
| 56 |
* 113 9/17/99 2:44p Kevin |
| 57 |
* preferred net buffer size == 16k |
| 58 |
* |
| 59 |
* 112 8/31/99 5:30p Jason |
| 60 |
* network statistics code |
| 61 |
* |
| 62 |
* 111 8/24/99 2:10p Kevin |
| 63 |
* Some debugging & Macintosh fixes |
| 64 |
* |
| 65 |
* 110 8/23/99 5:15p Kevin |
| 66 |
* Macintosh Byte ordering fixes |
| 67 |
* |
| 68 |
* 109 8/21/99 3:14a Jeff |
| 69 |
* real async lookup in Linux |
| 70 |
* |
| 71 |
* 108 8/10/99 11:00a Kevin |
| 72 |
* decreased receive buffer size |
| 73 |
* |
| 74 |
* 107 8/02/99 10:24p Kevin |
| 75 |
* fixed some mac stuff |
| 76 |
* |
| 77 |
* 106 7/29/99 10:33a Kevin |
| 78 |
* More Mac |
| 79 |
* |
| 80 |
* 105 7/26/99 12:05p Kevin |
| 81 |
* Macintosh stuff |
| 82 |
* |
| 83 |
* 104 5/23/99 5:55p Jeff |
| 84 |
* mprintf for easy debugging |
| 85 |
* |
| 86 |
* 103 5/19/99 5:21p Kevin |
| 87 |
* changed return value of nw_GetHostAddressFromNumbers() |
| 88 |
* |
| 89 |
* 102 5/19/99 1:12p Kevin |
| 90 |
* fixed an mprintf and added a saftey check |
| 91 |
* |
| 92 |
* 101 5/06/99 3:27a Kevin |
| 93 |
* directplay fixes |
| 94 |
* |
| 95 |
* 100 4/30/99 5:07p Kevin |
| 96 |
* misc dedicated server, networking and low memory enhancements |
| 97 |
* |
| 98 |
* 99 4/25/99 3:19p Kevin |
| 99 |
* removed really bad call to Error() when the reliable buffer overflows. |
| 100 |
* It is possible for this to happen when one client disconnects and |
| 101 |
* shouldn't cause the server to shutdown. |
| 102 |
* |
| 103 |
* 98 4/22/99 6:32p Kevin |
| 104 |
* Hopefully fixed linux gehostbyname problem |
| 105 |
* |
| 106 |
* 97 4/19/99 7:57p Jeff |
| 107 |
* pack structures for Linux version |
| 108 |
* |
| 109 |
* 96 4/19/99 4:02a Jeff |
| 110 |
* fixed select calls for Linux |
| 111 |
* |
| 112 |
* 95 4/17/99 5:56a Jeff |
| 113 |
* ported to Linux |
| 114 |
* |
| 115 |
* 94 4/15/99 2:58a Jeff |
| 116 |
* added some defines and includes needed for linux ipx |
| 117 |
* |
| 118 |
* 93 4/14/99 1:38a Jeff |
| 119 |
* fixed case mismatched #includes |
| 120 |
* |
| 121 |
* 92 4/12/99 3:16p Kevin |
| 122 |
* Added a bunch of stuff for the linux version |
| 123 |
* |
| 124 |
* 91 3/08/99 3:59p Kevin |
| 125 |
* Idle processing of network packets fixed |
| 126 |
* |
| 127 |
* 90 2/24/99 12:48p Kevin |
| 128 |
* Added urgent flag to nw_SendReliable. It causes the packet to go out |
| 129 |
* that frame. |
| 130 |
* |
| 131 |
* 89 2/23/99 3:09p Jason |
| 132 |
* changed queue time to tenth of a second, as a test. 4 tenths of a |
| 133 |
* second might be too long, especially on a LAN. |
| 134 |
* |
| 135 |
* 88 2/08/99 11:12p Kevin |
| 136 |
* Fixed ip selection & RAS code |
| 137 |
* |
| 138 |
* 87 2/08/99 4:08p Kevin |
| 139 |
* Fixed a stupid bug I introduced last week |
| 140 |
* |
| 141 |
* 86 2/05/99 7:24p Kevin |
| 142 |
* Added NAGLE type packet buffering to reliable networking code |
| 143 |
* |
| 144 |
* 85 1/26/99 9:45p Jeff |
| 145 |
* moved tcplog from networking to mono lib |
| 146 |
* |
| 147 |
* 84 1/08/99 4:51p Jeff |
| 148 |
* don't put the null char at the end of the buffer when sending the |
| 149 |
* TCPPrintf |
| 150 |
* |
| 151 |
* 83 1/08/99 2:58p Kevin |
| 152 |
* Added TCP mprintf support so you can log to a remote machine. |
| 153 |
* |
| 154 |
* 82 1/07/99 11:51a Kevin |
| 155 |
* Added support for joining servers on alternate ports and hosting behind |
| 156 |
* a proxy/firewall |
| 157 |
* |
| 158 |
* 81 1/06/99 3:08p Jason |
| 159 |
* changed recommended pps |
| 160 |
* |
| 161 |
* 80 1/04/99 12:22p Jeff |
| 162 |
* commented out assert no longer needed (nw_GetHostAddressFromNumbers) |
| 163 |
* |
| 164 |
* 79 12/28/98 10:02a Kevin |
| 165 |
* removed mprintfs |
| 166 |
* |
| 167 |
* 78 12/23/98 6:38p Kevin |
| 168 |
* All UDP data (except gamespy) now uses one (registered) port number |
| 169 |
* |
| 170 |
* 77 12/14/98 3:07p Kevin |
| 171 |
* Added +ip to specify IP to bind to (gamespy command line arg) |
| 172 |
* |
| 173 |
* 76 12/03/98 9:29a Kevin |
| 174 |
* Added better ip selection code |
| 175 |
* |
| 176 |
* 75 11/06/98 4:46p Jason |
| 177 |
* added runtime error for being unable to send reliable packet |
| 178 |
* |
| 179 |
* 74 10/29/98 5:08p Jason |
| 180 |
* added an Int3 for when the unthinkable actually happens |
| 181 |
* |
| 182 |
* 73 10/19/98 7:51p Kevin |
| 183 |
* performance testing |
| 184 |
* |
| 185 |
* 72 10/16/98 11:55a Kevin |
| 186 |
* Made dlls loadable in a hog |
| 187 |
* |
| 188 |
* 71 10/14/98 7:20p Kevin |
| 189 |
* More dsp changes... |
| 190 |
* |
| 191 |
* 70 10/12/98 8:39p Kevin |
| 192 |
* removed mprintf's and fixed some smallish bugs |
| 193 |
* |
| 194 |
* 69 10/12/98 4:10p Kevin |
| 195 |
* Made sockets reuasable so if the game locks you don't have to reboot |
| 196 |
* |
| 197 |
* 68 10/08/98 12:30p Nate |
| 198 |
* For Kevin. Fixed stupidity bug I just introduced |
| 199 |
* |
| 200 |
* 67 10/08/98 9:59a Kevin |
| 201 |
* made change to async gethostbyname |
| 202 |
* |
| 203 |
* 66 10/06/98 6:07p Jason |
| 204 |
* added protective layer for reliable packets |
| 205 |
* |
| 206 |
* 65 9/30/98 10:36a Kevin |
| 207 |
* Added command line launching of URLs and command line directory |
| 208 |
* specification |
| 209 |
* |
| 210 |
* 64 9/28/98 4:22p Kevin |
| 211 |
* Redesigned game list menus |
| 212 |
* |
| 213 |
* 63 9/28/98 11:02a Kevin |
| 214 |
* added Networking defer, and fixed some UI issues |
| 215 |
* |
| 216 |
* 62 9/28/98 9:53a Kevin |
| 217 |
* Fixing misc UI problems, and fixed some bugs that VC 6 found |
| 218 |
* |
| 219 |
* 61 9/22/98 2:29p Kevin |
| 220 |
* moved ships allowed code out of dll and into main app. Also added |
| 221 |
* powerup exclusions |
| 222 |
* |
| 223 |
* 60 9/04/98 1:51p Kevin |
| 224 |
* implemented asyncronous gethostbyname |
| 225 |
* |
| 226 |
* 59 9/03/98 11:12a Kevin |
| 227 |
* fixed bug related to the size of reliable packet header... |
| 228 |
* |
| 229 |
* 58 8/31/98 10:15a Kevin |
| 230 |
* Misc. multi-UI fixes |
| 231 |
* |
| 232 |
* 57 8/24/98 5:04p Kevin |
| 233 |
* Made msn files have the option to not be playable in multiplayer |
| 234 |
* |
| 235 |
* 56 8/24/98 10:55a Kevin |
| 236 |
* new directplay stuff |
| 237 |
* |
| 238 |
* 55 8/19/98 11:50a Kevin |
| 239 |
* Got DirectPlay IPX working, and localized connection DLLs |
| 240 |
* |
| 241 |
* 54 8/17/98 11:00a Kevin |
| 242 |
* Moved DLLs into subdirectories |
| 243 |
* |
| 244 |
* 53 8/14/98 4:54p Kevin |
| 245 |
* More directplay stuff |
| 246 |
* |
| 247 |
* 52 8/13/98 6:32p Kevin |
| 248 |
* Initial implementation of directplay API |
| 249 |
* |
| 250 |
* 51 8/11/98 11:18a Kevin |
| 251 |
* Cleaned up unused code and unused function |
| 252 |
* |
| 253 |
* 50 8/11/98 10:46a Kevin |
| 254 |
* removed TCPIP only code from reliable code |
| 255 |
* |
| 256 |
* 49 8/11/98 10:28a Kevin |
| 257 |
* Added a bunch of return code checking to help throttle bandwidth |
| 258 |
* |
| 259 |
* 48 8/10/98 4:32p Kevin |
| 260 |
* added RAS code to correctly Identify IP address |
| 261 |
* |
| 262 |
* 47 8/10/98 12:56p Kevin |
| 263 |
* Removed blocking writes |
| 264 |
* |
| 265 |
* 46 8/07/98 7:02p Kevin |
| 266 |
* |
| 267 |
* 45 8/07/98 7:02p Kevin |
| 268 |
* dumb bug fix for below |
| 269 |
* |
| 270 |
* 44 8/07/98 6:44p Kevin |
| 271 |
* made unreliable sockets non blocking |
| 272 |
* |
| 273 |
* 43 8/05/98 2:25p Kevin |
| 274 |
* improved network address reporting |
| 275 |
* |
| 276 |
* 42 8/05/98 12:07p Kevin |
| 277 |
* minor fixes to reliable |
| 278 |
* |
| 279 |
* 41 7/29/98 6:11p Kevin |
| 280 |
* took out sequence hack |
| 281 |
* |
| 282 |
* 40 7/29/98 5:31p Kevin |
| 283 |
* added rcs header |
| 284 |
* |
| 285 |
*/ |
| 286 |
|
| 287 |
#ifdef WIN32 |
| 288 |
#include <windows.h> |
| 289 |
#include <winsock.h> |
| 290 |
#include <process.h> |
| 291 |
#include <wsipx.h> |
| 292 |
#include <ras.h> |
| 293 |
typedef int socklen_t; |
| 294 |
#endif |
| 295 |
#include <stdlib.h> |
| 296 |
#include <string.h> |
| 297 |
#if defined(POSIXcxx . . $ `<built-in>:478:9`!) |
| 298 |
#if defined(__LINUX__cxx . . $ `<built-in>:482:9`!) |
| 299 |
#include <netinet/in.h> |
| 300 |
#endif |
| 301 |
#include <arpa/inet.h> |
| 302 |
#include <sys/socket.h> |
| 303 |
#include <sys/stat.h> |
| 304 |
#include <sys/types.h> |
| 305 |
#include <sys/time.h> |
| 306 |
#include <stdlib.h> |
| 307 |
#include <unistd.h> |
| 308 |
|
| 309 |
#define TRUEcxx . . $ `networking/networking.cpp:309:9`! true |
| 310 |
#define FALSEcxx . . $ `networking/networking.cpp:310:9`! false |
| 311 |
#define LPSTRcxx . . $ `networking/networking.cpp:311:9`! char * |
| 312 |
#endif |
| 313 |
|
| 314 |
#ifdef WIN32 |
| 315 |
#include "dplay.h" |
| 316 |
#include "dplobby.h" |
| 317 |
#endif |
| 318 |
|
| 319 |
#include "descent.h"cxx . . $ `<file>/Descent3/descent.h`/ |
| 320 |
// #include "../manage/shippage.h" |
| 321 |
#include "appdatabase.h"cxx . . $ `<file>/lib/appdatabase.h`/ |
| 322 |
|
| 323 |
#include "pstypes.h"cxx . . $ `<file>/lib/pstypes.h`/ |
| 324 |
#include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/ |
| 325 |
#include "mono.h"cxx . . $ `<file>/ddebug/mono.h`/ |
| 326 |
#include "networking.h"cxx . . $ `<file>/lib/networking.h`/ |
| 327 |
#include "ddio.h"cxx . . $ `<file>/ddio/ddio.h`/ |
| 328 |
#include "mem.h"cxx . . $ `<file>/mem/mem.h`/ |
| 329 |
#include "game.h"cxx . . $ `<file>/Descent3/game.h`/ |
| 330 |
#include "args.h"cxx . . $ `<file>/Descent3/args.h`/ |
| 331 |
#include "byteswap.h"cxx . . $ `<file>/lib/byteswap.h`/ |
| 332 |
|
| 333 |
#ifdef WIN32 |
| 334 |
#include "directplay.h" |
| 335 |
#endif |
| 336 |
|
| 337 |
#include "pstring.h"cxx . . $ `<file>/misc/pstring.h`/ |
| 338 |
|
| 339 |
#ifndef WIN32 |
| 340 |
bool Use_DirectPlaycxx . . $ Use_DirectPlay. = false; |
| 341 |
#endif |
| 342 |
|
| 343 |
#include "module.h"cxx . . $ `<file>/lib/module.h`/ //for some nice defines to use below |
| 344 |
|
| 345 |
#define MAX_CONNECT_TRIEScxx . . $ `networking/networking.cpp:345:9`! 50 |
| 346 |
#define MAX_RECEIVE_BUFSIZEcxx . . $ `networking/networking.cpp:346:9`! 32768 |
| 347 |
//(1<<16) // 16 K, eh? |
| 348 |
|
| 349 |
int iMaxReceiveBufsizecxx . . $ iMaxReceiveBufsize. = MAX_RECEIVE_BUFSIZEcxx . . $ `networking/networking.cpp:346:9`!; |
| 350 |
|
| 351 |
#ifdef WIN32 |
| 352 |
DWORD(DLLFUNCCALL *pRasEnumConnections)(LPRASCONN lprasconn, LPDWORD lpcb, LPDWORD lpcConnections) = NULL; |
| 353 |
DWORD(DLLFUNCCALL *pRasGetConnectStatus)(HRASCONN hrasconn, LPRASCONNSTATUS lprasconnstatus) = NULL; |
| 354 |
DWORD(DLLFUNCCALL *pRasGetProjectionInfo) |
| 355 |
(HRASCONN hrasconn, RASPROJECTION rasprojection, LPVOID lpprojection, LPDWORD lpcb) = NULL; |
| 356 |
#endif |
| 357 |
|
| 358 |
int Dialup_connectioncxx . . $ Dialup_connection. = 0; |
| 359 |
|
| 360 |
int nw_ServerSocketcxx . . $ nw_ServerSocket. = -1; |
| 361 |
int nw_ClientSocketcxx . . $ nw_ClientSocket. = -1; |
| 362 |
|
| 363 |
network_protocolcxx . . $ network_protocol# NetworkProtocolcxx . . $ NetworkProtocol. = NP_NONEcxx . . $ NP_NONE.; |
| 364 |
|
| 365 |
int Sockets_inittedcxx . . $ Sockets_initted. = 0; |
| 366 |
int Network_inittedcxx . . $ Network_initted. = 0; |
| 367 |
|
| 368 |
uint32_tcxx . . $ uint32_t# Net_fixed_ipcxx . . $ Net_fixed_ip. = INADDR_NONEcxx . . $ `<external>/9581057695539925927/in.h:202:9`!; |
| 369 |
// sockets for IPX and TCP |
| 370 |
|
| 371 |
SOCKETcxx . . $ `lib/networking.h:217:9`! TCP_socketcxx . . $ TCP_socket.; |
| 372 |
SOCKETcxx . . $ `lib/networking.h:217:9`! TCP_reliable_socketcxx . . $ TCP_reliable_socket.; |
| 373 |
SOCKETcxx . . $ `lib/networking.h:217:9`! TCP_listen_socketcxx . . $ TCP_listen_socket.; |
| 374 |
|
| 375 |
// the sockets that the game will use when selecting network type |
| 376 |
static SOCKETcxx . . $ `lib/networking.h:217:9`! *Unreliable_socketcxx . . $ Unreliable_socket.; |
| 377 |
static SOCKETcxx . . $ `lib/networking.h:217:9`! *Reliable_socketcxx . . $ Reliable_socket.; |
| 378 |
static SOCKETcxx . . $ `lib/networking.h:217:9`! *Listen_socketcxx . . $ Listen_socket.; |
| 379 |
|
| 380 |
// our current running statistics |
| 381 |
static tNetworkStatuscxx . . $ tNetworkStatus# NetStatisticscxx . . $ NetStatistics.; |
| 382 |
|
| 383 |
BOOLcxx . . $ `lib/networking.h:218:9`! TCP_activecxx . . $ TCP_active. = FALSEcxx . . $ `lib/networking.h:231:9`!; |
| 384 |
BOOLcxx . . $ `lib/networking.h:218:9`! IPX_activecxx . . $ IPX_active. = FALSEcxx . . $ `lib/networking.h:231:9`!; |
| 385 |
BOOLcxx . . $ `lib/networking.h:218:9`! DP_activecxx . . $ DP_active. = FALSEcxx . . $ `lib/networking.h:231:9`!; // Direct Play active |
| 386 |
// BOOL TCP_MT_active = FALSE; |
| 387 |
|
| 388 |
// This structure contains the local computer info |
| 389 |
network_addresscxx . . $ network_address# My_addrcxx . . $ My_addr.; |
| 390 |
|
| 391 |
struct network_checksum_packetcxx . . $ network_checksum_packet# { |
| 392 |
int sequence_numbercxx . . $ network_checksum_packet#sequence_number.; |
| 393 |
uint16_tcxx . . $ uint16_t# flagscxx . . $ network_checksum_packet#flags.; |
| 394 |
uint16_tcxx . . $ uint16_t# checksumcxx . . $ network_checksum_packet#checksum.; |
| 395 |
uint8_tcxx . . $ uint8_t# datacxx . . $ network_checksum_packet#data.[MAX_PACKET_SIZEcxx . . $ `lib/networking.h:321:9`!]; |
| 396 |
}; |
| 397 |
|
| 398 |
// definition for a non-checksum packet |
| 399 |
struct network_naked_packetcxx . . $ network_naked_packet# { |
| 400 |
int sequence_numbercxx . . $ network_naked_packet#sequence_number.; |
| 401 |
uint16_tcxx . . $ uint16_t# flagscxx . . $ network_naked_packet#flags.; |
| 402 |
uint8_tcxx . . $ uint8_t# datacxx . . $ network_naked_packet#data.[MAX_PACKET_SIZEcxx . . $ `lib/networking.h:321:9`!]; |
| 403 |
}; |
| 404 |
|
| 405 |
// structure definition for our packet buffers |
| 406 |
struct network_packet_buffercxx . . $ network_packet_buffer# { |
| 407 |
int sequence_numbercxx . . $ network_packet_buffer#sequence_number.; |
| 408 |
int lencxx . . $ network_packet_buffer#len.; |
| 409 |
network_addresscxx . . $ network_address# from_addrcxx . . $ network_packet_buffer#from_addr.; |
| 410 |
uint8_tcxx . . $ uint8_t# datacxx . . $ network_packet_buffer#data.[MAX_PACKET_SIZEcxx . . $ `lib/networking.h:321:9`!]; |
| 411 |
}; |
| 412 |
|
| 413 |
#define MAX_PACKET_BUFFERScxx . . $ `networking/networking.cpp:413:9`! 96 |
| 414 |
|
| 415 |
static network_packet_buffercxx . . $ network_packet_buffer# Packet_bufferscxx . . $ Packet_buffers.[MAX_PACKET_BUFFERScxx . . $ `networking/networking.cpp:413:9`!]; // buffer to hold packets sent to us |
| 416 |
static int16_t Packet_free_listcxx . . $ Packet_free_list.[MAX_PACKET_BUFFERScxx . . $ `networking/networking.cpp:413:9`!]; // contains id's of free packet buffers |
| 417 |
static int Num_packet_bufferscxx . . $ Num_packet_buffers.; |
| 418 |
static int Largest_packet_indexcxx . . $ Largest_packet_index. = 0; |
| 419 |
|
| 420 |
static int Uncompressed_outgoing_data_lencxx . . $ Uncompressed_outgoing_data_len. = 0; |
| 421 |
static int Compressed_outgoing_data_lencxx . . $ Compressed_outgoing_data_len. = 0; |
| 422 |
|
| 423 |
int Next_packet_idcxx . . $ Next_packet_id.; |
| 424 |
int Last_packet_idcxx . . $ Last_packet_id.; |
| 425 |
|
| 426 |
static CFILEcxx . . $ CFILE# *NetDebugFilecxx . . $ NetDebugFile. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 427 |
|
| 428 |
// An array of callbacks |
| 429 |
static NetworkReceiveCallbackcxx . . $ NetworkReceiveCallback# Netcallbackscxx . . $ Netcallbacks.[16]; |
| 430 |
|
| 431 |
#define R_NET_SEQUENCE_NONEcxx . . $ `networking/networking.cpp:431:9`! 0 |
| 432 |
#define R_NET_SEQUENCE_CONNECTINGcxx . . $ `networking/networking.cpp:432:9`! 1 |
| 433 |
#define R_NET_SEQUENCE_CONNECTEDcxx . . $ `networking/networking.cpp:433:9`! 2 |
| 434 |
#define R_NET_SEQUENCE_FAILEDcxx . . $ `networking/networking.cpp:434:9`! 3 |
| 435 |
|
| 436 |
#define R_NET_PACKET_QUEUE_TIMEcxx . . $ `networking/networking.cpp:436:9`! .1f |
| 437 |
|
| 438 |
static int Net_connect_socket_idcxx . . $ Net_connect_socket_id. = INVALID_SOCKETcxx . . $ `lib/networking.h:221:9`!; |
| 439 |
static int Net_connect_sequencecxx . . $ Net_connect_sequence. = R_NET_SEQUENCE_NONEcxx . . $ `networking/networking.cpp:431:9`!; |
| 440 |
|
| 441 |
// ------------------------------------------------------------------------------------------------------ |
| 442 |
// PACKET BUFFERING FUNCTIONS |
| 443 |
// |
| 444 |
|
| 445 |
// a sequence number of -1 will indicate that this packet is not valid |
| 446 |
static network_packet_buffercxx . . $ network_packet_buffer# Psnet_bufferscxx . . $ Psnet_buffers.[MAX_PACKET_BUFFERScxx . . $ `networking/networking.cpp:413:9`!]; |
| 447 |
static int Psnet_seq_numbercxx . . $ Psnet_seq_number. = 0; |
| 448 |
static int Psnet_lowest_idcxx . . $ Psnet_lowest_id. = 0; |
| 449 |
static int Psnet_highest_idcxx . . $ Psnet_highest_id. = 0; |
| 450 |
|
| 451 |
// Reliable UDP stuff |
| 452 |
//******************************* |
| 453 |
#ifdef WIN32 |
| 454 |
#pragma pack(push, r_udp) |
| 455 |
#endif |
| 456 |
#pragma pack(1) |
| 457 |
struct reliable_headercxx . . $ reliable_header# { |
| 458 |
uint8_tcxx . . $ uint8_t# typecxx . . $ reliable_header#type.; // packet type |
| 459 |
uint8_tcxx . . $ uint8_t# compressedcxx . . $ reliable_header#compressed.; // |
| 460 |
uint16_tcxx . . $ uint16_t# seqcxx . . $ reliable_header#seq.; // sequence packet 0-65535 used for ACKing also |
| 461 |
uint16_tcxx . . $ uint16_t# data_lencxx . . $ reliable_header#data_len.; // length of data |
| 462 |
float send_timecxx . . $ reliable_header#send_time.; // Time the packet was sent, if an ACK the time the packet being ACK'd was sent. |
| 463 |
uint8_tcxx . . $ uint8_t# datacxx . . $ reliable_header#data.[NETBUFFERSIZEcxx . . $ `lib/networking.h:457:9`!]; // Packet data |
| 464 |
}; |
| 465 |
|
| 466 |
#define RELIABLE_PACKET_HEADER_ONLY_SIZEcxx . . $ `networking/networking.cpp:466:9`! (sizeof(reliable_header) - NETBUFFERSIZEcxx . . $ `lib/networking.h:457:9`!) |
| 467 |
#define MAX_PING_HISTORYcxx . . $ `networking/networking.cpp:467:9`! 10 |
| 468 |
|
| 469 |
struct reliable_net_sendbuffercxx . . $ reliable_net_sendbuffer# { |
| 470 |
uint8_tcxx . . $ uint8_t# buffercxx . . $ reliable_net_sendbuffer#buffer.[NETBUFFERSIZEcxx . . $ `lib/networking.h:457:9`!]; |
| 471 |
|
| 472 |
}; |
| 473 |
|
| 474 |
struct reliable_net_rcvbuffercxx . . $ reliable_net_rcvbuffer# { |
| 475 |
uint8_tcxx . . $ uint8_t# buffercxx . . $ reliable_net_rcvbuffer#buffer.[NETBUFFERSIZEcxx . . $ `lib/networking.h:457:9`!]; |
| 476 |
}; |
| 477 |
|
| 478 |
static SOCKETcxx . . $ `lib/networking.h:217:9`! Reliable_UDP_socketcxx . . $ Reliable_UDP_socket. = INVALID_SOCKETcxx . . $ `lib/networking.h:221:9`!; |
| 479 |
|
| 480 |
static float first_sent_iamherecxx . . $ first_sent_iamhere. = 0; |
| 481 |
static float last_sent_iamherecxx . . $ last_sent_iamhere. = 0; |
| 482 |
|
| 483 |
static uint32_tcxx . . $ uint32_t# serverconncxx . . $ serverconn. = 0xFFFFFFFF; |
| 484 |
|
| 485 |
#ifdef WIN32 |
| 486 |
#pragma pack(pop, r_udp) |
| 487 |
#else |
| 488 |
#pragma pack() |
| 489 |
#endif |
| 490 |
|
| 491 |
struct reliable_socketcxx . . $ reliable_socket# { |
| 492 |
|
| 493 |
float timesentcxx . . $ reliable_socket#timesent.[MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`!]; |
| 494 |
int16_t send_lencxx . . $ reliable_socket#send_len.[MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`!]; |
| 495 |
int16_t recv_lencxx . . $ reliable_socket#recv_len.[MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`!]; |
| 496 |
float last_packet_receivedcxx . . $ reliable_socket#last_packet_received.; // For a given connection, this is the last packet we received |
| 497 |
float last_packet_sentcxx . . $ reliable_socket#last_packet_sent.; |
| 498 |
float pingscxx . . $ reliable_socket#pings.[MAX_PING_HISTORYcxx . . $ `networking/networking.cpp:467:9`!]; |
| 499 |
uint32_tcxx . . $ uint32_t# num_ping_samplescxx . . $ reliable_socket#num_ping_samples.; |
| 500 |
float mean_pingcxx . . $ reliable_socket#mean_ping.; |
| 501 |
float last_sentcxx . . $ reliable_socket#last_sent.; // The last time we sent a packet (used for NAGLE emulation) |
| 502 |
int waiting_packet_numbercxx . . $ reliable_socket#waiting_packet_number.; // Which packet has data in it that is waiting for the interval to send |
| 503 |
|
| 504 |
uint16_tcxx . . $ uint16_t# statuscxx . . $ reliable_socket#status.; // Status of this connection |
| 505 |
uint16_tcxx . . $ uint16_t# oursequencecxx . . $ reliable_socket#oursequence.; // This is the next sequence number the application is expecting |
| 506 |
uint16_tcxx . . $ uint16_t# theirsequencecxx . . $ reliable_socket#theirsequence.; // This is the next sequence number the peer is expecting |
| 507 |
uint16_tcxx . . $ uint16_t# rsequencecxx . . $ reliable_socket#rsequence.[MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`!]; // This is the sequence number of the given packet |
| 508 |
|
| 509 |
uint8_tcxx . . $ uint8_t# ping_poscxx . . $ reliable_socket#ping_pos.; |
| 510 |
|
| 511 |
network_addresscxx . . $ network_address# net_addrcxx . . $ reliable_socket#net_addr.; // A D3 network address structure |
| 512 |
network_protocolcxx . . $ network_protocol# connection_typecxx . . $ reliable_socket#connection_type.; // IPX, IP, modem, etc. |
| 513 |
reliable_net_rcvbuffercxx . . $ reliable_net_rcvbuffer# *rbufferscxx . . $ reliable_socket#rbuffers.[MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`!]; |
| 514 |
SOCKADDRcxx . . $ `lib/networking.h:220:9`! addrcxx . . $ reliable_socket#addr.; // SOCKADDR of our peer |
| 515 |
reliable_net_sendbuffercxx . . $ reliable_net_sendbuffer# *sbufferscxx . . $ reliable_socket#sbuffers.[MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`!]; // This is an array of pointers for quick sorting |
| 516 |
uint16_tcxx . . $ uint16_t# ssequencecxx . . $ reliable_socket#ssequence.[MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`!]; // This is the sequence number of the given packet |
| 517 |
uint8_tcxx . . $ uint8_t# send_urgentcxx . . $ reliable_socket#send_urgent.; |
| 518 |
}; |
| 519 |
|
| 520 |
static reliable_socketcxx . . $ reliable_socket# reliable_socketscxx . . $ reliable_sockets.[MAXRELIABLESOCKETScxx . . $ `lib/networking.h:456:9`!]; |
| 521 |
//******************************* |
| 522 |
#if defined(POSIXcxx . . $ `<built-in>:478:9`!) |
| 523 |
#include <fcntl.h> |
| 524 |
#endif |
| 525 |
|
| 526 |
int make_nonblockingcxx . . $ make_nonblocking(7864480464b09eea).(SOCKETcxx . . $ `lib/networking.h:217:9`! sock) |
| 527 |
{ |
| 528 |
#ifdef WIN32 |
| 529 |
unsigned long arg = 1; |
| 530 |
return ioctlsocket(sock, FIONBIO, &arg); |
| 531 |
#else // WIN32 |
| 532 |
return fcntl(sock, F_SETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:169:9`!, fcntl(sock, F_GETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:168:9`!, 0) | O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!); |
| 533 |
#endif |
| 534 |
} |
| 535 |
|
| 536 |
void CloseNetworkingcxx . . $ CloseNetworking(49f6e7a06ebc5aa8).() { |
| 537 |
if (Sockets_inittedcxx . . $ Sockets_initted. != 1) |
| 538 |
return; |
| 539 |
|
| 540 |
if (NetDebugFilecxx . . $ NetDebugFile.) { |
| 541 |
cfprintfcxx . . $ cfprintf(4762586383887345).(NetDebugFilecxx . . $ NetDebugFile., "NetDebug.log closed at %f seconds.\n", timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!()); |
| 542 |
cfclosecxx . . $ cfclose(3639e799710acb68).(NetDebugFilecxx . . $ NetDebugFile.); |
| 543 |
NetDebugFilecxx . . $ NetDebugFile. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 544 |
} |
| 545 |
|
| 546 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Shutting down networking...\n"); |
| 547 |
#ifdef WIN32 |
| 548 |
WSACancelBlockingCall(); |
| 549 |
|
| 550 |
dp_ShutdownDirectPlay(); |
| 551 |
#endif |
| 552 |
|
| 553 |
if (TCP_socketcxx . . $ TCP_socket. != INVALID_SOCKETcxx . . $ `lib/networking.h:221:9`!) { |
| 554 |
shutdown(TCP_socketcxx . . $ TCP_socket., 1); |
| 555 |
#ifdef WIN32 |
| 556 |
closesocket(TCP_socket); |
| 557 |
#else |
| 558 |
close(TCP_socketcxx . . $ TCP_socket.); |
| 559 |
#endif |
| 560 |
} |
| 561 |
#ifdef WIN32 |
| 562 |
if (WSACleanup()) { |
| 563 |
mprintf(0, "Error closing wsock!\n"); |
| 564 |
} |
| 565 |
#endif |
| 566 |
|
| 567 |
Network_inittedcxx . . $ Network_initted. = 0; |
| 568 |
Sockets_inittedcxx . . $ Sockets_initted. = 0; |
| 569 |
|
| 570 |
NetworkProtocolcxx . . $ NetworkProtocol. = NP_NONEcxx . . $ NP_NONE.; |
| 571 |
} |
| 572 |
|
| 573 |
// Inits the sockets layer to activity |
| 574 |
void nw_InitNetworkingcxx . . $ nw_InitNetworking(d4f767463ce0a6b3).(int iReadBufSizeOverride) { |
| 575 |
if (iReadBufSizeOverride == -1) { |
| 576 |
iMaxReceiveBufsizecxx . . $ iMaxReceiveBufsize. = MAX_RECEIVE_BUFSIZEcxx . . $ `networking/networking.cpp:346:9`!; |
| 577 |
} else { |
| 578 |
iMaxReceiveBufsizecxx . . $ iMaxReceiveBufsize. = iReadBufSizeOverride; |
| 579 |
} |
| 580 |
|
| 581 |
// reset our stats so we are ready to use them |
| 582 |
nw_GetNetworkStatscxx . . $ nw_GetNetworkStats(3e736517eddecfba).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 583 |
|
| 584 |
#ifdef WIN32 |
| 585 |
WSADATA ws_data; |
| 586 |
WORD ver = MAKEWORD(1, 1); |
| 587 |
#endif |
| 588 |
|
| 589 |
static char exewithpath[_MAX_PATHcxx . . $ `linux/linux_fix.h:34:9`! * 2]; |
| 590 |
static char exefile[_MAX_PATHcxx . . $ `linux/linux_fix.h:34:9`! * 2]; |
| 591 |
static char ourargs[_MAX_PATHcxx . . $ `linux/linux_fix.h:34:9`! * 2]; |
| 592 |
static char exedir[_MAX_PATHcxx . . $ `linux/linux_fix.h:34:9`! * 2]; |
| 593 |
static char exeext[_MAX_PATHcxx . . $ `linux/linux_fix.h:34:9`!]; |
| 594 |
static char *fixdir; |
| 595 |
static char szconntype[100]; |
| 596 |
int parmlen; |
| 597 |
int len = 99; |
| 598 |
Databasecxx . . $ Database.->readcxx . . $ oeAppDatabase#read(3bcbb53201fcdcb8).("NetworkConnection", szconntype, &len); |
| 599 |
if (stricmpcxx . . $ `linux/linux_fix.h:43:9`!(szconntype, "DIALUP") == 0) { |
| 600 |
Dialup_connectioncxx . . $ Dialup_connection. = 1; |
| 601 |
} else { |
| 602 |
Dialup_connectioncxx . . $ Dialup_connection. = 0; |
| 603 |
} |
| 604 |
int iparg; |
| 605 |
|
| 606 |
if (FindArgcxx . . $ FindArg(5c4306d8553b3696).("-netdebug")) { |
| 607 |
NetDebugFilecxx . . $ NetDebugFile. = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).("netdebug.log"cxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "wa"); |
| 608 |
ASSERTcxx . . $ `misc/pserror.h:246:9`!(NetDebugFile); |
| 609 |
cfprintfcxx . . $ cfprintf(4762586383887345).(NetDebugFilecxx . . $ NetDebugFile., "NetDebug.log opened at %f seconds\n", timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!()); |
| 610 |
} |
| 611 |
|
| 612 |
iparg = FindArgcxx . . $ FindArg(5c4306d8553b3696).("-useip"); |
| 613 |
if (!iparg) { |
| 614 |
iparg = FindArgcxx . . $ FindArg(5c4306d8553b3696).("+ip"); |
| 615 |
} |
| 616 |
if (iparg) { |
| 617 |
Net_fixed_ipcxx . . $ Net_fixed_ip. = inet_addr(GameArgscxx . . $ GameArgs.[iparg + 1]); |
| 618 |
if (Net_fixed_ipcxx . . $ Net_fixed_ip. == INADDR_NONEcxx . . $ `<external>/9581057695539925927/in.h:202:9`!) { |
| 619 |
Net_fixed_ipcxx . . $ Net_fixed_ip. = INADDR_NONEcxx . . $ `<external>/9581057695539925927/in.h:202:9`!; |
| 620 |
} |
| 621 |
} |
| 622 |
#ifdef WIN32 |
| 623 |
if (!dp_DidLobbyLaunchGame()) { |
| 624 |
// Tell direct play about this game |
| 625 |
char *p = GetCommandLine(); |
| 626 |
mprintf(0, "Command line: %s\n", p); |
| 627 |
parmlen = strlen(p); |
| 628 |
|
| 629 |
int a; |
| 630 |
for (a = 0; a < parmlen; ++a) { |
| 631 |
if (p[a] == ' ') { |
| 632 |
break; |
| 633 |
} |
| 634 |
} |
| 635 |
if (a < parmlen) { |
| 636 |
strcpy(ourargs, p + a + 1); |
| 637 |
} else { |
| 638 |
strcpy(ourargs, ""); |
| 639 |
} |
| 640 |
strncpy(exewithpath, p, a); |
| 641 |
exewithpath[a] = NULL; |
| 642 |
ddio_SplitPath(exewithpath, exedir, exefile, exeext); |
| 643 |
if (exedir[0] == '\"') { |
| 644 |
fixdir = exedir + 1; |
| 645 |
} else { |
| 646 |
fixdir = exedir; |
| 647 |
} |
| 648 |
if (exeext[strlen(exeext) - 1] == '\"') { |
| 649 |
exeext[strlen(exeext) - 1] = NULL; |
| 650 |
} |
| 651 |
strcat(exefile, exeext); |
| 652 |
// dp_RegisterLobbyApplication("Descent 3",exefile,fixdir,ourargs,Base_directory,"Descent 3"); |
| 653 |
} |
| 654 |
#endif |
| 655 |
|
| 656 |
#ifdef WIN32 |
| 657 |
int error = WSAStartup(ver, &ws_data); |
| 658 |
#else |
| 659 |
int error = 0; |
| 660 |
#endif |
| 661 |
if (error != 0) { |
| 662 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "There was an error initializing networking! Error=%d\n", error); |
| 663 |
return; |
| 664 |
} else { |
| 665 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Network initted successfully!\n"); |
| 666 |
Network_inittedcxx . . $ Network_initted. = 1; |
| 667 |
atexitcxx . . $ atexit(cc8c495369588262).(CloseNetworkingcxx . . $ CloseNetworking(49f6e7a06ebc5aa8).); |
| 668 |
} |
| 669 |
} |
| 670 |
|
| 671 |
// Sets the size of buffers |
| 672 |
void nw_SetSocketOptionscxx . . $ nw_SetSocketOptions(d4f767463ce0a6b3).(SOCKETcxx . . $ `lib/networking.h:217:9`! sock) { |
| 673 |
int broadcast; |
| 674 |
int ret, cursize, bufsize, trysize; |
| 675 |
socklen_t cursizesize; |
| 676 |
|
| 677 |
// Set the mode of the socket to allow broadcasting. We need to be able to broadcast |
| 678 |
// when a game is searched for in IPX mode. |
| 679 |
broadcast = 1; |
| 680 |
setsockopt(sock, SOL_SOCKETcxx . . $ `<external>/9030916627833342711/socket.h:9:9`!, SO_BROADCASTcxx . . $ `<external>/9030916627833342711/socket.h:16:9`!, (LPSTRcxx . . $ `networking/networking.cpp:311:9`!)&broadcast, sizeof(broadcast)); |
| 681 |
setsockopt(sock, SOL_SOCKETcxx . . $ `<external>/9030916627833342711/socket.h:9:9`!, SO_REUSEADDRcxx . . $ `<external>/9030916627833342711/socket.h:12:9`!, (LPSTRcxx . . $ `networking/networking.cpp:311:9`!)&broadcast, sizeof(broadcast)); |
| 682 |
|
| 683 |
int error = make_nonblockingcxx . . $ make_nonblocking(7864480464b09eea).(sock); |
| 684 |
if (error == SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`!) { |
| 685 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Unable to make socket non-blocking -- %d", WSAGetLastError()); |
| 686 |
} |
| 687 |
|
| 688 |
// try and increase the size of my receive buffer |
| 689 |
bufsize = iMaxReceiveBufsizecxx . . $ iMaxReceiveBufsize.; |
| 690 |
|
| 691 |
// set the current size of the receive buffer |
| 692 |
cursizesize = sizeof(int); |
| 693 |
getsockopt(sock, SOL_SOCKETcxx . . $ `<external>/9030916627833342711/socket.h:9:9`!, SO_RCVBUFcxx . . $ `<external>/9030916627833342711/socket.h:18:9`!, (LPSTRcxx . . $ `networking/networking.cpp:311:9`!)&cursize, &cursizesize); |
| 694 |
for (trysize = bufsize; trysize >= cursize; trysize >>= 1) { |
| 695 |
ret = setsockopt(sock, SOL_SOCKETcxx . . $ `<external>/9030916627833342711/socket.h:9:9`!, SO_RCVBUFcxx . . $ `<external>/9030916627833342711/socket.h:18:9`!, (LPSTRcxx . . $ `networking/networking.cpp:311:9`!)&trysize, sizeof(trysize)); |
| 696 |
if (ret == SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`!) { |
| 697 |
int wserr; |
| 698 |
|
| 699 |
wserr = WSAGetLastErrorcxx . . $ `lib/networking.h:241:9`!(); |
| 700 |
if ((wserr == WSAENOPROTOOPTcxx . . $ `lib/networking.h:238:9`!) || (wserr == WSAEINVALcxx . . $ `lib/networking.h:237:9`!)) |
| 701 |
break; |
| 702 |
|
| 703 |
} else |
| 704 |
break; |
| 705 |
} |
| 706 |
getsockopt(sock, SOL_SOCKETcxx . . $ `<external>/9030916627833342711/socket.h:9:9`!, SO_RCVBUFcxx . . $ `<external>/9030916627833342711/socket.h:18:9`!, (LPSTRcxx . . $ `networking/networking.cpp:311:9`!)&cursize, &cursizesize); |
| 707 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Receive buffer set to %d\n", cursize); |
| 708 |
/* |
| 709 |
// set the current size of the send buffer |
| 710 |
bufsize = MAX_RECEIVE_BUFSIZE/4; |
| 711 |
cursizesize = sizeof(int); |
| 712 |
getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (LPSTR)&cursize, &cursizesize); |
| 713 |
for ( trysize = bufsize; trysize >= cursize; trysize >>= 1 ) |
| 714 |
{ |
| 715 |
ret = setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (LPSTR)&trysize, sizeof(trysize)); |
| 716 |
if ( ret == SOCKET_ERROR ) |
| 717 |
{ |
| 718 |
int wserr; |
| 719 |
|
| 720 |
wserr = WSAGetLastError(); |
| 721 |
if ( (wserr == WSAENOPROTOOPT) || (wserr == WSAEINVAL) ) |
| 722 |
break; |
| 723 |
} |
| 724 |
else |
| 725 |
break; |
| 726 |
} |
| 727 |
getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (LPSTR)&cursize, &cursizesize); |
| 728 |
mprintf(0, "Send buffer set to %d\n", cursize); |
| 729 |
*/ |
| 730 |
} |
| 731 |
|
| 732 |
uint16_tcxx . . $ uint16_t# nw_ListenPortcxx . . $ nw_ListenPort. = 0; |
| 733 |
|
| 734 |
// Inits the sockets that the application will be using |
| 735 |
void nw_InitSocketscxx . . $ nw_InitSockets(ed53e3bbd3fa2f69).(uint16_tcxx . . $ uint16_t# port) { |
| 736 |
|
| 737 |
nw_ListenPortcxx . . $ nw_ListenPort. = port; |
| 738 |
// UDP/TCP socket structure |
| 739 |
SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! sock_addr; |
| 740 |
|
| 741 |
// Now do tcp! |
| 742 |
TCP_activecxx . . $ TCP_active. = 0; |
| 743 |
TCP_socketcxx . . $ TCP_socket. = INVALID_SOCKETcxx . . $ `lib/networking.h:221:9`!; |
| 744 |
// TCP_reliable_socket = INVALID_SOCKET; |
| 745 |
TCP_listen_socketcxx . . $ TCP_listen_socket. = INVALID_SOCKETcxx . . $ `lib/networking.h:221:9`!; |
| 746 |
|
| 747 |
// Initialize the UDP socket |
| 748 |
TCP_socketcxx . . $ TCP_socket. = socket(AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, SOCK_DGRAMcxx . . $ `<external>/5956532346368192945/socket_type.h:31:9`!, IPPROTO_UDPcxx . . $ `<external>/9581057695539925927/in.h:57:9`!); |
| 749 |
|
| 750 |
// Initialize all reliable sockets, IPX and TCP |
| 751 |
nw_InitReliableSocketcxx . . $ nw_InitReliableSocket(b126dc7c1de90089).(); |
| 752 |
|
| 753 |
if (TCP_socketcxx . . $ TCP_socket. != INVALID_SOCKETcxx . . $ `lib/networking.h:221:9`!) { |
| 754 |
// bind the socket |
| 755 |
memset(&sock_addr, 0, sizeof(SOCKADDR_INcxx . . $ `lib/networking.h:219:9`!)); |
| 756 |
sock_addr.sin_family = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!; |
| 757 |
|
| 758 |
uint32_tcxx . . $ uint32_t# my_ip; |
| 759 |
|
| 760 |
my_ip = nw_GetThisIPcxx . . $ nw_GetThisIP(db52760e79bf9054).(); |
| 761 |
|
| 762 |
memcpy(&sock_addr.sin_addr.s_addr, &my_ip, sizeof(uint32_tcxx . . $ uint32_t#)); |
| 763 |
|
| 764 |
sock_addr.sin_port = htons(port); |
| 765 |
if (bind(TCP_socketcxx . . $ TCP_socket., (SOCKADDRcxx . . $ `lib/networking.h:220:9`! *)&sock_addr, sizeof(sock_addr)) == SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`!) { |
| 766 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Couldn't bind TCP socket (%d)! Invalidating TCP\n", WSAGetLastError()); |
| 767 |
goto tcp_done; |
| 768 |
} |
| 769 |
|
| 770 |
nw_SetSocketOptionscxx . . $ nw_SetSocketOptions(d4f767463ce0a6b3).(TCP_socketcxx . . $ TCP_socket.); |
| 771 |
TCP_activecxx . . $ TCP_active. = 1; |
| 772 |
} else { |
| 773 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Cannot create TCP socket (%d)!\n", WSAGetLastError()); |
| 774 |
} |
| 775 |
|
| 776 |
tcp_done: |
| 777 |
int ret; |
| 778 |
uint32_tcxx . . $ uint32_t# isocktrue = 1; |
| 779 |
|
| 780 |
setsockopt(TCP_socketcxx . . $ TCP_socket., SOL_SOCKETcxx . . $ `<external>/9030916627833342711/socket.h:9:9`!, SO_REUSEADDRcxx . . $ `<external>/9030916627833342711/socket.h:12:9`!, (LPSTRcxx . . $ `networking/networking.cpp:311:9`!)&isocktrue, sizeof(isocktrue)); |
| 781 |
ret = setsockopt(TCP_socketcxx . . $ TCP_socket., SOL_SOCKETcxx . . $ `<external>/9030916627833342711/socket.h:9:9`!, SO_BROADCASTcxx . . $ `<external>/9030916627833342711/socket.h:16:9`!, (LPSTRcxx . . $ `networking/networking.cpp:311:9`!)&isocktrue, sizeof(uint32_tcxx . . $ uint32_t#)); |
| 782 |
if (ret == SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`!) { |
| 783 |
int wserr; |
| 784 |
wserr = WSAGetLastErrorcxx . . $ `lib/networking.h:241:9`!(); |
| 785 |
if ((wserr == WSAENOPROTOOPTcxx . . $ `lib/networking.h:238:9`!) || (wserr == WSAEINVALcxx . . $ `lib/networking.h:237:9`!)) { |
| 786 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Unable to make socket broadcastable!"); |
| 787 |
|
| 788 |
Int3cxx . . $ `misc/pserror.h:247:9`!(); // Get Kevin |
| 789 |
} |
| 790 |
} |
| 791 |
|
| 792 |
Sockets_inittedcxx . . $ Sockets_initted. = 1; |
| 793 |
|
| 794 |
if (TCP_activecxx . . $ TCP_active.) |
| 795 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "TCP Initialized\n"); |
| 796 |
|
| 797 |
nw_psnet_buffer_initcxx . . $ nw_psnet_buffer_init(49f6e7a06ebc5aa8).(); |
| 798 |
nw_RegisterCallbackcxx . . $ nw_RegisterCallback(d121e3b72e81a360).((NetworkReceiveCallbackcxx . . $ NetworkReceiveCallback#)nw_HandleUnreliableDatacxx . . $ nw_HandleUnreliableData(c3263a6d42f31e8c)., NWT_UNRELIABLEcxx . . $ `lib/networking.h:317:9`!); |
| 799 |
} |
| 800 |
|
| 801 |
// Copies my address into the passed argument |
| 802 |
void nw_GetMyAddresscxx . . $ nw_GetMyAddress(f2758234d0c8cb80).(network_addresscxx . . $ network_address# *addr) { |
| 803 |
socklen_t len; |
| 804 |
SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! in_addr; |
| 805 |
|
| 806 |
memset(&My_addrcxx . . $ My_addr., 0, sizeof(network_addresscxx . . $ network_address#)); |
| 807 |
if (TCP_activecxx . . $ TCP_active.) { |
| 808 |
// assign the TCP_* sockets to the socket values used elsewhere |
| 809 |
Unreliable_socketcxx . . $ Unreliable_socket. = &TCP_socketcxx . . $ TCP_socket.; |
| 810 |
Reliable_socketcxx . . $ Reliable_socket. = &TCP_reliable_socketcxx . . $ TCP_reliable_socket.; |
| 811 |
Listen_socketcxx . . $ Listen_socket. = &TCP_listen_socketcxx . . $ TCP_listen_socket.; |
| 812 |
|
| 813 |
// get the socket name for the TCP_socket, and put it into My_addr |
| 814 |
len = sizeof(SOCKADDR_INcxx . . $ `lib/networking.h:219:9`!); |
| 815 |
if (getsockname(*Unreliable_socketcxx . . $ Unreliable_socket., (SOCKADDRcxx . . $ `lib/networking.h:220:9`! *)&in_addr, &len) == SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`!) { |
| 816 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Unable to get sock name for TCP unreliable socket (%s)\n", WSAGetLastError()); |
| 817 |
return; |
| 818 |
} |
| 819 |
|
| 820 |
memcpy(My_addrcxx . . $ My_addr..addresscxx . . $ network_address#address., &in_addr.sin_addr, 4); |
| 821 |
|
| 822 |
// My_addr.port = in_addr.sin_port; |
| 823 |
My_addrcxx . . $ My_addr..portcxx . . $ network_address#port. = ntohs(in_addr.sin_port); |
| 824 |
} |
| 825 |
|
| 826 |
*addr =cxx . . $ network_address#`operator=`(b327fd2abe52d802). My_addrcxx . . $ My_addr.; |
| 827 |
} |
| 828 |
|
| 829 |
// Returns internet address format from string address format...ie "204.243.217.14" |
| 830 |
// turns into 1414829242 |
| 831 |
uint32_tcxx . . $ uint32_t# nw_GetHostAddressFromNumberscxx . . $ nw_GetHostAddressFromNumbers(33ab057182e9f89d).(char *str) { |
| 832 |
// ASSERT (NetworkProtocol==NP_TCP); |
| 833 |
|
| 834 |
return inet_addr(str); |
| 835 |
} |
| 836 |
|
| 837 |
// Fills in the string with the string address from the internet address |
| 838 |
void nw_GetNumbersFromHostAddresscxx . . $ nw_GetNumbersFromHostAddress(29331e2dd3eba175).(network_addresscxx . . $ network_address# *address, char *str) { |
| 839 |
// ASSERT(NetworkProtocol==NP_TCP); |
| 840 |
ASSERTcxx . . $ `misc/pserror.h:246:9`!(str); |
| 841 |
struct in_addr addr; |
| 842 |
|
| 843 |
if (address->connection_typecxx . . $ network_address#connection_type. == NP_TCPcxx . . $ NP_TCP.) { |
| 844 |
memcpy(&addr, address->addresscxx . . $ network_address#address., sizeof(struct in_addr)); |
| 845 |
sprintf(str, "IP: %s:%d", inet_ntoa(addr), address->portcxx . . $ network_address#port.); |
| 846 |
} |
| 847 |
|
| 848 |
#ifdef WIN32 |
| 849 |
else if (Use_DirectPlay && (address->connection_type == NP_DIRECTPLAY)) { |
| 850 |
DPID id; |
| 851 |
memcpy(&id, address->address, sizeof(DPID)); |
| 852 |
sprintf(str, "DirectPlay: 0x%x", id); |
| 853 |
} |
| 854 |
#endif |
| 855 |
} |
| 856 |
|
| 857 |
#define CLOSE_TIMEOUT_TIMEcxx . . $ `networking/networking.cpp:857:9`! 3 // 3 seconds |
| 858 |
|
| 859 |
// returns the ip address of this computer |
| 860 |
uint32_tcxx . . $ uint32_t# nw_GetThisIPcxx . . $ nw_GetThisIP(db52760e79bf9054).() { |
| 861 |
SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! local_address; |
| 862 |
int address_size = sizeof(SOCKADDRcxx . . $ `lib/networking.h:220:9`!); |
| 863 |
|
| 864 |
if (Net_fixed_ipcxx . . $ Net_fixed_ip. != INADDR_NONEcxx . . $ `<external>/9581057695539925927/in.h:202:9`!) { |
| 865 |
return Net_fixed_ipcxx . . $ Net_fixed_ip.; |
| 866 |
} |
| 867 |
// Init local address to zero |
| 868 |
local_address.sin_addr.s_addr = INADDR_ANYcxx . . $ `<external>/9581057695539925927/in.h:198:9`!; |
| 869 |
if (Dialup_connectioncxx . . $ Dialup_connection.) { |
| 870 |
#ifdef WIN32 |
| 871 |
local_address.sin_addr.s_addr = psnet_ras_status(); |
| 872 |
#else |
| 873 |
local_address.sin_addr.s_addr = INADDR_ANYcxx . . $ `<external>/9581057695539925927/in.h:198:9`!; |
| 874 |
#endif |
| 875 |
} |
| 876 |
if ((!Dialup_connectioncxx . . $ Dialup_connection.) || (!local_address.sin_addr.s_addr)) { |
| 877 |
// Removed the fancy way, it worked worse than the easy way (some adsl/cable people had problems. |
| 878 |
/* |
| 879 |
// Get the local host name |
| 880 |
ret = gethostname(local, 255 ); |
| 881 |
if (ret != SOCKET_ERROR ) |
| 882 |
{ |
| 883 |
// Resolve host name for local address |
| 884 |
hostent = gethostbyname((LPSTR)local); |
| 885 |
if ( hostent ) |
| 886 |
local_address.sin_addr.s_addr = *((u_long FAR *)(hostent->h_addr)); |
| 887 |
} |
| 888 |
*/ |
| 889 |
local_address.sin_addr.s_addr = INADDR_ANYcxx . . $ `<external>/9581057695539925927/in.h:198:9`!; |
| 890 |
} |
| 891 |
return local_address.sin_addr.s_addr; |
| 892 |
} |
| 893 |
|
| 894 |
// Calculates a unique uint16_t checksum for a stream of data |
| 895 |
uint16_tcxx . . $ uint16_t# nw_CalculateChecksumcxx . . $ nw_CalculateChecksum(c5bffbc6db657e6d).(void *vptr, int len) { |
| 896 |
uint8_tcxx . . $ uint8_t# *ptr = (uint8_tcxx . . $ uint8_t# *)vptr; |
| 897 |
uint32_tcxx . . $ uint32_t# sum1, sum2; |
| 898 |
|
| 899 |
sum1 = sum2 = 0; |
| 900 |
|
| 901 |
while (len--) { |
| 902 |
sum1 += *ptr++; |
| 903 |
if (sum1 >= 255) |
| 904 |
sum1 -= 255; |
| 905 |
sum2 += sum1; |
| 906 |
} |
| 907 |
sum2 %= 255; |
| 908 |
|
| 909 |
return (uint16_tcxx . . $ uint16_t#)((sum1 << 8) + sum2); |
| 910 |
} |
| 911 |
|
| 912 |
// Sends data on an unreliable socket |
| 913 |
int nw_Sendcxx . . $ nw_Send(102d2f582237fe86).(network_addresscxx . . $ network_address# *who_to, void *data, int len, int flags) { |
| 914 |
if (len == 0) { |
| 915 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Attempting to send 0 byte network packet in nw_Send()\n"); |
| 916 |
Int3cxx . . $ `misc/pserror.h:247:9`!(); |
| 917 |
} |
| 918 |
if (NetDebugFilecxx . . $ NetDebugFile.) { |
| 919 |
uint8_tcxx . . $ uint8_t# *ptr = (uint8_tcxx . . $ uint8_t# *)data; |
| 920 |
cfprintfcxx . . $ cfprintf(4762586383887345).(NetDebugFilecxx . . $ NetDebugFile., "nw_Send packet of type %d at %f seconds.\n", ptr[0], timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!()); |
| 921 |
} |
| 922 |
return nw_SendWithIDcxx . . $ nw_SendWithID(4aa96ed29f5182c6).(NWT_UNRELIABLEcxx . . $ `lib/networking.h:317:9`!, (uint8_tcxx . . $ uint8_t# *)data, len, who_to); |
| 923 |
} |
| 924 |
|
| 925 |
// MTS: only used in this file? |
| 926 |
void nw_HandleUnreliableDatacxx . . $ nw_HandleUnreliableData(c3263a6d42f31e8c).(uint8_tcxx . . $ uint8_t# *data, int len, network_addresscxx . . $ network_address# *from_addr) { |
| 927 |
nw_psnet_buffer_packetcxx . . $ nw_psnet_buffer_packet(c3263a6d42f31e8c).((uint8_tcxx . . $ uint8_t# *)data, len, from_addr); |
| 928 |
} |
| 929 |
|
| 930 |
// MTS: unused? |
| 931 |
// routine to "free" a packet buffer |
| 932 |
void nw_FreePacketcxx . . $ nw_FreePacket(d4f767463ce0a6b3).(int id) { |
| 933 |
Packet_bufferscxx . . $ Packet_buffers.[id].sequence_numbercxx . . $ network_packet_buffer#sequence_number. = -1; |
| 934 |
Packet_free_listcxx . . $ Packet_free_list.[--Num_packet_bufferscxx . . $ Num_packet_buffers.] = (int16_t)id; |
| 935 |
if (Largest_packet_indexcxx . . $ Largest_packet_index. == id) |
| 936 |
while ((--Largest_packet_indexcxx . . $ Largest_packet_index. > 0) && (Packet_bufferscxx . . $ Packet_buffers.[Largest_packet_indexcxx . . $ Largest_packet_index.].sequence_numbercxx . . $ network_packet_buffer#sequence_number. == -1)) |
| 937 |
; |
| 938 |
} |
| 939 |
|
| 940 |
// nw_Recieve will call the above function to read data out of the socket. It will then determine |
| 941 |
// which of the buffers we should use and pass to the routine which called us |
| 942 |
int nw_Receivecxx . . $ nw_Receive(4faaf8d0141e84f4).(void *data, network_addresscxx . . $ network_address# *from_addr) { |
| 943 |
// call the routine to read data out of the socket (which stuffs it into the packet buffers) |
| 944 |
|
| 945 |
if (Use_DirectPlaycxx . . $ Use_DirectPlay.) { |
| 946 |
#ifdef WIN32 |
| 947 |
dp_DirectPlayDispatch(); |
| 948 |
#endif |
| 949 |
} else { |
| 950 |
// nw_ReceiveFromSocket(); |
| 951 |
nw_DoReceiveCallbackscxx . . $ nw_DoReceiveCallbacks(b126dc7c1de90089).(); |
| 952 |
} |
| 953 |
|
| 954 |
int buffer_size; |
| 955 |
|
| 956 |
// try and get a free buffer and return its size |
| 957 |
if (nw_psnet_buffer_get_nextcxx . . $ nw_psnet_buffer_get_next(c5ce5346f0e0aa21).((uint8_tcxx . . $ uint8_t# *)data, &buffer_size, from_addr)) { |
| 958 |
return buffer_size; |
| 959 |
} |
| 960 |
return 0; |
| 961 |
} |
| 962 |
|
| 963 |
int ExtraBufferTempHackcxx . . $ ExtraBufferTempHack. = 0; |
| 964 |
// Temp hack to figure out this buffer overflow thing |
| 965 |
|
| 966 |
// Return codes: |
| 967 |
//-1 socket not connected |
| 968 |
// 0 No packet ready to receive |
| 969 |
// >0 Buffer filled with the number of bytes recieved |
| 970 |
|
| 971 |
int nw_ReceiveReliablecxx . . $ nw_ReceiveReliable(ef9024b465536c23).(SOCKETcxx . . $ `lib/networking.h:217:9`! socketid, uint8_tcxx . . $ uint8_t# *buffer, int max_len) { |
| 972 |
|
| 973 |
int i; |
| 974 |
if (Use_DirectPlaycxx . . $ Use_DirectPlay.) { |
| 975 |
#ifdef WIN32 |
| 976 |
dp_DirectPlayDispatch(); |
| 977 |
|
| 978 |
// try and get a free buffer and return its size |
| 979 |
if (nw_psnet_buffer_get_next_by_packet_id((uint8_t *)buffer, &max_len, socketid)) { |
| 980 |
return max_len; |
| 981 |
} |
| 982 |
return 0; |
| 983 |
#endif |
| 984 |
} |
| 985 |
reliable_socketcxx . . $ reliable_socket# *rsocket = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 986 |
// nw_WorkReliable(); |
| 987 |
nw_DoReceiveCallbackscxx . . $ nw_DoReceiveCallbacks(b126dc7c1de90089).(); |
| 988 |
if (socketid >= MAXRELIABLESOCKETScxx . . $ `lib/networking.h:456:9`!) { |
| 989 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Invalid socket id passed to nw_NewReceiveReliable() -- %d\n", socketid); |
| 990 |
return -1; |
| 991 |
} |
| 992 |
rsocket = &reliable_socketscxx . . $ reliable_sockets.[socketid]; |
| 993 |
if ((RNF_CONNECTEDcxx . . $ `lib/networking.h:470:9`! != rsocket->statuscxx . . $ reliable_socket#status.) && (RNF_LIMBOcxx . . $ `lib/networking.h:474:9`! != rsocket->statuscxx . . $ reliable_socket#status.)) { |
| 994 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Can't receive packet because it isn't connected in nw_ReceiveReliable(). socket = %d\n", socketid); |
| 995 |
return 0; |
| 996 |
} |
| 997 |
// If the buffer position is the position we are waiting for, fill in |
| 998 |
// the buffer we received in the call to this function and return true |
| 999 |
|
| 1000 |
for (i = 0; i < MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`!; i++) { |
| 1001 |
if ((rsocket->rsequencecxx . . $ reliable_socket#rsequence.[i] == rsocket->oursequencecxx . . $ reliable_socket#oursequence.) && (rsocket->rbufferscxx . . $ reliable_socket#rbuffers.[i])) { |
| 1002 |
memcpy(buffer, rsocket->rbufferscxx . . $ reliable_socket#rbuffers.[i]->buffercxx . . $ reliable_net_rcvbuffer#buffer., rsocket->recv_lencxx . . $ reliable_socket#recv_len.[i]); |
| 1003 |
mem_freecxx . . $ `mem/mem.h:80:9`!(rsocket->rbuffers[i]); |
| 1004 |
rsocket->rbufferscxx . . $ reliable_socket#rbuffers.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 1005 |
rsocket->rsequencecxx . . $ reliable_socket#rsequence.[i] = 0; |
| 1006 |
/* |
| 1007 |
mprintf(0,"Found packet for upper layer in nw_ReceiveReliable() %d bytes. seq:%d.\n", |
| 1008 |
rsocket->recv_len[i], |
| 1009 |
rsocket->oursequence); |
| 1010 |
*/ |
| 1011 |
rsocket->oursequencecxx . . $ reliable_socket#oursequence.++; |
| 1012 |
return rsocket->recv_lencxx . . $ reliable_socket#recv_len.[i]; |
| 1013 |
} |
| 1014 |
} |
| 1015 |
|
| 1016 |
return 0; |
| 1017 |
} |
| 1018 |
|
| 1019 |
// This function will look for a control packet, indicating a |
| 1020 |
// desire to establish a reliable link. |
| 1021 |
// When is makes a link, it will return a SOCKET, and fill in from_addr. |
| 1022 |
// if there is no waiting line, it returns -1 |
| 1023 |
int nw_CheckListenSocketcxx . . $ nw_CheckListenSocket(974bd2fc5f961852).(network_addresscxx . . $ network_address# *from_addr) { |
| 1024 |
SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *ip_addr; // UDP/TCP socket structure |
| 1025 |
|
| 1026 |
#ifdef WIN32 |
| 1027 |
DPID id; |
| 1028 |
#endif |
| 1029 |
|
| 1030 |
if (Use_DirectPlaycxx . . $ Use_DirectPlay.) { |
| 1031 |
#ifdef WIN32 |
| 1032 |
// look for a pending connection |
| 1033 |
for (int i = 0; i < MAX_PENDING_NEW_CONNECTIONS; i++) { |
| 1034 |
if (Pending_dp_conn[i] != DPID_UNKNOWN) { |
| 1035 |
memset(from_addr, 0, sizeof(network_address)); |
| 1036 |
memcpy(from_addr->address, &Pending_dp_conn[i], sizeof(DPID)); |
| 1037 |
from_addr->connection_type = NP_DIRECTPLAY; |
| 1038 |
id = Pending_dp_conn[i]; |
| 1039 |
Pending_dp_conn[i] = DPID_UNKNOWN; |
| 1040 |
mprintf(0, "New DirectPlay connection in nw_CheckListenSocket().\n"); |
| 1041 |
return id; |
| 1042 |
} |
| 1043 |
} |
| 1044 |
return -1; |
| 1045 |
#endif |
| 1046 |
} |
| 1047 |
|
| 1048 |
// nw_WorkReliable(); |
| 1049 |
nw_DoReceiveCallbackscxx . . $ nw_DoReceiveCallbacks(b126dc7c1de90089).(); |
| 1050 |
int i; |
| 1051 |
for (i = 1; i < MAXRELIABLESOCKETScxx . . $ `lib/networking.h:456:9`!; i++) { |
| 1052 |
if (reliable_socketscxx . . $ reliable_sockets.[i].statuscxx . . $ reliable_socket#status. == RNF_CONNECTINGcxx . . $ `lib/networking.h:473:9`!) { |
| 1053 |
reliable_socketscxx . . $ reliable_sockets.[i].statuscxx . . $ reliable_socket#status. = RNF_CONNECTEDcxx . . $ `lib/networking.h:470:9`!; |
| 1054 |
// memcpy(from_addr,&reliable_sockets[i].addr,sizeof(SOCKADDR)); |
| 1055 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "New reliable connection in nw_CheckListenSocket().\n"); |
| 1056 |
|
| 1057 |
switch (reliable_socketscxx . . $ reliable_sockets.[i].connection_typecxx . . $ reliable_socket#connection_type.) { |
| 1058 |
case NP_TCPcxx . . $ NP_TCP.: |
| 1059 |
ip_addr = (SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *)&reliable_socketscxx . . $ reliable_sockets.[i].addrcxx . . $ reliable_socket#addr.; |
| 1060 |
memset(from_addr, 0x00, sizeof(network_addresscxx . . $ network_address#)); |
| 1061 |
from_addr->portcxx . . $ network_address#port. = ntohs(ip_addr->sin_port); |
| 1062 |
from_addr->connection_typecxx . . $ network_address#connection_type. = NP_TCPcxx . . $ NP_TCP.; |
| 1063 |
#ifdef WIN32 |
| 1064 |
memcpy(from_addr->address, &ip_addr->sin_addr.S_un.S_addr, 4); |
| 1065 |
#else |
| 1066 |
memcpy(from_addr->addresscxx . . $ network_address#address., &ip_addr->sin_addr.s_addr, 4); |
| 1067 |
#endif |
| 1068 |
break; |
| 1069 |
|
| 1070 |
default: |
| 1071 |
Int3cxx . . $ `misc/pserror.h:247:9`!(); |
| 1072 |
break; |
| 1073 |
} |
| 1074 |
char dbg_output[50]; |
| 1075 |
nw_GetNumbersFromHostAddresscxx . . $ nw_GetNumbersFromHostAddress(29331e2dd3eba175).(from_addr, dbg_output); |
| 1076 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Got address from: %s\n", dbg_output); |
| 1077 |
return i; |
| 1078 |
} |
| 1079 |
} |
| 1080 |
return INVALID_SOCKETcxx . . $ `lib/networking.h:221:9`!; |
| 1081 |
} |
| 1082 |
|
| 1083 |
int nw_SendReliablecxx . . $ nw_SendReliable(f6b56715d3e5e15a).(uint32_tcxx . . $ uint32_t# socketid, uint8_tcxx . . $ uint8_t# *data, int length, bool urgent) { |
| 1084 |
int i; |
| 1085 |
int bytesout; |
| 1086 |
int use_buffer = -1; |
| 1087 |
reliable_socketcxx . . $ reliable_socket# *rsocket; |
| 1088 |
reliable_headercxx . . $ reliable_header# send_header; |
| 1089 |
int send_this_packet = 1; |
| 1090 |
|
| 1091 |
if (length == 0) { |
| 1092 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Attempting to send 0 byte network packet in nw_SendReliable()\n"); |
| 1093 |
Int3cxx . . $ `misc/pserror.h:247:9`!(); |
| 1094 |
} |
| 1095 |
// mprintf(0,"Socket id passed to nw_NewSendReliable() -- %d\n",socketid); |
| 1096 |
|
| 1097 |
if (NetDebugFilecxx . . $ NetDebugFile.) { |
| 1098 |
cfprintfcxx . . $ cfprintf(4762586383887345).(NetDebugFilecxx . . $ NetDebugFile., "nw_SendReliable packet of type %d at %f seconds.\n", data[0], timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!()); |
| 1099 |
} |
| 1100 |
|
| 1101 |
if (Use_DirectPlaycxx . . $ Use_DirectPlay.) { |
| 1102 |
#ifdef WIN32 |
| 1103 |
network_address who_to; |
| 1104 |
who_to.connection_type = NP_DIRECTPLAY; |
| 1105 |
memcpy(&who_to.address, &socketid, sizeof(DPID)); |
| 1106 |
return dp_DirectPlaySend(&who_to, data, length, true); |
| 1107 |
#endif |
| 1108 |
} |
| 1109 |
|
| 1110 |
ASSERTcxx . . $ `misc/pserror.h:246:9`!(length < sizeof(reliable_header)); |
| 1111 |
// nw_WorkReliable(); |
| 1112 |
nw_DoReceiveCallbackscxx . . $ nw_DoReceiveCallbacks(b126dc7c1de90089).(); |
| 1113 |
|
| 1114 |
if (socketid >= MAXRELIABLESOCKETScxx . . $ `lib/networking.h:456:9`!) { |
| 1115 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Invalid socket id passed to nw_NewSendReliable() -- %d\n", socketid); |
| 1116 |
return -1; |
| 1117 |
} |
| 1118 |
|
| 1119 |
rsocket = &reliable_socketscxx . . $ reliable_sockets.[socketid]; |
| 1120 |
if (rsocket->statuscxx . . $ reliable_socket#status. != RNF_CONNECTEDcxx . . $ `lib/networking.h:470:9`!) { |
| 1121 |
// We can't send because this isn't a connected reliable socket. |
| 1122 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Can't send packet because of status %d in nw_SendReliable(). socket = %d\n", rsocket->status, socketid); |
| 1123 |
return -1; |
| 1124 |
} |
| 1125 |
if (urgent) |
| 1126 |
rsocket->send_urgentcxx . . $ reliable_socket#send_urgent. = 1; |
| 1127 |
// See if there is a packet waiting to be sent |
| 1128 |
if (-1 != rsocket->waiting_packet_numbercxx . . $ reliable_socket#waiting_packet_number.) { |
| 1129 |
int pnum = rsocket->waiting_packet_numbercxx . . $ reliable_socket#waiting_packet_number.; |
| 1130 |
ASSERTcxx . . $ `misc/pserror.h:246:9`!(rsocket->sbuffers[pnum]); |
| 1131 |
// See if there's room for this data |
| 1132 |
if (sizeof(reliable_net_sendbuffercxx . . $ reliable_net_sendbuffer#) < (rsocket->send_lencxx . . $ reliable_socket#send_len.[pnum] + length)) { |
| 1133 |
// Send the previous packet, then use the normal code to generate a new packet |
| 1134 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Pending reliable packet buffer full, sending packet now.\n"); |
| 1135 |
rsocket->waiting_packet_numbercxx . . $ reliable_socket#waiting_packet_number. = -1; |
| 1136 |
|
| 1137 |
use_buffer = pnum; |
| 1138 |
network_addresscxx . . $ network_address# send_address; |
| 1139 |
memset(&send_address, 0, sizeof(network_addresscxx . . $ network_address#)); |
| 1140 |
|
| 1141 |
memcpy(send_header.datacxx . . $ reliable_header#data., rsocket->sbufferscxx . . $ reliable_socket#sbuffers.[pnum], rsocket->send_lencxx . . $ reliable_socket#send_len.[pnum]); |
| 1142 |
send_header.data_lencxx . . $ reliable_header#data_len. = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(rsocket->send_len[pnum]); |
| 1143 |
send_header.typecxx . . $ reliable_header#type. = RNT_DATAcxx . . $ `lib/networking.h:461:9`!; |
| 1144 |
send_header.send_timecxx . . $ reliable_header#send_time. = INTEL_FLOATcxx . . $ `lib/byteswap.h:109:9`!(timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!()); |
| 1145 |
|
| 1146 |
send_address.connection_typecxx . . $ network_address#connection_type. = rsocket->connection_typecxx . . $ reliable_socket#connection_type.; |
| 1147 |
|
| 1148 |
if (NP_TCPcxx . . $ NP_TCP. == rsocket->connection_typecxx . . $ reliable_socket#connection_type.) { |
| 1149 |
SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *inaddr = (SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *)&rsocket->addrcxx . . $ reliable_socket#addr.; |
| 1150 |
memcpy(send_address.addresscxx . . $ network_address#address., &inaddr->sin_addr, 4); |
| 1151 |
send_address.portcxx . . $ network_address#port. = htons(inaddr->sin_port); |
| 1152 |
send_address.connection_typecxx . . $ network_address#connection_type. = NP_TCPcxx . . $ NP_TCP.; |
| 1153 |
} |
| 1154 |
|
| 1155 |
// mprintf(0,"Sending reliable packet! Sequence %d\n",send_header.seq); |
| 1156 |
bytesout = nw_SendWithIDcxx . . $ nw_SendWithID(4aa96ed29f5182c6).(NWT_RELIABLEcxx . . $ `lib/networking.h:318:9`!, (uint8_tcxx . . $ uint8_t# *)&send_header, |
| 1157 |
RELIABLE_PACKET_HEADER_ONLY_SIZEcxx . . $ `networking/networking.cpp:466:9`! + rsocket->send_lencxx . . $ reliable_socket#send_len.[use_buffer], &send_address); |
| 1158 |
|
| 1159 |
if ((bytesout == SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`!) && (WSAEWOULDBLOCKcxx . . $ `lib/networking.h:236:9`! == WSAGetLastErrorcxx . . $ `lib/networking.h:241:9`!())) { |
| 1160 |
// This will cause it to try to send again next frame. (or sooner) |
| 1161 |
rsocket->timesentcxx . . $ reliable_socket#timesent.[use_buffer] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - (NETRETRYTIMEcxx . . $ `lib/networking.h:452:9`! * 4); |
| 1162 |
} else { |
| 1163 |
rsocket->timesentcxx . . $ reliable_socket#timesent.[use_buffer] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1164 |
} |
| 1165 |
} else { |
| 1166 |
// tack this data on the end of the previous packet |
| 1167 |
// mprintf(0,"Appending to delayed packet...\n"); |
| 1168 |
ASSERTcxx . . $ `misc/pserror.h:246:9`!(rsocket->sbuffers[pnum]); |
| 1169 |
memcpy(rsocket->sbufferscxx . . $ reliable_socket#sbuffers.[pnum]->buffercxx . . $ reliable_net_sendbuffer#buffer. + rsocket->send_lencxx . . $ reliable_socket#send_len.[pnum], data, length); |
| 1170 |
// int msize = mem_size(rsocket->sbuffers[pnum]); |
| 1171 |
rsocket->send_lencxx . . $ reliable_socket#send_len.[pnum] += length; |
| 1172 |
return length; |
| 1173 |
} |
| 1174 |
} |
| 1175 |
|
| 1176 |
// Add the new packet to the sending list and send it. |
| 1177 |
for (i = 0; i < MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`!; i++) { |
| 1178 |
use_buffer = -1; |
| 1179 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! == rsocket->sbufferscxx . . $ reliable_socket#sbuffers.[i]) { |
| 1180 |
// mprintf(0,"Sending in nw_SendReliable() %d bytes seq=%d.\n",length,rsocket->theirsequence); |
| 1181 |
|
| 1182 |
rsocket->send_lencxx . . $ reliable_socket#send_len.[i] = length; |
| 1183 |
rsocket->sbufferscxx . . $ reliable_socket#sbuffers.[i] = (reliable_net_sendbuffercxx . . $ reliable_net_sendbuffer# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(sizeof(reliable_net_sendbuffer)); |
| 1184 |
|
| 1185 |
memcpy(rsocket->sbufferscxx . . $ reliable_socket#sbuffers.[i]->buffercxx . . $ reliable_net_sendbuffer#buffer., data, length); |
| 1186 |
|
| 1187 |
send_header.seqcxx . . $ reliable_header#seq. = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(rsocket->theirsequence); |
| 1188 |
rsocket->ssequencecxx . . $ reliable_socket#ssequence.[i] = rsocket->theirsequencecxx . . $ reliable_socket#theirsequence.; |
| 1189 |
|
| 1190 |
use_buffer = i; |
| 1191 |
rsocket->waiting_packet_numbercxx . . $ reliable_socket#waiting_packet_number. = i; |
| 1192 |
|
| 1193 |
rsocket->theirsequencecxx . . $ reliable_socket#theirsequence.++; |
| 1194 |
return length; |
| 1195 |
} |
| 1196 |
} |
| 1197 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Can't send packet because a buffer overflow nw_SendReliable(). socket = %d\n", socketid); |
| 1198 |
rsocket->statuscxx . . $ reliable_socket#status. = RNF_BROKENcxx . . $ `lib/networking.h:471:9`!; |
| 1199 |
|
| 1200 |
for (i = 0; i < MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`!; i++) { |
| 1201 |
if (rsocket->sbufferscxx . . $ reliable_socket#sbuffers.[i]) { |
| 1202 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Buffer %d: %d,%d,%d,%d,%d,%d\n", |
| 1203 |
i, |
| 1204 |
rsocket->sbuffers[i]->buffer[0], |
| 1205 |
rsocket->sbuffers[i]->buffer[1], |
| 1206 |
rsocket->sbuffers[i]->buffer[2], |
| 1207 |
rsocket->sbuffers[i]->buffer[3], |
| 1208 |
rsocket->sbuffers[i]->buffer[4], |
| 1209 |
rsocket->sbuffers[i]->buffer[5]); |
| 1210 |
} |
| 1211 |
} |
| 1212 |
|
| 1213 |
// Error ("Couldn't send packet because of buffer overflow!"); |
| 1214 |
|
| 1215 |
// Int3(); |
| 1216 |
return 0; |
| 1217 |
} |
| 1218 |
|
| 1219 |
// MTS: only used in this file |
| 1220 |
int nw_InitReliableSocketcxx . . $ nw_InitReliableSocket(b126dc7c1de90089).() { |
| 1221 |
nw_RegisterCallbackcxx . . $ nw_RegisterCallback(d121e3b72e81a360).((NetworkReceiveCallbackcxx . . $ NetworkReceiveCallback#)nw_WorkReliablecxx . . $ nw_WorkReliable(c3263a6d42f31e8c)., NWT_RELIABLEcxx . . $ `lib/networking.h:318:9`!); |
| 1222 |
return 1; |
| 1223 |
} |
| 1224 |
// MTS: only used in this file |
| 1225 |
void nw_SendReliableAckcxx . . $ nw_SendReliableAck(763f9aad6809bec8).(SOCKADDRcxx . . $ `lib/networking.h:220:9`! *raddr, uint32_tcxx . . $ uint32_t# sig, network_protocolcxx . . $ network_protocol# link_type, float time_sent) { |
| 1226 |
int ret; |
| 1227 |
reliable_headercxx . . $ reliable_header# ack_header; |
| 1228 |
ack_header.typecxx . . $ reliable_header#type. = RNT_ACKcxx . . $ `lib/networking.h:460:9`!; |
| 1229 |
// mprintf(0,"Sending ACK for sig %d.\n",sig); |
| 1230 |
ack_header.data_lencxx . . $ reliable_header#data_len. = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!((int16_t)sizeof(uint32_t)); |
| 1231 |
ack_header.send_timecxx . . $ reliable_header#send_time. = INTEL_FLOATcxx . . $ `lib/byteswap.h:109:9`!(time_sent); |
| 1232 |
sig = INTEL_INTcxx . . $ `lib/byteswap.h:107:9`!(sig); |
| 1233 |
memcpy(&ack_header.datacxx . . $ reliable_header#data., &sig, sizeof(uint32_tcxx . . $ uint32_t#)); |
| 1234 |
|
| 1235 |
network_addresscxx . . $ network_address# send_address; |
| 1236 |
memset(&send_address, 0, sizeof(network_addresscxx . . $ network_address#)); |
| 1237 |
|
| 1238 |
send_address.connection_typecxx . . $ network_address#connection_type. = link_type; |
| 1239 |
|
| 1240 |
if (NP_TCPcxx . . $ NP_TCP. == link_type) { |
| 1241 |
SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *inaddr = (SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *)raddr; |
| 1242 |
memcpy(send_address.addresscxx . . $ network_address#address., &inaddr->sin_addr, 4); |
| 1243 |
send_address.portcxx . . $ network_address#port. = htons(inaddr->sin_port); |
| 1244 |
send_address.connection_typecxx . . $ network_address#connection_type. = NP_TCPcxx . . $ NP_TCP.; |
| 1245 |
} |
| 1246 |
|
| 1247 |
ret = nw_SendWithIDcxx . . $ nw_SendWithID(4aa96ed29f5182c6).(NWT_RELIABLEcxx . . $ `lib/networking.h:318:9`!, (uint8_tcxx . . $ uint8_t# *)&ack_header, RELIABLE_PACKET_HEADER_ONLY_SIZEcxx . . $ `networking/networking.cpp:466:9`! + sizeof(uint32_tcxx . . $ uint32_t#), |
| 1248 |
&send_address); |
| 1249 |
} |
| 1250 |
|
| 1251 |
void nw_DoNetworkIdlecxx . . $ nw_DoNetworkIdle(49f6e7a06ebc5aa8).(void) { |
| 1252 |
if (!Use_DirectPlaycxx . . $ Use_DirectPlay.) { |
| 1253 |
nw_DoReceiveCallbackscxx . . $ nw_DoReceiveCallbacks(b126dc7c1de90089).(); |
| 1254 |
nw_ReliableResendcxx . . $ nw_ReliableResend(49f6e7a06ebc5aa8).(); |
| 1255 |
} |
| 1256 |
} |
| 1257 |
|
| 1258 |
#define CONNECTSEQcxx . . $ `networking/networking.cpp:1258:9`! 0x142 // Magic number for starting a connection, just so it isn't 0 |
| 1259 |
|
| 1260 |
void nw_WorkReliablecxx . . $ nw_WorkReliable(c3263a6d42f31e8c).(uint8_tcxx . . $ uint8_t# *data, int len, network_addresscxx . . $ network_address# *naddr) { |
| 1261 |
int i; |
| 1262 |
int rcode = -1; |
| 1263 |
int16_t max_len = NETBUFFERSIZEcxx . . $ `lib/networking.h:457:9`!; |
| 1264 |
static reliable_headercxx . . $ reliable_header# rcv_buff; |
| 1265 |
static SOCKADDRcxx . . $ `lib/networking.h:220:9`! rcv_addr; |
| 1266 |
int bytesin = 0; |
| 1267 |
int addrlen = sizeof(SOCKADDRcxx . . $ `lib/networking.h:220:9`!); |
| 1268 |
uint32_tcxx . . $ uint32_t# rcvid; // The id of who we actually received a packet from, as opposed to socketid parm |
| 1269 |
|
| 1270 |
if (NP_TCPcxx . . $ NP_TCP. == naddr->connection_typecxx . . $ network_address#connection_type.) { |
| 1271 |
SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *inaddr = (SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *)&rcv_addr; |
| 1272 |
memcpy(&inaddr->sin_addr, &naddr->addresscxx . . $ network_address#address., 4); |
| 1273 |
inaddr->sin_port = htons(naddr->portcxx . . $ network_address#port.); |
| 1274 |
} |
| 1275 |
|
| 1276 |
if (Net_connect_sequencecxx . . $ Net_connect_sequence. == R_NET_SEQUENCE_CONNECTINGcxx . . $ `networking/networking.cpp:432:9`!) { |
| 1277 |
nw_HandleConnectResponsecxx . . $ nw_HandleConnectResponse(c3263a6d42f31e8c).(data, len, naddr); |
| 1278 |
return; |
| 1279 |
} |
| 1280 |
// Check for incoming data |
| 1281 |
|
| 1282 |
reliable_socketcxx . . $ reliable_socket# *rsocket = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 1283 |
// Check to see if we need to send a packet out. |
| 1284 |
if ((serverconncxx . . $ serverconn. != -1) && (reliable_socketscxx . . $ reliable_sockets.[serverconncxx . . $ serverconn.].statuscxx . . $ reliable_socket#status. == RNF_LIMBOcxx . . $ `lib/networking.h:474:9`!) && |
| 1285 |
((timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - last_sent_iamherecxx . . $ last_sent_iamhere.) > NETRETRYTIMEcxx . . $ `lib/networking.h:452:9`!)) { |
| 1286 |
reliable_headercxx . . $ reliable_header# conn_header; |
| 1287 |
// Now send I_AM_HERE packet |
| 1288 |
conn_header.typecxx . . $ reliable_header#type. = RNT_I_AM_HEREcxx . . $ `lib/networking.h:466:9`!; |
| 1289 |
conn_header.seqcxx . . $ reliable_header#seq. = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!((int16_t)(~CONNECTSEQcxx . . $ `networking/networking.cpp:1258:9`!)); |
| 1290 |
conn_header.data_lencxx . . $ reliable_header#data_len. = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!((int16_t)0); |
| 1291 |
last_sent_iamherecxx . . $ last_sent_iamhere. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1292 |
network_addresscxx . . $ network_address# send_address; |
| 1293 |
memset(&send_address, 0, sizeof(network_addresscxx . . $ network_address#)); |
| 1294 |
|
| 1295 |
send_address.connection_typecxx . . $ network_address#connection_type. = reliable_socketscxx . . $ reliable_sockets.[serverconncxx . . $ serverconn.].connection_typecxx . . $ reliable_socket#connection_type.; |
| 1296 |
if (NP_TCPcxx . . $ NP_TCP. == send_address.connection_typecxx . . $ network_address#connection_type.) { |
| 1297 |
SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *inaddr = (SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *)&reliable_socketscxx . . $ reliable_sockets.[serverconncxx . . $ serverconn.].addrcxx . . $ reliable_socket#addr.; |
| 1298 |
memcpy(send_address.addresscxx . . $ network_address#address., &inaddr->sin_addr, 4); |
| 1299 |
send_address.portcxx . . $ network_address#port. = htons(inaddr->sin_port); |
| 1300 |
send_address.connection_typecxx . . $ network_address#connection_type. = NP_TCPcxx . . $ NP_TCP.; |
| 1301 |
} |
| 1302 |
|
| 1303 |
int ret = nw_SendWithIDcxx . . $ nw_SendWithID(4aa96ed29f5182c6).(NWT_RELIABLEcxx . . $ `lib/networking.h:318:9`!, (uint8_tcxx . . $ uint8_t# *)&conn_header, RELIABLE_PACKET_HEADER_ONLY_SIZEcxx . . $ `networking/networking.cpp:466:9`!, &send_address); |
| 1304 |
|
| 1305 |
if ((ret == SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`!) && (WSAEWOULDBLOCKcxx . . $ `lib/networking.h:236:9`! == WSAGetLastErrorcxx . . $ `lib/networking.h:241:9`!())) { |
| 1306 |
reliable_socketscxx . . $ reliable_sockets.[serverconncxx . . $ serverconn.].last_packet_sentcxx . . $ reliable_socket#last_packet_sent. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - NETRETRYTIMEcxx . . $ `lib/networking.h:452:9`!; |
| 1307 |
} else { |
| 1308 |
reliable_socketscxx . . $ reliable_sockets.[serverconncxx . . $ serverconn.].last_packet_sentcxx . . $ reliable_socket#last_packet_sent. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1309 |
} |
| 1310 |
} |
| 1311 |
network_protocolcxx . . $ network_protocol# link_type = naddr->connection_typecxx . . $ network_address#connection_type.; |
| 1312 |
network_addresscxx . . $ network_address# d3_rcv_addr; |
| 1313 |
memcpy(&d3_rcv_addr, naddr, sizeof(network_addresscxx . . $ network_address#)); |
| 1314 |
memcpy((uint8_tcxx . . $ uint8_t# *)&rcv_buff, data, len); |
| 1315 |
SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *rcvaddr, *rsockaddr; |
| 1316 |
|
| 1317 |
do { |
| 1318 |
|
| 1319 |
rsocket = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 1320 |
if (len) { |
| 1321 |
// Someone wants to connect, so find a slot |
| 1322 |
if (rcv_buff.typecxx . . $ reliable_header#type. == RNT_REQ_CONNcxx . . $ `lib/networking.h:463:9`!) { |
| 1323 |
for (i = 1; i < MAXRELIABLESOCKETScxx . . $ `lib/networking.h:456:9`!; i++) { |
| 1324 |
if ((reliable_socketscxx . . $ reliable_sockets.[i].statuscxx . . $ reliable_socket#status. == RNF_CONNECTEDcxx . . $ `lib/networking.h:470:9`!) || (reliable_socketscxx . . $ reliable_sockets.[i].statuscxx . . $ reliable_socket#status. == RNF_LIMBOcxx . . $ `lib/networking.h:474:9`!)) |
| 1325 |
// if(memcmp(&rcv_addr,&reliable_sockets[i].addr,sizeof(SOCKADDR))==0) |
| 1326 |
if (memcmp(&d3_rcv_addr, &reliable_socketscxx . . $ reliable_sockets.[i].net_addrcxx . . $ reliable_socket#net_addr., sizeof(network_addresscxx . . $ network_address#)) == 0) |
| 1327 |
// d3_rcv_addr |
| 1328 |
{ |
| 1329 |
// We already have a reliable link to this user, so we will ignore it... |
| 1330 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Received duplicate connection request. %d\n", i); |
| 1331 |
// reliable_sockets[i].last_packet_received = timer_GetTime(); |
| 1332 |
nw_SendReliableAckcxx . . $ nw_SendReliableAck(763f9aad6809bec8).(&reliable_socketscxx . . $ reliable_sockets.[i].addrcxx . . $ reliable_socket#addr., INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(rcv_buff.seq), link_type, |
| 1333 |
INTEL_FLOATcxx . . $ `lib/byteswap.h:109:9`!(rcv_buff.send_time)); |
| 1334 |
// We will change this as a hack to prevent later code from hooking us up |
| 1335 |
rcv_buff.typecxx . . $ reliable_header#type. = 0xff; |
| 1336 |
continue; |
| 1337 |
} |
| 1338 |
} |
| 1339 |
for (i = 1; i < MAXRELIABLESOCKETScxx . . $ `lib/networking.h:456:9`!; i++) { |
| 1340 |
if (reliable_socketscxx . . $ reliable_sockets.[i].statuscxx . . $ reliable_socket#status. == RNF_UNUSEDcxx . . $ `lib/networking.h:469:9`!) { |
| 1341 |
// Add the new connection here. |
| 1342 |
reliable_socketscxx . . $ reliable_sockets.[i].connection_typecxx . . $ reliable_socket#connection_type. = link_type; |
| 1343 |
memcpy(&reliable_socketscxx . . $ reliable_sockets.[i].net_addrcxx . . $ reliable_socket#net_addr., naddr, sizeof(network_addresscxx . . $ network_address#)); |
| 1344 |
memcpy(&reliable_socketscxx . . $ reliable_sockets.[i].addrcxx . . $ reliable_socket#addr., &rcv_addr, sizeof(SOCKADDRcxx . . $ `lib/networking.h:220:9`!)); |
| 1345 |
reliable_socketscxx . . $ reliable_sockets.[i].ping_poscxx . . $ reliable_socket#ping_pos. = 0; |
| 1346 |
reliable_socketscxx . . $ reliable_sockets.[i].num_ping_samplescxx . . $ reliable_socket#num_ping_samples. = 0; |
| 1347 |
reliable_socketscxx . . $ reliable_sockets.[i].statuscxx . . $ reliable_socket#status. = RNF_LIMBOcxx . . $ `lib/networking.h:474:9`!; |
| 1348 |
reliable_socketscxx . . $ reliable_sockets.[i].last_packet_receivedcxx . . $ reliable_socket#last_packet_received. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1349 |
reliable_socketscxx . . $ reliable_sockets.[i].last_sentcxx . . $ reliable_socket#last_sent. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1350 |
reliable_socketscxx . . $ reliable_sockets.[i].waiting_packet_numbercxx . . $ reliable_socket#waiting_packet_number. = -1; |
| 1351 |
reliable_socketscxx . . $ reliable_sockets.[i].send_urgentcxx . . $ reliable_socket#send_urgent. = 0; |
| 1352 |
|
| 1353 |
rsocket = &reliable_socketscxx . . $ reliable_sockets.[i]; |
| 1354 |
rcvaddr = (SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *)&rcv_addr; |
| 1355 |
// Int3(); |
| 1356 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Connect from %s:%d\n", inet_ntoa(rcvaddr->sin_addr), htons(rcvaddr->sin_port)); |
| 1357 |
break; |
| 1358 |
} |
| 1359 |
} |
| 1360 |
if (i == MAXRELIABLESOCKETScxx . . $ `lib/networking.h:456:9`!) { |
| 1361 |
// No more connections! |
| 1362 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Out of incoming reliable connection sockets\n"); |
| 1363 |
// Int3();//See Kevin |
| 1364 |
continue; |
| 1365 |
} |
| 1366 |
nw_SendReliableAckcxx . . $ nw_SendReliableAck(763f9aad6809bec8).(&rsocket->addrcxx . . $ reliable_socket#addr., INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(rcv_buff.seq), link_type, INTEL_FLOATcxx . . $ `lib/byteswap.h:109:9`!(rcv_buff.send_time)); |
| 1367 |
} |
| 1368 |
|
| 1369 |
// Find out if this is a packet from someone we were expecting a packet. |
| 1370 |
rcvaddr = (SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *)&rcv_addr; |
| 1371 |
for (i = 1; i < MAXRELIABLESOCKETScxx . . $ `lib/networking.h:456:9`!; i++) { |
| 1372 |
|
| 1373 |
rsockaddr = (SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *)&reliable_socketscxx . . $ reliable_sockets.[i].addrcxx . . $ reliable_socket#addr.; |
| 1374 |
if (memcmp(&d3_rcv_addr, &reliable_socketscxx . . $ reliable_sockets.[i].net_addrcxx . . $ reliable_socket#net_addr., sizeof(network_addresscxx . . $ network_address#)) == 0) { |
| 1375 |
rsocket = &reliable_socketscxx . . $ reliable_sockets.[i]; |
| 1376 |
rcvid = i; |
| 1377 |
break; |
| 1378 |
} |
| 1379 |
} |
| 1380 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! == rsocket) { |
| 1381 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Received reliable data from unconnected client.\n"); |
| 1382 |
char addrstr[200]; |
| 1383 |
nw_GetNumbersFromHostAddresscxx . . $ nw_GetNumbersFromHostAddress(29331e2dd3eba175).(&d3_rcv_addr, addrstr); |
| 1384 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Received from %s\n", addrstr); |
| 1385 |
continue; |
| 1386 |
} |
| 1387 |
rsocket->last_packet_receivedcxx . . $ reliable_socket#last_packet_received. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1388 |
|
| 1389 |
if (rsocket->statuscxx . . $ reliable_socket#status. != RNF_CONNECTEDcxx . . $ `lib/networking.h:470:9`!) { |
| 1390 |
// Get out of limbo |
| 1391 |
if (rsocket->statuscxx . . $ reliable_socket#status. == RNF_LIMBOcxx . . $ `lib/networking.h:474:9`!) { |
| 1392 |
// this is our connection to the server |
| 1393 |
if ((serverconncxx . . $ serverconn. != -1)) { |
| 1394 |
if (rcv_buff.typecxx . . $ reliable_header#type. == RNT_ACKcxx . . $ `lib/networking.h:460:9`!) { |
| 1395 |
int *acknum = (int *)&rcv_buff.datacxx . . $ reliable_header#data.; |
| 1396 |
*acknum = INTEL_INTcxx . . $ `lib/byteswap.h:107:9`!(*acknum); |
| 1397 |
if (*acknum == (~CONNECTSEQcxx . . $ `networking/networking.cpp:1258:9`! & 0xffff)) { |
| 1398 |
rsocket->statuscxx . . $ reliable_socket#status. = RNF_CONNECTEDcxx . . $ `lib/networking.h:470:9`!; |
| 1399 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Got ACK for IAMHERE!\n"); |
| 1400 |
} |
| 1401 |
continue; |
| 1402 |
} |
| 1403 |
} else if (rcv_buff.typecxx . . $ reliable_header#type. == RNT_I_AM_HEREcxx . . $ `lib/networking.h:466:9`!) { |
| 1404 |
rsocket->statuscxx . . $ reliable_socket#status. = RNF_CONNECTINGcxx . . $ `lib/networking.h:473:9`!; |
| 1405 |
nw_SendReliableAckcxx . . $ nw_SendReliableAck(763f9aad6809bec8).(&rsocket->addrcxx . . $ reliable_socket#addr., INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(rcv_buff.seq), link_type, INTEL_FLOATcxx . . $ `lib/byteswap.h:109:9`!(rcv_buff.send_time)); |
| 1406 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Got IAMHERE!\n"); |
| 1407 |
continue; |
| 1408 |
} |
| 1409 |
} |
| 1410 |
if ((rcv_buff.typecxx . . $ reliable_header#type. == RNT_DATAcxx . . $ `lib/networking.h:461:9`!) && (serverconncxx . . $ serverconn. != -1)) { |
| 1411 |
rsocket->statuscxx . . $ reliable_socket#status. = RNF_CONNECTEDcxx . . $ `lib/networking.h:470:9`!; |
| 1412 |
} else { |
| 1413 |
// mprintf(0,"Packet from nonconnected socket -- seq: %d status: %d\n",rcv_buff.seq,rsocket->status); |
| 1414 |
rsocket->last_packet_receivedcxx . . $ reliable_socket#last_packet_received. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1415 |
continue; |
| 1416 |
} |
| 1417 |
} |
| 1418 |
// Update the last recv variable so we don't need a heartbeat |
| 1419 |
rsocket->last_packet_receivedcxx . . $ reliable_socket#last_packet_received. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1420 |
|
| 1421 |
if (rcv_buff.typecxx . . $ reliable_header#type. == RNT_HEARTBEATcxx . . $ `lib/networking.h:465:9`!) { |
| 1422 |
continue; |
| 1423 |
} |
| 1424 |
if (rcv_buff.typecxx . . $ reliable_header#type. == RNT_ACKcxx . . $ `lib/networking.h:460:9`!) { |
| 1425 |
// Update ping time |
| 1426 |
rsocket->num_ping_samplescxx . . $ reliable_socket#num_ping_samples.++; |
| 1427 |
|
| 1428 |
rsocket->pingscxx . . $ reliable_socket#pings.[rsocket->ping_poscxx . . $ reliable_socket#ping_pos.] = rsocket->last_packet_receivedcxx . . $ reliable_socket#last_packet_received. - INTEL_FLOATcxx . . $ `lib/byteswap.h:109:9`!(rcv_buff.send_time); |
| 1429 |
// mprintf(0,"ping time: %f\n",rsocket->pings[rsocket->ping_pos]); |
| 1430 |
if (rsocket->num_ping_samplescxx . . $ reliable_socket#num_ping_samples. >= MAX_PING_HISTORYcxx . . $ `networking/networking.cpp:467:9`!) { |
| 1431 |
float sort_ping[MAX_PING_HISTORYcxx . . $ `networking/networking.cpp:467:9`!]; |
| 1432 |
for (int a = 0; a < MAX_PING_HISTORYcxx . . $ `networking/networking.cpp:467:9`!; a++) |
| 1433 |
sort_ping[a] = rsocket->pingscxx . . $ reliable_socket#pings.[a]; |
| 1434 |
|
| 1435 |
qsortcxx . . $ qsort(ebb60b13a65e77d7).(sort_ping, MAX_PING_HISTORYcxx . . $ `networking/networking.cpp:467:9`!, sizeof(float), nw_PingComparecxx . . $ nw_PingCompare(9148c8c3ff42c9d8).); |
| 1436 |
rsocket->mean_pingcxx . . $ reliable_socket#mean_ping. = ((sort_ping[MAX_PING_HISTORYcxx . . $ `networking/networking.cpp:467:9`! / 2] + sort_ping[(MAX_PING_HISTORYcxx . . $ `networking/networking.cpp:467:9`! / 2) + 1])) / 2; |
| 1437 |
// mprintf_at(2,i+1,0,"Ping: %f ",rsocket->mean_ping); |
| 1438 |
} |
| 1439 |
rsocket->ping_poscxx . . $ reliable_socket#ping_pos.++; |
| 1440 |
if (rsocket->ping_poscxx . . $ reliable_socket#ping_pos. >= MAX_PING_HISTORYcxx . . $ `networking/networking.cpp:467:9`!) { |
| 1441 |
rsocket->ping_poscxx . . $ reliable_socket#ping_pos. = 0; |
| 1442 |
} |
| 1443 |
for (i = 0; i < MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`!; i++) { |
| 1444 |
uint32_tcxx . . $ uint32_t# *acksig = (uint32_tcxx . . $ uint32_t# *)&rcv_buff.datacxx . . $ reliable_header#data.; |
| 1445 |
*acksig = INTEL_INTcxx . . $ `lib/byteswap.h:107:9`!(*acksig); |
| 1446 |
if (rsocket) |
| 1447 |
if (rsocket->sbufferscxx . . $ reliable_socket#sbuffers.[i]) |
| 1448 |
if (rsocket->ssequencecxx . . $ reliable_socket#ssequence.[i] == *acksig) { |
| 1449 |
// mprintf(0,"Received ACK %d\n",*acksig); |
| 1450 |
mem_freecxx . . $ `mem/mem.h:80:9`!(rsocket->sbuffers[i]); |
| 1451 |
rsocket->sbufferscxx . . $ reliable_socket#sbuffers.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 1452 |
rsocket->ssequencecxx . . $ reliable_socket#ssequence.[i] = 0; |
| 1453 |
} |
| 1454 |
} |
| 1455 |
// remove that packet from the send buffer |
| 1456 |
rsocket->last_packet_receivedcxx . . $ reliable_socket#last_packet_received. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1457 |
continue; |
| 1458 |
} |
| 1459 |
|
| 1460 |
if (rcv_buff.typecxx . . $ reliable_header#type. == RNT_DATA_COMPcxx . . $ `lib/networking.h:462:9`!) { |
| 1461 |
// More2Come |
| 1462 |
// Decompress it. Put it back in the buffer. Process it as RNT_DATA |
| 1463 |
rcv_buff.typecxx . . $ reliable_header#type. = RNT_DATAcxx . . $ `lib/networking.h:461:9`!; |
| 1464 |
} |
| 1465 |
if (rcv_buff.typecxx . . $ reliable_header#type. == RNT_DATAcxx . . $ `lib/networking.h:461:9`!) { |
| 1466 |
|
| 1467 |
// If the data is out of order by >= MAXNETBUFFERS-1 ignore that packet for now |
| 1468 |
int seqdelta; |
| 1469 |
seqdelta = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(rcv_buff.seq) - rsocket->oursequencecxx . . $ reliable_socket#oursequence.; |
| 1470 |
if (seqdelta < 0) |
| 1471 |
seqdelta = seqdelta * -1; |
| 1472 |
if (seqdelta >= MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`! - 1) { |
| 1473 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Received reliable packet out of order!\n"); |
| 1474 |
// It's out of order, so we won't ack it, which will mean we will get it again soon. |
| 1475 |
continue; |
| 1476 |
} |
| 1477 |
// else move data into the proper buffer position |
| 1478 |
int savepacket = 1; |
| 1479 |
|
| 1480 |
if (rsocket->oursequencecxx . . $ reliable_socket#oursequence. < (0xffff - (MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`! - 1))) { |
| 1481 |
if (rsocket->oursequencecxx . . $ reliable_socket#oursequence. > INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(rcv_buff.seq)) { |
| 1482 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Received old packet with seq of %d\n", INTEL_SHORT(rcv_buff.seq)); |
| 1483 |
savepacket = 0; |
| 1484 |
} |
| 1485 |
|
| 1486 |
} else { |
| 1487 |
// Sequence is high, so prepare for wrap around |
| 1488 |
if (((uint16_tcxx . . $ uint16_t#)(INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(rcv_buff.seq) + rsocket->oursequencecxx . . $ reliable_socket#oursequence.)) > (MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`! - 1)) { |
| 1489 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Received old packet with seq of %d\n", INTEL_SHORT(rcv_buff.seq)); |
| 1490 |
savepacket = 0; |
| 1491 |
} |
| 1492 |
} |
| 1493 |
|
| 1494 |
for (i = 0; i < MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`!; i++) { |
| 1495 |
if ((NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! != rsocket->rbufferscxx . . $ reliable_socket#rbuffers.[i]) && (rsocket->rsequencecxx . . $ reliable_socket#rsequence.[i] == INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(rcv_buff.seq))) { |
| 1496 |
// Received duplicate packet! |
| 1497 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Received duplicate packet!\n"); |
| 1498 |
savepacket = 0; |
| 1499 |
} |
| 1500 |
} |
| 1501 |
if (savepacket) { |
| 1502 |
for (i = 0; i < MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`!; i++) { |
| 1503 |
if (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! == rsocket->rbufferscxx . . $ reliable_socket#rbuffers.[i]) { |
| 1504 |
// mprintf(0,"Got good data seq: %d\n",rcv_buff.seq); |
| 1505 |
if (INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(rcv_buff.data_len) > max_len) |
| 1506 |
rsocket->recv_lencxx . . $ reliable_socket#recv_len.[i] = max_len; // INTEL_SHORT(rcv_buff.data_len); |
| 1507 |
else |
| 1508 |
rsocket->recv_lencxx . . $ reliable_socket#recv_len.[i] = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(rcv_buff.data_len); |
| 1509 |
rsocket->rbufferscxx . . $ reliable_socket#rbuffers.[i] = (reliable_net_rcvbuffercxx . . $ reliable_net_rcvbuffer# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(sizeof(reliable_net_rcvbuffer)); |
| 1510 |
memcpy(rsocket->rbufferscxx . . $ reliable_socket#rbuffers.[i]->buffercxx . . $ reliable_net_rcvbuffer#buffer., rcv_buff.datacxx . . $ reliable_header#data., rsocket->recv_lencxx . . $ reliable_socket#recv_len.[i]); |
| 1511 |
rsocket->rsequencecxx . . $ reliable_socket#rsequence.[i] = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(rcv_buff.seq); |
| 1512 |
// mprintf(0,"Adding packet to receive buffer in nw_ReceiveReliable().\n"); |
| 1513 |
break; |
| 1514 |
} |
| 1515 |
} |
| 1516 |
} |
| 1517 |
nw_SendReliableAckcxx . . $ nw_SendReliableAck(763f9aad6809bec8).(&rsocket->addrcxx . . $ reliable_socket#addr., INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(rcv_buff.seq), link_type, INTEL_FLOATcxx . . $ `lib/byteswap.h:109:9`!(rcv_buff.send_time)); |
| 1518 |
} |
| 1519 |
} |
| 1520 |
} while (0); // while((IPX_has_data>0) || (UDP_has_data>0)); |
| 1521 |
} |
| 1522 |
|
| 1523 |
// MTS: only used in this file |
| 1524 |
void nw_HandleConnectResponsecxx . . $ nw_HandleConnectResponse(c3263a6d42f31e8c).(uint8_tcxx . . $ uint8_t# *data, int len, network_addresscxx . . $ network_address# *server_addr) { |
| 1525 |
|
| 1526 |
int i; |
| 1527 |
static reliable_headercxx . . $ reliable_header# ack_header; |
| 1528 |
static reliable_headercxx . . $ reliable_header# conn_header; |
| 1529 |
SOCKADDRcxx . . $ `lib/networking.h:220:9`! rcv_addr; |
| 1530 |
|
| 1531 |
memcpy(&ack_header, data, len); |
| 1532 |
|
| 1533 |
if (NP_TCPcxx . . $ NP_TCP. == server_addr->connection_typecxx . . $ network_address#connection_type.) { |
| 1534 |
SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *inaddr = (SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *)&rcv_addr; |
| 1535 |
memcpy(&inaddr->sin_addr, &server_addr->addresscxx . . $ network_address#address., 4); |
| 1536 |
inaddr->sin_port = htons(server_addr->portcxx . . $ network_address#port.); |
| 1537 |
} |
| 1538 |
|
| 1539 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Got a connect response!\n"); |
| 1540 |
if (ack_header.typecxx . . $ reliable_header#type. == RNT_ACKcxx . . $ `lib/networking.h:460:9`!) { |
| 1541 |
int *acknum = (int *)&ack_header.datacxx . . $ reliable_header#data.; |
| 1542 |
if (INTEL_INTcxx . . $ `lib/byteswap.h:107:9`!(*acknum) == CONNECTSEQcxx . . $ `networking/networking.cpp:1258:9`!) { |
| 1543 |
// if(memcmp(&rcv_addr,&sockaddr,sizeof(SOCKADDR))==0) |
| 1544 |
{ |
| 1545 |
for (i = 1; i < MAXRELIABLESOCKETScxx . . $ `lib/networking.h:456:9`!; i++) { |
| 1546 |
if (reliable_socketscxx . . $ reliable_sockets.[i].statuscxx . . $ reliable_socket#status. == RNF_UNUSEDcxx . . $ `lib/networking.h:469:9`!) { |
| 1547 |
// Add the new connection here. |
| 1548 |
memset(&reliable_socketscxx . . $ reliable_sockets.[i], 0, sizeof(reliable_socketcxx . . $ reliable_socket#)); |
| 1549 |
reliable_socketscxx . . $ reliable_sockets.[i].connection_typecxx . . $ reliable_socket#connection_type. = server_addr->connection_typecxx . . $ network_address#connection_type.; |
| 1550 |
memcpy(&reliable_socketscxx . . $ reliable_sockets.[i].net_addrcxx . . $ reliable_socket#net_addr., server_addr, sizeof(network_addresscxx . . $ network_address#)); |
| 1551 |
reliable_socketscxx . . $ reliable_sockets.[i].last_packet_receivedcxx . . $ reliable_socket#last_packet_received. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1552 |
memcpy(&reliable_socketscxx . . $ reliable_sockets.[i].addrcxx . . $ reliable_socket#addr., &rcv_addr, sizeof(SOCKADDRcxx . . $ `lib/networking.h:220:9`!)); |
| 1553 |
reliable_socketscxx . . $ reliable_sockets.[i].statuscxx . . $ reliable_socket#status. = RNF_LIMBOcxx . . $ `lib/networking.h:474:9`!; |
| 1554 |
Net_connect_socket_idcxx . . $ Net_connect_socket_id. = i; |
| 1555 |
reliable_socketscxx . . $ reliable_sockets.[i].last_sentcxx . . $ reliable_socket#last_sent. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1556 |
reliable_socketscxx . . $ reliable_sockets.[i].waiting_packet_numbercxx . . $ reliable_socket#waiting_packet_number. = -1; |
| •1557 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Successfully connected to server in nw_ConnectToServer().\n"); |
| 1558 |
// Now send I_AM_HERE packet |
| 1559 |
conn_header.typecxx . . $ reliable_header#type. = RNT_I_AM_HEREcxx . . $ `lib/networking.h:466:9`!; |
| 1560 |
conn_header.seqcxx . . $ reliable_header#seq. = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!((int16_t)(~CONNECTSEQcxx . . $ `networking/networking.cpp:1258:9`!)); |
| 1561 |
conn_header.data_lencxx . . $ reliable_header#data_len. = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!((int16_t)0); |
| 1562 |
serverconncxx . . $ serverconn. = i; |
| 1563 |
first_sent_iamherecxx . . $ first_sent_iamhere. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1564 |
last_sent_iamherecxx . . $ last_sent_iamhere. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1565 |
|
| 1566 |
int rcode = |
| 1567 |
nw_SendWithIDcxx . . $ nw_SendWithID(4aa96ed29f5182c6).(NWT_RELIABLEcxx . . $ `lib/networking.h:318:9`!, (uint8_tcxx . . $ uint8_t# *)&conn_header, RELIABLE_PACKET_HEADER_ONLY_SIZEcxx . . $ `networking/networking.cpp:466:9`!, server_addr); |
| 1568 |
// int rcode = sendto(typeless_sock,(char |
| 1569 |
// *)&conn_header,RELIABLE_PACKET_HEADER_ONLY_SIZE,0,addr,sizeof(SOCKADDR)); |
| 1570 |
if (rcode == SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`!) { |
| 1571 |
Net_connect_socket_idcxx . . $ Net_connect_socket_id. = INVALID_SOCKETcxx . . $ `lib/networking.h:221:9`!; |
| 1572 |
reliable_socketscxx . . $ reliable_sockets.[i].statuscxx . . $ reliable_socket#status. = RNF_UNUSEDcxx . . $ `lib/networking.h:469:9`!; |
| 1573 |
memset(&reliable_socketscxx . . $ reliable_sockets.[i], 0, sizeof(reliable_socketcxx . . $ reliable_socket#)); |
| 1574 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Unable to send packet in nw_ConnectToServer()\n"); |
| 1575 |
|
| 1576 |
Net_connect_sequencecxx . . $ Net_connect_sequence. = R_NET_SEQUENCE_FAILEDcxx . . $ `networking/networking.cpp:434:9`!; |
| 1577 |
return; |
| 1578 |
} |
| 1579 |
reliable_socketscxx . . $ reliable_sockets.[i].last_packet_sentcxx . . $ reliable_socket#last_packet_sent. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1580 |
/* |
| 1581 |
float f; |
| 1582 |
f = timer_GetTime(); |
| 1583 |
while(((timer_GetTime() - f)<2) && (reliable_sockets[i].status!=RNF_CONNECTING)) |
| 1584 |
{ |
| 1585 |
//nw_WorkReliable(); |
| 1586 |
nw_DoReceiveCallbacks(); |
| 1587 |
} |
| 1588 |
*/ |
| 1589 |
Net_connect_sequencecxx . . $ Net_connect_sequence. = R_NET_SEQUENCE_CONNECTEDcxx . . $ `networking/networking.cpp:433:9`!; |
| 1590 |
return; |
| 1591 |
} |
| 1592 |
} |
| 1593 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Out of reliable socket space in nw_ConnectToServer().\n"); |
| 1594 |
Net_connect_sequencecxx . . $ Net_connect_sequence. = R_NET_SEQUENCE_FAILEDcxx . . $ `networking/networking.cpp:434:9`!; |
| 1595 |
return; |
| 1596 |
} |
| 1597 |
// else |
| 1598 |
//{ |
| 1599 |
// mprintf(0,"Received a reliable packet from a server other than the current server\n"); |
| 1600 |
//} |
| 1601 |
} else { |
| 1602 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Received out of sequence ACK in nw_ConnectToServer().\n"); |
| 1603 |
} |
| 1604 |
} else { |
| 1605 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Received something that isn't an ACK in nw_ConnectToServer().\n"); |
| 1606 |
} |
| 1607 |
} |
| 1608 |
|
| 1609 |
void nw_ConnectToServercxx . . $ nw_ConnectToServer(cabc7cbaf24da8c).(SOCKETcxx . . $ `lib/networking.h:217:9`! *socket, network_addresscxx . . $ network_address# *server_addr) { |
| 1610 |
|
| 1611 |
// Send out a RNT_REQ_CONN packet, and wait for it to be acked. |
| 1612 |
|
| 1613 |
float time_sent_req = 0; |
| 1614 |
float first_sent_req = 0; |
| 1615 |
static reliable_headercxx . . $ reliable_header# conn_header; |
| 1616 |
static reliable_headercxx . . $ reliable_header# ack_header; |
| 1617 |
int bytesin; |
| 1618 |
struct timeval timeout; |
| 1619 |
*socket = INVALID_SOCKETcxx . . $ `lib/networking.h:221:9`!; |
| 1620 |
|
| 1621 |
if (Use_DirectPlaycxx . . $ Use_DirectPlay.) { |
| 1622 |
// We need a session description to do this, so we don't use this function |
| 1623 |
return; |
| 1624 |
} |
| 1625 |
|
| 1626 |
conn_header.typecxx . . $ reliable_header#type. = RNT_REQ_CONNcxx . . $ `lib/networking.h:463:9`!; |
| 1627 |
conn_header.seqcxx . . $ reliable_header#seq. = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!((int16_t)CONNECTSEQcxx . . $ `networking/networking.cpp:1258:9`!); |
| 1628 |
conn_header.data_lencxx . . $ reliable_header#data_len. = 0; |
| 1629 |
|
| 1630 |
timeout.tv_sec = 0; |
| 1631 |
timeout.tv_usec = 0; |
| 1632 |
|
| 1633 |
if ((server_addr->connection_typecxx . . $ network_address#connection_type. == NP_TCPcxx . . $ NP_TCP.) && (!TCP_activecxx . . $ TCP_active.)) { |
| 1634 |
return; |
| 1635 |
} |
| 1636 |
|
| 1637 |
Net_connect_sequencecxx . . $ Net_connect_sequence. = R_NET_SEQUENCE_CONNECTINGcxx . . $ `networking/networking.cpp:432:9`!; |
| 1638 |
|
| 1639 |
memset(&ack_header, 0, sizeof(reliable_headercxx . . $ reliable_header#)); |
| 1640 |
bytesin = 0; |
| 1641 |
|
| 1642 |
network_addresscxx . . $ network_address# d3_rcv_addr; |
| 1643 |
memset(&d3_rcv_addr, 0, sizeof(network_addresscxx . . $ network_address#)); |
| 1644 |
|
| 1645 |
int ret = nw_SendWithIDcxx . . $ nw_SendWithID(4aa96ed29f5182c6).(NWT_RELIABLEcxx . . $ `lib/networking.h:318:9`!, (uint8_tcxx . . $ uint8_t# *)&conn_header, RELIABLE_PACKET_HEADER_ONLY_SIZEcxx . . $ `networking/networking.cpp:466:9`!, server_addr); |
| 1646 |
if (SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`! == ret) { |
| 1647 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Unable to send packet in nw_ConnectToServer()! -- %d\n", WSAGetLastError()); |
| 1648 |
return; |
| 1649 |
} |
| 1650 |
|
| 1651 |
first_sent_req = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1652 |
time_sent_req = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1653 |
|
| 1654 |
// Wait until we get a response from the server or we timeout |
| 1655 |
|
| 1656 |
do { |
| 1657 |
nw_DoReceiveCallbackscxx . . $ nw_DoReceiveCallbacks(b126dc7c1de90089).(); |
| 1658 |
// Now we wait for the connection to be made.... |
| 1659 |
if (Net_connect_sequencecxx . . $ Net_connect_sequence. == R_NET_SEQUENCE_CONNECTEDcxx . . $ `networking/networking.cpp:433:9`!) { |
| 1660 |
*socket = Net_connect_socket_idcxx . . $ Net_connect_socket_id.; |
| 1661 |
return; |
| 1662 |
} |
| 1663 |
if ((timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - time_sent_req) > 2) { |
| 1664 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Resending connect request.\n"); |
| 1665 |
int ret = nw_SendWithIDcxx . . $ nw_SendWithID(4aa96ed29f5182c6).(NWT_RELIABLEcxx . . $ `lib/networking.h:318:9`!, (uint8_tcxx . . $ uint8_t# *)&conn_header, RELIABLE_PACKET_HEADER_ONLY_SIZEcxx . . $ `networking/networking.cpp:466:9`!, server_addr); |
| 1666 |
if (ret != SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`!) { |
| 1667 |
time_sent_req = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 1668 |
} else { |
| 1669 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Error sending connection request! -- %d\n", WSAGetLastError()); |
| 1670 |
} |
| 1671 |
} |
| 1672 |
|
| 1673 |
} while ((timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - first_sent_req) < NETTIMEOUTcxx . . $ `lib/networking.h:454:9`!); |
| 1674 |
return; |
| 1675 |
} |
| 1676 |
|
| 1677 |
void nw_CloseSocketcxx . . $ nw_CloseSocket(11b0e290e57a7e53).(SOCKETcxx . . $ `lib/networking.h:217:9`! *sockp) { |
| 1678 |
reliable_headercxx . . $ reliable_header# diss_conn_header; |
| 1679 |
#ifdef WIN32 |
| 1680 |
if (DP_active) { |
| 1681 |
dp_DirectPlayDestroyPlayer(*sockp); |
| 1682 |
return; |
| 1683 |
} |
| 1684 |
#endif |
| 1685 |
|
| 1686 |
if (*sockp >= MAXRELIABLESOCKETScxx . . $ `lib/networking.h:456:9`!) { |
| 1687 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Invalid socket id passed to nw_NewCloseSocket() -- %d\n", *sockp); |
| 1688 |
return; |
| 1689 |
} |
| 1690 |
|
| 1691 |
if (reliable_socketscxx . . $ reliable_sockets.[*sockp].statuscxx . . $ reliable_socket#status. == RNF_UNUSEDcxx . . $ `lib/networking.h:469:9`!) { |
| 1692 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Trying to close an unused socket (%d) -- ignoring request.\n", *sockp); |
| 1693 |
} |
| 1694 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Closing socket %d\n", *sockp); |
| 1695 |
// Go through every buffer and "free it up(tm)" |
| 1696 |
int i; |
| 1697 |
for (i = 0; i < MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`!; i++) { |
| 1698 |
if (reliable_socketscxx . . $ reliable_sockets.[*sockp].rbufferscxx . . $ reliable_socket#rbuffers.[i]) { |
| 1699 |
mem_freecxx . . $ `mem/mem.h:80:9`!(reliable_sockets[*sockp].rbuffers[i]); |
| 1700 |
reliable_socketscxx . . $ reliable_sockets.[*sockp].rbufferscxx . . $ reliable_socket#rbuffers.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 1701 |
reliable_socketscxx . . $ reliable_sockets.[*sockp].rsequencecxx . . $ reliable_socket#rsequence.[i] = 0; |
| 1702 |
} |
| 1703 |
if (reliable_socketscxx . . $ reliable_sockets.[*sockp].sbufferscxx . . $ reliable_socket#sbuffers.[i]) { |
| 1704 |
mem_freecxx . . $ `mem/mem.h:80:9`!(reliable_sockets[*sockp].sbuffers[i]); |
| 1705 |
reliable_socketscxx . . $ reliable_sockets.[*sockp].sbufferscxx . . $ reliable_socket#sbuffers.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 1706 |
reliable_socketscxx . . $ reliable_sockets.[*sockp].rsequencecxx . . $ reliable_socket#rsequence.[i] = 0; |
| 1707 |
} |
| 1708 |
} |
| 1709 |
diss_conn_header.typecxx . . $ reliable_header#type. = RNT_DISCONNECTcxx . . $ `lib/networking.h:464:9`!; |
| 1710 |
diss_conn_header.seqcxx . . $ reliable_header#seq. = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!((int16_t)(CONNECTSEQcxx . . $ `networking/networking.cpp:1258:9`!)); |
| 1711 |
diss_conn_header.data_lencxx . . $ reliable_header#data_len. = 0; |
| 1712 |
if (*sockp == serverconncxx . . $ serverconn.) |
| 1713 |
serverconncxx . . $ serverconn. = -1; |
| 1714 |
|
| 1715 |
network_addresscxx . . $ network_address# send_address; |
| 1716 |
memset(&send_address, 0, sizeof(network_addresscxx . . $ network_address#)); |
| 1717 |
|
| 1718 |
send_address.connection_typecxx . . $ network_address#connection_type. = reliable_socketscxx . . $ reliable_sockets.[*sockp].connection_typecxx . . $ reliable_socket#connection_type.; |
| 1719 |
if (NP_TCPcxx . . $ NP_TCP. == reliable_socketscxx . . $ reliable_sockets.[*sockp].connection_typecxx . . $ reliable_socket#connection_type.) { |
| 1720 |
SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *inaddr = (SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *)&reliable_socketscxx . . $ reliable_sockets.[*sockp].addrcxx . . $ reliable_socket#addr.; |
| 1721 |
memcpy(send_address.addresscxx . . $ network_address#address., &inaddr->sin_addr, 4); |
| 1722 |
send_address.portcxx . . $ network_address#port. = htons(inaddr->sin_port); |
| 1723 |
send_address.connection_typecxx . . $ network_address#connection_type. = NP_TCPcxx . . $ NP_TCP.; |
| 1724 |
} |
| 1725 |
|
| 1726 |
nw_SendWithIDcxx . . $ nw_SendWithID(4aa96ed29f5182c6).(NWT_RELIABLEcxx . . $ `lib/networking.h:318:9`!, (uint8_tcxx . . $ uint8_t# *)&diss_conn_header, RELIABLE_PACKET_HEADER_ONLY_SIZEcxx . . $ `networking/networking.cpp:466:9`!, &send_address); |
| 1727 |
|
| 1728 |
memset(&reliable_socketscxx . . $ reliable_sockets.[*sockp], 0, sizeof(reliable_socketcxx . . $ reliable_socket#)); |
| 1729 |
reliable_socketscxx . . $ reliable_sockets.[*sockp].statuscxx . . $ reliable_socket#status. = RNF_UNUSEDcxx . . $ `lib/networking.h:469:9`!; |
| 1730 |
} |
| 1731 |
|
| 1732 |
int nw_CheckReliableSocketcxx . . $ nw_CheckReliableSocket(7864480464b09eea).(int socknum) { |
| 1733 |
// Checks to see if a socket is connected or not. |
| 1734 |
if (Use_DirectPlaycxx . . $ Use_DirectPlay.) { |
| 1735 |
return true; |
| 1736 |
} |
| 1737 |
if (socknum >= MAXRELIABLESOCKETScxx . . $ `lib/networking.h:456:9`!) { |
| 1738 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Invalid socket id passed to nw_CheckReliableSocket() -- %d\n", socknum); |
| 1739 |
return 0; |
| 1740 |
} |
| 1741 |
switch (reliable_socketscxx . . $ reliable_sockets.[socknum].statuscxx . . $ reliable_socket#status.) { |
| 1742 |
case RNF_UNUSEDcxx . . $ `lib/networking.h:469:9`!: |
| 1743 |
case RNF_BROKENcxx . . $ `lib/networking.h:471:9`!: |
| 1744 |
case RNF_DISCONNECTEDcxx . . $ `lib/networking.h:472:9`!: |
| 1745 |
return 0; |
| 1746 |
default: |
| 1747 |
return 1; |
| 1748 |
} |
| 1749 |
} |
| 1750 |
|
| 1751 |
// MTS: only used in this file. |
| 1752 |
int nw_PingComparecxx . . $ nw_PingCompare(9148c8c3ff42c9d8).(const void *arg1, const void *arg2) { |
| 1753 |
float *ping1 = (float *)arg1; |
| 1754 |
float *ping2 = (float *)arg2; |
| 1755 |
|
| 1756 |
if (*ping1 == *ping2) |
| 1757 |
return 0; |
| 1758 |
else if (*ping1 > *ping2) |
| 1759 |
return 1; |
| 1760 |
else if (*ping1 < *ping2) |
| 1761 |
return -1; |
| 1762 |
|
| 1763 |
return 0; |
| 1764 |
} |
| 1765 |
|
| 1766 |
// MTS: only used in this file |
| 1767 |
// Warning, experimental compression below, if you want to use it, talk to Kevin. Doesn't do much currently, only |
| 1768 |
// reduces 0's |
| 1769 |
#define COMPRESS_KEYcxx . . $ `networking/networking.cpp:1769:9`! 0xfd |
| 1770 |
int nw_Compresscxx . . $ nw_Compress(8bc41909eac9e5d8).(void *srcdata, void *destdata, int count) { |
| 1771 |
int i; |
| 1772 |
uint8_tcxx . . $ uint8_t# *curr_src = (uint8_tcxx . . $ uint8_t# *)srcdata; |
| 1773 |
uint8_tcxx . . $ uint8_t# *currp = (uint8_tcxx . . $ uint8_t# *)destdata; |
| 1774 |
for (i = 0; i < count; i++) { |
| 1775 |
// Woops, we have a char that matches our compress key, so add it as it's own type |
| 1776 |
if (curr_src[i] == COMPRESS_KEYcxx . . $ `networking/networking.cpp:1769:9`!) { |
| 1777 |
*currp = COMPRESS_KEYcxx . . $ `networking/networking.cpp:1769:9`!; |
| 1778 |
currp++; |
| 1779 |
//*currp = 1; |
| 1780 |
// currp++; |
| 1781 |
*currp = COMPRESS_KEYcxx . . $ `networking/networking.cpp:1769:9`!; |
| 1782 |
currp++; |
| 1783 |
} |
| 1784 |
// Look for 3 in a row |
| 1785 |
else if ((curr_src[i] == 0) && (curr_src[i + 1] == 0) && (curr_src[i + 2] == 0) && (i + 3 < count)) { |
| 1786 |
int repeat_count = 3; |
| 1787 |
*currp = COMPRESS_KEYcxx . . $ `networking/networking.cpp:1769:9`!; |
| 1788 |
currp++; |
| 1789 |
while ((curr_src[i] == curr_src[i + repeat_count]) && (repeat_count < 250) && (i + repeat_count < count)) { |
| 1790 |
repeat_count++; |
| 1791 |
} |
| 1792 |
*currp = repeat_count; |
| 1793 |
currp++; |
| 1794 |
//*currp = curr_src[i]; |
| 1795 |
// currp++; |
| 1796 |
i += (repeat_count - 1); |
| 1797 |
} else { |
| 1798 |
*currp = curr_src[i]; |
| 1799 |
currp++; |
| 1800 |
} |
| 1801 |
} |
| 1802 |
return currp - (uint8_tcxx . . $ uint8_t# *)destdata; |
| 1803 |
} |
| 1804 |
|
| 1805 |
// MTS: only used in this file |
| 1806 |
int nw_Uncompresscxx . . $ nw_Uncompress(8bc41909eac9e5d8).(void *compdata, void *uncompdata, int count) { |
| 1807 |
int i; |
| 1808 |
int destlen = 0; |
| 1809 |
uint8_tcxx . . $ uint8_t# *comp_src = (uint8_tcxx . . $ uint8_t# *)compdata; |
| 1810 |
uint8_tcxx . . $ uint8_t# *currp = (uint8_tcxx . . $ uint8_t# *)uncompdata; |
| 1811 |
for (i = 0; i < count; i++) { |
| 1812 |
if (*comp_src == COMPRESS_KEYcxx . . $ `networking/networking.cpp:1769:9`!) { |
| 1813 |
comp_src++; |
| 1814 |
if (*comp_src == COMPRESS_KEYcxx . . $ `networking/networking.cpp:1769:9`!) { |
| 1815 |
currp[destlen] = COMPRESS_KEYcxx . . $ `networking/networking.cpp:1769:9`!; |
| 1816 |
destlen++; |
| 1817 |
} else { |
| 1818 |
for (int a = 0; a < (*comp_src); a++) { |
| 1819 |
currp[destlen] = 0; //*(comp_src+1); |
| 1820 |
destlen++; |
| 1821 |
} |
| 1822 |
} |
| 1823 |
i++; |
| 1824 |
// comp_src++; |
| 1825 |
comp_src++; |
| 1826 |
} else { |
| 1827 |
currp[destlen] = *comp_src; |
| 1828 |
destlen++; |
| 1829 |
comp_src++; |
| 1830 |
} |
| 1831 |
} |
| 1832 |
return destlen; |
| 1833 |
} |
| 1834 |
|
| 1835 |
// MTS: only used in this file |
| 1836 |
// initialize the buffering system |
| 1837 |
void nw_psnet_buffer_initcxx . . $ nw_psnet_buffer_init(49f6e7a06ebc5aa8).() { |
| 1838 |
int idx; |
| 1839 |
|
| 1840 |
// blast the buffer clean |
| 1841 |
memset(Psnet_bufferscxx . . $ Psnet_buffers., 0, sizeof(network_packet_buffercxx . . $ network_packet_buffer#) * MAX_PACKET_BUFFERScxx . . $ `networking/networking.cpp:413:9`!); |
| 1842 |
|
| 1843 |
// set all buffer sequence #'s to -1 |
| 1844 |
for (idx = 0; idx < MAX_PACKET_BUFFERScxx . . $ `networking/networking.cpp:413:9`!; idx++) { |
| 1845 |
Psnet_bufferscxx . . $ Psnet_buffers.[idx].sequence_numbercxx . . $ network_packet_buffer#sequence_number. = -1; |
| 1846 |
} |
| 1847 |
|
| 1848 |
// initialize the sequence # |
| 1849 |
Psnet_seq_numbercxx . . $ Psnet_seq_number. = 0; |
| 1850 |
Psnet_lowest_idcxx . . $ Psnet_lowest_id. = -1; |
| 1851 |
Psnet_highest_idcxx . . $ Psnet_highest_id. = -1; |
| 1852 |
} |
| 1853 |
|
| 1854 |
// MTS: only used in this file |
| 1855 |
// buffer a packet (maintain order!) |
| 1856 |
void nw_psnet_buffer_packetcxx . . $ nw_psnet_buffer_packet(c3263a6d42f31e8c).(uint8_tcxx . . $ uint8_t# *data, int length, network_addresscxx . . $ network_address# *from) { |
| 1857 |
int idx; |
| 1858 |
int found_buf = 0; |
| 1859 |
|
| 1860 |
// find the first empty packet |
| 1861 |
for (idx = 0; idx < MAX_PACKET_BUFFERScxx . . $ `networking/networking.cpp:413:9`!; idx++) { |
| 1862 |
if (Psnet_bufferscxx . . $ Psnet_buffers.[idx].sequence_numbercxx . . $ network_packet_buffer#sequence_number. == -1) { |
| 1863 |
found_buf = 1; |
| 1864 |
break; |
| 1865 |
} |
| 1866 |
} |
| 1867 |
|
| 1868 |
// if we didn't find the buffer, report an overrun |
| 1869 |
if (!found_buf) { |
| 1870 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "WARNING - Buffer overrun in psnet\n"); |
| 1871 |
} else { |
| 1872 |
// copy in the data |
| 1873 |
memcpy(Psnet_bufferscxx . . $ Psnet_buffers.[idx].datacxx . . $ network_packet_buffer#data., data, length); |
| 1874 |
Psnet_bufferscxx . . $ Psnet_buffers.[idx].lencxx . . $ network_packet_buffer#len. = length; |
| 1875 |
memcpy(&Psnet_bufferscxx . . $ Psnet_buffers.[idx].from_addrcxx . . $ network_packet_buffer#from_addr., from, sizeof(network_addresscxx . . $ network_address#)); |
| 1876 |
Psnet_bufferscxx . . $ Psnet_buffers.[idx].sequence_numbercxx . . $ network_packet_buffer#sequence_number. = Psnet_seq_numbercxx . . $ Psnet_seq_number.; |
| 1877 |
|
| 1878 |
// keep track of the highest id# |
| 1879 |
Psnet_highest_idcxx . . $ Psnet_highest_id. = Psnet_seq_numbercxx . . $ Psnet_seq_number.++; |
| 1880 |
|
| 1881 |
// set the lowest id# for the first time |
| 1882 |
if (Psnet_lowest_idcxx . . $ Psnet_lowest_id. == -1) { |
| 1883 |
Psnet_lowest_idcxx . . $ Psnet_lowest_id. = Psnet_highest_idcxx . . $ Psnet_highest_id.; |
| 1884 |
} |
| 1885 |
} |
| 1886 |
} |
| 1887 |
|
| 1888 |
// MTS: only used in this file |
| 1889 |
// get the index of the next packet in order! |
| 1890 |
int nw_psnet_buffer_get_next_by_packet_idcxx . . $ nw_psnet_buffer_get_next_by_packet_id(9ff6ce25d7357603).(uint8_tcxx . . $ uint8_t# *data, int *length, uint32_tcxx . . $ uint32_t# packet_id) { |
| 1891 |
int idx; |
| 1892 |
int found_buf = 0; |
| 1893 |
|
| 1894 |
// if there are no buffers, do nothing |
| 1895 |
if ((Psnet_lowest_idcxx . . $ Psnet_lowest_id. == -1) || (Psnet_lowest_idcxx . . $ Psnet_lowest_id. > Psnet_highest_idcxx . . $ Psnet_highest_id.)) { |
| 1896 |
return 0; |
| 1897 |
} |
| 1898 |
|
| 1899 |
// search until we find the lowest packet index id# |
| 1900 |
for (idx = 0; idx < MAX_PACKET_BUFFERScxx . . $ `networking/networking.cpp:413:9`!; idx++) { |
| 1901 |
uint32_tcxx . . $ uint32_t# *thisid; |
| 1902 |
thisid = (uint32_tcxx . . $ uint32_t# *)&Psnet_bufferscxx . . $ Psnet_buffers.[idx].from_addrcxx . . $ network_packet_buffer#from_addr..addresscxx . . $ network_address#address.; |
| 1903 |
// if we found the buffer |
| 1904 |
if ((Psnet_bufferscxx . . $ Psnet_buffers.[idx].sequence_numbercxx . . $ network_packet_buffer#sequence_number. == Psnet_lowest_idcxx . . $ Psnet_lowest_id.) && (packet_id == *thisid)) { |
| 1905 |
found_buf = 1; |
| 1906 |
break; |
| 1907 |
} |
| 1908 |
} |
| 1909 |
|
| 1910 |
if (!found_buf) |
| 1911 |
return 0; |
| 1912 |
|
| 1913 |
// copy out the buffer data |
| 1914 |
memcpy(data, Psnet_bufferscxx . . $ Psnet_buffers.[idx].datacxx . . $ network_packet_buffer#data., Psnet_bufferscxx . . $ Psnet_buffers.[idx].lencxx . . $ network_packet_buffer#len.); |
| 1915 |
*length = Psnet_bufferscxx . . $ Psnet_buffers.[idx].lencxx . . $ network_packet_buffer#len.; |
| 1916 |
|
| 1917 |
// now we need to cleanup the packet list |
| 1918 |
|
| 1919 |
// mark the buffer as free |
| 1920 |
Psnet_bufferscxx . . $ Psnet_buffers.[idx].sequence_numbercxx . . $ network_packet_buffer#sequence_number. = -1; |
| 1921 |
Psnet_lowest_idcxx . . $ Psnet_lowest_id.++; |
| 1922 |
|
| 1923 |
return 1; |
| 1924 |
} |
| 1925 |
|
| 1926 |
// MTS: only used in this file |
| 1927 |
// get the index of the next packet in order! |
| 1928 |
int nw_psnet_buffer_get_nextcxx . . $ nw_psnet_buffer_get_next(c5ce5346f0e0aa21).(uint8_tcxx . . $ uint8_t# *data, int *length, network_addresscxx . . $ network_address# *from) { |
| 1929 |
int idx; |
| 1930 |
int found_buf = 0; |
| 1931 |
|
| 1932 |
// if there are no buffers, do nothing |
| 1933 |
if ((Psnet_lowest_idcxx . . $ Psnet_lowest_id. == -1) || (Psnet_lowest_idcxx . . $ Psnet_lowest_id. > Psnet_highest_idcxx . . $ Psnet_highest_id.)) { |
| 1934 |
return 0; |
| 1935 |
} |
| 1936 |
|
| 1937 |
// search until we find the lowest packet index id# |
| 1938 |
for (idx = 0; idx < MAX_PACKET_BUFFERScxx . . $ `networking/networking.cpp:413:9`!; idx++) { |
| 1939 |
// if we found the buffer |
| 1940 |
if (Psnet_bufferscxx . . $ Psnet_buffers.[idx].sequence_numbercxx . . $ network_packet_buffer#sequence_number. == Psnet_lowest_idcxx . . $ Psnet_lowest_id.) { |
| 1941 |
found_buf = 1; |
| 1942 |
break; |
| 1943 |
} |
| 1944 |
} |
| 1945 |
|
| 1946 |
// at this point, we should _always_ have found the buffer |
| 1947 |
ASSERTcxx . . $ `misc/pserror.h:246:9`!(found_buf); |
| 1948 |
|
| 1949 |
// copy out the buffer data |
| 1950 |
memcpy(data, Psnet_bufferscxx . . $ Psnet_buffers.[idx].datacxx . . $ network_packet_buffer#data., Psnet_bufferscxx . . $ Psnet_buffers.[idx].lencxx . . $ network_packet_buffer#len.); |
| 1951 |
*length = Psnet_bufferscxx . . $ Psnet_buffers.[idx].lencxx . . $ network_packet_buffer#len.; |
| 1952 |
memcpy(from, &Psnet_bufferscxx . . $ Psnet_buffers.[idx].from_addrcxx . . $ network_packet_buffer#from_addr., sizeof(network_addresscxx . . $ network_address#)); |
| 1953 |
|
| 1954 |
// now we need to cleanup the packet list |
| 1955 |
|
| 1956 |
// mark the buffer as free |
| 1957 |
Psnet_bufferscxx . . $ Psnet_buffers.[idx].sequence_numbercxx . . $ network_packet_buffer#sequence_number. = -1; |
| 1958 |
Psnet_lowest_idcxx . . $ Psnet_lowest_id.++; |
| 1959 |
|
| 1960 |
return 1; |
| 1961 |
} |
| 1962 |
|
| 1963 |
#ifdef WIN32 |
| 1964 |
// MTS: only used in this file |
| 1965 |
// functions to get the status of a RAS connection |
| 1966 |
uint32_t psnet_ras_status() { |
| 1967 |
int rval; |
| 1968 |
DWORD size, num_connections, i; |
| 1969 |
RASCONN rasbuffer[25]; |
| 1970 |
HINSTANCE ras_handle; |
| 1971 |
uint32_t rasip = 0; |
| 1972 |
RASPPPIP projection; |
| 1973 |
int Ras_connected; |
| 1974 |
|
| 1975 |
Ras_connected = 0; |
| 1976 |
|
| 1977 |
// first, call a LoadLibrary to load the RAS api |
| 1978 |
ras_handle = LoadLibrary("rasapi32.dll"); |
| 1979 |
if (ras_handle == NULL) { |
| 1980 |
return INADDR_ANY; |
| 1981 |
} |
| 1982 |
|
| 1983 |
pRasEnumConnections = |
| 1984 |
(DWORD(__stdcall *)(LPRASCONN, LPDWORD, LPDWORD))GetProcAddress(ras_handle, "RasEnumConnectionsA"); |
| 1985 |
if (!pRasEnumConnections) { |
| 1986 |
FreeLibrary(ras_handle); |
| 1987 |
return INADDR_ANY; |
| 1988 |
} |
| 1989 |
pRasGetConnectStatus = |
| 1990 |
(DWORD(__stdcall *)(HRASCONN, LPRASCONNSTATUS))GetProcAddress(ras_handle, "RasGetConnectStatusA"); |
| 1991 |
if (!pRasGetConnectStatus) { |
| 1992 |
FreeLibrary(ras_handle); |
| 1993 |
return INADDR_ANY; |
| 1994 |
} |
| 1995 |
pRasGetProjectionInfo = |
| 1996 |
(DWORD(__stdcall *)(HRASCONN, RASPROJECTION, LPVOID, LPDWORD))GetProcAddress(ras_handle, "RasGetProjectionInfoA"); |
| 1997 |
if (!pRasGetProjectionInfo) { |
| 1998 |
FreeLibrary(ras_handle); |
| 1999 |
return INADDR_ANY; |
| 2000 |
} |
| 2001 |
|
| 2002 |
size = sizeof(rasbuffer); |
| 2003 |
rasbuffer[0].dwSize = sizeof(RASCONN); |
| 2004 |
|
| 2005 |
rval = pRasEnumConnections(rasbuffer, &size, &num_connections); |
| 2006 |
if (rval) { |
| 2007 |
FreeLibrary(ras_handle); |
| 2008 |
return INADDR_ANY; |
| 2009 |
} |
| 2010 |
|
| 2011 |
// JAS: My computer gets to this point, but I have no RAS connections, |
| 2012 |
// so just exit |
| 2013 |
if (num_connections < 1) { |
| 2014 |
mprintf(0, "Found no RAS connections\n"); |
| 2015 |
FreeLibrary(ras_handle); |
| 2016 |
return INADDR_ANY; |
| 2017 |
} |
| 2018 |
|
| 2019 |
mprintf(0, "Found %d connections\n", num_connections); |
| 2020 |
|
| 2021 |
for (i = 0; i < num_connections; i++) { |
| 2022 |
RASCONNSTATUS status; |
| 2023 |
DWORD size; |
| 2024 |
|
| 2025 |
mprintf(0, "Connection %d:\n", i); |
| 2026 |
mprintf(0, "Entry Name: %s\n", rasbuffer[i].szEntryName); |
| 2027 |
mprintf(0, "Device Type: %s\n", rasbuffer[i].szDeviceType); |
| 2028 |
mprintf(0, "Device Name: %s\n", rasbuffer[i].szDeviceName); |
| 2029 |
|
| 2030 |
// get the connection status |
| 2031 |
status.dwSize = sizeof(RASCONNSTATUS); |
| 2032 |
rval = pRasGetConnectStatus(rasbuffer[i].hrasconn, &status); |
| 2033 |
if (rval != 0) { |
| 2034 |
FreeLibrary(ras_handle); |
| 2035 |
return INADDR_ANY; |
| 2036 |
} |
| 2037 |
|
| 2038 |
mprintf(0, "\tStatus: %s\n", (status.rasconnstate == RASCS_Connected) ? "Connected" : "Not Connected"); |
| 2039 |
|
| 2040 |
// get the projection informatiom |
| 2041 |
size = sizeof(projection); |
| 2042 |
projection.dwSize = size; |
| 2043 |
rval = pRasGetProjectionInfo(rasbuffer[i].hrasconn, RASP_PppIp, &projection, &size); |
| 2044 |
if (rval != 0) { |
| 2045 |
FreeLibrary(ras_handle); |
| 2046 |
return INADDR_ANY; |
| 2047 |
} |
| 2048 |
|
| 2049 |
mprintf(0, "\tIP Address: %s\n", projection.szIpAddress); |
| 2050 |
} |
| 2051 |
|
| 2052 |
Ras_connected = 1; |
| 2053 |
|
| 2054 |
FreeLibrary(ras_handle); |
| 2055 |
rasip = inet_addr(projection.szIpAddress); |
| 2056 |
if (rasip == INADDR_NONE) |
| 2057 |
return INADDR_ANY; |
| 2058 |
// The ip of the RAS connection |
| 2059 |
return rasip; |
| 2060 |
} |
| 2061 |
#endif |
| 2062 |
|
| 2063 |
static async_dns_lookupcxx . . $ async_dns_lookup# aslucxx . . $ aslu.; |
| 2064 |
static async_dns_lookupcxx . . $ async_dns_lookup# *lastaslucxx . . $ lastaslu. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 2065 |
|
| 2066 |
#ifdef WIN32 |
| 2067 |
#define CDECLCALL __cdecl |
| 2068 |
#else |
| 2069 |
#define CDECLCALLcxx . . $ `networking/networking.cpp:2069:9`! |
| 2070 |
#endif |
| 2071 |
|
| 2072 |
#if defined(POSIXcxx . . $ `<built-in>:478:9`!) |
| 2073 |
int CDECLCALLcxx . . $ `networking/networking.cpp:2069:9`! gethostbynameworkercxx . . $ gethostbynameworker(dedf1e9b1c614a07).(void *parm); |
| 2074 |
#include "SDL.h" |
| 2075 |
#include "SDL_thread.h" |
| 2076 |
|
| 2077 |
// rcg06192000 use SDL threads. |
| 2078 |
// #include <pthread.h> |
| 2079 |
// #include <dlfcn.h> |
| 2080 |
// typedef int (*pthread_create_fp)(pthread_t *__thread,__const pthread_attr_t *__attr,void *(*__start_routine) (void |
| 2081 |
// *),void *__arg); typedef int (*pthread_detach_fp)(pthread_t __th); typedef pthread_t (*pthread_self_fp)(void); static |
| 2082 |
// pthread_create_fp dpthread_create = NULL; static pthread_detach_fp dpthread_detach = NULL; static pthread_self_fp |
| 2083 |
// dpthread_self = NULL; |
| 2084 |
|
| 2085 |
void nw_LoadThreadLibrarycxx . . $ nw_LoadThreadLibrary(49f6e7a06ebc5aa8).(void) { |
| 2086 |
// rcg06192000 use SDL threads. |
| 2087 |
/* |
| 2088 |
if(dpthread_create) |
| 2089 |
return; |
| 2090 |
|
| 2091 |
void *lib; |
| 2092 |
|
| 2093 |
lib = dlopen("libpthread.so",RTLD_GLOBAL|RTLD_NOW); |
| 2094 |
if(!lib) |
| 2095 |
{ |
| 2096 |
Int3(); |
| 2097 |
return; |
| 2098 |
} |
| 2099 |
|
| 2100 |
dpthread_create = (pthread_create_fp)dlsym(lib,"pthread_create"); |
| 2101 |
dpthread_detach = (pthread_detach_fp)dlsym(lib,"pthread_detach"); |
| 2102 |
dpthread_self = (pthread_self_fp)dlsym(lib,"pthread_self"); |
| 2103 |
|
| 2104 |
if(!dpthread_create || !dpthread_detach || !dpthread_self) |
| 2105 |
{ |
| 2106 |
dpthread_create = NULL; //this variable I use to see if the library is loaded |
| 2107 |
Int3(); |
| 2108 |
return; |
| 2109 |
} |
| 2110 |
|
| 2111 |
// don't close the library...we need it open for future use |
| 2112 |
// and we can't close it on atexit() because linux will segfault for some stupid reason |
| 2113 |
*/ |
| 2114 |
} |
| 2115 |
#else |
| 2116 |
void CDECLCALL gethostbynameworker(void *parm); |
| 2117 |
#endif |
| 2118 |
|
| 2119 |
int nw_Asyncgethostbynamecxx . . $ nw_Asyncgethostbyname(d1564d04be42e0f9).(uint32_tcxx . . $ uint32_t# *ip, int command, char *hostname) { |
| 2120 |
|
| 2121 |
if (command == NW_AGHBN_LOOKUPcxx . . $ `lib/networking.h:482:9`!) { |
| 2122 |
if (lastaslucxx . . $ lastaslu.) { |
| 2123 |
lastaslucxx . . $ lastaslu.->abortcxx . . $ async_dns_lookup#abort. = true; |
| 2124 |
|
| 2125 |
// rcg06212000 join the thread. |
| 2126 |
#if defined(POSIXcxx . . $ `<built-in>:478:9`!) |
| 2127 |
SDL_WaitThread(lastaslucxx . . $ lastaslu.->threadIdcxx . . $ async_dns_lookup#threadId., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 2128 |
freecxx . . $ free(bd21765a0afc8e3c).(lastaslucxx . . $ lastaslu.); |
| 2129 |
#endif |
| 2130 |
} // if |
| 2131 |
|
| 2132 |
// rcg06262000 don't need all the rigamarole since we join the thread. |
| 2133 |
|
| 2134 |
#if (!defined(POSIXcxx . . $ `<built-in>:478:9`!)) |
| 2135 |
async_dns_lookup *newaslu; |
| 2136 |
newaslu = (async_dns_lookup *)mem_malloc(sizeof(async_dns_lookup)); |
| 2137 |
memset(&newaslu->ip, 0, sizeof(uint32_t)); |
| 2138 |
newaslu->host = hostname; |
| 2139 |
newaslu->done = false; |
| 2140 |
newaslu->error = false; |
| 2141 |
newaslu->abort = false; |
| 2142 |
lastaslu = newaslu; |
| 2143 |
aslu.done = false; |
| 2144 |
#else |
| 2145 |
memset(&aslucxx . . $ aslu..ipcxx . . $ async_dns_lookup#ip., 0, sizeof(uint32_tcxx . . $ uint32_t#)); |
| 2146 |
aslucxx . . $ aslu..hostcxx . . $ async_dns_lookup#host. = hostname; |
| 2147 |
aslucxx . . $ aslu..donecxx . . $ async_dns_lookup#done. = false; |
| 2148 |
aslucxx . . $ aslu..errorcxx . . $ async_dns_lookup#error. = false; |
| 2149 |
aslucxx . . $ aslu..abortcxx . . $ async_dns_lookup#abort. = false; |
| 2150 |
lastaslucxx . . $ lastaslu. = &aslucxx . . $ aslu.; |
| 2151 |
aslucxx . . $ aslu..donecxx . . $ async_dns_lookup#done. = false; |
| 2152 |
#endif |
| 2153 |
|
| 2154 |
#ifdef WIN32 |
| 2155 |
_beginthread(gethostbynameworker, 0, newaslu); |
| 2156 |
#elif defined(POSIXcxx . . $ `<built-in>:478:9`!) |
| 2157 |
// rcg06192000 use SDL threads. |
| 2158 |
/* |
| 2159 |
nw_LoadThreadLibrary(); |
| 2160 |
if(!dpthread_create) |
| 2161 |
{ |
| 2162 |
|
| 2163 |
HOSTENT *he = gethostbyname(lastaslu->host); |
| 2164 |
if(he==NULL) |
| 2165 |
{ |
| 2166 |
lastaslu->error = true; |
| 2167 |
} |
| 2168 |
else |
| 2169 |
{ |
| 2170 |
memcpy(&lastaslu->ip,he->h_addr_list[0],sizeof(uint32_t)); |
| 2171 |
lastaslu->done = true; |
| 2172 |
memcpy(&aslu,lastaslu,sizeof(async_dns_lookup)); |
| 2173 |
} |
| 2174 |
}else |
| 2175 |
*/ |
| 2176 |
|
| 2177 |
{ |
| 2178 |
// rcg06192000 SDLified. |
| 2179 |
// pthread_t thread; |
| 2180 |
// dpthread_create(&thread, NULL, gethostbynameworker,newaslu); |
| 2181 |
aslucxx . . $ aslu..threadIdcxx . . $ async_dns_lookup#threadId. = SDL_CreateThread(gethostbynameworkercxx . . $ gethostbynameworker(dedf1e9b1c614a07)., "dnsworker", &aslucxx . . $ aslu.); |
| 2182 |
} |
| 2183 |
#else |
| 2184 |
HOSTENT *he = gethostbyname(lastaslu->host); |
| 2185 |
if (he == NULL) { |
| 2186 |
lastaslu->error = true; |
| 2187 |
} else { |
| 2188 |
memcpy(&lastaslu->ip, he->h_addr_list[0], sizeof(uint32_t)); |
| 2189 |
lastaslu->done = true; |
| 2190 |
memcpy(&aslu, lastaslu, sizeof(async_dns_lookup)); |
| 2191 |
} |
| 2192 |
#endif |
| 2193 |
return 1; |
| 2194 |
} else if (command == NW_AGHBN_CANCELcxx . . $ `lib/networking.h:481:9`!) { |
| 2195 |
if (lastaslucxx . . $ lastaslu.) { |
| 2196 |
lastaslucxx . . $ lastaslu.->abortcxx . . $ async_dns_lookup#abort. = true; |
| 2197 |
|
| 2198 |
// rcg06212000 join the thread. |
| 2199 |
#if defined(POSIXcxx . . $ `<built-in>:478:9`!) |
| 2200 |
SDL_WaitThread(lastaslucxx . . $ lastaslu.->threadIdcxx . . $ async_dns_lookup#threadId., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 2201 |
#endif |
| 2202 |
} // if |
| 2203 |
lastaslucxx . . $ lastaslu. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 2204 |
} else if (command == NW_AGHBN_READcxx . . $ `lib/networking.h:483:9`!) { |
| 2205 |
if (!lastaslucxx . . $ lastaslu.) |
| 2206 |
return -1; |
| 2207 |
if (aslucxx . . $ aslu..donecxx . . $ async_dns_lookup#done.) { |
| 2208 |
// rcg06212000 join the thread. |
| 2209 |
#if defined(POSIXcxx . . $ `<built-in>:478:9`!) |
| 2210 |
SDL_WaitThread(aslucxx . . $ aslu..threadIdcxx . . $ async_dns_lookup#threadId., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 2211 |
#endif |
| 2212 |
|
| 2213 |
lastaslucxx . . $ lastaslu. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 2214 |
memcpy(ip, &aslucxx . . $ aslu..ipcxx . . $ async_dns_lookup#ip., sizeof(uint32_tcxx . . $ uint32_t#)); |
| 2215 |
return 1; |
| 2216 |
} else if (aslucxx . . $ aslu..errorcxx . . $ async_dns_lookup#error.) { |
| 2217 |
// rcg06212000 join the thread. |
| 2218 |
#if defined(POSIXcxx . . $ `<built-in>:478:9`!) |
| 2219 |
SDL_WaitThread(aslucxx . . $ aslu..threadIdcxx . . $ async_dns_lookup#threadId., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!); |
| 2220 |
#else |
| 2221 |
mem_free(lastaslu); |
| 2222 |
#endif |
| 2223 |
|
| 2224 |
lastaslucxx . . $ lastaslu. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 2225 |
return -1; |
| 2226 |
} else |
| 2227 |
return 0; |
| 2228 |
} |
| 2229 |
return -2; |
| 2230 |
} |
| 2231 |
|
| 2232 |
// This is the worker thread which does the lookup. |
| 2233 |
#if defined(POSIXcxx . . $ `<built-in>:478:9`!) |
| 2234 |
int CDECLCALLcxx . . $ `networking/networking.cpp:2069:9`! gethostbynameworkercxx . . $ gethostbynameworker(dedf1e9b1c614a07).(void *parm) |
| 2235 |
#else |
| 2236 |
void CDECLCALL gethostbynameworker(void *parm) |
| 2237 |
#endif |
| 2238 |
{ |
| 2239 |
// rcg06192000 nope. |
| 2240 |
// #if defined(POSIX) |
| 2241 |
// dpthread_detach(dpthread_self()); |
| 2242 |
// #endif |
| 2243 |
|
| 2244 |
async_dns_lookupcxx . . $ async_dns_lookup# *lookup = (async_dns_lookupcxx . . $ async_dns_lookup# *)parm; |
| 2245 |
|
| 2246 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "IPLOOKUP: Starting threaded lookup ..."); |
| 2247 |
HOSTENTcxx . . $ `lib/networking.h:232:9`! *he = gethostbyname(lookup->hostcxx . . $ async_dns_lookup#host.); |
| 2248 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "IPLOOKUP: Threaded lookup complete."); |
| 2249 |
|
| 2250 |
if (he == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 2251 |
lookup->errorcxx . . $ async_dns_lookup#error. = true; |
| 2252 |
#if defined(POSIXcxx . . $ `<built-in>:478:9`!) |
| 2253 |
return 0; |
| 2254 |
#else |
| 2255 |
return; |
| 2256 |
#endif |
| 2257 |
} else if (!lookup->abortcxx . . $ async_dns_lookup#abort.) { |
| 2258 |
memcpy(&lookup->ipcxx . . $ async_dns_lookup#ip., he->h_addr_list[0], sizeof(uint32_tcxx . . $ uint32_t#)); |
| 2259 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "IPLOOKUP: [%s] is %d.%d.%d.%d ...", |
| 2260 |
lookup->host, |
| 2261 |
(lookup->ip & 0x000000FF), |
| 2262 |
(lookup->ip & 0x0000FF00) >> 8, |
| 2263 |
(lookup->ip & 0x00FF0000) >> 16, |
| 2264 |
(lookup->ip & 0xFF000000) >> 24); |
| 2265 |
// memcpy(&aslu,lookup,sizeof(async_dns_lookup)); |
| 2266 |
lookup->donecxx . . $ async_dns_lookup#done. = true; |
| 2267 |
} |
| 2268 |
|
| 2269 |
// rcg06252000 don't free this, 'cause we need the threadId. |
| 2270 |
#if !defined(POSIXcxx . . $ `<built-in>:478:9`!) |
| 2271 |
mem_free(lookup); |
| 2272 |
#endif |
| 2273 |
|
| 2274 |
#if defined(POSIXcxx . . $ `<built-in>:478:9`!) |
| 2275 |
return 0; |
| 2276 |
#endif |
| 2277 |
} |
| 2278 |
|
| 2279 |
int nw_ReccomendPPScxx . . $ nw_ReccomendPPS(b126dc7c1de90089).() { |
| 2280 |
static char szconnspeed[100]; |
| 2281 |
int len = 99; |
| 2282 |
strcpy(szconnspeed, ""); |
| 2283 |
Databasecxx . . $ Database.->readcxx . . $ oeAppDatabase#read(3bcbb53201fcdcb8).("ConnectionSpeed", szconnspeed, &len); |
| 2284 |
if (stricmpcxx . . $ `linux/linux_fix.h:43:9`!(szconnspeed, "28K") == 0) |
| 2285 |
return 5; |
| 2286 |
else if (stricmpcxx . . $ `linux/linux_fix.h:43:9`!(szconnspeed, "33K") == 0) |
| 2287 |
return 6; |
| 2288 |
else if (stricmpcxx . . $ `linux/linux_fix.h:43:9`!(szconnspeed, "56K") == 0) |
| 2289 |
return 7; |
| 2290 |
else if (stricmpcxx . . $ `linux/linux_fix.h:43:9`!(szconnspeed, "ISDN") == 0) |
| 2291 |
return 8; |
| 2292 |
else if (stricmpcxx . . $ `linux/linux_fix.h:43:9`!(szconnspeed, "Cable") == 0) |
| 2293 |
return 9; |
| 2294 |
else if (stricmpcxx . . $ `linux/linux_fix.h:43:9`!(szconnspeed, "Fast") == 0) |
| 2295 |
return 12; |
| 2296 |
else |
| 2297 |
return 7; |
| 2298 |
} |
| 2299 |
|
| 2300 |
// Register the networking library to call your function back |
| 2301 |
// When data containing your ID is found |
| 2302 |
// Returns non-zero if succesfull, Zero if this ID is already registered |
| 2303 |
int nw_RegisterCallbackcxx . . $ nw_RegisterCallback(d121e3b72e81a360).(NetworkReceiveCallbackcxx . . $ NetworkReceiveCallback# nfp, uint8_tcxx . . $ uint8_t# id) { |
| 2304 |
ASSERTcxx . . $ `misc/pserror.h:246:9`!(id < 16); |
| 2305 |
|
| 2306 |
// rcg06212000 this happens all the time; let it slide. |
| 2307 |
// if(Netcallbacks[id]) |
| 2308 |
//{ |
| 2309 |
// mprintf(0,"Trying to reregister a callback!\n"); |
| 2310 |
// Int3(); // Get Kevin! |
| 2311 |
//} |
| 2312 |
|
| 2313 |
Netcallbackscxx . . $ Netcallbacks.[id] = nfp; |
| 2314 |
return 0; |
| 2315 |
} |
| 2316 |
|
| 2317 |
NetworkReceiveCallbackcxx . . $ NetworkReceiveCallback# nw_UnRegisterCallbackcxx . . $ nw_UnRegisterCallback(bb45880c2285615c).(uint8_tcxx . . $ uint8_t# id) { |
| 2318 |
NetworkReceiveCallbackcxx . . $ NetworkReceiveCallback# nfp; |
| 2319 |
ASSERTcxx . . $ `misc/pserror.h:246:9`!(id < 16); |
| 2320 |
nfp = Netcallbackscxx . . $ Netcallbacks.[id]; |
| 2321 |
Netcallbackscxx . . $ Netcallbacks.[id] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 2322 |
return nfp; |
| 2323 |
} |
| 2324 |
|
| 2325 |
int nw_SendWithIDcxx . . $ nw_SendWithID(4aa96ed29f5182c6).(uint8_tcxx . . $ uint8_t# id, uint8_tcxx . . $ uint8_t# *data, int len, network_addresscxx . . $ network_address# *who_to) { |
| 2326 |
uint8_tcxx . . $ uint8_t# packet_data[1500]; |
| 2327 |
int send_this_packet = 1; |
| 2328 |
SOCKETcxx . . $ `lib/networking.h:217:9`! send_sock; |
| 2329 |
SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! sock_addr; // UDP/TCP socket structure |
| 2330 |
|
| 2331 |
int ret, send_len; |
| 2332 |
uint8_tcxx . . $ uint8_t# iaddr[6], *send_data; |
| 2333 |
int16_t port; |
| 2334 |
fd_set wfds; |
| 2335 |
|
| 2336 |
ASSERTcxx . . $ `misc/pserror.h:246:9`!(data); |
| 2337 |
ASSERTcxx . . $ `misc/pserror.h:246:9`!(len); |
| 2338 |
ASSERTcxx . . $ `misc/pserror.h:246:9`!(who_to); |
| 2339 |
|
| 2340 |
timeval timeout = {0, 0}; |
| 2341 |
|
| 2342 |
packet_data[0] = id; |
| 2343 |
memcpy(packet_data + 1, data, len); |
| 2344 |
len++; // Account for the added byte |
| 2345 |
|
| 2346 |
// if (NetDebugFile) |
| 2347 |
// cfprintf (NetDebugFile,"nw_SendWithID packet of id=%d type %d at %f |
| 2348 |
// seconds.\n",id,data[0],timer_GetTime()); |
| 2349 |
|
| 2350 |
// mprintf(0,"Sending packet for id %d.\n",id); |
| 2351 |
#ifdef WIN32 |
| 2352 |
if (Use_DirectPlay) |
| 2353 |
return dp_DirectPlaySend(who_to, (uint8_t *)data, len, false); |
| 2354 |
#endif |
| 2355 |
|
| 2356 |
// mprintf(1, "network: type %d\n", who_to->connection_type); |
| 2357 |
// send_sock = *Unreliable_socket; |
| 2358 |
switch (who_to->connection_typecxx . . $ network_address#connection_type.) { |
| 2359 |
case NP_TCPcxx . . $ NP_TCP.: |
| 2360 |
if (id == NWT_RELIABLEcxx . . $ `lib/networking.h:318:9`!) { |
| 2361 |
NetStatisticscxx . . $ NetStatistics..tcp_total_packets_sentcxx . . $ tNetworkStatus#tcp_total_packets_sent.++; |
| 2362 |
NetStatisticscxx . . $ NetStatistics..tcp_total_bytes_sentcxx . . $ tNetworkStatus#tcp_total_bytes_sent. += len; |
| 2363 |
} else if (id == NWT_UNRELIABLEcxx . . $ `lib/networking.h:317:9`!) { |
| 2364 |
NetStatisticscxx . . $ NetStatistics..udp_total_packets_sentcxx . . $ tNetworkStatus#udp_total_packets_sent.++; |
| 2365 |
NetStatisticscxx . . $ NetStatistics..udp_total_bytes_sentcxx . . $ tNetworkStatus#udp_total_bytes_sent. += len; |
| 2366 |
} |
| 2367 |
|
| 2368 |
send_sock = TCP_socketcxx . . $ TCP_socket.; |
| 2369 |
if (!TCP_activecxx . . $ TCP_active.) |
| 2370 |
return 0; |
| 2371 |
break; |
| 2372 |
default: |
| 2373 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(2, "Unknown protocol type in nw_Send()\n"); |
| 2374 |
Int3cxx . . $ `misc/pserror.h:247:9`!(); |
| 2375 |
return 0; |
| 2376 |
} |
| 2377 |
|
| 2378 |
/* |
| 2379 |
uint8_t compdata[MAX_PACKET_SIZE*3]; |
| 2380 |
uint8_t testdata[MAX_PACKET_SIZE*3]; |
| 2381 |
int uncompsize; |
| 2382 |
|
| 2383 |
////Int3(); |
| 2384 |
Uncompressed_outgoing_data_len += len; |
| 2385 |
int compsize = nw_Compress(data,compdata,len); |
| 2386 |
Compressed_outgoing_data_len += compsize; |
| 2387 |
uncompsize = nw_Uncompress(compdata,testdata,compsize); |
| 2388 |
|
| 2389 |
ASSERT(uncompsize==len); |
| 2390 |
ASSERT(memcmp(data,testdata,uncompsize)==0); |
| 2391 |
|
| 2392 |
int my_comp_ratio = (float) ((float)Uncompressed_outgoing_data_len/(float)Compressed_outgoing_data_len); |
| 2393 |
|
| 2394 |
mprintf_at(2,1,0,"Compression: %d%% ",my_comp_ratio); |
| 2395 |
*/ |
| 2396 |
if (!Sockets_inittedcxx . . $ Sockets_initted.) { |
| 2397 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Network ==> Socket not inited in nw_Send\n"); |
| 2398 |
return 0; |
| 2399 |
} |
| 2400 |
|
| 2401 |
memset(iaddr, 0x00, 6); |
| 2402 |
memcpy(iaddr, who_to->addresscxx . . $ network_address#address., 6); |
| 2403 |
|
| 2404 |
port = who_to->portcxx . . $ network_address#port.; |
| 2405 |
|
| 2406 |
if (port == 0) { |
| 2407 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Network ==> destination port %d invalid in psnet_send\n", port); |
| 2408 |
Int3cxx . . $ `misc/pserror.h:247:9`!(); |
| 2409 |
return 0; |
| 2410 |
} |
| 2411 |
|
| 2412 |
send_len = len; |
| 2413 |
send_data = (uint8_tcxx . . $ uint8_t# *)packet_data; |
| 2414 |
|
| 2415 |
FD_ZEROcxx . . $ `<external>/946878812840035423/select.h:88:9`!(&wfds); |
| 2416 |
FD_SETcxx . . $ `<external>/946878812840035423/select.h:85:9`!(send_sock, &wfds); |
| 2417 |
|
| 2418 |
int sock_writable = select(send_sock + 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, &wfds, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, &timeout); |
| 2419 |
if (sock_writable == SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`!) { |
| 2420 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Error on blocking select for write %d\n", WSAGetLastError()); |
| 2421 |
return 0; |
| 2422 |
} |
| 2423 |
|
| 2424 |
if (!sock_writable) { |
| 2425 |
// This packet gets dropped. |
| 2426 |
return 0; |
| 2427 |
} |
| 2428 |
|
| 2429 |
if (send_this_packet) { |
| 2430 |
switch (who_to->connection_typecxx . . $ network_address#connection_type.) { |
| 2431 |
case NP_TCPcxx . . $ NP_TCP.: |
| 2432 |
sock_addr.sin_family = AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!; |
| 2433 |
memcpy(&sock_addr.sin_addr.s_addr, iaddr, 4); |
| 2434 |
sock_addr.sin_port = htons(port); |
| 2435 |
|
| 2436 |
ret = sendto(TCP_socketcxx . . $ TCP_socket., (char *)send_data, send_len, 0, (SOCKADDRcxx . . $ `lib/networking.h:220:9`! *)&sock_addr, sizeof(sock_addr)); |
| 2437 |
break; |
| 2438 |
|
| 2439 |
default: |
| 2440 |
Int3cxx . . $ `misc/pserror.h:247:9`!(); // Unknown protocol |
| 2441 |
break; |
| 2442 |
|
| 2443 |
} // end switch |
| 2444 |
} |
| 2445 |
int lasterr; |
| 2446 |
if (ret != SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`!) { |
| 2447 |
return 1; |
| 2448 |
} |
| 2449 |
lasterr = WSAGetLastErrorcxx . . $ `lib/networking.h:241:9`!(); |
| 2450 |
if (lasterr == WSAEWOULDBLOCKcxx . . $ `lib/networking.h:236:9`!) { |
| 2451 |
return 0; |
| 2452 |
} |
| 2453 |
|
| 2454 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Couldn't send data (%d)!\n", lasterr); |
| 2455 |
return 0; |
| 2456 |
} |
| 2457 |
|
| 2458 |
int nw_DoReceiveCallbackscxx . . $ nw_DoReceiveCallbacks(b126dc7c1de90089).(void) { |
| 2459 |
SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! ip_addr; // UDP/TCP socket structure |
| 2460 |
socklen_t read_len, from_len; |
| 2461 |
network_addresscxx . . $ network_address# from_addr; |
| 2462 |
|
| 2463 |
uint8_tcxx . . $ uint8_t# packet_data[1500]; |
| 2464 |
|
| 2465 |
nw_ReliableResendcxx . . $ nw_ReliableResend(49f6e7a06ebc5aa8).(); |
| 2466 |
|
| 2467 |
while (TCP_activecxx . . $ TCP_active.) { |
| 2468 |
// check if there is any data on the socket to be read. The amount of data that can be |
| 2469 |
// atomically read is stored in len. |
| 2470 |
|
| 2471 |
#if 0 |
| 2472 |
fd_set rfds; |
| 2473 |
FD_ZERO(&rfds); |
| 2474 |
FD_SET( TCP_socket, &rfds ); |
| 2475 |
timeout.tv_sec = 0; |
| 2476 |
timeout.tv_usec = 0; |
| 2477 |
|
| 2478 |
timeval timeout; |
| 2479 |
if ( select( TCP_socket+1, &rfds, NULL, NULL, &timeout) == SOCKET_ERROR) |
| 2480 |
{ |
| 2481 |
mprintf(0, "Error %d doing a socket select on IP read\n", WSAGetLastError()); |
| 2482 |
break; |
| 2483 |
} |
| 2484 |
|
| 2485 |
// if the read file descriptor is not set, then bail! |
| 2486 |
if ( !FD_ISSET(TCP_socket, &rfds ) ) |
| 2487 |
break; |
| 2488 |
#endif |
| 2489 |
// get data off the socket and process |
| 2490 |
from_len = sizeof(SOCKADDR_INcxx . . $ `lib/networking.h:219:9`!); |
| 2491 |
read_len = recvfrom(TCP_socketcxx . . $ TCP_socket., (char *)packet_data, 1500, 0, (SOCKADDRcxx . . $ `lib/networking.h:220:9`! *)&ip_addr, &from_len); |
| 2492 |
|
| 2493 |
if (read_len == SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`!) { |
| 2494 |
int x = WSAGetLastErrorcxx . . $ `lib/networking.h:241:9`!(); |
| 2495 |
if (x != WSAEWOULDBLOCKcxx . . $ `lib/networking.h:236:9`!) { |
| 2496 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Read error on IP socket. Winsock error %d \n", x); |
| 2497 |
} |
| 2498 |
break; |
| 2499 |
} |
| 2500 |
memset(&from_addr, 0x00, sizeof(network_addresscxx . . $ network_address#)); |
| 2501 |
from_addr.connection_typecxx . . $ network_address#connection_type. = NP_TCPcxx . . $ NP_TCP.; |
| 2502 |
from_addr.portcxx . . $ network_address#port. = ntohs(ip_addr.sin_port); |
| 2503 |
|
| 2504 |
#ifdef WIN32 |
| 2505 |
memcpy(from_addr.address, &ip_addr.sin_addr.S_un.S_addr, 4); |
| 2506 |
#else |
| 2507 |
memcpy(from_addr.addresscxx . . $ network_address#address., &ip_addr.sin_addr.s_addr, 4); |
| 2508 |
#endif |
| 2509 |
uint8_tcxx . . $ uint8_t# packet_id = (packet_data[0] & 0x0f); |
| 2510 |
if (Netcallbackscxx . . $ Netcallbacks.[packet_id]) { |
| 2511 |
// mprintf(0,"Calling network callback for id %d.\n",packet_id); |
| 2512 |
int rlen = read_len - 1; |
| 2513 |
if (packet_id == NWT_UNRELIABLEcxx . . $ `lib/networking.h:317:9`!) { |
| 2514 |
NetStatisticscxx . . $ NetStatistics..udp_total_packets_reccxx . . $ tNetworkStatus#udp_total_packets_rec.++; |
| 2515 |
NetStatisticscxx . . $ NetStatistics..udp_total_bytes_reccxx . . $ tNetworkStatus#udp_total_bytes_rec. += rlen; |
| 2516 |
} else if (packet_id == NWT_RELIABLEcxx . . $ `lib/networking.h:318:9`!) { |
| 2517 |
NetStatisticscxx . . $ NetStatistics..tcp_total_packets_reccxx . . $ tNetworkStatus#tcp_total_packets_rec.++; |
| 2518 |
NetStatisticscxx . . $ NetStatistics..tcp_total_bytes_reccxx . . $ tNetworkStatus#tcp_total_bytes_rec. += rlen; |
| 2519 |
} |
| 2520 |
|
| 2521 |
Netcallbackscxx . . $ Netcallbacks.[packet_id](packet_data + 1, rlen, &from_addr); |
| 2522 |
} |
| 2523 |
} |
| 2524 |
|
| 2525 |
return 0; |
| 2526 |
} |
| 2527 |
|
| 2528 |
// MTS: only used in this file? |
| 2529 |
// Resend any unack'd packets and send any buffered packets, heartbeats, etc. |
| 2530 |
void nw_ReliableResendcxx . . $ nw_ReliableResend(49f6e7a06ebc5aa8).(void) { |
| 2531 |
int i, j; |
| 2532 |
int rcode = -1; |
| 2533 |
int16_t max_len = NETBUFFERSIZEcxx . . $ `lib/networking.h:457:9`!; |
| 2534 |
static reliable_headercxx . . $ reliable_header# rcv_buff; |
| 2535 |
static SOCKADDRcxx . . $ `lib/networking.h:220:9`! rcv_addr; |
| 2536 |
int bytesin = 0; |
| 2537 |
int addrlen = sizeof(SOCKADDRcxx . . $ `lib/networking.h:220:9`!); |
| 2538 |
reliable_socketcxx . . $ reliable_socket# *rsocket = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 2539 |
// Go through each reliable socket that is connected and do any needed work. |
| 2540 |
for (j = 0; j < MAXRELIABLESOCKETScxx . . $ `lib/networking.h:456:9`!; j++) { |
| 2541 |
rsocket = &reliable_socketscxx . . $ reliable_sockets.[j]; |
| 2542 |
|
| 2543 |
if (serverconncxx . . $ serverconn. == -1) { |
| 2544 |
if (rsocket->statuscxx . . $ reliable_socket#status. == RNF_LIMBOcxx . . $ `lib/networking.h:474:9`!) |
| 2545 |
if ((timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - rsocket->last_packet_receivedcxx . . $ reliable_socket#last_packet_received.) > NETTIMEOUTcxx . . $ `lib/networking.h:454:9`!) { |
| 2546 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Reliable (but in limbo) socket (%d) timed out in nw_WorkReliable().\n", j); |
| 2547 |
memset(rsocket, 0, sizeof(reliable_socketcxx . . $ reliable_socket#)); |
| 2548 |
rsocket->statuscxx . . $ reliable_socket#status. = RNF_UNUSEDcxx . . $ `lib/networking.h:469:9`!; // Won't work if this is an outgoing connection. |
| 2549 |
} |
| 2550 |
} else { |
| 2551 |
if ((rsocket->statuscxx . . $ reliable_socket#status. == RNF_LIMBOcxx . . $ `lib/networking.h:474:9`!) && ((timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - first_sent_iamherecxx . . $ first_sent_iamhere.) > NETTIMEOUTcxx . . $ `lib/networking.h:454:9`!)) { |
| 2552 |
rsocket->statuscxx . . $ reliable_socket#status. = RNF_BROKENcxx . . $ `lib/networking.h:471:9`!; |
| 2553 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Reliable socket (%d) timed out in nw_WorkReliable().\n", j); |
| 2554 |
} |
| 2555 |
} |
| 2556 |
|
| 2557 |
if (rsocket->statuscxx . . $ reliable_socket#status. == RNF_CONNECTEDcxx . . $ `lib/networking.h:470:9`!) { |
| 2558 |
float retry_packet_time; |
| 2559 |
if ((rsocket->mean_pingcxx . . $ reliable_socket#mean_ping. == 0) || (rsocket->mean_pingcxx . . $ reliable_socket#mean_ping. > (NETRETRYTIMEcxx . . $ `lib/networking.h:452:9`! * 4))) { |
| 2560 |
retry_packet_time = NETRETRYTIMEcxx . . $ `lib/networking.h:452:9`!; |
| 2561 |
} else { |
| 2562 |
if (rsocket->mean_pingcxx . . $ reliable_socket#mean_ping. < MIN_NET_RETRYTIMEcxx . . $ `lib/networking.h:453:9`!) { |
| 2563 |
retry_packet_time = (float)MIN_NET_RETRYTIMEcxx . . $ `lib/networking.h:453:9`!; |
| 2564 |
// mprintf(0,"Using retransmission time of %f\n",retry_packet_time); |
| 2565 |
} else { |
| 2566 |
retry_packet_time = ((float)(float)rsocket->mean_pingcxx . . $ reliable_socket#mean_ping. * (float)1.25); |
| 2567 |
// mprintf(0,"Using retransmission time of %f\n",retry_packet_time); |
| 2568 |
} |
| 2569 |
} |
| 2570 |
// Iterate through send buffers. |
| 2571 |
for (i = 0; i < MAXNETBUFFERScxx . . $ `lib/networking.h:449:9`!; i++) { |
| 2572 |
if (((i == rsocket->waiting_packet_numbercxx . . $ reliable_socket#waiting_packet_number.) && |
| 2573 |
((((timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - rsocket->last_sentcxx . . $ reliable_socket#last_sent.) > R_NET_PACKET_QUEUE_TIMEcxx . . $ `networking/networking.cpp:436:9`!)) || |
| 2574 |
((rsocket->mean_pingcxx . . $ reliable_socket#mean_ping. > 0) && (rsocket->mean_pingcxx . . $ reliable_socket#mean_ping. < R_NET_PACKET_QUEUE_TIMEcxx . . $ `networking/networking.cpp:436:9`!)) || rsocket->send_urgentcxx . . $ reliable_socket#send_urgent.)) || |
| 2575 |
((rsocket->sbufferscxx . . $ reliable_socket#sbuffers.[i]) && ((timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - rsocket->timesentcxx . . $ reliable_socket#timesent.[i]) >= retry_packet_time))) // Send again |
| 2576 |
{ |
| 2577 |
|
| 2578 |
if (i == rsocket->waiting_packet_numbercxx . . $ reliable_socket#waiting_packet_number.) { |
| 2579 |
rsocket->waiting_packet_numbercxx . . $ reliable_socket#waiting_packet_number. = -1; |
| 2580 |
rsocket->last_sentcxx . . $ reliable_socket#last_sent. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 2581 |
// mprintf(0,"Sending delayed packet...\n"); |
| 2582 |
} |
| 2583 |
reliable_headercxx . . $ reliable_header# send_header; |
| 2584 |
// mprintf(0,"Resending reliable packet in nw_WorkReliable().\n"); |
| 2585 |
send_header.send_timecxx . . $ reliable_header#send_time. = INTEL_FLOATcxx . . $ `lib/byteswap.h:109:9`!(timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!()); |
| 2586 |
send_header.seqcxx . . $ reliable_header#seq. = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(rsocket->ssequence[i]); |
| 2587 |
memcpy(send_header.datacxx . . $ reliable_header#data., rsocket->sbufferscxx . . $ reliable_socket#sbuffers.[i]->buffercxx . . $ reliable_net_sendbuffer#buffer., rsocket->send_lencxx . . $ reliable_socket#send_len.[i]); |
| 2588 |
send_header.data_lencxx . . $ reliable_header#data_len. = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!(rsocket->send_len[i]); |
| 2589 |
send_header.typecxx . . $ reliable_header#type. = RNT_DATAcxx . . $ `lib/networking.h:461:9`!; |
| 2590 |
|
| 2591 |
network_addresscxx . . $ network_address# send_address; |
| 2592 |
memset(&send_address, 0, sizeof(network_addresscxx . . $ network_address#)); |
| 2593 |
|
| 2594 |
send_address.connection_typecxx . . $ network_address#connection_type. = rsocket->connection_typecxx . . $ reliable_socket#connection_type.; |
| 2595 |
|
| 2596 |
if (NP_TCPcxx . . $ NP_TCP. == send_address.connection_typecxx . . $ network_address#connection_type.) { |
| 2597 |
SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *inaddr = (SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *)&rsocket->addrcxx . . $ reliable_socket#addr.; |
| 2598 |
memcpy(send_address.addresscxx . . $ network_address#address., &inaddr->sin_addr, 4); |
| 2599 |
send_address.portcxx . . $ network_address#port. = htons(inaddr->sin_port); |
| 2600 |
send_address.connection_typecxx . . $ network_address#connection_type. = NP_TCPcxx . . $ NP_TCP.; |
| 2601 |
|
| 2602 |
int len = RELIABLE_PACKET_HEADER_ONLY_SIZEcxx . . $ `networking/networking.cpp:466:9`! + rsocket->send_lencxx . . $ reliable_socket#send_len.[i]; |
| 2603 |
NetStatisticscxx . . $ NetStatistics..tcp_total_packets_sentcxx . . $ tNetworkStatus#tcp_total_packets_sent.--; // decrement because we are going to inc |
| 2604 |
// in nw_SendWithID |
| 2605 |
NetStatisticscxx . . $ NetStatistics..tcp_total_bytes_sentcxx . . $ tNetworkStatus#tcp_total_bytes_sent. -= len; // see above |
| 2606 |
NetStatisticscxx . . $ NetStatistics..tcp_total_packets_resentcxx . . $ tNetworkStatus#tcp_total_packets_resent.++; |
| 2607 |
NetStatisticscxx . . $ NetStatistics..tcp_total_bytes_resentcxx . . $ tNetworkStatus#tcp_total_bytes_resent. += len; |
| 2608 |
} |
| 2609 |
|
| 2610 |
// mprintf(0,"Resending reliable packet! Sequence %d\n",send_header.seq); |
| 2611 |
rcode = nw_SendWithIDcxx . . $ nw_SendWithID(4aa96ed29f5182c6).(NWT_RELIABLEcxx . . $ `lib/networking.h:318:9`!, (uint8_tcxx . . $ uint8_t# *)&send_header, |
| 2612 |
RELIABLE_PACKET_HEADER_ONLY_SIZEcxx . . $ `networking/networking.cpp:466:9`! + rsocket->send_lencxx . . $ reliable_socket#send_len.[i], &send_address); |
| 2613 |
|
| 2614 |
if ((rcode == SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`!) && (WSAEWOULDBLOCKcxx . . $ `lib/networking.h:236:9`! == WSAGetLastErrorcxx . . $ `lib/networking.h:241:9`!())) { |
| 2615 |
// The packet didn't get sent, flag it to try again next frame |
| 2616 |
rsocket->timesentcxx . . $ reliable_socket#timesent.[i] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - (NETRETRYTIMEcxx . . $ `lib/networking.h:452:9`! * 4); |
| 2617 |
} else { |
| 2618 |
rsocket->last_packet_sentcxx . . $ reliable_socket#last_packet_sent. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 2619 |
rsocket->timesentcxx . . $ reliable_socket#timesent.[i] = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 2620 |
} |
| 2621 |
} |
| 2622 |
} |
| 2623 |
// We've sent all the packets, now we go out of urgent mode. |
| 2624 |
rsocket->send_urgentcxx . . $ reliable_socket#send_urgent. = 0; |
| 2625 |
if ((rsocket->statuscxx . . $ reliable_socket#status. == RNF_CONNECTEDcxx . . $ `lib/networking.h:470:9`!) && ((timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - rsocket->last_packet_sentcxx . . $ reliable_socket#last_packet_sent.) > NETHEARTBEATTIMEcxx . . $ `lib/networking.h:455:9`!)) { |
| 2626 |
reliable_headercxx . . $ reliable_header# send_header; |
| 2627 |
// mprintf(0,"Resending reliable packet in nw_WorkReliable().\n"); |
| 2628 |
send_header.send_timecxx . . $ reliable_header#send_time. = INTEL_FLOATcxx . . $ `lib/byteswap.h:109:9`!(timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!()); |
| 2629 |
send_header.seqcxx . . $ reliable_header#seq. = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!((int16_t)0); |
| 2630 |
send_header.data_lencxx . . $ reliable_header#data_len. = INTEL_SHORTcxx . . $ `lib/byteswap.h:108:9`!((int16_t)0); |
| 2631 |
send_header.typecxx . . $ reliable_header#type. = RNT_HEARTBEATcxx . . $ `lib/networking.h:465:9`!; |
| 2632 |
|
| 2633 |
rcode = -1; |
| 2634 |
network_addresscxx . . $ network_address# send_address; |
| 2635 |
memset(&send_address, 0, sizeof(network_addresscxx . . $ network_address#)); |
| 2636 |
|
| 2637 |
send_address.connection_typecxx . . $ network_address#connection_type. = rsocket->connection_typecxx . . $ reliable_socket#connection_type.; |
| 2638 |
|
| 2639 |
if (NP_TCPcxx . . $ NP_TCP. == send_address.connection_typecxx . . $ network_address#connection_type.) { |
| 2640 |
SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *inaddr = (SOCKADDR_INcxx . . $ `lib/networking.h:219:9`! *)&rsocket->addrcxx . . $ reliable_socket#addr.; |
| 2641 |
memcpy(send_address.addresscxx . . $ network_address#address., &inaddr->sin_addr, 4); |
| 2642 |
send_address.portcxx . . $ network_address#port. = htons(inaddr->sin_port); |
| 2643 |
send_address.connection_typecxx . . $ network_address#connection_type. = NP_TCPcxx . . $ NP_TCP.; |
| 2644 |
|
| 2645 |
int len = RELIABLE_PACKET_HEADER_ONLY_SIZEcxx . . $ `networking/networking.cpp:466:9`! + rsocket->send_lencxx . . $ reliable_socket#send_len.[i]; |
| 2646 |
NetStatisticscxx . . $ NetStatistics..tcp_total_packets_sentcxx . . $ tNetworkStatus#tcp_total_packets_sent.--; // decrement because we are going to inc |
| 2647 |
// in nw_SendWithID |
| 2648 |
NetStatisticscxx . . $ NetStatistics..tcp_total_bytes_sentcxx . . $ tNetworkStatus#tcp_total_bytes_sent. -= len; // see above |
| 2649 |
NetStatisticscxx . . $ NetStatistics..tcp_total_packets_resentcxx . . $ tNetworkStatus#tcp_total_packets_resent.++; |
| 2650 |
NetStatisticscxx . . $ NetStatistics..tcp_total_bytes_resentcxx . . $ tNetworkStatus#tcp_total_bytes_resent. += len; |
| 2651 |
} |
| 2652 |
|
| 2653 |
rcode = nw_SendWithIDcxx . . $ nw_SendWithID(4aa96ed29f5182c6).(NWT_RELIABLEcxx . . $ `lib/networking.h:318:9`!, (uint8_tcxx . . $ uint8_t# *)&send_header, RELIABLE_PACKET_HEADER_ONLY_SIZEcxx . . $ `networking/networking.cpp:466:9`!, &send_address); |
| 2654 |
|
| 2655 |
if ((rcode != SOCKET_ERRORcxx . . $ `lib/networking.h:233:9`!) && (WSAEWOULDBLOCKcxx . . $ `lib/networking.h:236:9`! != WSAGetLastErrorcxx . . $ `lib/networking.h:241:9`!())) { |
| 2656 |
// It must have been sent |
| 2657 |
rsocket->last_packet_sentcxx . . $ reliable_socket#last_packet_sent. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 2658 |
} |
| 2659 |
} |
| 2660 |
|
| 2661 |
if ((rsocket->statuscxx . . $ reliable_socket#status. == RNF_CONNECTEDcxx . . $ `lib/networking.h:470:9`!) && ((timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!() - rsocket->last_packet_receivedcxx . . $ reliable_socket#last_packet_received.) > NETTIMEOUTcxx . . $ `lib/networking.h:454:9`!)) { |
| 2662 |
// This socket is hosed.....inform someone? |
| 2663 |
mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Reliable Socket (%d) timed out in nw_WorkReliable().\n", j); |
| 2664 |
rsocket->statuscxx . . $ reliable_socket#status. = RNF_BROKENcxx . . $ `lib/networking.h:471:9`!; |
| 2665 |
} |
| 2666 |
} |
| 2667 |
} |
| 2668 |
} |
| 2669 |
|
| 2670 |
// fills in the buffer with network stats |
| 2671 |
// pass NULL to reset the stats |
| 2672 |
void nw_GetNetworkStatscxx . . $ nw_GetNetworkStats(3e736517eddecfba).(tNetworkStatuscxx . . $ tNetworkStatus# *stats) { |
| 2673 |
if (!stats) { |
| 2674 |
// reset the stats |
| 2675 |
memset(&NetStatisticscxx . . $ NetStatistics., 0, sizeof(NetStatisticscxx . . $ NetStatistics.)); |
| 2676 |
return; |
| 2677 |
} |
| 2678 |
|
| 2679 |
memcpy(stats, &NetStatisticscxx . . $ NetStatistics., sizeof(NetStatisticscxx . . $ NetStatistics.)); |
| 2680 |
} |