started with sqlmasters

+ added #ifdef for sql_server.cpp
(fixes compilation for release mode)
This commit is contained in:
H-M-H 2015-11-23 16:25:19 +01:00
parent 66bec0c712
commit 5e4456584f
4 changed files with 37 additions and 31 deletions

View file

@ -20,6 +20,8 @@ CGameContext *CSqlData::ms_pGameServer = 0;
IServer *CSqlData::ms_pServer = 0; IServer *CSqlData::ms_pServer = 0;
CPlayerData *CSqlData::ms_pPlayerData = 0; CPlayerData *CSqlData::ms_pPlayerData = 0;
const char *CSqlData::ms_pMap = 0; const char *CSqlData::ms_pMap = 0;
CSqlServer *CSqlData::ms_pSqlServer = 0;
CSqlServer **CSqlData::ms_pMasterSqlServers = 0;
CSqlScore::CSqlScore(CGameContext *pGameServer) : m_pGameServer(pGameServer), CSqlScore::CSqlScore(CGameContext *pGameServer) : m_pGameServer(pGameServer),
m_pServer(pGameServer->Server()), m_pServer(pGameServer->Server()),
@ -32,6 +34,8 @@ CSqlScore::CSqlScore(CGameContext *pGameServer) : m_pGameServer(pGameServer),
CSqlData::ms_pServer = m_pServer; CSqlData::ms_pServer = m_pServer;
CSqlData::ms_pPlayerData = PlayerData(0); CSqlData::ms_pPlayerData = PlayerData(0);
CSqlData::ms_pMap = m_aMap; CSqlData::ms_pMap = m_aMap;
CSqlData::ms_pSqlServer = &m_SqlServer;
CSqlData::ms_pMasterSqlServers = m_apMasterSqlServers;
if(gs_SqlLock == 0) if(gs_SqlLock == 0)
gs_SqlLock = lock_create(); gs_SqlLock = lock_create();
@ -142,7 +146,7 @@ void CSqlScore::LoadScoreThread(void *pUser)
void CSqlScore::LoadScore(int ClientID) void CSqlScore::LoadScore(int ClientID)
{ {
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer); CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;
str_copy(Tmp->m_aName, Server()->ClientName(ClientID), MAX_NAME_LENGTH); str_copy(Tmp->m_aName, Server()->ClientName(ClientID), MAX_NAME_LENGTH);
@ -273,7 +277,7 @@ void CSqlScore::SaveTeamScoreThread(void *pUser)
void CSqlScore::MapVote(int ClientID, const char* MapName) void CSqlScore::MapVote(int ClientID, const char* MapName)
{ {
CSqlMapData *Tmp = new CSqlMapData(&m_SqlServer); CSqlMapData *Tmp = new CSqlMapData();
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;
str_copy(Tmp->m_aMap, MapName, 128); str_copy(Tmp->m_aMap, MapName, 128);
@ -370,7 +374,7 @@ void CSqlScore::MapVoteThread(void *pUser)
void CSqlScore::MapInfo(int ClientID, const char* MapName) void CSqlScore::MapInfo(int ClientID, const char* MapName)
{ {
CSqlMapData *Tmp = new CSqlMapData(&m_SqlServer); CSqlMapData *Tmp = new CSqlMapData();
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;
str_copy(Tmp->m_aMap, MapName, 128); str_copy(Tmp->m_aMap, MapName, 128);
@ -534,7 +538,7 @@ void CSqlScore::SaveScore(int ClientID, float Time, float CpTime[NUM_CHECKPOINTS
CConsole* pCon = (CConsole*)GameServer()->Console(); CConsole* pCon = (CConsole*)GameServer()->Console();
if(pCon->m_Cheated) if(pCon->m_Cheated)
return; return;
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer); CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;
str_copy(Tmp->m_aName, Server()->ClientName(ClientID), MAX_NAME_LENGTH); str_copy(Tmp->m_aName, Server()->ClientName(ClientID), MAX_NAME_LENGTH);
Tmp->m_Time = Time; Tmp->m_Time = Time;
@ -550,7 +554,7 @@ void CSqlScore::SaveTeamScore(int* aClientIDs, unsigned int Size, float Time)
CConsole* pCon = (CConsole*)GameServer()->Console(); CConsole* pCon = (CConsole*)GameServer()->Console();
if(pCon->m_Cheated) if(pCon->m_Cheated)
return; return;
CSqlTeamScoreData *Tmp = new CSqlTeamScoreData(&m_SqlServer); CSqlTeamScoreData *Tmp = new CSqlTeamScoreData();
for(unsigned int i = 0; i < Size; i++) for(unsigned int i = 0; i < Size; i++)
{ {
Tmp->m_aClientIDs[i] = aClientIDs[i]; Tmp->m_aClientIDs[i] = aClientIDs[i];
@ -810,7 +814,7 @@ void CSqlScore::ShowRankThread(void *pUser)
void CSqlScore::ShowTeamRank(int ClientID, const char* pName, bool Search) void CSqlScore::ShowTeamRank(int ClientID, const char* pName, bool Search)
{ {
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer); CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;
str_copy(Tmp->m_aName, pName, MAX_NAME_LENGTH); str_copy(Tmp->m_aName, pName, MAX_NAME_LENGTH);
Tmp->m_Search = Search; Tmp->m_Search = Search;
@ -822,7 +826,7 @@ void CSqlScore::ShowTeamRank(int ClientID, const char* pName, bool Search)
void CSqlScore::ShowRank(int ClientID, const char* pName, bool Search) void CSqlScore::ShowRank(int ClientID, const char* pName, bool Search)
{ {
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer); CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;
str_copy(Tmp->m_aName, pName, MAX_NAME_LENGTH); str_copy(Tmp->m_aName, pName, MAX_NAME_LENGTH);
Tmp->m_Search = Search; Tmp->m_Search = Search;
@ -969,7 +973,7 @@ void CSqlScore::ShowTimesThread(void *pUser)
void CSqlScore::ShowTeamTop5(IConsole::IResult *pResult, int ClientID, void *pUserData, int Debut) void CSqlScore::ShowTeamTop5(IConsole::IResult *pResult, int ClientID, void *pUserData, int Debut)
{ {
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer); CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_Num = Debut; Tmp->m_Num = Debut;
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;
@ -979,7 +983,7 @@ void CSqlScore::ShowTeamTop5(IConsole::IResult *pResult, int ClientID, void *pUs
void CSqlScore::ShowTop5(IConsole::IResult *pResult, int ClientID, void *pUserData, int Debut) void CSqlScore::ShowTop5(IConsole::IResult *pResult, int ClientID, void *pUserData, int Debut)
{ {
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer); CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_Num = Debut; Tmp->m_Num = Debut;
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;
@ -989,7 +993,7 @@ void CSqlScore::ShowTop5(IConsole::IResult *pResult, int ClientID, void *pUserDa
void CSqlScore::ShowTimes(int ClientID, int Debut) void CSqlScore::ShowTimes(int ClientID, int Debut)
{ {
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer); CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_Num = Debut; Tmp->m_Num = Debut;
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;
Tmp->m_Search = false; Tmp->m_Search = false;
@ -1000,7 +1004,7 @@ void CSqlScore::ShowTimes(int ClientID, int Debut)
void CSqlScore::ShowTimes(int ClientID, const char* pName, int Debut) void CSqlScore::ShowTimes(int ClientID, const char* pName, int Debut)
{ {
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer); CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_Num = Debut; Tmp->m_Num = Debut;
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;
str_copy(Tmp->m_aName, pName, MAX_NAME_LENGTH); str_copy(Tmp->m_aName, pName, MAX_NAME_LENGTH);
@ -1069,7 +1073,7 @@ void CSqlScore::ShowPointsThread(void *pUser)
void CSqlScore::ShowPoints(int ClientID, const char* pName, bool Search) void CSqlScore::ShowPoints(int ClientID, const char* pName, bool Search)
{ {
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer); CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;
str_copy(Tmp->m_aName, pName, MAX_NAME_LENGTH); str_copy(Tmp->m_aName, pName, MAX_NAME_LENGTH);
Tmp->m_Search = Search; Tmp->m_Search = Search;
@ -1129,7 +1133,7 @@ void CSqlScore::ShowTopPointsThread(void *pUser)
void CSqlScore::ShowTopPoints(IConsole::IResult *pResult, int ClientID, void *pUserData, int Debut) void CSqlScore::ShowTopPoints(IConsole::IResult *pResult, int ClientID, void *pUserData, int Debut)
{ {
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer); CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_Num = Debut; Tmp->m_Num = Debut;
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;
@ -1245,7 +1249,7 @@ void CSqlScore::RandomUnfinishedMapThread(void *pUser)
void CSqlScore::RandomMap(int ClientID, int stars) void CSqlScore::RandomMap(int ClientID, int stars)
{ {
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer); CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_Num = stars; Tmp->m_Num = stars;
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;
str_copy(Tmp->m_aName, GameServer()->Server()->ClientName(ClientID), MAX_NAME_LENGTH); str_copy(Tmp->m_aName, GameServer()->Server()->ClientName(ClientID), MAX_NAME_LENGTH);
@ -1256,7 +1260,7 @@ void CSqlScore::RandomMap(int ClientID, int stars)
void CSqlScore::RandomUnfinishedMap(int ClientID, int stars) void CSqlScore::RandomUnfinishedMap(int ClientID, int stars)
{ {
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer); CSqlScoreData *Tmp = new CSqlScoreData();
Tmp->m_Num = stars; Tmp->m_Num = stars;
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;
str_copy(Tmp->m_aName, GameServer()->Server()->ClientName(ClientID), MAX_NAME_LENGTH); str_copy(Tmp->m_aName, GameServer()->Server()->ClientName(ClientID), MAX_NAME_LENGTH);
@ -1279,7 +1283,7 @@ void CSqlScore::SaveTeam(int Team, const char* Code, int ClientID, const char* S
return; return;
} }
CSqlTeamSave *Tmp = new CSqlTeamSave(&m_SqlServer); CSqlTeamSave *Tmp = new CSqlTeamSave();
Tmp->m_Team = Team; Tmp->m_Team = Team;
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;
str_copy(Tmp->m_Code, Code, 32); str_copy(Tmp->m_Code, Code, 32);
@ -1390,7 +1394,7 @@ void CSqlScore::SaveTeamThread(void *pUser)
void CSqlScore::LoadTeam(const char* Code, int ClientID) void CSqlScore::LoadTeam(const char* Code, int ClientID)
{ {
CSqlTeamLoad *Tmp = new CSqlTeamLoad(&m_SqlServer); CSqlTeamLoad *Tmp = new CSqlTeamLoad();
str_copy(Tmp->m_Code, Code, 32); str_copy(Tmp->m_Code, Code, 32);
Tmp->m_ClientID = ClientID; Tmp->m_ClientID = ClientID;

View file

@ -7,6 +7,10 @@
#include "sqlserver.h" #include "sqlserver.h"
#include "../score.h" #include "../score.h"
enum
{
MAX_SQLMASTERS=10
};
class CSqlScore: public IScore class CSqlScore: public IScore
{ {
@ -20,6 +24,7 @@ class CSqlScore: public IScore
IServer *m_pServer; IServer *m_pServer;
CSqlServer m_SqlServer; CSqlServer m_SqlServer;
CSqlServer* m_apMasterSqlServers[MAX_SQLMASTERS];
char m_aMap[64]; char m_aMap[64];
@ -71,7 +76,7 @@ public:
// generic implementation to provide sqlserver, gameserver and server // generic implementation to provide sqlserver, gameserver and server
struct CSqlData struct CSqlData
{ {
CSqlData(CSqlServer* pSqlServer) : m_pSqlServer(pSqlServer) {} CSqlData() : m_pSqlServer(ms_pSqlServer) {}
CGameContext* GameServer() { return ms_pGameServer; } CGameContext* GameServer() { return ms_pGameServer; }
IServer* Server() { return ms_pServer; } IServer* Server() { return ms_pServer; }
@ -83,21 +88,20 @@ struct CSqlData
static IServer *ms_pServer; static IServer *ms_pServer;
static CPlayerData *ms_pPlayerData; static CPlayerData *ms_pPlayerData;
static const char *ms_pMap; static const char *ms_pMap;
static CSqlServer *ms_pSqlServer;
static CSqlServer **ms_pMasterSqlServers;
CSqlServer *m_pSqlServer; CSqlServer *m_pSqlServer;
}; };
struct CSqlMapData : CSqlData struct CSqlMapData : CSqlData
{ {
CSqlMapData(CSqlServer* pSqlServer) : CSqlData(pSqlServer) {}
int m_ClientID; int m_ClientID;
char m_aMap[128]; char m_aMap[128];
}; };
struct CSqlScoreData : CSqlData struct CSqlScoreData : CSqlData
{ {
CSqlScoreData(CSqlServer* pSqlServer) : CSqlData(pSqlServer) {}
int m_ClientID; int m_ClientID;
#if defined(CONF_FAMILY_WINDOWS) #if defined(CONF_FAMILY_WINDOWS)
char m_aName[16]; // Don't edit this, or all your teeth will fall http://bugs.mysql.com/bug.php?id=50046 char m_aName[16]; // Don't edit this, or all your teeth will fall http://bugs.mysql.com/bug.php?id=50046
@ -114,8 +118,6 @@ struct CSqlScoreData : CSqlData
struct CSqlTeamScoreData : CSqlData struct CSqlTeamScoreData : CSqlData
{ {
CSqlTeamScoreData(CSqlServer* pSqlServer) : CSqlData(pSqlServer) {}
unsigned int m_Size; unsigned int m_Size;
int m_aClientIDs[MAX_CLIENTS]; int m_aClientIDs[MAX_CLIENTS];
#if defined(CONF_FAMILY_WINDOWS) #if defined(CONF_FAMILY_WINDOWS)
@ -133,8 +135,6 @@ struct CSqlTeamScoreData : CSqlData
struct CSqlTeamSave : CSqlData struct CSqlTeamSave : CSqlData
{ {
CSqlTeamSave(CSqlServer* pSqlServer) : CSqlData(pSqlServer) {}
int m_Team; int m_Team;
int m_ClientID; int m_ClientID;
char m_Code[128]; char m_Code[128];
@ -143,8 +143,6 @@ struct CSqlTeamSave : CSqlData
struct CSqlTeamLoad : CSqlData struct CSqlTeamLoad : CSqlData
{ {
CSqlTeamLoad(CSqlServer* pSqlServer) : CSqlData(pSqlServer) {}
char m_Code[128]; char m_Code[128];
int m_ClientID; int m_ClientID;
}; };

View file

@ -1,8 +1,10 @@
#if defined(CONF_SQL)
#include <base/system.h> #include <base/system.h>
#include <engine/shared/protocol.h> #include <engine/shared/protocol.h>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include "sqlserver.h" #include "sql_server.h"
CSqlServer::CSqlServer(const char* pDatabase, const char* pPrefix, const char* pUser, const char* pPass, const char* pIp, int Port) : CSqlServer::CSqlServer(const char* pDatabase, const char* pPrefix, const char* pUser, const char* pPass, const char* pIp, int Port) :
@ -192,3 +194,5 @@ const char* CSqlServer::GetPrefix()
{ {
return m_pPrefix; return m_pPrefix;
} }
#endif

View file

@ -1,5 +1,5 @@
#ifndef GAME_SERVER_SQLSERVER_H #ifndef GAME_SERVER_SQL_SERVER_H
#define GAME_SERVER_SQLSERVER_H #define GAME_SERVER_SQL_SERVER_H
#include <mysql_connection.h> #include <mysql_connection.h>