@@ -163,14 +163,14 @@ int consoleplayer = 0;
163
163
int Net_Arbitrator = 0 ;
164
164
FClientStack NetworkClients = {};
165
165
166
- uint64_t GameID = 0u ;
167
166
uint8_t TicDup = 1u ;
168
167
int MaxClients = 1 ;
169
168
int RemoteClient = -1 ;
170
169
size_t NetBufferLength = 0u ;
171
170
uint8_t NetBuffer[MAX_MSGLEN] = {};
172
171
173
172
static FRandom GameIDGen = {};
173
+ static uint8_t GameID[8 ] = {};
174
174
static u_short GamePort = (IPPORT_USERRESERVED + 29 );
175
175
static SOCKET MySocket = INVALID_SOCKET;
176
176
static FConnection Connected[MAXPLAYERS] = {};
@@ -348,6 +348,12 @@ static bool ClientsOnSameNetwork()
348
348
return true ;
349
349
}
350
350
351
+ static void GenerateGameID ()
352
+ {
353
+ const uint64_t val = GameIDGen.GenRand64 ();
354
+ memcpy (GameID, &val, sizeof (val));
355
+ }
356
+
351
357
// Print a network-related message to the console. This doesn't print to the window so should
352
358
// not be used for that and is mainly for logging.
353
359
static void I_NetLog (const char * text, ...)
@@ -506,7 +512,7 @@ static void SendPacket(const sockaddr_in& to)
506
512
I_Error (" Failed to compress data down to acceptable transmission size" );
507
513
508
514
// If a connection packet, don't check the game id since they might not have it yet.
509
- const uint32_t crc = (NetBuffer[0 ] & NCMD_SETUP) ? CalcCRC32 (dataStart, size) : AddCRC32 (CalcCRC32 (dataStart, size), ( uint8_t *)& GameID, sizeof (GameID));
515
+ const uint32_t crc = (NetBuffer[0 ] & NCMD_SETUP) ? CalcCRC32 (dataStart, size) : AddCRC32 (CalcCRC32 (dataStart, size), GameID, std::extent_v< decltype (GameID)> );
510
516
TransmitBuffer[0 ] = crc >> 24 ;
511
517
TransmitBuffer[1 ] = crc >> 16 ;
512
518
TransmitBuffer[2 ] = crc >> 8 ;
@@ -573,7 +579,7 @@ static void GetPacket(sockaddr_in* const from = nullptr)
573
579
}
574
580
else
575
581
{
576
- const uint32_t check = (*dataStart & NCMD_SETUP) ? CalcCRC32 (dataStart, msgSize - 4 ) : AddCRC32 (CalcCRC32 (dataStart, msgSize - 4 ), ( uint8_t *) GameID, sizeof (GameID));
582
+ const uint32_t check = (*dataStart & NCMD_SETUP) ? CalcCRC32 (dataStart, msgSize - 4 ) : AddCRC32 (CalcCRC32 (dataStart, msgSize - 4 ), GameID, std::extent_v< decltype (GameID)> );
577
583
const uint32_t crc = (TransmitBuffer[0 ] << 24 ) | (TransmitBuffer[1 ] << 16 ) | (TransmitBuffer[2 ] << 8 ) | TransmitBuffer[3 ];
578
584
if (check != crc)
579
585
{
@@ -874,14 +880,7 @@ static bool Host_CheckForConnections(void* connected)
874
880
{
875
881
NetBuffer[1 ] = PRE_GAME_INFO;
876
882
NetBuffer[2 ] = TicDup;
877
- NetBuffer[3 ] = GameID >> 56 ;
878
- NetBuffer[4 ] = GameID >> 48 ;
879
- NetBuffer[5 ] = GameID >> 40 ;
880
- NetBuffer[6 ] = GameID >> 32 ;
881
- NetBuffer[7 ] = GameID >> 24 ;
882
- NetBuffer[8 ] = GameID >> 16 ;
883
- NetBuffer[9 ] = GameID >> 8 ;
884
- NetBuffer[10 ] = GameID;
883
+ memcpy (&NetBuffer[3 ], GameID, 8 );
885
884
NetBufferLength = 11u ;
886
885
887
886
uint8_t * stream = &NetBuffer[NetBufferLength];
@@ -966,7 +965,7 @@ static bool HostGame(int arg, bool forcedNetMode)
966
965
if (MaxClients > MAXPLAYERS)
967
966
I_FatalError (" Cannot host a game with %u players. The limit is currently %u" , MaxClients, MAXPLAYERS);
968
967
969
- GameID = GameIDGen. GenRand64 ();
968
+ GenerateGameID ();
970
969
NetworkClients += 0 ;
971
970
Connected[consoleplayer].Status = CSTAT_READY;
972
971
Net_SetupUserInfo ();
@@ -1128,8 +1127,7 @@ static bool Guest_ContactHost(void* unused)
1128
1127
if (!Connected[consoleplayer].bHasGameInfo )
1129
1128
{
1130
1129
TicDup = clamp<int >(NetBuffer[2 ], 1 , MAXTICDUP);
1131
- GameID = ((uint64_t )NetBuffer[3 ] << 56 ) | ((uint64_t )NetBuffer[4 ] << 48 ) | ((uint64_t )NetBuffer[5 ] << 40 ) | ((uint64_t )NetBuffer[6 ] << 32 )
1132
- | ((uint64_t )NetBuffer[7 ] << 24 ) | ((uint64_t )NetBuffer[8 ] << 16 ) | ((uint64_t )NetBuffer[9 ] << 8 ) | (uint64_t )NetBuffer[10 ];
1130
+ memcpy (GameID, &NetBuffer[3 ], 8 );
1133
1131
uint8_t * stream = &NetBuffer[11 ];
1134
1132
Net_ReadGameInfo (stream);
1135
1133
Connected[consoleplayer].bHasGameInfo = true ;
@@ -1293,7 +1291,7 @@ bool I_InitNetwork()
1293
1291
else
1294
1292
{
1295
1293
// single player game
1296
- GameID = GameIDGen. GenRand64 ();
1294
+ GenerateGameID ();
1297
1295
TicDup = 1 ;
1298
1296
NetworkClients += 0 ;
1299
1297
Connected[0 ].Status = CSTAT_READY;
0 commit comments