From 16c5a60b53bc0679b0c7a86c148cebb1a92e22ea Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sun, 19 Nov 2023 16:19:47 +0100 Subject: [PATCH] Move `m_pLoadBestTimeResult` to `IGameController` Gets rid of more CGameControllerDDRace casts. Those did not show up during compile time only during runtime of another active controller when asan is active. --- src/game/server/ddracechat.cpp | 4 ++-- src/game/server/ddracecommands.cpp | 4 ++-- src/game/server/gamecontroller.cpp | 20 +++++++++++++++++++- src/game/server/gamecontroller.h | 3 +++ src/game/server/gamemodes/DDRace.cpp | 19 +------------------ src/game/server/gamemodes/DDRace.h | 3 --- src/game/server/score.cpp | 8 ++++---- 7 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/game/server/ddracechat.cpp b/src/game/server/ddracechat.cpp index 3a7702b2e..2be9d9405 100644 --- a/src/game/server/ddracechat.cpp +++ b/src/game/server/ddracechat.cpp @@ -953,7 +953,7 @@ void CGameContext::UnlockTeam(int ClientID, int Team) void CGameContext::ConInviteTeam(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; - CGameControllerDDRace *pController = (CGameControllerDDRace *)pSelf->m_pController; + auto *pController = pSelf->m_pController; const char *pName = pResult->GetString(0); if(g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO) @@ -1017,7 +1017,7 @@ void CGameContext::ConInviteTeam(IConsole::IResult *pResult, void *pUserData) void CGameContext::ConJoinTeam(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; - CGameControllerDDRace *pController = (CGameControllerDDRace *)pSelf->m_pController; + auto *pController = pSelf->m_pController; if(!CheckClientID(pResult->m_ClientID)) return; diff --git a/src/game/server/ddracecommands.cpp b/src/game/server/ddracecommands.cpp index 3b9ce551a..cba968a94 100644 --- a/src/game/server/ddracecommands.cpp +++ b/src/game/server/ddracecommands.cpp @@ -774,7 +774,7 @@ void CGameContext::ConModerate(IConsole::IResult *pResult, void *pUserData) void CGameContext::ConSetDDRTeam(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; - CGameControllerDDRace *pController = (CGameControllerDDRace *)pSelf->m_pController; + auto *pController = pSelf->m_pController; if(g_Config.m_SvTeam == SV_TEAM_FORBIDDEN || g_Config.m_SvTeam == SV_TEAM_FORCED_SOLO) { @@ -800,7 +800,7 @@ void CGameContext::ConSetDDRTeam(IConsole::IResult *pResult, void *pUserData) void CGameContext::ConUninvite(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; - CGameControllerDDRace *pController = (CGameControllerDDRace *)pSelf->m_pController; + auto *pController = pSelf->m_pController; pController->Teams().SetClientInvited(pResult->GetInteger(1), pResult->GetVictim(), false); } diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index c6aa0ce79..10badd466 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include "gamecontext.h" @@ -19,7 +20,7 @@ #include "entities/projectile.h" IGameController::IGameController(class CGameContext *pGameServer) : - m_Teams(pGameServer) + m_Teams(pGameServer), m_pLoadBestTimeResult(nullptr) { m_pGameServer = pGameServer; m_pConfig = m_pGameServer->Config(); @@ -537,6 +538,23 @@ void IGameController::Tick() } } + if(m_pLoadBestTimeResult != nullptr && m_pLoadBestTimeResult->m_Completed) + { + if(m_pLoadBestTimeResult->m_Success) + { + m_CurrentRecord = m_pLoadBestTimeResult->m_CurrentRecord; + + for(int i = 0; i < MAX_CLIENTS; i++) + { + if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetClientVersion() >= VERSION_DDRACE) + { + GameServer()->SendRecord(i); + } + } + } + m_pLoadBestTimeResult = nullptr; + } + DoActivityCheck(); } diff --git a/src/game/server/gamecontroller.h b/src/game/server/gamecontroller.h index c4f2c9f9a..81c3fa33b 100644 --- a/src/game/server/gamecontroller.h +++ b/src/game/server/gamecontroller.h @@ -11,6 +11,8 @@ #include #include +struct CScoreLoadBestTimeResult; + /* Class: Game Controller Controls the main game logic. Keeping track of team and player score, @@ -155,6 +157,7 @@ public: std::map> m_TeleOuts; std::map> m_TeleCheckOuts; CGameTeams &Teams() { return m_Teams; } + std::shared_ptr m_pLoadBestTimeResult; }; #endif diff --git a/src/game/server/gamemodes/DDRace.cpp b/src/game/server/gamemodes/DDRace.cpp index 4fd41028e..48a6d71bd 100644 --- a/src/game/server/gamemodes/DDRace.cpp +++ b/src/game/server/gamemodes/DDRace.cpp @@ -15,7 +15,7 @@ #define TEST_TYPE_NAME "TestDDraceNetwork" CGameControllerDDRace::CGameControllerDDRace(class CGameContext *pGameServer) : - IGameController(pGameServer), m_pLoadBestTimeResult(nullptr) + IGameController(pGameServer) { m_pGameType = g_Config.m_SvTestingCommands ? TEST_TYPE_NAME : GAME_TYPE_NAME; } @@ -159,23 +159,6 @@ void CGameControllerDDRace::Tick() IGameController::Tick(); Teams().ProcessSaveTeam(); Teams().Tick(); - - if(m_pLoadBestTimeResult != nullptr && m_pLoadBestTimeResult->m_Completed) - { - if(m_pLoadBestTimeResult->m_Success) - { - m_CurrentRecord = m_pLoadBestTimeResult->m_CurrentRecord; - - for(int i = 0; i < MAX_CLIENTS; i++) - { - if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetClientVersion() >= VERSION_DDRACE) - { - GameServer()->SendRecord(i); - } - } - } - m_pLoadBestTimeResult = nullptr; - } } void CGameControllerDDRace::DoTeamChange(class CPlayer *pPlayer, int Team, bool DoChatMsg) diff --git a/src/game/server/gamemodes/DDRace.h b/src/game/server/gamemodes/DDRace.h index f0237d449..17626f26a 100644 --- a/src/game/server/gamemodes/DDRace.h +++ b/src/game/server/gamemodes/DDRace.h @@ -4,7 +4,6 @@ #include -struct CScoreLoadBestTimeResult; class CGameControllerDDRace : public IGameController { public: @@ -23,7 +22,5 @@ public: void Tick() override; void DoTeamChange(class CPlayer *pPlayer, int Team, bool DoChatMsg = true) override; - - std::shared_ptr m_pLoadBestTimeResult; }; #endif // GAME_SERVER_GAMEMODES_DDRACE_H diff --git a/src/game/server/score.cpp b/src/game/server/score.cpp index 139bf6e51..b70fe8902 100644 --- a/src/game/server/score.cpp +++ b/src/game/server/score.cpp @@ -110,11 +110,11 @@ CScore::CScore(CGameContext *pGameServer, CDbConnectionPool *pPool) : void CScore::LoadBestTime() { - if(((CGameControllerDDRace *)(m_pGameServer->m_pController))->m_pLoadBestTimeResult) + if(m_pGameServer->m_pController->m_pLoadBestTimeResult) return; // already in progress auto LoadBestTimeResult = std::make_shared(); - ((CGameControllerDDRace *)(m_pGameServer->m_pController))->m_pLoadBestTimeResult = LoadBestTimeResult; + m_pGameServer->m_pController->m_pLoadBestTimeResult = LoadBestTimeResult; auto Tmp = std::make_unique(LoadBestTimeResult); str_copy(Tmp->m_aMap, g_Config.m_SvMap, sizeof(Tmp->m_aMap)); @@ -281,7 +281,7 @@ void CScore::SaveTeam(int ClientID, const char *pCode, const char *pServer) { if(RateLimitPlayer(ClientID)) return; - auto *pController = ((CGameControllerDDRace *)(GameServer()->m_pController)); + auto *pController = GameServer()->m_pController; int Team = pController->Teams().m_Core.Team(ClientID); if(pController->Teams().GetSaving(Team)) return; @@ -326,7 +326,7 @@ void CScore::LoadTeam(const char *pCode, int ClientID) { if(RateLimitPlayer(ClientID)) return; - auto *pController = ((CGameControllerDDRace *)(GameServer()->m_pController)); + auto *pController = GameServer()->m_pController; int Team = pController->Teams().m_Core.Team(ClientID); if(pController->Teams().GetSaving(Team)) return;