Skip to content

Commit 9ceed9c

Browse files
committed
Drop on impossible server command sequence nums
Have the client drop the connection in these cases: - A gamestate that decreases the sequence number. This should be impossible because the netchan guarantees that packets can't be reordered, although they may be dropped. - A server command which a sequence number higher than the next one. This should be impossible because the server re-sends all unacknowledged commands together each time. If the number jumped by more than one the client would end up re-executing old garbage from the buffer.
1 parent 0d65b8a commit 9ceed9c

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/engine/client/cl_cgame.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ void CL_ConfigstringModified( Cmd::Args& csCmd )
137137
/*
138138
===================
139139
CL_HandleServerCommand
140-
CL_GetServerCommand
140+
141+
Returns true if the command should be passed to the cgame
141142
===================
142143
*/
143144
bool CL_HandleServerCommand(Str::StringRef text, std::string& newText) {

src/engine/client/cl_parse.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,14 @@ void CL_ParseGamestate( msg_t *msg )
408408
CL_ClearState();
409409

410410
// a gamestate always marks a server command sequence
411-
clc.serverCommandSequence = MSG_ReadLong( msg );
411+
int commandNum = MSG_ReadLong( msg );
412+
413+
if ( commandNum < clc.serverCommandSequence )
414+
{
415+
Sys::Drop( "Gamestate moved serverCommandSequence backward" );
416+
}
417+
418+
clc.serverCommandSequence = commandNum;
412419

413420
// trash any commands from previous game
414421
clc.lastExecutedServerCommand = clc.serverCommandSequence;
@@ -499,6 +506,13 @@ void CL_ParseCommandString( msg_t *msg )
499506
return;
500507
}
501508

509+
if ( clc.serverCommandSequence + 1 != seq )
510+
{
511+
Sys::Drop( "Out-of-sequence server command: expected %d, got %d",
512+
clc.serverCommandSequence + 1, seq );
513+
return;
514+
}
515+
502516
clc.serverCommandSequence = seq;
503517

504518
index = seq & ( MAX_RELIABLE_COMMANDS - 1 );

0 commit comments

Comments
 (0)