Skip to content

Commit

Permalink
Fix crash with /restart kt
Browse files Browse the repository at this point in the history
G_ChangeTeam was doing ClientSpawn which shouldn't happen for clients
that haven't entered the game.
  • Loading branch information
slipher committed May 24, 2024
1 parent 5380d67 commit 6fbdca8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/sgame/sg_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,16 +1197,16 @@ const char *ClientConnect( int clientNum, bool firstTime )
Quote( client->pers.netname ) ) );
}

// count current clients and rank for scoreboard
CalculateRanks();

// if this is after !restart keepteams or !restart switchteams, apply said selection
if ( client->sess.restartTeam != TEAM_NONE )
{
G_ChangeTeam( ent, client->sess.restartTeam );
client->sess.restartTeam = TEAM_NONE;
}

// count current clients and rank for scoreboard
CalculateRanks();

return nullptr;
}

Expand Down
19 changes: 19 additions & 0 deletions src/sgame/sg_team.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,25 @@ void G_ChangeTeam( gentity_t *ent, team_t newTeam )
return;
}

if ( ent->client->pers.connected != CON_CONNECTED )
{
// This can happen with /restart ktl (or admin putteam maybe?).
// We shouldn't call ClientSpawn if it hasn't entered the game.

ent->client->pers.team = newTeam;

// userinfo configstrings
ClientUserinfoChanged( ent->client->ps.clientNum, false );

// configstring restrictions
G_UpdateTeamConfigStrings();

// Prevent the team from getting stomped on by G_namelog_restore later
G_namelog_update_score( ent->client );

return;
}

G_LeaveTeam( ent );
ent->client->pers.teamChangeTime = level.time;
ent->client->pers.team = newTeam;
Expand Down

0 comments on commit 6fbdca8

Please sign in to comment.