Reworked PlayerResult to signal finished with use_count == 1

Therefore if the sql thread crashes, the result is deleted automatically
This commit is contained in:
Zwelf 2020-05-30 17:41:34 +02:00
parent 1d7289c8f0
commit 8fc81e7eca
3 changed files with 15 additions and 24 deletions

View file

@ -794,20 +794,24 @@ void CPlayer::SpectatePlayerName(const char *pName)
#if defined(CONF_SQL)
void CPlayer::ProcessSqlResult()
{
if(m_SqlQueryResult == nullptr || !m_SqlQueryResult->m_Done)
if(m_SqlQueryResult == nullptr || m_SqlQueryResult.use_count() != 1)
return;
for(int i = 0; i < (int)(sizeof(m_SqlQueryResult->m_aaMessages)/sizeof(m_SqlQueryResult->m_aaMessages[0])); i++)
if(m_SqlQueryResult->m_Done) // sql was query successful
{
if(m_SqlQueryResult->m_aaMessages[i][0] == 0)
break;
switch(m_SqlQueryResult->m_MessageTarget)
for(int i = 0; i < (int)(sizeof(m_SqlQueryResult->m_aaMessages)/sizeof(m_SqlQueryResult->m_aaMessages[0])); i++)
{
case CSqlPlayerResult::DIRECT:
GameServer()->SendChatTarget(m_ClientID, m_SqlQueryResult->m_aaMessages[i]);
break;
case CSqlPlayerResult::ALL:
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, m_SqlQueryResult->m_aaMessages[i]);
break;
if(m_SqlQueryResult->m_aaMessages[i][0] == 0)
break;
switch(m_SqlQueryResult->m_MessageTarget)
{
case CSqlPlayerResult::DIRECT:
GameServer()->SendChatTarget(m_ClientID, m_SqlQueryResult->m_aaMessages[i]);
break;
case CSqlPlayerResult::ALL:
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, m_SqlQueryResult->m_aaMessages[i]);
break;
}
}
}
m_SqlQueryResult = nullptr;

View file

@ -21,7 +21,6 @@ std::atomic_int CSqlScore::ms_InstanceCount(0);
CSqlPlayerResult::CSqlPlayerResult() :
m_Done(0),
m_Failed(0),
m_MessageTarget(DIRECT)
{
for(int i = 0; i < (int)(sizeof(m_aaMessages)/sizeof(m_aaMessages[0])); i++)
@ -540,8 +539,6 @@ bool CSqlScore::MapInfoThread(CSqlServer* pSqlServer, const CSqlData<CSqlPlayerR
{
dbg_msg("sql", "MySQL Error: %s", e.what());
dbg_msg("sql", "ERROR: Could not get Mapinfo");
pData->m_pResult->m_Failed = true;
pData->m_pResult->m_Done = true;
}
return false;
}
@ -996,11 +993,7 @@ bool CSqlScore::ShowTop5Thread(CSqlServer* pSqlServer, const CSqlData<CSqlPlayer
{
const CSqlPlayerRequest *pData = dynamic_cast<const CSqlPlayerRequest *>(pGameData);
if (HandleFailure)
{
pData->m_pResult->m_Failed = true;
pData->m_pResult->m_Done = true;
return true;
}
int LimitStart = maximum(abs(pData->m_Offset)-1, 0);
const char *pOrder = pData->m_Offset >= 0 ? "ASC" : "DESC";
@ -1067,11 +1060,7 @@ bool CSqlScore::ShowTeamTop5Thread(CSqlServer* pSqlServer, const CSqlData<CSqlPl
const CSqlPlayerRequest *pData = dynamic_cast<const CSqlPlayerRequest *>(pGameData);
auto paMessages = pData->m_pResult->m_aaMessages;
if (HandleFailure)
{
pData->m_pResult->m_Failed = true;
pData->m_pResult->m_Done = true;
return true;
}
int LimitStart = maximum(abs(pData->m_Offset)-1, 0);
const char *pOrder = pData->m_Offset >= 0 ? "ASC" : "DESC";

View file

@ -15,7 +15,6 @@ class CSqlPlayerResult {
public:
CSqlPlayerResult();
std::atomic_bool m_Done;
bool m_Failed;
enum
{
@ -30,7 +29,6 @@ class CSqlResult
{
public:
std::atomic_bool m_Done;
bool m_Failed;
// specify where chat messages should be returned
enum
{