mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Adjust file based ShowRank, ShowTeamRank, ShowPoints consistent functions to sql
This commit is contained in:
parent
3d25953036
commit
69cf72dae4
|
@ -790,8 +790,7 @@ void CGameContext::ConTeamRank(IConsole::IResult *pResult, void *pUserData)
|
|||
|
||||
if (pResult->NumArguments() > 0)
|
||||
if (!g_Config.m_SvHideScore)
|
||||
pSelf->Score()->ShowTeamRank(pResult->m_ClientID, pResult->GetString(0),
|
||||
true);
|
||||
pSelf->Score()->ShowTeamRank(pResult->m_ClientID, pResult->GetString(0));
|
||||
else
|
||||
pSelf->Console()->Print(
|
||||
IConsole::OUTPUT_LEVEL_STANDARD,
|
||||
|
@ -825,8 +824,7 @@ void CGameContext::ConRank(IConsole::IResult *pResult, void *pUserData)
|
|||
|
||||
if (pResult->NumArguments() > 0)
|
||||
if (!g_Config.m_SvHideScore)
|
||||
pSelf->Score()->ShowRank(pResult->m_ClientID, pResult->GetString(0),
|
||||
true);
|
||||
pSelf->Score()->ShowRank(pResult->m_ClientID, pResult->GetString(0));
|
||||
else
|
||||
pSelf->Console()->Print(
|
||||
IConsole::OUTPUT_LEVEL_STANDARD,
|
||||
|
@ -1548,8 +1546,7 @@ void CGameContext::ConPoints(IConsole::IResult *pResult, void *pUserData)
|
|||
|
||||
if (pResult->NumArguments() > 0)
|
||||
if (!g_Config.m_SvHideScore)
|
||||
pSelf->Score()->ShowPoints(pResult->m_ClientID, pResult->GetString(0),
|
||||
true);
|
||||
pSelf->Score()->ShowPoints(pResult->m_ClientID, pResult->GetString(0));
|
||||
else
|
||||
pSelf->Console()->Print(
|
||||
IConsole::OUTPUT_LEVEL_STANDARD,
|
||||
|
|
|
@ -69,13 +69,13 @@ public:
|
|||
virtual void SaveTeamScore(int *pClientIDs, unsigned int Size, float Time, const char *pTimestamp) = 0;
|
||||
|
||||
virtual void ShowTop5(void *pResult, int ClientID, void *pUserData, int Debut=1) = 0;
|
||||
virtual void ShowRank(int ClientID, const char *pName, bool Search=false) = 0;
|
||||
virtual void ShowRank(int ClientID, const char *pName) = 0;
|
||||
|
||||
virtual void ShowTeamTop5(void *pResult, int ClientID, void *pUserData, int Debut=1) = 0;
|
||||
virtual void ShowTeamRank(int ClientID, const char *pName, bool Search=false) = 0;
|
||||
virtual void ShowTeamRank(int ClientID, const char *pName) = 0;
|
||||
|
||||
virtual void ShowTopPoints(void *pResult, int ClientID, void *pUserData, int Debut=1) = 0;
|
||||
virtual void ShowPoints(int ClientID, const char *pName, bool Search=false) = 0;
|
||||
virtual void ShowPoints(int ClientID, const char *pName) = 0;
|
||||
|
||||
virtual void RandomMap(int ClientID, int Stars) = 0;
|
||||
virtual void RandomUnfinishedMap(int ClientID, int Stars) = 0;
|
||||
|
|
|
@ -262,16 +262,13 @@ void CFileScore::ShowTop5(void *pResult, int ClientID,
|
|||
pSelf->SendChatTarget(ClientID, "------------------------------");
|
||||
}
|
||||
|
||||
void CFileScore::ShowRank(int ClientID, const char* pName, bool Search)
|
||||
void CFileScore::ShowRank(int ClientID, const char* pName)
|
||||
{
|
||||
CPlayerScore *pScore;
|
||||
int Pos = -2;
|
||||
char aBuf[512];
|
||||
|
||||
if (!Search)
|
||||
pScore = SearchScore(ClientID, &Pos);
|
||||
else
|
||||
pScore = SearchName(pName, &Pos, 1);
|
||||
pScore = SearchName(pName, &Pos, 1);
|
||||
|
||||
if (pScore && Pos > -1)
|
||||
{
|
||||
|
@ -285,17 +282,16 @@ void CFileScore::ShowRank(int ClientID, const char* pName, bool Search)
|
|||
"%d. %s Time: %d minute(s) %5.2f second(s), requested by (%s)", Pos,
|
||||
pScore->m_aName, (int)Time / 60,
|
||||
Time - ((int)Time / 60 * 60), Server()->ClientName(ClientID));
|
||||
if (!Search)
|
||||
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, ClientID);
|
||||
else
|
||||
if (g_Config.m_SvHideScore)
|
||||
GameServer()->SendChatTarget(ClientID, aBuf);
|
||||
else
|
||||
GameServer()->SendChat(-1, CGameContext::CHAT_ALL, aBuf, ClientID);
|
||||
return;
|
||||
}
|
||||
else if (Pos == -1)
|
||||
str_format(aBuf, sizeof(aBuf), "Several players were found.");
|
||||
else
|
||||
str_format(aBuf, sizeof(aBuf), "%s is not ranked",
|
||||
Search ? pName : Server()->ClientName(ClientID));
|
||||
str_format(aBuf, sizeof(aBuf), "%s is not ranked", pName);
|
||||
|
||||
GameServer()->SendChatTarget(ClientID, aBuf);
|
||||
}
|
||||
|
@ -307,7 +303,7 @@ void CFileScore::ShowTeamTop5(void *pResult, int ClientID, void *pUserData, int
|
|||
GameServer()->SendChatTarget(ClientID, aBuf);
|
||||
}
|
||||
|
||||
void CFileScore::ShowTeamRank(int ClientID, const char* pName, bool Search)
|
||||
void CFileScore::ShowTeamRank(int ClientID, const char* pName)
|
||||
{
|
||||
char aBuf[512];
|
||||
str_format(aBuf, sizeof(aBuf), "Team ranks not supported in file based servers");
|
||||
|
@ -321,7 +317,7 @@ void CFileScore::ShowTopPoints(void *pResult, int ClientID, void *pUserData, int
|
|||
GameServer()->SendChatTarget(ClientID, aBuf);
|
||||
}
|
||||
|
||||
void CFileScore::ShowPoints(int ClientID, const char* pName, bool Search)
|
||||
void CFileScore::ShowPoints(int ClientID, const char* pName)
|
||||
{
|
||||
char aBuf[512];
|
||||
str_format(aBuf, sizeof(aBuf), "Points not supported in file based servers");
|
||||
|
|
|
@ -21,10 +21,8 @@ class CFileScore: public IScore
|
|||
float m_Score;
|
||||
float m_aCpTime[NUM_CHECKPOINTS];
|
||||
|
||||
CPlayerScore()
|
||||
{
|
||||
}
|
||||
;
|
||||
CPlayerScore() {}
|
||||
|
||||
CPlayerScore(const char *pName, float Score,
|
||||
float aCpTime[NUM_CHECKPOINTS]);
|
||||
|
||||
|
@ -49,7 +47,6 @@ class CFileScore: public IScore
|
|||
{
|
||||
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_CHECKPOINTS]);
|
||||
|
@ -73,14 +70,14 @@ public:
|
|||
|
||||
virtual void ShowTop5(void *pResult, int ClientID,
|
||||
void *pUserData, int Debut = 1);
|
||||
virtual void ShowRank(int ClientID, const char* pName, bool Search = false);
|
||||
virtual void ShowRank(int ClientID, const char* pName);
|
||||
|
||||
virtual void ShowTeamTop5(void *pResult, int ClientID,
|
||||
void *pUserData, int Debut = 1);
|
||||
virtual void ShowTeamRank(int ClientID, const char* pName, bool Search = false);
|
||||
virtual void ShowTeamRank(int ClientID, const char* pName);
|
||||
|
||||
virtual void ShowTopPoints(void *pResult, int ClientID, void *pUserData, int Debut);
|
||||
virtual void ShowPoints(int ClientID, const char* pName, bool Search);
|
||||
virtual void ShowPoints(int ClientID, const char* pName);
|
||||
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);
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "../gamemodes/DDRace.h"
|
||||
#include "../save.h"
|
||||
|
||||
std::atomic_int CSqlExecData::ms_InstanceCount(0);
|
||||
std::atomic_int CSqlScore::ms_InstanceCount(0);
|
||||
|
||||
CSqlResult::CSqlResult() :
|
||||
m_Done(false),
|
||||
|
@ -26,6 +26,7 @@ CSqlResult::CSqlResult() :
|
|||
{
|
||||
m_Message[0] = 0;
|
||||
}
|
||||
|
||||
CSqlResult::~CSqlResult() {
|
||||
switch(m_Tag)
|
||||
{
|
||||
|
@ -44,6 +45,23 @@ CSqlResult::~CSqlResult() {
|
|||
}
|
||||
}
|
||||
|
||||
CSqlExecData::CSqlExecData(
|
||||
bool (*pFuncPtr) (CSqlServer*, const CSqlData *, bool),
|
||||
CSqlData *pSqlResult,
|
||||
bool ReadOnly
|
||||
) :
|
||||
m_pFuncPtr(pFuncPtr),
|
||||
m_pSqlData(pSqlResult),
|
||||
m_ReadOnly(ReadOnly)
|
||||
{
|
||||
++CSqlScore::ms_InstanceCount;
|
||||
}
|
||||
|
||||
CSqlExecData::~CSqlExecData()
|
||||
{
|
||||
--CSqlScore::ms_InstanceCount;
|
||||
}
|
||||
|
||||
std::shared_ptr<CSqlResult> CSqlScore::NewSqlResult(int ClientID)
|
||||
{
|
||||
CPlayer *pCurPlayer = GameServer()->m_apPlayers[ClientID];
|
||||
|
@ -67,7 +85,7 @@ CSqlScore::CSqlScore(CGameContext *pGameServer) :
|
|||
void CSqlScore::OnShutdown()
|
||||
{
|
||||
int i = 0;
|
||||
while (CSqlExecData::ms_InstanceCount != 0)
|
||||
while (CSqlScore::ms_InstanceCount != 0)
|
||||
{
|
||||
if (i > 600) {
|
||||
dbg_msg("sql", "Waited 60 seconds for score-threads to complete, quitting anyway");
|
||||
|
@ -76,7 +94,7 @@ void CSqlScore::OnShutdown()
|
|||
|
||||
// print a log about every two seconds
|
||||
if (i % 20 == 0)
|
||||
dbg_msg("sql", "Waiting for score-threads to complete (%d left)", CSqlExecData::ms_InstanceCount.load());
|
||||
dbg_msg("sql", "Waiting for score-threads to complete (%d left)", CSqlScore::ms_InstanceCount.load());
|
||||
++i;
|
||||
thread_sleep(100000);
|
||||
}
|
||||
|
@ -739,13 +757,12 @@ bool CSqlScore::SaveTeamScoreThread(CSqlServer* pSqlServer, const CSqlData *pGam
|
|||
return false;
|
||||
}
|
||||
|
||||
void CSqlScore::ShowRank(int ClientID, const char* pName, bool Search)
|
||||
void CSqlScore::ShowRank(int ClientID, const char* pName)
|
||||
{
|
||||
/*
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_ClientID = ClientID;
|
||||
Tmp->m_Name = pName;
|
||||
Tmp->m_Search = Search;
|
||||
str_copy(Tmp->m_aRequestingPlayer, Server()->ClientName(ClientID), sizeof(Tmp->m_aRequestingPlayer));
|
||||
|
||||
thread_init_and_detach(ExecSqlFunc, new CSqlExecData(ShowRankThread, Tmp), "show rank");
|
||||
|
@ -813,13 +830,12 @@ bool CSqlScore::ShowRankThread(CSqlServer* pSqlServer, const CSqlData *pGameData
|
|||
return false;
|
||||
}
|
||||
|
||||
void CSqlScore::ShowTeamRank(int ClientID, const char* pName, bool Search)
|
||||
void CSqlScore::ShowTeamRank(int ClientID, const char* pName)
|
||||
{
|
||||
/*
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_ClientID = ClientID;
|
||||
Tmp->m_Name = pName;
|
||||
Tmp->m_Search = Search;
|
||||
str_copy(Tmp->m_aRequestingPlayer, Server()->ClientName(ClientID), sizeof(Tmp->m_aRequestingPlayer));
|
||||
|
||||
thread_init_and_detach(ExecSqlFunc, new CSqlExecData(ShowTeamRankThread, Tmp), "show team rank");
|
||||
|
@ -1186,13 +1202,12 @@ bool CSqlScore::ShowTimesThread(CSqlServer* pSqlServer, const CSqlData *pGameDat
|
|||
return false;
|
||||
}
|
||||
|
||||
void CSqlScore::ShowPoints(int ClientID, const char* pName, bool Search)
|
||||
void CSqlScore::ShowPoints(int ClientID, const char* pName)
|
||||
{
|
||||
/*
|
||||
CSqlScoreData *Tmp = new CSqlScoreData();
|
||||
Tmp->m_ClientID = ClientID;
|
||||
Tmp->m_Name = pName;
|
||||
Tmp->m_Search = Search;
|
||||
str_copy(Tmp->m_aRequestingPlayer, Server()->ClientName(ClientID), sizeof(Tmp->m_aRequestingPlayer));
|
||||
|
||||
thread_init_and_detach(ExecSqlFunc, new CSqlExecData(ShowPointsThread, Tmp), "show points");
|
||||
|
|
|
@ -143,24 +143,12 @@ struct CSqlExecData
|
|||
bool (*pFuncPtr) (CSqlServer*, const CSqlData *, bool),
|
||||
CSqlData *pSqlResult,
|
||||
bool ReadOnly = true
|
||||
) :
|
||||
m_pFuncPtr(pFuncPtr),
|
||||
m_pSqlData(pSqlResult),
|
||||
m_ReadOnly(ReadOnly)
|
||||
{
|
||||
++ms_InstanceCount;
|
||||
}
|
||||
~CSqlExecData()
|
||||
{
|
||||
--ms_InstanceCount;
|
||||
}
|
||||
);
|
||||
~CSqlExecData();
|
||||
|
||||
bool (*m_pFuncPtr) (CSqlServer*, const CSqlData *, bool);
|
||||
CSqlData *m_pSqlData;
|
||||
bool m_ReadOnly;
|
||||
|
||||
// keeps track of score-threads
|
||||
static std::atomic_int ms_InstanceCount;
|
||||
};
|
||||
|
||||
class IServer;
|
||||
|
@ -207,26 +195,28 @@ class CSqlScore: public IScore
|
|||
std::shared_ptr<CSqlResult> NewSqlResult(int ClientID);
|
||||
|
||||
public:
|
||||
// keeps track of score-threads
|
||||
static std::atomic_int ms_InstanceCount;
|
||||
|
||||
CSqlScore(CGameContext *pGameServer);
|
||||
~CSqlScore() {}
|
||||
|
||||
// Requested by game context
|
||||
virtual void CheckBirthday(int ClientID);
|
||||
virtual void LoadScore(int ClientID);
|
||||
virtual void RandomMap(int ClientID, int Stars);
|
||||
virtual void RandomUnfinishedMap(int ClientID, int Stars);
|
||||
virtual void MapVote(int ClientID, const char* MapName);
|
||||
virtual void CheckBirthday(int ClientID);
|
||||
virtual void LoadScore(int ClientID);
|
||||
|
||||
// Requested by players (fails if another request by this player is active)
|
||||
virtual void MapInfo(int ClientID, const char* MapName);
|
||||
virtual void ShowRank(int ClientID, const char* pName, bool Search = false);
|
||||
virtual void ShowTeamRank(int ClientID, const char* pName, bool Search = false);
|
||||
virtual void ShowRank(int ClientID, const char* pName);
|
||||
virtual void ShowTeamRank(int ClientID, const char* pName);
|
||||
virtual void ShowTimes(int ClientID, const char* pName, int Debut = 1);
|
||||
virtual void ShowTimes(int ClientID, int Debut = 1);
|
||||
virtual void ShowTop5(void *pResult, int ClientID, void *pUserData, int Debut = 1);
|
||||
virtual void ShowTeamTop5(void *pResult, int ClientID, void *pUserData, int Debut = 1);
|
||||
virtual void ShowPoints(int ClientID, const char* pName, bool Search = false);
|
||||
virtual void ShowPoints(int ClientID, const char* pName);
|
||||
virtual void ShowTopPoints(void *pResult, int ClientID, void *pUserData, int Debut = 1);
|
||||
virtual void GetSaves(int ClientID);
|
||||
|
||||
|
|
Loading…
Reference in a new issue