From f4cc6e4efdb3f2c16e266eefa4fef07c7c810d51 Mon Sep 17 00:00:00 2001 From: def Date: Mon, 3 Feb 2014 20:03:49 +0100 Subject: [PATCH] Huge SQL bug --- src/game/server/score/sql_score.cpp | 24 ++++++++++++------------ src/game/server/score/sql_score.h | 9 --------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/game/server/score/sql_score.cpp b/src/game/server/score/sql_score.cpp index 64389f91a..22eeb1593 100644 --- a/src/game/server/score/sql_score.cpp +++ b/src/game/server/score/sql_score.cpp @@ -21,8 +21,7 @@ CSqlScore::CSqlScore(CGameContext *pGameServer) : m_pGameServer(pGameServer), m_pUser(g_Config.m_SvSqlUser), m_pPass(g_Config.m_SvSqlPw), m_pIp(g_Config.m_SvSqlIp), - m_Port(g_Config.m_SvSqlPort), - m_PointsInfos(NULL) + m_Port(g_Config.m_SvSqlPort) { m_pDriver = NULL; str_copy(m_aMap, g_Config.m_SvMap, sizeof(m_aMap)); @@ -35,7 +34,6 @@ CSqlScore::CSqlScore(CGameContext *pGameServer) : m_pGameServer(pGameServer), CSqlScore::~CSqlScore() { - delete m_PointsInfos; lock_wait(gs_SqlLock); lock_release(gs_SqlLock); @@ -465,20 +463,22 @@ void CSqlScore::SaveScoreThread(void *pUser) pData->m_pSqlData->m_pResults = pData->m_pSqlData->m_pStatement->executeQuery(aBuf); if(!pData->m_pSqlData->m_pResults->next()) { - unsigned int PointsSize = pData->m_pSqlData->m_PointsSize; - CPointsInfo *PointsInfos = pData->m_pSqlData->m_PointsInfos; + delete pData->m_pSqlData->m_pResults; - for (unsigned int i = 0; i < PointsSize; i++) + str_format(aBuf, sizeof(aBuf), "SELECT Points FROM %s_maps WHERE Map ='%s'", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap); + pData->m_pSqlData->m_pResults = pData->m_pSqlData->m_pStatement->executeQuery(aBuf); + + if(pData->m_pSqlData->m_pResults->rowsCount() == 1) { - if (str_comp(PointsInfos[i].m_aMapName, pData->m_pSqlData->m_aMap) == 0) - { - str_format(aBuf, sizeof(aBuf), "You earned %d points for finishing this map!", PointsInfos[i].m_Points); - pData->m_pSqlData->GameServer()->SendChatTarget(pData->m_ClientID, aBuf); - break; - } + pData->m_pSqlData->m_pResults->next(); + int points = (int)pData->m_pSqlData->m_pResults->getInt("Points"); + str_format(aBuf, sizeof(aBuf), "You earned %d points for finishing this map!", points); + pData->m_pSqlData->GameServer()->SendChatTarget(pData->m_ClientID, aBuf); } } + delete pData->m_pSqlData->m_pResults; + // if no entry found... create a new one str_format(aBuf, sizeof(aBuf), "INSERT IGNORE INTO %s_race(Map, Name, Timestamp, Time, cp1, cp2, cp3, cp4, cp5, cp6, cp7, cp8, cp9, cp10, cp11, cp12, cp13, cp14, cp15, cp16, cp17, cp18, cp19, cp20, cp21, cp22, cp23, cp24, cp25) VALUES ('%s', '%s', CURRENT_TIMESTAMP(), '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f', '%.2f');", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aName, pData->m_Time, pData->m_aCpCurrent[0], pData->m_aCpCurrent[1], pData->m_aCpCurrent[2], pData->m_aCpCurrent[3], pData->m_aCpCurrent[4], pData->m_aCpCurrent[5], pData->m_aCpCurrent[6], pData->m_aCpCurrent[7], pData->m_aCpCurrent[8], pData->m_aCpCurrent[9], pData->m_aCpCurrent[10], pData->m_aCpCurrent[11], pData->m_aCpCurrent[12], pData->m_aCpCurrent[13], pData->m_aCpCurrent[14], pData->m_aCpCurrent[15], pData->m_aCpCurrent[16], pData->m_aCpCurrent[17], pData->m_aCpCurrent[18], pData->m_aCpCurrent[19], pData->m_aCpCurrent[20], pData->m_aCpCurrent[21], pData->m_aCpCurrent[22], pData->m_aCpCurrent[23], pData->m_aCpCurrent[24]); pData->m_pSqlData->m_pStatement->execute(aBuf); diff --git a/src/game/server/score/sql_score.h b/src/game/server/score/sql_score.h index 2f88886ba..c446e2cfe 100644 --- a/src/game/server/score/sql_score.h +++ b/src/game/server/score/sql_score.h @@ -12,12 +12,6 @@ #include "../score.h" -struct CPointsInfo -{ - char m_aMapName[128]; - unsigned int m_Points; -}; - class CSqlScore: public IScore { CGameContext *m_pGameServer; @@ -73,9 +67,6 @@ public: CSqlScore(CGameContext *pGameServer); ~CSqlScore(); - CPointsInfo* m_PointsInfos; - unsigned int m_PointsSize; - virtual void LoadScore(int ClientID); virtual void MapPoints(int ClientID, const char* MapName); virtual void SaveScore(int ClientID, float Time,