mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 18:18:18 +00:00
started with sqlmasters
+ added #ifdef for sql_server.cpp (fixes compilation for release mode)
This commit is contained in:
parent
66bec0c712
commit
5e4456584f
|
@ -20,6 +20,8 @@ CGameContext *CSqlData::ms_pGameServer = 0;
|
|||
IServer *CSqlData::ms_pServer = 0;
|
||||
CPlayerData *CSqlData::ms_pPlayerData = 0;
|
||||
const char *CSqlData::ms_pMap = 0;
|
||||
CSqlServer *CSqlData::ms_pSqlServer = 0;
|
||||
CSqlServer **CSqlData::ms_pMasterSqlServers = 0;
|
||||
|
||||
CSqlScore::CSqlScore(CGameContext *pGameServer) : m_pGameServer(pGameServer),
|
||||
m_pServer(pGameServer->Server()),
|
||||
|
@ -32,6 +34,8 @@ CSqlScore::CSqlScore(CGameContext *pGameServer) : m_pGameServer(pGameServer),
|
|||
CSqlData::ms_pServer = m_pServer;
|
||||
CSqlData::ms_pPlayerData = PlayerData(0);
|
||||
CSqlData::ms_pMap = m_aMap;
|
||||
CSqlData::ms_pSqlServer = &m_SqlServer;
|
||||
CSqlData::ms_pMasterSqlServers = m_apMasterSqlServers;
|
||||
|
||||
if(gs_SqlLock == 0)
|
||||
gs_SqlLock = lock_create();
|
||||
|
@ -142,7 +146,7 @@ void CSqlScore::LoadScoreThread(void *pUser)
|
|||
|
||||
void CSqlScore::LoadScore(int ClientID)
|
||||
{
|
||||
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer);
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_ClientID = ClientID;
|
||||
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)
|
||||
{
|
||||
CSqlMapData *Tmp = new CSqlMapData(&m_SqlServer);
|
||||
CSqlMapData *Tmp = new CSqlMapData();
|
||||
Tmp->m_ClientID = ClientID;
|
||||
str_copy(Tmp->m_aMap, MapName, 128);
|
||||
|
||||
|
@ -370,7 +374,7 @@ void CSqlScore::MapVoteThread(void *pUser)
|
|||
|
||||
void CSqlScore::MapInfo(int ClientID, const char* MapName)
|
||||
{
|
||||
CSqlMapData *Tmp = new CSqlMapData(&m_SqlServer);
|
||||
CSqlMapData *Tmp = new CSqlMapData();
|
||||
Tmp->m_ClientID = ClientID;
|
||||
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();
|
||||
if(pCon->m_Cheated)
|
||||
return;
|
||||
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer);
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_ClientID = ClientID;
|
||||
str_copy(Tmp->m_aName, Server()->ClientName(ClientID), MAX_NAME_LENGTH);
|
||||
Tmp->m_Time = Time;
|
||||
|
@ -550,7 +554,7 @@ void CSqlScore::SaveTeamScore(int* aClientIDs, unsigned int Size, float Time)
|
|||
CConsole* pCon = (CConsole*)GameServer()->Console();
|
||||
if(pCon->m_Cheated)
|
||||
return;
|
||||
CSqlTeamScoreData *Tmp = new CSqlTeamScoreData(&m_SqlServer);
|
||||
CSqlTeamScoreData *Tmp = new CSqlTeamScoreData();
|
||||
for(unsigned int i = 0; i < Size; 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)
|
||||
{
|
||||
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer);
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_ClientID = ClientID;
|
||||
str_copy(Tmp->m_aName, pName, MAX_NAME_LENGTH);
|
||||
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)
|
||||
{
|
||||
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer);
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_ClientID = ClientID;
|
||||
str_copy(Tmp->m_aName, pName, MAX_NAME_LENGTH);
|
||||
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)
|
||||
{
|
||||
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer);
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_Num = Debut;
|
||||
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)
|
||||
{
|
||||
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer);
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_Num = Debut;
|
||||
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)
|
||||
{
|
||||
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer);
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_Num = Debut;
|
||||
Tmp->m_ClientID = ClientID;
|
||||
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)
|
||||
{
|
||||
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer);
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_Num = Debut;
|
||||
Tmp->m_ClientID = ClientID;
|
||||
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)
|
||||
{
|
||||
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer);
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_ClientID = ClientID;
|
||||
str_copy(Tmp->m_aName, pName, MAX_NAME_LENGTH);
|
||||
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)
|
||||
{
|
||||
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer);
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_Num = Debut;
|
||||
Tmp->m_ClientID = ClientID;
|
||||
|
||||
|
@ -1245,7 +1249,7 @@ void CSqlScore::RandomUnfinishedMapThread(void *pUser)
|
|||
|
||||
void CSqlScore::RandomMap(int ClientID, int stars)
|
||||
{
|
||||
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer);
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_Num = stars;
|
||||
Tmp->m_ClientID = ClientID;
|
||||
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)
|
||||
{
|
||||
CSqlScoreData *Tmp = new CSqlScoreData(&m_SqlServer);
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_Num = stars;
|
||||
Tmp->m_ClientID = ClientID;
|
||||
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;
|
||||
}
|
||||
|
||||
CSqlTeamSave *Tmp = new CSqlTeamSave(&m_SqlServer);
|
||||
CSqlTeamSave *Tmp = new CSqlTeamSave();
|
||||
Tmp->m_Team = Team;
|
||||
Tmp->m_ClientID = ClientID;
|
||||
str_copy(Tmp->m_Code, Code, 32);
|
||||
|
@ -1390,7 +1394,7 @@ void CSqlScore::SaveTeamThread(void *pUser)
|
|||
|
||||
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);
|
||||
Tmp->m_ClientID = ClientID;
|
||||
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
#include "sqlserver.h"
|
||||
#include "../score.h"
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_SQLMASTERS=10
|
||||
};
|
||||
|
||||
class CSqlScore: public IScore
|
||||
{
|
||||
|
@ -20,6 +24,7 @@ class CSqlScore: public IScore
|
|||
IServer *m_pServer;
|
||||
|
||||
CSqlServer m_SqlServer;
|
||||
CSqlServer* m_apMasterSqlServers[MAX_SQLMASTERS];
|
||||
|
||||
char m_aMap[64];
|
||||
|
||||
|
@ -71,7 +76,7 @@ public:
|
|||
// generic implementation to provide sqlserver, gameserver and server
|
||||
struct CSqlData
|
||||
{
|
||||
CSqlData(CSqlServer* pSqlServer) : m_pSqlServer(pSqlServer) {}
|
||||
CSqlData() : m_pSqlServer(ms_pSqlServer) {}
|
||||
|
||||
CGameContext* GameServer() { return ms_pGameServer; }
|
||||
IServer* Server() { return ms_pServer; }
|
||||
|
@ -83,21 +88,20 @@ struct CSqlData
|
|||
static IServer *ms_pServer;
|
||||
static CPlayerData *ms_pPlayerData;
|
||||
static const char *ms_pMap;
|
||||
static CSqlServer *ms_pSqlServer;
|
||||
static CSqlServer **ms_pMasterSqlServers;
|
||||
|
||||
CSqlServer *m_pSqlServer;
|
||||
};
|
||||
|
||||
struct CSqlMapData : CSqlData
|
||||
{
|
||||
CSqlMapData(CSqlServer* pSqlServer) : CSqlData(pSqlServer) {}
|
||||
|
||||
int m_ClientID;
|
||||
char m_aMap[128];
|
||||
};
|
||||
|
||||
struct CSqlScoreData : CSqlData
|
||||
{
|
||||
CSqlScoreData(CSqlServer* pSqlServer) : CSqlData(pSqlServer) {}
|
||||
|
||||
int m_ClientID;
|
||||
#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
|
||||
|
@ -114,8 +118,6 @@ struct CSqlScoreData : CSqlData
|
|||
|
||||
struct CSqlTeamScoreData : CSqlData
|
||||
{
|
||||
CSqlTeamScoreData(CSqlServer* pSqlServer) : CSqlData(pSqlServer) {}
|
||||
|
||||
unsigned int m_Size;
|
||||
int m_aClientIDs[MAX_CLIENTS];
|
||||
#if defined(CONF_FAMILY_WINDOWS)
|
||||
|
@ -133,8 +135,6 @@ struct CSqlTeamScoreData : CSqlData
|
|||
|
||||
struct CSqlTeamSave : CSqlData
|
||||
{
|
||||
CSqlTeamSave(CSqlServer* pSqlServer) : CSqlData(pSqlServer) {}
|
||||
|
||||
int m_Team;
|
||||
int m_ClientID;
|
||||
char m_Code[128];
|
||||
|
@ -143,8 +143,6 @@ struct CSqlTeamSave : CSqlData
|
|||
|
||||
struct CSqlTeamLoad : CSqlData
|
||||
{
|
||||
CSqlTeamLoad(CSqlServer* pSqlServer) : CSqlData(pSqlServer) {}
|
||||
|
||||
char m_Code[128];
|
||||
int m_ClientID;
|
||||
};
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#if defined(CONF_SQL)
|
||||
|
||||
#include <base/system.h>
|
||||
#include <engine/shared/protocol.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) :
|
||||
|
@ -192,3 +194,5 @@ const char* CSqlServer::GetPrefix()
|
|||
{
|
||||
return m_pPrefix;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef GAME_SERVER_SQLSERVER_H
|
||||
#define GAME_SERVER_SQLSERVER_H
|
||||
#ifndef GAME_SERVER_SQL_SERVER_H
|
||||
#define GAME_SERVER_SQL_SERVER_H
|
||||
|
||||
#include <mysql_connection.h>
|
||||
|
Loading…
Reference in a new issue