diff --git a/src/game/server/teams.cpp b/src/game/server/teams.cpp index 9252b4b27..d31edc2ec 100644 --- a/src/game/server/teams.cpp +++ b/src/game/server/teams.cpp @@ -269,6 +269,21 @@ void CGameTeams::SetForceCharacterTeam(int ClientID, int Team) m_MembersCount[m_Core.Team(ClientID)]--; } + SetForceCharacterNewTeam(ClientID, Team); + + if (OldTeam != Team) + { + for(int LoopClientID = 0; LoopClientID < MAX_CLIENTS; ++LoopClientID) + if(GetPlayer(LoopClientID)) + SendTeamsState(LoopClientID); + + if(GetPlayer(ClientID)) + GetPlayer(ClientID)->m_VotedForPractice = false; + } +} + +void CGameTeams::SetForceCharacterNewTeam(int ClientID, int Team) +{ m_Core.Team(ClientID, Team); if (m_Core.Team(ClientID) != TEAM_SUPER) @@ -287,16 +302,6 @@ void CGameTeams::SetForceCharacterTeam(int ClientID, int Team) } } } - - if (OldTeam != Team) - { - for(int LoopClientID = 0; LoopClientID < MAX_CLIENTS; ++LoopClientID) - if(GetPlayer(LoopClientID)) - SendTeamsState(LoopClientID); - - if(GetPlayer(ClientID)) - GetPlayer(ClientID)->m_VotedForPractice = false; - } } void CGameTeams::ForceLeaveTeam(int ClientID) @@ -670,7 +675,10 @@ void CGameTeams::OnCharacterSpawn(int ClientID) m_Core.SetSolo(ClientID, false); if (m_Core.Team(ClientID) >= TEAM_SUPER || !m_TeamLocked[m_Core.Team(ClientID)]) - SetForceCharacterTeam(ClientID, 0); + // Important to only set a new team here, don't remove from an existing + // team since a newly joined player does by definition not have an old team + // to remove from. Doing so would destroy the count in m_MembersCount. + SetForceCharacterNewTeam(ClientID, 0); } void CGameTeams::OnCharacterDeath(int ClientID, int Weapon) diff --git a/src/game/server/teams.h b/src/game/server/teams.h index de5e5a0e5..36fd34d32 100644 --- a/src/game/server/teams.h +++ b/src/game/server/teams.h @@ -65,13 +65,14 @@ public: int Count(int Team) const; - //need to be very careful using this method - void SetForceCharacterTeam(int id, int Team); - void ForceLeaveTeam(int id); + //need to be very careful using this method. SERIOUSLY... + void SetForceCharacterTeam(int ClientID, int Team); + void SetForceCharacterNewTeam(int ClientID, int Team); + void ForceLeaveTeam(int ClientID); void Reset(); - void SendTeamsState(int Cid); + void SendTeamsState(int ClientID); void SetTeamLock(int Team, bool Lock); void ResetInvited(int Team); void SetClientInvited(int Team, int ClientID, bool Invited);