mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 18:18:18 +00:00
handle exceptions from sql properly
- write failed sqlinserts to a file - improved structure
This commit is contained in:
parent
1314085928
commit
88ed7391da
|
@ -428,6 +428,8 @@ IOHANDLE io_open(const char *filename, int flags)
|
||||||
return (IOHANDLE)fopen(filename, "rb");
|
return (IOHANDLE)fopen(filename, "rb");
|
||||||
if(flags == IOFLAG_WRITE)
|
if(flags == IOFLAG_WRITE)
|
||||||
return (IOHANDLE)fopen(filename, "wb");
|
return (IOHANDLE)fopen(filename, "wb");
|
||||||
|
if(flags == IOFLAG_APPEND)
|
||||||
|
return (IOHANDLE)fopen(filename, "ab");
|
||||||
return 0x0;
|
return 0x0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,7 @@ void mem_zero(void *block, unsigned size);
|
||||||
Returns:
|
Returns:
|
||||||
<0 - Block a is lesser then block b
|
<0 - Block a is lesser then block b
|
||||||
0 - Block a is equal to block b
|
0 - Block a is equal to block b
|
||||||
>0 - Block a is greater then block b
|
>0 - Block a is greater than block b
|
||||||
*/
|
*/
|
||||||
int mem_comp(const void *a, const void *b, int size);
|
int mem_comp(const void *a, const void *b, int size);
|
||||||
|
|
||||||
|
@ -184,6 +184,7 @@ enum {
|
||||||
IOFLAG_READ = 1,
|
IOFLAG_READ = 1,
|
||||||
IOFLAG_WRITE = 2,
|
IOFLAG_WRITE = 2,
|
||||||
IOFLAG_RANDOM = 4,
|
IOFLAG_RANDOM = 4,
|
||||||
|
IOFLAG_APPEND = 8,
|
||||||
|
|
||||||
IOSEEK_START = 0,
|
IOSEEK_START = 0,
|
||||||
IOSEEK_CUR = 1,
|
IOSEEK_CUR = 1,
|
||||||
|
@ -198,7 +199,7 @@ typedef struct IOINTERNAL *IOHANDLE;
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
filename - File to open.
|
filename - File to open.
|
||||||
flags - A set of flags. IOFLAG_READ, IOFLAG_WRITE, IOFLAG_RANDOM.
|
flags - A set of flags. IOFLAG_READ, IOFLAG_WRITE, IOFLAG_RANDOM, IOFLAG_APPEND.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Returns a handle to the file on success and 0 on failure.
|
Returns a handle to the file on success and 0 on failure.
|
||||||
|
|
|
@ -31,8 +31,8 @@ bool CSqlConnector::ConnectSqlServer(bool ReadOnly)
|
||||||
m_pSqlServer = SqlServer(i, ReadOnly);
|
m_pSqlServer = SqlServer(i, ReadOnly);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (SqlServer())
|
if (SqlServer(i, ReadOnly))
|
||||||
dbg_msg("SQL", "Warning: Unable to connect to Sql%sServer %d ('%s'), trying next...", ReadOnly ? "read" : "write", i, SqlServer()->GetIP());
|
dbg_msg("SQL", "Warning: Unable to connect to Sql%sServer %d ('%s'), trying next...", ReadOnly ? "read" : "write", i, SqlServer(i, ReadOnly)->GetIP());
|
||||||
}
|
}
|
||||||
dbg_msg("SQL", "ERROR: No Sql%sServers available", ReadOnly ? "Read" : "Write");
|
dbg_msg("SQL", "ERROR: No Sql%sServers available", ReadOnly ? "Read" : "Write");
|
||||||
m_pSqlServer = 0;
|
m_pSqlServer = 0;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef ENGINE_SERVER_SQL_STRING_HELPERS_H
|
#ifndef ENGINE_SERVER_SQL_STRING_HELPERS_H
|
||||||
#define ENGINE_SERVER_SQL_STRING_HELPERS_H
|
#define ENGINE_SERVER_SQL_STRING_HELPERS_H
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstring>
|
||||||
#include <base/system.h>
|
#include <base/system.h>
|
||||||
|
|
||||||
void FuzzyString(char *pString)
|
void FuzzyString(char *pString)
|
||||||
|
|
|
@ -221,6 +221,8 @@ MACRO_CONFIG_INT(SvSqlCreateTables, sv_sql_create_tables, 0, 0, 3, CFGFLAG_SERVE
|
||||||
MACRO_CONFIG_STR(SvSqlServerName, sv_sql_servername, 5, "UNK", CFGFLAG_SERVER, "SQL Server name that is inserted into record table")
|
MACRO_CONFIG_STR(SvSqlServerName, sv_sql_servername, 5, "UNK", CFGFLAG_SERVER, "SQL Server name that is inserted into record table")
|
||||||
MACRO_CONFIG_INT(SvSaveGames, sv_savegames, 1, 0, 1, CFGFLAG_SERVER, "Enables savegames (/save and /load)")
|
MACRO_CONFIG_INT(SvSaveGames, sv_savegames, 1, 0, 1, CFGFLAG_SERVER, "Enables savegames (/save and /load)")
|
||||||
MACRO_CONFIG_INT(SvSaveGamesDelay, sv_savegames_delay, 60, 0, 10000, CFGFLAG_SERVER, "Delay in seconds for loading a savegame")
|
MACRO_CONFIG_INT(SvSaveGamesDelay, sv_savegames_delay, 60, 0, 10000, CFGFLAG_SERVER, "Delay in seconds for loading a savegame")
|
||||||
|
|
||||||
|
MACRO_CONFIG_STR(SvSqlFailureFile, sv_sql_failure_file, 64, "failed_sql.sql", CFGFLAG_SERVER, "File to store failed Sql-Inserts (ranks)")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MACRO_CONFIG_INT(SvDDRaceRules, sv_ddrace_rules, 1, 0, 1, CFGFLAG_SERVER, "Whether the default mod rules are displayed or not")
|
MACRO_CONFIG_INT(SvDDRaceRules, sv_ddrace_rules, 1, 0, 1, CFGFLAG_SERVER, "Whether the default mod rules are displayed or not")
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -9,65 +9,11 @@
|
||||||
|
|
||||||
#include "../score.h"
|
#include "../score.h"
|
||||||
|
|
||||||
class CSqlScore: public IScore
|
|
||||||
{
|
|
||||||
CGameContext *GameServer() { return m_pGameServer; }
|
|
||||||
IServer *Server() { return m_pServer; }
|
|
||||||
|
|
||||||
CGameContext *m_pGameServer;
|
|
||||||
IServer *m_pServer;
|
|
||||||
|
|
||||||
void Init();
|
|
||||||
|
|
||||||
char m_aMap[64];
|
|
||||||
|
|
||||||
static void MapInfoThread(void *pUser);
|
|
||||||
static void MapVoteThread(void *pUser);
|
|
||||||
static void LoadScoreThread(void *pUser);
|
|
||||||
static void SaveScoreThread(void *pUser);
|
|
||||||
static void SaveTeamScoreThread(void *pUser);
|
|
||||||
static void ShowRankThread(void *pUser);
|
|
||||||
static void ShowTop5Thread(void *pUser);
|
|
||||||
static void ShowTeamRankThread(void *pUser);
|
|
||||||
static void ShowTeamTop5Thread(void *pUser);
|
|
||||||
static void ShowTimesThread(void *pUser);
|
|
||||||
static void ShowPointsThread(void *pUser);
|
|
||||||
static void ShowTopPointsThread(void *pUser);
|
|
||||||
static void RandomMapThread(void *pUser);
|
|
||||||
static void RandomUnfinishedMapThread(void *pUser);
|
|
||||||
static void SaveTeamThread(void *pUser);
|
|
||||||
static void LoadTeamThread(void *pUser);
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
CSqlScore(CGameContext *pGameServer);
|
|
||||||
|
|
||||||
virtual void LoadScore(int ClientID);
|
|
||||||
virtual void MapInfo(int ClientID, const char* MapName);
|
|
||||||
virtual void MapVote(int ClientID, const char* MapName);
|
|
||||||
virtual void SaveScore(int ClientID, float Time,
|
|
||||||
float CpTime[NUM_CHECKPOINTS]);
|
|
||||||
virtual void SaveTeamScore(int* aClientIDs, unsigned int Size, float Time);
|
|
||||||
virtual void ShowRank(int ClientID, const char* pName, bool Search = false);
|
|
||||||
virtual void ShowTeamRank(int ClientID, const char* pName, bool Search = false);
|
|
||||||
virtual void ShowTimes(int ClientID, const char* pName, int Debut = 1);
|
|
||||||
virtual void ShowTimes(int ClientID, int Debut = 1);
|
|
||||||
virtual void ShowTop5(IConsole::IResult *pResult, int ClientID,
|
|
||||||
void *pUserData, int Debut = 1);
|
|
||||||
virtual void ShowTeamTop5(IConsole::IResult *pResult, int ClientID,
|
|
||||||
void *pUserData, int Debut = 1);
|
|
||||||
virtual void ShowPoints(int ClientID, const char* pName, bool Search = false);
|
|
||||||
virtual void ShowTopPoints(IConsole::IResult *pResult, int ClientID,
|
|
||||||
void *pUserData, int Debut = 1);
|
|
||||||
virtual void RandomMap(int ClientID, int stars);
|
|
||||||
virtual void RandomUnfinishedMap(int ClientID, int stars);
|
|
||||||
virtual void SaveTeam(int Team, const char* Code, int ClientID, const char* Server);
|
|
||||||
virtual void LoadTeam(const char* Code, int ClientID);
|
|
||||||
};
|
|
||||||
|
|
||||||
// generic implementation to provide gameserver and server
|
// generic implementation to provide gameserver and server
|
||||||
struct CSqlData
|
struct CSqlData
|
||||||
{
|
{
|
||||||
|
virtual ~CSqlData() {}
|
||||||
|
|
||||||
CGameContext* GameServer() { return ms_pGameServer; }
|
CGameContext* GameServer() { return ms_pGameServer; }
|
||||||
IServer* Server() { return ms_pServer; }
|
IServer* Server() { return ms_pServer; }
|
||||||
CPlayerData* PlayerData(int ID) { return &ms_pPlayerData[ID]; }
|
CPlayerData* PlayerData(int ID) { return &ms_pPlayerData[ID]; }
|
||||||
|
@ -79,6 +25,18 @@ struct CSqlData
|
||||||
static const char *ms_pMap;
|
static const char *ms_pMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CSqlExecData
|
||||||
|
{
|
||||||
|
CSqlExecData(bool (*pFuncPtr) (CSqlServer*, CSqlData *, bool), CSqlData *pSqlData, bool ReadOnly = true) :
|
||||||
|
m_pFuncPtr(pFuncPtr),
|
||||||
|
m_pSqlData(pSqlData),
|
||||||
|
m_ReadOnly(ReadOnly)
|
||||||
|
{}
|
||||||
|
bool (*m_pFuncPtr) (CSqlServer*, CSqlData *, bool);
|
||||||
|
CSqlData *m_pSqlData;
|
||||||
|
bool m_ReadOnly;
|
||||||
|
};
|
||||||
|
|
||||||
struct CSqlMapData : CSqlData
|
struct CSqlMapData : CSqlData
|
||||||
{
|
{
|
||||||
int m_ClientID;
|
int m_ClientID;
|
||||||
|
@ -132,4 +90,62 @@ struct CSqlTeamLoad : CSqlData
|
||||||
int m_ClientID;
|
int m_ClientID;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CSqlScore: public IScore
|
||||||
|
{
|
||||||
|
CGameContext *GameServer() { return m_pGameServer; }
|
||||||
|
IServer *Server() { return m_pServer; }
|
||||||
|
|
||||||
|
CGameContext *m_pGameServer;
|
||||||
|
IServer *m_pServer;
|
||||||
|
|
||||||
|
static void ExecSqlFunc(void *pUser);
|
||||||
|
|
||||||
|
static bool Init(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure);
|
||||||
|
|
||||||
|
char m_aMap[64];
|
||||||
|
|
||||||
|
static bool MapInfoThread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
static bool MapVoteThread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
static bool LoadScoreThread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
static bool SaveScoreThread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
static bool SaveTeamScoreThread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
static bool ShowRankThread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
static bool ShowTop5Thread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
static bool ShowTeamRankThread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
static bool ShowTeamTop5Thread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
static bool ShowTimesThread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
static bool ShowPointsThread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
static bool ShowTopPointsThread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
static bool RandomMapThread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
static bool RandomUnfinishedMapThread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
static bool SaveTeamThread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
static bool LoadTeamThread(CSqlServer* pSqlServer, CSqlData *pGameData, bool HandleFailure = false);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
CSqlScore(CGameContext *pGameServer);
|
||||||
|
|
||||||
|
virtual void LoadScore(int ClientID);
|
||||||
|
virtual void MapInfo(int ClientID, const char* MapName);
|
||||||
|
virtual void MapVote(int ClientID, const char* MapName);
|
||||||
|
virtual void SaveScore(int ClientID, float Time,
|
||||||
|
float CpTime[NUM_CHECKPOINTS]);
|
||||||
|
virtual void SaveTeamScore(int* aClientIDs, unsigned int Size, float Time);
|
||||||
|
virtual void ShowRank(int ClientID, const char* pName, bool Search = false);
|
||||||
|
virtual void ShowTeamRank(int ClientID, const char* pName, bool Search = false);
|
||||||
|
virtual void ShowTimes(int ClientID, const char* pName, int Debut = 1);
|
||||||
|
virtual void ShowTimes(int ClientID, int Debut = 1);
|
||||||
|
virtual void ShowTop5(IConsole::IResult *pResult, int ClientID,
|
||||||
|
void *pUserData, int Debut = 1);
|
||||||
|
virtual void ShowTeamTop5(IConsole::IResult *pResult, int ClientID,
|
||||||
|
void *pUserData, int Debut = 1);
|
||||||
|
virtual void ShowPoints(int ClientID, const char* pName, bool Search = false);
|
||||||
|
virtual void ShowTopPoints(IConsole::IResult *pResult, int ClientID,
|
||||||
|
void *pUserData, int Debut = 1);
|
||||||
|
virtual void RandomMap(int ClientID, int stars);
|
||||||
|
virtual void RandomUnfinishedMap(int ClientID, int stars);
|
||||||
|
virtual void SaveTeam(int Team, const char* Code, int ClientID, const char* Server);
|
||||||
|
virtual void LoadTeam(const char* Code, int ClientID);
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue