mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Fix crash when player voting random_map leaves and vote passes
Closes #2310
This commit is contained in:
parent
4a810091b1
commit
b96d8673f3
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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];
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue