Defer character kill from thread to prevent race conditions

This commit is contained in:
def 2014-12-07 03:42:43 +01:00
parent 6ecd02d410
commit 87ebb2f03e
3 changed files with 17 additions and 1 deletions

View file

@ -26,6 +26,7 @@ CPlayer::CPlayer(CGameContext *pGameServer, int ClientID, int Team)
m_Team = GameServer()->m_pController->ClampTeam(Team);
m_pCharacter = 0;
m_NumInputs = 0;
m_KillMe = 0;
Reset();
}
@ -43,6 +44,7 @@ void CPlayer::Reset()
if (m_pCharacter)
delete m_pCharacter;
m_pCharacter = 0;
m_KillMe = 0;
m_SpectatorID = SPEC_FREEVIEW;
m_LastActionTick = Server()->Tick();
m_TeamChangeTick = Server()->Tick();
@ -133,6 +135,13 @@ void CPlayer::Tick()
if(!Server()->ClientIngame(m_ClientID))
return;
if(m_KillMe != 0)
{
KillCharacter(m_KillMe);
m_KillMe = 0;
return;
}
if (m_ChatScore > 0)
m_ChatScore--;
@ -430,6 +439,11 @@ CCharacter *CPlayer::GetCharacter()
return 0;
}
void CPlayer::ThreadKillCharacter(int Weapon)
{
m_KillMe = Weapon;
}
void CPlayer::KillCharacter(int Weapon)
{
if(m_pCharacter)

View file

@ -36,6 +36,7 @@ public:
void OnPredictedInput(CNetObj_PlayerInput *NewInput);
void OnDisconnect(const char *pReason);
void ThreadKillCharacter(int Weapon = WEAPON_GAME);
void KillCharacter(int Weapon = WEAPON_GAME);
CCharacter *GetCharacter();
@ -152,6 +153,7 @@ public:
bool m_SpecTeam;
bool m_NinjaJetpack;
bool m_Afk;
int m_KillMe;
int m_ChatScore;

View file

@ -646,7 +646,7 @@ void CGameTeams::KillSavedTeam(int Team)
for (int i = 0; i < MAX_CLIENTS; i++)
if(m_Core.Team(i) == Team && GameServer()->m_apPlayers[i])
GameServer()->m_apPlayers[i]->KillCharacter(-2);
GameServer()->m_apPlayers[i]->ThreadKillCharacter(-2);
ChangeTeamState(Team, CGameTeams::TEAMSTATE_EMPTY);