Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent SV_DropClient() from being called recursively #693

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions code/server/sv_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,16 @@ void SV_DropClient( client_t *drop, const char *reason ) {
// Free all allocated data on the client structure
SV_FreeClient(drop);

// Reset the reliable sequence to the currently acknowledged command
// This prevents SV_AddServerCommand() from making another recursive call to SV_DropClient()
// if the client lacks sufficient space for another reliable command
// it also guarantees that the client receives both the print and disconnect commands
drop->reliableSequence = drop->reliableAcknowledge;
// Setting the gamestate message number to -1 ensures that SV_AddServerCommand()
// will not call SV_DropClient() again, even though it is unlikely the client
// will receive many server commands during the drop
drop->gamestateMessageNum = -1;

// tell everyone why they got dropped
SV_SendServerCommand( NULL, "print \"%s" S_COLOR_WHITE " %s\n\"", drop->name, reason );

Expand Down
6 changes: 6 additions & 0 deletions code/server/sv_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ void SV_AddServerCommand( client_t *client, const char *cmd ) {
// we check == instead of >= so a broadcast print added by SV_DropClient()
// doesn't cause a recursive drop client
if ( client->reliableSequence - client->reliableAcknowledge == MAX_RELIABLE_COMMANDS + 1 ) {
if ( client->gamestateMessageNum == -1 ) {
// invalid game state message
// this can occur in SV_DropClient() to avoid calling it more than once
return;
}

Com_Printf( "===== pending server commands =====\n" );
for ( i = client->reliableAcknowledge + 1 ; i <= client->reliableSequence ; i++ ) {
Com_Printf( "cmd %5d: %s\n", i, client->reliableCommands[ i & (MAX_RELIABLE_COMMANDS-1) ] );
Expand Down
Loading