diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 69c80798c..ac66f94c4 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 d15466090..24932b34c 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 a12149c54..b0b136d9f 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 b1e81e519..6f5f7eee3 100644 --- a/src/game/server/score/sql_score.h +++ b/src/game/server/score/sql_score.h @@ -56,12 +56,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]; };