2312: Fix crash when player voting random_map leaves and vote passes r=def- a=Zwelf

Closes #2310 

Co-authored-by: Zwelf <zwelf@strct.cc>
This commit is contained in:
bors[bot] 2020-06-22 05:47:46 +00:00 committed by GitHub
commit 39eae1935b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 24 deletions

View file

@ -51,6 +51,8 @@ void CGameContext::Construct(int Resetting)
m_LastMapVote = 0; m_LastMapVote = 0;
//m_LockTeams = 0; //m_LockTeams = 0;
m_SqlRandomMapResult = nullptr;
if(Resetting==NO_RESET) if(Resetting==NO_RESET)
{ {
m_pVoteOptionHeap = new CHeap(); 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 #ifdef CONF_DEBUG
if(g_Config.m_DbgDummies) if(g_Config.m_DbgDummies)
{ {

View file

@ -58,6 +58,7 @@ class IConsole;
class IEngine; class IEngine;
class IStorage; class IStorage;
struct CAntibotData; struct CAntibotData;
struct CSqlRandomMapResult;
class CGameContext : public IGameServer class CGameContext : public IGameServer
{ {
@ -268,6 +269,8 @@ public:
bool RateLimitPlayerVote(int ClientID); bool RateLimitPlayerVote(int ClientID);
bool RateLimitPlayerMapVote(int ClientID); bool RateLimitPlayerMapVote(int ClientID);
std::shared_ptr<CSqlRandomMapResult> m_SqlRandomMapResult;
private: private:
bool m_VoteWillPass; bool m_VoteWillPass;

View file

@ -124,7 +124,6 @@ void CPlayer::Reset()
m_LastSQLQuery = 0; m_LastSQLQuery = 0;
m_SqlQueryResult = nullptr; m_SqlQueryResult = nullptr;
m_SqlFinishResult = nullptr; m_SqlFinishResult = nullptr;
m_SqlRandomMapResult = nullptr;
#endif #endif
int64 Now = Server()->Tick(); int64 Now = Server()->Tick();
@ -182,19 +181,6 @@ void CPlayer::Tick()
ProcessSqlResult(*m_SqlFinishResult); ProcessSqlResult(*m_SqlFinishResult);
m_SqlFinishResult = nullptr; 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 #endif
if(!Server()->ClientIngame(m_ClientID)) if(!Server()->ClientIngame(m_ClientID))

View file

@ -12,7 +12,6 @@
#if defined(CONF_SQL) #if defined(CONF_SQL)
class CSqlPlayerResult; class CSqlPlayerResult;
class CSqlRandomMapResult;
#endif #endif
// player object // player object
@ -197,7 +196,6 @@ public:
int64 m_LastSQLQuery; int64 m_LastSQLQuery;
std::shared_ptr<CSqlPlayerResult> m_SqlQueryResult; std::shared_ptr<CSqlPlayerResult> m_SqlQueryResult;
std::shared_ptr<CSqlPlayerResult> m_SqlFinishResult; std::shared_ptr<CSqlPlayerResult> m_SqlFinishResult;
std::shared_ptr<CSqlRandomMapResult> m_SqlRandomMapResult;
#endif #endif
bool m_NotEligibleForFinish; bool m_NotEligibleForFinish;
int64 m_EligibleForFinishCheck; int64 m_EligibleForFinishCheck;

View file

@ -1347,9 +1347,8 @@ bool CSqlScore::ShowTopPointsThread(CSqlServer* pSqlServer, const CSqlData<CSqlP
void CSqlScore::RandomMap(int ClientID, int Stars) void CSqlScore::RandomMap(int ClientID, int Stars)
{ {
CPlayer *pCurPlayer = GameServer()->m_apPlayers[ClientID]; auto pResult = std::make_shared<CSqlRandomMapResult>(ClientID);
auto pResult = std::make_shared<CSqlRandomMapResult>(); GameServer()->m_SqlRandomMapResult = pResult;
pCurPlayer->m_SqlRandomMapResult = pResult;
auto *Tmp = new CSqlRandomMapRequest(pResult); auto *Tmp = new CSqlRandomMapRequest(pResult);
Tmp->m_Stars = Stars; Tmp->m_Stars = Stars;
@ -1423,9 +1422,8 @@ bool CSqlScore::RandomMapThread(CSqlServer* pSqlServer, const CSqlData<CSqlRando
void CSqlScore::RandomUnfinishedMap(int ClientID, int Stars) void CSqlScore::RandomUnfinishedMap(int ClientID, int Stars)
{ {
CPlayer *pCurPlayer = GameServer()->m_apPlayers[ClientID]; auto pResult = std::make_shared<CSqlRandomMapResult>(ClientID);
auto pResult = std::make_shared<CSqlRandomMapResult>(); GameServer()->m_SqlRandomMapResult = pResult;
pCurPlayer->m_SqlRandomMapResult = pResult;
auto *Tmp = new CSqlRandomMapRequest(pResult); auto *Tmp = new CSqlRandomMapRequest(pResult);
Tmp->m_Stars = Stars; Tmp->m_Stars = Stars;

View file

@ -56,12 +56,14 @@ struct CSqlPlayerResult
struct CSqlRandomMapResult struct CSqlRandomMapResult
{ {
std::atomic_bool m_Done; std::atomic_bool m_Done;
CSqlRandomMapResult() : CSqlRandomMapResult(int ClientID) :
m_Done(false) m_Done(false),
m_ClientID(ClientID)
{ {
m_Map[0] = '\0'; m_Map[0] = '\0';
m_aMessage[0] = '\0'; m_aMessage[0] = '\0';
} }
int m_ClientID;
char m_Map[MAX_MAP_LENGTH]; char m_Map[MAX_MAP_LENGTH];
char m_aMessage[512]; char m_aMessage[512];
}; };