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_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)
{

View file

@ -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<CSqlRandomMapResult> m_SqlRandomMapResult;
private:
bool m_VoteWillPass;

View file

@ -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))

View file

@ -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<CSqlPlayerResult> m_SqlQueryResult;
std::shared_ptr<CSqlPlayerResult> m_SqlFinishResult;
std::shared_ptr<CSqlRandomMapResult> m_SqlRandomMapResult;
#endif
bool m_NotEligibleForFinish;
int64 m_EligibleForFinishCheck;

View file

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

View file

@ -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];
};