From b96d8673f399f581e84e7151c73c78517ccfe147 Mon Sep 17 00:00:00 2001 From: Zwelf Date: Mon, 22 Jun 2020 00:45:17 +0200 Subject: [PATCH] Fix crash when player voting random_map leaves and vote passes Closes #2310 --- src/game/server/gamecontext.cpp | 18 ++++++++++++++++++ src/game/server/gamecontext.h | 3 +++ src/game/server/player.cpp | 14 -------------- src/game/server/player.h | 2 -- src/game/server/score/sql_score.cpp | 10 ++++------ src/game/server/score/sql_score.h | 6 ++++-- 6 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index ace7ed13f..64637c281 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -51,6 +51,8 @@ void CGameContext::Construct(int Resetting) m_LastMapVote = 0; //m_LockTeams = 0; + m_SqlRandomMapResult = nullptr; + if(Resetting==NO_RESET) { m_pVoteOptionHeap = new CHeap(); @@ -920,6 +922,22 @@ void CGameContext::OnTick() } } +#if defined(CONF_SQL) + if(m_SqlRandomMapResult != nullptr && m_SqlRandomMapResult.use_count() == 1) + { + if(m_SqlRandomMapResult->m_Done) + { + if(PlayerExists(m_SqlRandomMapResult->m_ClientID) && m_SqlRandomMapResult->m_aMessage[0] != '\0') + SendChatTarget(m_SqlRandomMapResult->m_ClientID, m_SqlRandomMapResult->m_aMessage); + if(m_SqlRandomMapResult->m_Map[0] != '\0') + str_copy(g_Config.m_SvMap, m_SqlRandomMapResult->m_Map, sizeof(g_Config.m_SvMap)); + else + m_LastMapVote = 0; + } + m_SqlRandomMapResult = nullptr; + } +#endif + #ifdef CONF_DEBUG if(g_Config.m_DbgDummies) { diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 5b2e3a970..1d98fdacb 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -58,6 +58,7 @@ class IConsole; class IEngine; class IStorage; struct CAntibotData; +struct CSqlRandomMapResult; class CGameContext : public IGameServer { @@ -268,6 +269,8 @@ public: bool RateLimitPlayerVote(int ClientID); bool RateLimitPlayerMapVote(int ClientID); + std::shared_ptr m_SqlRandomMapResult; + private: bool m_VoteWillPass; diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 3c205480f..f07313764 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -124,7 +124,6 @@ void CPlayer::Reset() m_LastSQLQuery = 0; m_SqlQueryResult = nullptr; m_SqlFinishResult = nullptr; - m_SqlRandomMapResult = nullptr; #endif int64 Now = Server()->Tick(); @@ -182,19 +181,6 @@ void CPlayer::Tick() ProcessSqlResult(*m_SqlFinishResult); m_SqlFinishResult = nullptr; } - if(m_SqlRandomMapResult != nullptr && m_SqlRandomMapResult.use_count() == 1) - { - if(m_SqlRandomMapResult->m_Done) - { - if(m_SqlRandomMapResult->m_aMessage[0] != '\0') - GameServer()->SendChatTarget(m_ClientID, m_SqlRandomMapResult->m_aMessage); - if(m_SqlRandomMapResult->m_Map[0] != '\0') - str_copy(g_Config.m_SvMap, m_SqlRandomMapResult->m_Map, sizeof(g_Config.m_SvMap)); - else - GameServer()->m_LastMapVote = 0; - } - m_SqlRandomMapResult = nullptr; - } #endif if(!Server()->ClientIngame(m_ClientID)) diff --git a/src/game/server/player.h b/src/game/server/player.h index 4765727a4..34927c966 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -12,7 +12,6 @@ #if defined(CONF_SQL) class CSqlPlayerResult; -class CSqlRandomMapResult; #endif // player object @@ -197,7 +196,6 @@ public: int64 m_LastSQLQuery; std::shared_ptr m_SqlQueryResult; std::shared_ptr m_SqlFinishResult; - std::shared_ptr m_SqlRandomMapResult; #endif bool m_NotEligibleForFinish; int64 m_EligibleForFinishCheck; diff --git a/src/game/server/score/sql_score.cpp b/src/game/server/score/sql_score.cpp index 230f4780b..ca50752bc 100644 --- a/src/game/server/score/sql_score.cpp +++ b/src/game/server/score/sql_score.cpp @@ -1347,9 +1347,8 @@ bool CSqlScore::ShowTopPointsThread(CSqlServer* pSqlServer, const CSqlDatam_apPlayers[ClientID]; - auto pResult = std::make_shared(); - pCurPlayer->m_SqlRandomMapResult = pResult; + auto pResult = std::make_shared(ClientID); + GameServer()->m_SqlRandomMapResult = pResult; auto *Tmp = new CSqlRandomMapRequest(pResult); Tmp->m_Stars = Stars; @@ -1423,9 +1422,8 @@ bool CSqlScore::RandomMapThread(CSqlServer* pSqlServer, const CSqlDatam_apPlayers[ClientID]; - auto pResult = std::make_shared(); - pCurPlayer->m_SqlRandomMapResult = pResult; + auto pResult = std::make_shared(ClientID); + GameServer()->m_SqlRandomMapResult = pResult; auto *Tmp = new CSqlRandomMapRequest(pResult); Tmp->m_Stars = Stars; diff --git a/src/game/server/score/sql_score.h b/src/game/server/score/sql_score.h index 43c5ebf24..13fb22950 100644 --- a/src/game/server/score/sql_score.h +++ b/src/game/server/score/sql_score.h @@ -52,12 +52,14 @@ struct CSqlPlayerResult struct CSqlRandomMapResult { std::atomic_bool m_Done; - CSqlRandomMapResult() : - m_Done(false) + CSqlRandomMapResult(int ClientID) : + m_Done(false), + m_ClientID(ClientID) { m_Map[0] = '\0'; m_aMessage[0] = '\0'; } + int m_ClientID; char m_Map[MAX_MAP_LENGTH]; char m_aMessage[512]; };