Generate checksum with noncompat protocol

This commit is contained in:
smallmodel 2025-01-04 17:55:33 +01:00
parent 6e357459e6
commit 3c26b98b65
No known key found for this signature in database
GPG key ID: A96F163ED4891440
2 changed files with 32 additions and 8 deletions

View file

@ -325,7 +325,12 @@ void Netchan_TransmitNextFragment( netchan_t *chan, netprofpacketlist_t *packetl
// send the qport if we are a client
if ( chan->sock == NS_CLIENT ) {
MSG_WriteShort( &send, qport->integer );
}
}
#ifdef LEGACY_PROTOCOL
if (!chan->compat)
#endif
MSG_WriteLong(&send, NETCHAN_GENCHECKSUM(chan->challenge, chan->outgoingSequence));
// copy the reliable message to the packet first
fragmentLength = FRAGMENT_SIZE;
@ -402,12 +407,17 @@ void Netchan_Transmit( netchan_t *chan, size_t length, const byte *data, netprof
MSG_InitOOB (&send, send_buf, chan->remoteAddress.type == NA_LOOPBACK ? MAX_PACKETLEN : MAX_REMOTE_PACKETLEN);
MSG_WriteLong( &send, chan->outgoingSequence );
chan->outgoingSequence++;
// send the qport if we are a client
if ( chan->sock == NS_CLIENT ) {
MSG_WriteShort( &send, qport->integer );
}
if(chan->sock == NS_CLIENT)
MSG_WriteShort(&send, qport->integer);
#ifdef LEGACY_PROTOCOL
if(!chan->compat)
#endif
MSG_WriteLong(&send, NETCHAN_GENCHECKSUM(chan->challenge, chan->outgoingSequence));
chan->outgoingSequence++;
MSG_WriteData( &send, data, length );
@ -469,6 +479,17 @@ qboolean Netchan_Process( netchan_t *chan, msg_t *msg, netprofpacketlist_t *pack
qport = MSG_ReadShort( msg );
}
#ifdef LEGACY_PROTOCOL
if(!chan->compat)
#endif
{
int checksum = MSG_ReadLong(msg);
// UDP spoofing protection
if(NETCHAN_GENCHECKSUM(chan->challenge, sequence) != checksum)
return qfalse;
}
// read the fragment information
if ( fragmented ) {
fragmentStart = MSG_ReadLong( msg );

View file

@ -255,11 +255,14 @@ void NET_LeaveMulticast6(void);
void NET_Sleep(int msec);
#define MAX_MSGLEN 49152 // max length of a message, which may
#define MAX_MSGLEN 49152 // max length of a message, which may
// be fragmented into multiple packets
#define MAX_DOWNLOAD_WINDOW 8 // max of eight download frames
#define MAX_DOWNLOAD_BLKSIZE 2048 // 2048 byte block chunks
#define MAX_DOWNLOAD_WINDOW 48 // ACK window of 48 download chunks. Cannot set this higher, or clients
// will overflow the reliable commands buffer
#define MAX_DOWNLOAD_BLKSIZE 1024 // 896 byte block chunks
#define NETCHAN_GENCHECKSUM(challenge, sequence) ((challenge) ^ ((sequence) * (challenge)))
/*