mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Total IP Scoring Annihilation ( doesn't make sense ), please test this, also delete the old records
This commit is contained in:
parent
8ac101d60e
commit
3756c98715
|
@ -122,7 +122,6 @@ MACRO_CONFIG_INT(SvSuicidePenalty, sv_suicide_penalty,0,0,9999,CFGFLAG_SERVER, "
|
|||
MACRO_CONFIG_INT(SvVotePercentage, sv_vote_percentage, 50, 1, 100, CFGFLAG_SERVER, "The percent of people that need to agree or deny for the vote to succeed/fail", 3)
|
||||
MACRO_CONFIG_INT(SvShotgunBulletSound, sv_shotgun_bullet_sound, 0, 0, 1, CFGFLAG_SERVER, "Crazy shotgun bullet sound on/off", 3)
|
||||
|
||||
MACRO_CONFIG_INT(SvScoreIP, sv_score_ip, 0, 0, 0, CFGFLAG_SERVER, "Wheather to save also the IP in the score file", 3)
|
||||
MACRO_CONFIG_INT(SvCheckpointSave, sv_checkpoint_save, 1, 0, 1, CFGFLAG_SERVER, "Whether to save checkpoint times to the score file", 3)
|
||||
MACRO_CONFIG_STR(SvScoreFolder, sv_score_folder, 32, "records", CFGFLAG_SERVER, "Folder to save score files to", 3)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "entities/character.h"
|
||||
#include "gamecontext.h"
|
||||
|
||||
#define NUM_TELEPORT 25
|
||||
#define NUM_CHECKPOINTS 25
|
||||
|
||||
class CPlayerData
|
||||
{
|
||||
|
@ -18,20 +18,20 @@ public:
|
|||
{
|
||||
m_BestTime = 0;
|
||||
m_CurrentTime = 0;
|
||||
for(int i = 0; i < NUM_TELEPORT; i++)
|
||||
for(int i = 0; i < NUM_CHECKPOINTS; i++)
|
||||
m_aBestCpTime[i] = 0;
|
||||
}
|
||||
|
||||
void Set(float Time, float CpTime[NUM_TELEPORT])
|
||||
void Set(float Time, float CpTime[NUM_CHECKPOINTS])
|
||||
{
|
||||
m_BestTime = Time;
|
||||
for(int i = 0; i < NUM_TELEPORT; i++)
|
||||
for(int i = 0; i < NUM_CHECKPOINTS; i++)
|
||||
m_aBestCpTime[i] = CpTime[i];
|
||||
}
|
||||
|
||||
float m_BestTime;
|
||||
float m_CurrentTime;
|
||||
float m_aBestCpTime[NUM_TELEPORT];
|
||||
float m_aBestCpTime[NUM_CHECKPOINTS];
|
||||
};
|
||||
|
||||
class IScore
|
||||
|
|
|
@ -9,12 +9,11 @@
|
|||
|
||||
static LOCK gs_ScoreLock = 0;
|
||||
|
||||
CFileScore::CPlayerScore::CPlayerScore(const char *pName, float Score, const char *pIP, float aCpTime[NUM_TELEPORT])
|
||||
CFileScore::CPlayerScore::CPlayerScore(const char *pName, float Score, float aCpTime[NUM_CHECKPOINTS])
|
||||
{
|
||||
str_copy(m_aName, pName, sizeof(m_aName));
|
||||
m_Score = Score;
|
||||
str_copy(m_aIP, pIP, sizeof(m_aIP));
|
||||
for(int i = 0; i < NUM_TELEPORT; i++)
|
||||
for(int i = 0; i < NUM_CHECKPOINTS; i++)
|
||||
m_aCpTime[i] = aCpTime[i];
|
||||
}
|
||||
|
||||
|
@ -57,10 +56,10 @@ void CFileScore::SaveScoreThread(void *pUser)
|
|||
int t = 0;
|
||||
for(sorted_array<CPlayerScore>::range r = pSelf->m_Top.all(); !r.empty(); r.pop_front())
|
||||
{
|
||||
f << r.front().m_aName << std::endl << r.front().m_Score << std::endl << r.front().m_aIP << std::endl;
|
||||
f << r.front().m_aName << std::endl << r.front().m_Score << std::endl;
|
||||
if(g_Config.m_SvCheckpointSave)
|
||||
{
|
||||
for(int c = 0; c < NUM_TELEPORT; c++)
|
||||
for(int c = 0; c < NUM_CHECKPOINTS; c++)
|
||||
f << r.front().m_aCpTime[c] << " ";
|
||||
f << std::endl;
|
||||
}
|
||||
|
@ -94,26 +93,25 @@ void CFileScore::Init()
|
|||
|
||||
while(!f.eof() && !f.fail())
|
||||
{
|
||||
std::string TmpName, TmpScore, TmpIP, TmpCpLine;
|
||||
std::string TmpName, TmpScore, TmpCpLine;
|
||||
std::getline(f, TmpName);
|
||||
if(!f.eof() && TmpName != "")
|
||||
{
|
||||
std::getline(f, TmpScore);
|
||||
std::getline(f, TmpIP);
|
||||
float aTmpCpTime[NUM_TELEPORT] = {0};
|
||||
float aTmpCpTime[NUM_CHECKPOINTS] = {0};
|
||||
if(g_Config.m_SvCheckpointSave)
|
||||
{
|
||||
std::getline(f, TmpCpLine);
|
||||
char *pTime = strtok((char*)TmpCpLine.c_str(), " ");
|
||||
int i = 0;
|
||||
while(pTime != NULL && i < NUM_TELEPORT)
|
||||
while(pTime != NULL && i < NUM_CHECKPOINTS)
|
||||
{
|
||||
aTmpCpTime[i] = atof(pTime);
|
||||
pTime = strtok(NULL, " ");
|
||||
i++;
|
||||
}
|
||||
}
|
||||
m_Top.add(*new CPlayerScore(TmpName.c_str(), atof(TmpScore.c_str()), TmpIP.c_str(), aTmpCpTime));
|
||||
m_Top.add(*new CPlayerScore(TmpName.c_str(), atof(TmpScore.c_str()), aTmpCpTime));
|
||||
}
|
||||
}
|
||||
f.close();
|
||||
|
@ -124,26 +122,6 @@ void CFileScore::Init()
|
|||
((CGameControllerDDRace*)GameServer()->m_pController)->m_CurrentRecord = m_Top[0].m_Score;
|
||||
}
|
||||
|
||||
CFileScore::CPlayerScore *CFileScore::SearchScore(int ID, bool ScoreIP, int *pPosition)
|
||||
{
|
||||
char aIP[16];
|
||||
Server()->GetClientIP(ID, aIP, sizeof(aIP));
|
||||
|
||||
int Pos = 1;
|
||||
for(sorted_array<CPlayerScore>::range r = m_Top.all(); !r.empty(); r.pop_front())
|
||||
{
|
||||
if(!strcmp(r.front().m_aIP, aIP) && g_Config.m_SvScoreIP && ScoreIP)
|
||||
{
|
||||
if(pPosition)
|
||||
*pPosition = Pos;
|
||||
return &r.front();
|
||||
}
|
||||
Pos++;
|
||||
}
|
||||
|
||||
return SearchName(Server()->ClientName(ID), pPosition, 0);
|
||||
}
|
||||
|
||||
CFileScore::CPlayerScore *CFileScore::SearchName(const char *pName, int *pPosition, bool NoCase)
|
||||
{
|
||||
CPlayerScore *pPlayer = 0;
|
||||
|
@ -174,18 +152,16 @@ CFileScore::CPlayerScore *CFileScore::SearchName(const char *pName, int *pPositi
|
|||
return pPlayer;
|
||||
}
|
||||
|
||||
void CFileScore::UpdatePlayer(int ID, float Score, float aCpTime[NUM_TELEPORT])
|
||||
void CFileScore::UpdatePlayer(int ID, float Score, float aCpTime[NUM_CHECKPOINTS])
|
||||
{
|
||||
const char *pName = Server()->ClientName(ID);
|
||||
char aIP[16];
|
||||
Server()->GetClientIP(ID, aIP, sizeof(aIP));
|
||||
|
||||
lock_wait(gs_ScoreLock);
|
||||
CPlayerScore *pPlayer = SearchScore(ID, 1, 0);
|
||||
CPlayerScore *pPlayer = SearchScore(ID, 0);
|
||||
|
||||
if(pPlayer)
|
||||
{
|
||||
for(int c = 0; c < NUM_TELEPORT; c++)
|
||||
for(int c = 0; c < NUM_CHECKPOINTS; c++)
|
||||
pPlayer->m_aCpTime[c] = aCpTime[c];
|
||||
|
||||
pPlayer->m_Score = Score;
|
||||
|
@ -194,7 +170,7 @@ void CFileScore::UpdatePlayer(int ID, float Score, float aCpTime[NUM_TELEPORT])
|
|||
sort(m_Top.all());
|
||||
}
|
||||
else
|
||||
m_Top.add(*new CPlayerScore(pName, Score, aIP, aCpTime));
|
||||
m_Top.add(*new CPlayerScore(pName, Score, aCpTime));
|
||||
|
||||
lock_release(gs_ScoreLock);
|
||||
Save();
|
||||
|
@ -202,13 +178,10 @@ void CFileScore::UpdatePlayer(int ID, float Score, float aCpTime[NUM_TELEPORT])
|
|||
|
||||
void CFileScore::LoadScore(int ClientID)
|
||||
{
|
||||
char aIP[16];
|
||||
Server()->GetClientIP(ClientID, aIP, sizeof(aIP));
|
||||
CPlayerScore *pPlayer = SearchScore(ClientID, 0, 0);
|
||||
if(pPlayer && strcmp(pPlayer->m_aIP, aIP) != 0)
|
||||
CPlayerScore *pPlayer = SearchScore(ClientID, 0);
|
||||
if(pPlayer)
|
||||
{
|
||||
lock_wait(gs_ScoreLock);
|
||||
str_copy(pPlayer->m_aIP, aIP, sizeof(pPlayer->m_aIP));
|
||||
lock_release(gs_ScoreLock);
|
||||
Save();
|
||||
}
|
||||
|
@ -246,7 +219,7 @@ void CFileScore::ShowRank(int ClientID, const char* pName, bool Search)
|
|||
char aBuf[512];
|
||||
|
||||
if(!Search)
|
||||
pScore = SearchScore(ClientID, 1, &Pos);
|
||||
pScore = SearchScore(ClientID, &Pos);
|
||||
else
|
||||
pScore = SearchName(pName, &Pos, 1);
|
||||
|
||||
|
|
|
@ -17,11 +17,10 @@ class CFileScore : public IScore
|
|||
public:
|
||||
char m_aName[MAX_NAME_LENGTH];
|
||||
float m_Score;
|
||||
char m_aIP[16];
|
||||
float m_aCpTime[NUM_TELEPORT];
|
||||
float m_aCpTime[NUM_CHECKPOINTS];
|
||||
|
||||
CPlayerScore() {};
|
||||
CPlayerScore(const char *pName, float Score, const char *pIP, float aCpTime[NUM_TELEPORT]);
|
||||
CPlayerScore(const char *pName, float Score, float aCpTime[NUM_CHECKPOINTS]);
|
||||
|
||||
bool operator<(const CPlayerScore& other) { return (this->m_Score < other.m_Score); }
|
||||
};
|
||||
|
@ -31,9 +30,10 @@ class CFileScore : public IScore
|
|||
CGameContext *GameServer() { return m_pGameServer; }
|
||||
IServer *Server() { return m_pServer; }
|
||||
|
||||
CPlayerScore *SearchScore(int ID, bool ScoreIP, int *pPosition);
|
||||
CPlayerScore *SearchScore(int ID, int *pPosition){ return SearchName(Server()->ClientName(ID), pPosition, 0 );};
|
||||
;
|
||||
CPlayerScore *SearchName(const char *pName, int *pPosition, bool MatchCase);
|
||||
void UpdatePlayer(int ID, float Score, float aCpTime[NUM_TELEPORT]);
|
||||
void UpdatePlayer(int ID, float Score, float aCpTime[NUM_CHECKPOINTS]);
|
||||
|
||||
void Init();
|
||||
void Save();
|
||||
|
|
|
@ -87,7 +87,7 @@ void CSqlScore::Init()
|
|||
{
|
||||
// create tables
|
||||
char aBuf[768];
|
||||
str_format(aBuf, sizeof(aBuf), "CREATE TABLE IF NOT EXISTS %s_%s_race (Name VARCHAR(31) NOT NULL, Time FLOAT DEFAULT 0, IP VARCHAR(16) DEFAULT '0.0.0.0', cp1 FLOAT DEFAULT 0, cp2 FLOAT DEFAULT 0, cp3 FLOAT DEFAULT 0, cp4 FLOAT DEFAULT 0, cp5 FLOAT DEFAULT 0, cp6 FLOAT DEFAULT 0, cp7 FLOAT DEFAULT 0, cp8 FLOAT DEFAULT 0, cp9 FLOAT DEFAULT 0, cp10 FLOAT DEFAULT 0, cp11 FLOAT DEFAULT 0, cp12 FLOAT DEFAULT 0, cp13 FLOAT DEFAULT 0, cp14 FLOAT DEFAULT 0, cp15 FLOAT DEFAULT 0, cp16 FLOAT DEFAULT 0, cp17 FLOAT DEFAULT 0, cp18 FLOAT DEFAULT 0, cp19 FLOAT DEFAULT 0, cp20 FLOAT DEFAULT 0, cp21 FLOAT DEFAULT 0, cp22 FLOAT DEFAULT 0, cp23 FLOAT DEFAULT 0, cp24 FLOAT DEFAULT 0, cp25 FLOAT DEFAULT 0);", m_pPrefix, m_aMap);
|
||||
str_format(aBuf, sizeof(aBuf), "CREATE TABLE IF NOT EXISTS %s_%s_race (Name VARCHAR(31) NOT NULL, Time FLOAT DEFAULT 0, cp1 FLOAT DEFAULT 0, cp2 FLOAT DEFAULT 0, cp3 FLOAT DEFAULT 0, cp4 FLOAT DEFAULT 0, cp5 FLOAT DEFAULT 0, cp6 FLOAT DEFAULT 0, cp7 FLOAT DEFAULT 0, cp8 FLOAT DEFAULT 0, cp9 FLOAT DEFAULT 0, cp10 FLOAT DEFAULT 0, cp11 FLOAT DEFAULT 0, cp12 FLOAT DEFAULT 0, cp13 FLOAT DEFAULT 0, cp14 FLOAT DEFAULT 0, cp15 FLOAT DEFAULT 0, cp16 FLOAT DEFAULT 0, cp17 FLOAT DEFAULT 0, cp18 FLOAT DEFAULT 0, cp19 FLOAT DEFAULT 0, cp20 FLOAT DEFAULT 0, cp21 FLOAT DEFAULT 0, cp22 FLOAT DEFAULT 0, cp23 FLOAT DEFAULT 0, cp24 FLOAT DEFAULT 0, cp25 FLOAT DEFAULT 0);", m_pPrefix, m_aMap);
|
||||
m_pStatement->execute(aBuf);
|
||||
dbg_msg("SQL", "Tables were created successfully");
|
||||
|
||||
|
@ -134,60 +134,18 @@ void CSqlScore::LoadScoreThread(void *pUser)
|
|||
pData->m_pSqlData->ClearString(pData->m_aName);
|
||||
|
||||
char aBuf[512];
|
||||
// check if there is an entry with the same ip
|
||||
if(g_Config.m_SvScoreIP)
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "SELECT * FROM %s_%s_race WHERE IP='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aIP);
|
||||
pData->m_pSqlData->m_pResults = pData->m_pSqlData->m_pStatement->executeQuery(aBuf);
|
||||
|
||||
if(pData->m_pSqlData->m_pResults->next())
|
||||
{
|
||||
// get the best time
|
||||
pData->m_pSqlData->PlayerData(pData->m_ClientID)->m_BestTime = (float)pData->m_pSqlData->m_pResults->getDouble("Time");
|
||||
char aColumn[8];
|
||||
for(int i = 0; i < NUM_TELEPORT; i++)
|
||||
{
|
||||
str_format(aColumn, sizeof(aColumn), "cp%d", i+1);
|
||||
pData->m_pSqlData->PlayerData(pData->m_ClientID)->m_aBestCpTime[i] = (float)pData->m_pSqlData->m_pResults->getDouble(aColumn);
|
||||
}
|
||||
|
||||
dbg_msg("SQL", "Getting best time done");
|
||||
|
||||
// delete statement and results
|
||||
delete pData->m_pSqlData->m_pStatement;
|
||||
delete pData->m_pSqlData->m_pResults;
|
||||
|
||||
// disconnect from database
|
||||
pData->m_pSqlData->Disconnect();
|
||||
|
||||
delete pData;
|
||||
|
||||
lock_release(gs_SqlLock);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
str_format(aBuf, sizeof(aBuf), "SELECT * FROM %s_%s_race WHERE Name='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aName);
|
||||
pData->m_pSqlData->m_pResults = pData->m_pSqlData->m_pStatement->executeQuery(aBuf);
|
||||
if(pData->m_pSqlData->m_pResults->next())
|
||||
{
|
||||
// check if IP differs
|
||||
const char* pIP = pData->m_pSqlData->m_pResults->getString("IP").c_str();
|
||||
if(str_comp(pIP, pData->m_aIP) != 0)
|
||||
{
|
||||
// set the new ip
|
||||
str_format(aBuf, sizeof(aBuf), "UPDATE %s_%s_race SET IP='%s' WHERE Name='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aIP, pData->m_aName);
|
||||
pData->m_pSqlData->m_pStatement->execute(aBuf);
|
||||
}
|
||||
|
||||
// get the best time
|
||||
pData->m_pSqlData->PlayerData(pData->m_ClientID)->m_BestTime = (float)pData->m_pSqlData->m_pResults->getDouble("Time");
|
||||
char aColumn[8];
|
||||
if(g_Config.m_SvCheckpointSave)
|
||||
{
|
||||
for(int i = 0; i < NUM_TELEPORT; i++)
|
||||
for(int i = 0; i < NUM_CHECKPOINTS; i++)
|
||||
{
|
||||
str_format(aColumn, sizeof(aColumn), "cp%d", i+1);
|
||||
pData->m_pSqlData->PlayerData(pData->m_ClientID)->m_aBestCpTime[i] = (float)pData->m_pSqlData->m_pResults->getDouble(aColumn);
|
||||
|
@ -220,7 +178,6 @@ void CSqlScore::LoadScore(int ClientID)
|
|||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_ClientID = ClientID;
|
||||
str_copy(Tmp->m_aName, Server()->ClientName(ClientID), sizeof(Tmp->m_aName));
|
||||
Server()->GetClientIP(ClientID, Tmp->m_aIP, sizeof(Tmp->m_aIP));
|
||||
Tmp->m_pSqlData = this;
|
||||
|
||||
void *LoadThread = thread_create(LoadScoreThread, Tmp);
|
||||
|
@ -245,21 +202,21 @@ void CSqlScore::SaveScoreThread(void *pUser)
|
|||
|
||||
char aBuf[768];
|
||||
|
||||
// fisrt check for IP
|
||||
str_format(aBuf, sizeof(aBuf), "SELECT * FROM %s_%s_race WHERE IP='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aIP);
|
||||
// fisrt check for the name
|
||||
str_format(aBuf, sizeof(aBuf), "SELECT * FROM %s_%s_race WHERE Name='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aName);
|
||||
pData->m_pSqlData->m_pResults = pData->m_pSqlData->m_pStatement->executeQuery(aBuf);
|
||||
|
||||
// if ip found...
|
||||
// if the name is found...
|
||||
if(pData->m_pSqlData->m_pResults->next())
|
||||
{
|
||||
// update time
|
||||
if(g_Config.m_SvCheckpointSave)
|
||||
str_format(aBuf, sizeof(aBuf), "UPDATE %s_%s_race SET Name='%s', Time='%.2f', cp1='%.2f', cp2='%.2f', cp3='%.2f', cp4='%.2f', cp5='%.2f', cp6='%.2f', cp7='%.2f', cp8='%.2f', cp9='%.2f', cp10='%.2f', cp11='%.2f', cp12='%.2f', cp13='%.2f', cp14='%.2f', cp15='%.2f', cp16='%.2f', cp17='%.2f', cp18='%.2f', cp19='%.2f', cp20='%.2f', cp21='%.2f', cp22='%.2f', cp23='%.2f', cp24='%.2f', cp25='%.2f' WHERE IP='%s';", 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_aIP);
|
||||
str_format(aBuf, sizeof(aBuf), "UPDATE %s_%s_race SET Time='%.2f', cp1='%.2f', cp2='%.2f', cp3='%.2f', cp4='%.2f', cp5='%.2f', cp6='%.2f', cp7='%.2f', cp8='%.2f', cp9='%.2f', cp10='%.2f', cp11='%.2f', cp12='%.2f', cp13='%.2f', cp14='%.2f', cp15='%.2f', cp16='%.2f', cp17='%.2f', cp18='%.2f', cp19='%.2f', cp20='%.2f', cp21='%.2f', cp22='%.2f', cp23='%.2f', cp24='%.2f', cp25='%.2f' WHERE Name='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, 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_aName);
|
||||
else
|
||||
str_format(aBuf, sizeof(aBuf), "UPDATE %s_%s_race SET Name='%s', Time='%.2f' WHERE IP='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_aName, pData->m_Time, pData->m_aIP);
|
||||
str_format(aBuf, sizeof(aBuf), "UPDATE %s_%s_race SET Time='%.2f' WHERE Name='%s';", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap, pData->m_Time, pData->m_aName);
|
||||
pData->m_pSqlData->m_pStatement->execute(aBuf);
|
||||
|
||||
dbg_msg("SQL", "Updateing time done");
|
||||
dbg_msg("SQL", "Updating time done");
|
||||
|
||||
// delete results statement
|
||||
delete pData->m_pSqlData->m_pResults;
|
||||
|
@ -276,10 +233,10 @@ void CSqlScore::SaveScoreThread(void *pUser)
|
|||
}
|
||||
|
||||
// if no entry found... create a new one
|
||||
str_format(aBuf, sizeof(aBuf), "INSERT IGNORE INTO %s_%s_race(Name, IP, 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', '%.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_aIP, 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]);
|
||||
str_format(aBuf, sizeof(aBuf), "INSERT IGNORE INTO %s_%s_race(Name, 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', '%.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);
|
||||
|
||||
dbg_msg("SQL", "Updateing time done");
|
||||
dbg_msg("SQL", "Updating time done");
|
||||
|
||||
// delete results statement
|
||||
delete pData->m_pSqlData->m_pResults;
|
||||
|
@ -291,7 +248,7 @@ void CSqlScore::SaveScoreThread(void *pUser)
|
|||
}
|
||||
|
||||
// disconnect from database
|
||||
pData->m_pSqlData->Disconnect();
|
||||
pData->m_pSqlData->Disconnect(); //TODO:Check if an exception is caught will this still execute ?
|
||||
}
|
||||
|
||||
delete pData;
|
||||
|
@ -304,9 +261,8 @@ void CSqlScore::SaveScore(int ClientID, float Time, CCharacter *pChar)
|
|||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_ClientID = ClientID;
|
||||
str_copy(Tmp->m_aName, Server()->ClientName(ClientID), sizeof(Tmp->m_aName));
|
||||
Server()->GetClientIP(ClientID, Tmp->m_aIP, sizeof(Tmp->m_aIP));
|
||||
Tmp->m_Time = Time;
|
||||
for(int i = 0; i < NUM_TELEPORT; i++)
|
||||
for(int i = 0; i < NUM_CHECKPOINTS; i++)
|
||||
Tmp->m_aCpCurrent[i] = pChar->m_CpCurrent[i];
|
||||
Tmp->m_pSqlData = this;
|
||||
|
||||
|
@ -332,7 +288,7 @@ void CSqlScore::ShowRankThread(void *pUser)
|
|||
|
||||
// check sort methode
|
||||
char aBuf[512];
|
||||
str_format(aBuf, sizeof(aBuf), "SELECT Name, IP, Time FROM %s_%s_race ORDER BY `Time` ASC;", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap);
|
||||
str_format(aBuf, sizeof(aBuf), "SELECT Name, Time FROM %s_%s_race ORDER BY `Time` ASC;", pData->m_pSqlData->m_pPrefix, pData->m_pSqlData->m_aMap);
|
||||
pData->m_pSqlData->m_pResults = pData->m_pSqlData->m_pStatement->executeQuery(aBuf);
|
||||
int RowCount = 0;
|
||||
bool Found = false;
|
||||
|
@ -348,11 +304,6 @@ void CSqlScore::ShowRankThread(void *pUser)
|
|||
break;
|
||||
}
|
||||
}
|
||||
else if(!str_comp(pData->m_pSqlData->m_pResults->getString("IP").c_str(), pData->m_aIP))
|
||||
{
|
||||
Found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!Found)
|
||||
|
@ -386,7 +337,7 @@ void CSqlScore::ShowRankThread(void *pUser)
|
|||
}
|
||||
|
||||
// disconnect from database
|
||||
pData->m_pSqlData->Disconnect();
|
||||
pData->m_pSqlData->Disconnect();//TODO:Check if an exception is caught will this still execute ?
|
||||
}
|
||||
|
||||
delete pData;
|
||||
|
@ -399,7 +350,6 @@ void CSqlScore::ShowRank(int ClientID, const char* pName, bool Search)
|
|||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_ClientID = ClientID;
|
||||
str_copy(Tmp->m_aName, pName, sizeof(Tmp->m_aName));
|
||||
Server()->GetClientIP(ClientID, Tmp->m_aIP, sizeof(Tmp->m_aIP));
|
||||
Tmp->m_Search = Search;
|
||||
str_format(Tmp->m_aRequestingPlayer, sizeof(Tmp->m_aRequestingPlayer), " (%s)", Server()->ClientName(ClientID));
|
||||
Tmp->m_pSqlData = this;
|
||||
|
|
|
@ -64,9 +64,8 @@ struct CSqlScoreData
|
|||
CSqlScore *m_pSqlData;
|
||||
int m_ClientID;
|
||||
char m_aName[16];
|
||||
char m_aIP[16];
|
||||
float m_Time;
|
||||
float m_aCpCurrent[NUM_TELEPORT];
|
||||
float m_aCpCurrent[NUM_CHECKPOINTS];
|
||||
int m_Num;
|
||||
bool m_Search;
|
||||
char m_aRequestingPlayer[MAX_NAME_LENGTH];
|
||||
|
|
Loading…
Reference in a new issue