From f5e8b9d822811d8b9fe0eb011e9eb3d8c30d3f83 Mon Sep 17 00:00:00 2001 From: def Date: Thu, 10 Jan 2019 09:32:23 +0100 Subject: [PATCH] Fix potential inconsistencies in rank/teamrank --- src/game/server/teams.cpp | 31 +++++++++++++++++-------------- src/game/server/teams.h | 10 +++++----- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/game/server/teams.cpp b/src/game/server/teams.cpp index bb6da473e..55b0e63d2 100644 --- a/src/game/server/teams.cpp +++ b/src/game/server/teams.cpp @@ -136,7 +136,13 @@ void CGameTeams::OnCharacterFinish(int ClientID) { CPlayer* pPlayer = GetPlayer(ClientID); if (pPlayer && pPlayer->IsPlaying()) - OnFinish(pPlayer); + { + float Time = (float)(Server()->Tick() - GetStartTime(pPlayer)) + / ((float)Server()->TickSpeed()); + if (Time < 0.000001f) + return; + OnFinish(pPlayer, Time); + } } else { @@ -160,7 +166,6 @@ void CGameTeams::CheckTeamFinished(int Team) CPlayer* pPlayer = GetPlayer(i); if (pPlayer && pPlayer->IsPlaying()) { - OnFinish(pPlayer); m_TeeFinished[i] = false; TeamPlayers[PlayersCount++] = pPlayer; @@ -170,9 +175,16 @@ void CGameTeams::CheckTeamFinished(int Team) if (PlayersCount > 0) { + float Time = (float)(Server()->Tick() - GetStartTime(TeamPlayers[0])) + / ((float)Server()->TickSpeed()); + if (Time < 0.000001f) + return; + + for (auto pPlayer : TeamPlayers) + OnFinish(pPlayer, Time); ChangeTeamState(Team, TEAMSTATE_FINISHED); //TODO: Make it better //ChangeTeamState(Team, TEAMSTATE_OPEN); - OnTeamFinish(TeamPlayers, PlayersCount); + OnTeamFinish(TeamPlayers, PlayersCount, Time); } } } @@ -443,13 +455,8 @@ float *CGameTeams::GetCpCurrent(CPlayer* Player) return NULL; } -void CGameTeams::OnTeamFinish(CPlayer** Players, unsigned int Size) +void CGameTeams::OnTeamFinish(CPlayer** Players, unsigned int Size, float Time) { - float Time = (float)(Server()->Tick() - GetStartTime(Players[0])) - / ((float)Server()->TickSpeed()); - if (Time < 0.000001f) - return; - bool CallSaveScore = false; #if defined(CONF_SQL) @@ -476,15 +483,11 @@ void CGameTeams::OnTeamFinish(CPlayer** Players, unsigned int Size) GameServer()->Score()->SaveTeamScore(PlayerCIDs, Size, Time); } -void CGameTeams::OnFinish(CPlayer* Player) +void CGameTeams::OnFinish(CPlayer* Player, float Time) { if (!Player || !Player->IsPlaying()) return; //TODO:DDRace:btd: this ugly - float Time = (float)(Server()->Tick() - GetStartTime(Player)) - / ((float)Server()->TickSpeed()); - if (Time < 0.000001f) - return; CPlayerData *pData = GameServer()->Score()->PlayerData(Player->GetCID()); char aBuf[128]; SetCpActive(Player, -2); diff --git a/src/game/server/teams.h b/src/game/server/teams.h index 250c23394..a40229250 100644 --- a/src/game/server/teams.h +++ b/src/game/server/teams.h @@ -16,6 +16,11 @@ class CGameTeams class CGameContext * m_pGameContext; + void CheckTeamFinished(int ClientID); + bool TeamFinished(int Team); + void OnTeamFinish(CPlayer** Players, unsigned int Size, float Time); + void OnFinish(CPlayer* Player, float Time); + public: enum { @@ -50,14 +55,11 @@ public: void OnCharacterSpawn(int ClientID); void OnCharacterDeath(int ClientID, int Weapon); - void CheckTeamFinished(int ClientID); bool SetCharacterTeam(int ClientID, int Team); void ChangeTeamState(int Team, int State); void onChangeTeamState(int Team, int State, int OldState); - bool TeamFinished(int Team); - int64_t TeamMask(int Team, int ExceptID = -1, int Asker = -1); int Count(int Team) const; @@ -81,8 +83,6 @@ public: void SetDDRaceState(CPlayer* Player, int DDRaceState); void SetStartTime(CPlayer* Player, int StartTime); void SetCpActive(CPlayer* Player, int CpActive); - void OnTeamFinish(CPlayer** Players, unsigned int Size); - void OnFinish(CPlayer* Player); void KillSavedTeam(int Team); bool TeeFinished(int ClientID)