Skip to content

Commit 5b4a368

Browse files
committed
add gores and race distinction for cotd sql database
1 parent 1a5aa41 commit 5b4a368

5 files changed

Lines changed: 35 additions & 23 deletions

File tree

src/engine/server/databases/connection.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,25 @@ void IDbConnection::FormatCreatePoints(char *aBuf, unsigned int BufferSize) cons
9191
GetPrefix(), MAX_NAME_LENGTH_SQL, BinaryCollate());
9292
}
9393

94-
void IDbConnection::FormatCreateCOTD_Points(char *aBuf, unsigned int BufferSize) const
94+
void IDbConnection::FormatCreateCOTD_Points(char *aBuf, unsigned int BufferSize, const char * mode) const
9595
{
9696
str_format(aBuf, BufferSize,
97-
"CREATE TABLE IF NOT EXISTS %s_cotd_points ("
97+
"CREATE TABLE IF NOT EXISTS %s_cotd_points_%s ("
9898
" Name VARCHAR(%d) COLLATE %s NOT NULL, "
9999
" Points INT DEFAULT 0, "
100100
" PRIMARY KEY (Name)"
101101
")",
102-
GetPrefix(), MAX_NAME_LENGTH_SQL, BinaryCollate());
102+
GetPrefix(), mode, MAX_NAME_LENGTH_SQL, BinaryCollate());
103103
}
104104

105-
void IDbConnection::FormatCreateCOTD_Ranks(char *aBuf, unsigned int BufferSize) const
105+
void IDbConnection::FormatCreateCOTD_Ranks(char *aBuf, unsigned int BufferSize, const char * mode) const
106106
{
107107
str_format(aBuf, BufferSize,
108-
"CREATE TABLE IF NOT EXISTS %s_cotd_ranks ("
108+
"CREATE TABLE IF NOT EXISTS %s_cotd_ranks_%s ("
109109
" Name VARCHAR(%d) COLLATE %s NOT NULL, "
110110
" Map VARCHAR(128) COLLATE %s NOT NULL, "
111111
" Rank INT DEFAULT 0, "
112112
" PRIMARY KEY (Name)"
113113
")",
114-
GetPrefix(), MAX_NAME_LENGTH_SQL, BinaryCollate(), BinaryCollate());
114+
GetPrefix(), mode, MAX_NAME_LENGTH_SQL, BinaryCollate(), BinaryCollate());
115115
}

src/engine/server/databases/connection.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ class IDbConnection
9898
void FormatCreateMaps(char *aBuf, unsigned int BufferSize) const;
9999
void FormatCreateSaves(char *aBuf, unsigned int BufferSize, bool Backup) const;
100100
void FormatCreatePoints(char *aBuf, unsigned int BufferSize) const;
101-
void FormatCreateCOTD_Points(char *aBuf, unsigned int BufferSize) const;
102-
void FormatCreateCOTD_Ranks(char *aBuf, unsigned int BufferSize) const;
101+
void FormatCreateCOTD_Points(char *aBuf, unsigned int BufferSize, const char * mode) const;
102+
void FormatCreateCOTD_Ranks(char *aBuf, unsigned int BufferSize, const char * mode) const;
103103
};
104104

105105
bool MysqlAvailable();

src/engine/server/databases/sqlite.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <base/math.h>
66
#include <engine/console.h>
7+
#include <engine/shared/config.h>
78

89
#include <atomic>
910

@@ -166,12 +167,20 @@ bool CSqliteConnection::ConnectImpl(char *pError, int ErrorSize)
166167
FormatCreatePoints(aBuf, sizeof(aBuf));
167168
if(Execute(aBuf, pError, ErrorSize))
168169
return true;
170+
171+
FormatCreateCOTD_Points(aBuf, sizeof(aBuf), "race");
172+
if(Execute(aBuf, pError, ErrorSize))
173+
return true;
174+
175+
FormatCreateCOTD_Points(aBuf, sizeof(aBuf), "gores");
176+
if(Execute(aBuf, pError, ErrorSize))
177+
return true;
169178

170-
FormatCreateCOTD_Points(aBuf, sizeof(aBuf));
179+
FormatCreateCOTD_Ranks(aBuf, sizeof(aBuf), "race");
171180
if(Execute(aBuf, pError, ErrorSize))
172181
return true;
173182

174-
FormatCreateCOTD_Ranks(aBuf, sizeof(aBuf));
183+
FormatCreateCOTD_Ranks(aBuf, sizeof(aBuf), "gores");
175184
if(Execute(aBuf, pError, ErrorSize))
176185
return true;
177186

@@ -425,10 +434,10 @@ bool CSqliteConnection::AddPoints_COTD(const char *pPlayer, int Points, char *pE
425434
{
426435
char aBuf[512];
427436
str_format(aBuf, sizeof(aBuf),
428-
"INSERT INTO %s_cotd_points(Name, Points) "
437+
"INSERT INTO %s_cotd_points_%s(Name, Points) "
429438
"VALUES (?, ?) "
430439
"ON CONFLICT(Name) DO UPDATE SET Points=Points+?",
431-
GetPrefix());
440+
GetPrefix(), g_Config.m_SvKoMode == 0 ? "gores" : "race");
432441
if(PrepareStatement(aBuf, pError, ErrorSize))
433442
{
434443
return true;

src/engine/shared/config_variables.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ MACRO_CONFIG_INT(SvKoPublicChat, sv_ko_public_chat, 0, 0, 1, CFGFLAG_SERVER, "ma
660660
MACRO_CONFIG_INT(SvKoBo3, sv_ko_bo3, 0, 0, 5, CFGFLAG_SERVER, "Best of X wins (KO GAME)")
661661
MACRO_CONFIG_INT(SvForcePredictionMargin, sv_force_prediction_margin, 0, 0, 200, CFGFLAG_SERVER, "force players to have a higher prediction margin for more consistant gameplay")
662662
MACRO_CONFIG_INT(SvKoSQL, sv_ko_sql, 0, 0, 1, CFGFLAG_SERVER, "Save result of cup of the day in database")
663+
MACRO_CONFIG_INT(SvKoMode, sv_ko_mode, 0, 0, 1, CFGFLAG_SERVER, "Cup of the day Mode: 0 = gores, 1 = race")
663664

664665

665666
MACRO_CONFIG_STR(SvRoundStatsDiscordWebhooks, sv_round_stats_discord_webhooks, 512, "", CFGFLAG_SERVER, "If set will post score stats there on round end. Is JSON")

src/game/server/scoreworker.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,8 @@ bool CScoreWorker::SaveCOTD_Points(IDbConnection *pSqlServer, const ISqlData *pG
828828
if(w == Write::NORMAL)
829829
{
830830
str_format(aBuf, sizeof(aBuf),
831-
"SELECT COUNT(*) AS COTD_FINISH FROM %s_cotd_ranks WHERE Map=? AND Name=? ORDER BY Rank ASC LIMIT 1",
832-
pSqlServer->GetPrefix());
831+
"SELECT COUNT(*) AS COTD_FINISH FROM %s_cotd_ranks_%s WHERE Map=? AND Name=? ORDER BY Rank ASC LIMIT 1",
832+
pSqlServer->GetPrefix(), g_Config.m_SvKoMode == 0 ? "gores" : "race");
833833
if(pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
834834
{
835835
return true;
@@ -846,8 +846,8 @@ bool CScoreWorker::SaveCOTD_Points(IDbConnection *pSqlServer, const ISqlData *pG
846846
if(NumFinished == 0)
847847
{
848848
str_format(aBuf, sizeof(aBuf),
849-
"INSERT INTO %s_cotd_ranks(Name, Map, Rank) VALUES(?, ?, %i)",
850-
pSqlServer->GetPrefix(), pData->m_Rank);
849+
"INSERT INTO %s_cotd_ranks_%s(Name, Map, Rank) VALUES(?, ?, %i)",
850+
pSqlServer->GetPrefix(), g_Config.m_SvKoMode == 0 ? "gores" : "race", pData->m_Rank);
851851

852852
if(pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
853853
{
@@ -881,11 +881,13 @@ bool CScoreWorker::ShowCOTD_Points(IDbConnection *pSqlServer, const ISqlData *pG
881881
char aBuf[512];
882882
str_format(aBuf, sizeof(aBuf),
883883
"SELECT ("
884-
" SELECT COUNT(Name) + 1 FROM %s_cotd_points WHERE Points > ("
885-
" SELECT Points FROM %s_cotd_points WHERE Name = ?"
884+
" SELECT COUNT(Name) + 1 FROM %s_cotd_points_%s WHERE Points > ("
885+
" SELECT Points FROM %s_cotd_points_%s WHERE Name = ?"
886886
")) as Ranking, Points, Name "
887-
"FROM %s_cotd_points WHERE Name = ?",
888-
pSqlServer->GetPrefix(), pSqlServer->GetPrefix(), pSqlServer->GetPrefix());
887+
"FROM %s_cotd_points_%s WHERE Name = ?",
888+
pSqlServer->GetPrefix(), g_Config.m_SvKoMode == 0 ? "gores" : "race", pSqlServer->GetPrefix(),
889+
g_Config.m_SvKoMode == 0 ? "gores" : "race", pSqlServer->GetPrefix(), g_Config.m_SvKoMode == 0 ? "gores" : "race");
890+
889891
if(pSqlServer->PrepareStatement(aBuf, pError, ErrorSize))
890892
{
891893
return true;
@@ -906,13 +908,13 @@ bool CScoreWorker::ShowCOTD_Points(IDbConnection *pSqlServer, const ISqlData *pG
906908
pSqlServer->GetString(3, aName, sizeof(aName));
907909
pResult->m_MessageKind = CScorePlayerResult::ALL;
908910
str_format(paMessages[0], sizeof(paMessages[0]),
909-
"%d. %s COTD Points: %d, requested by %s",
910-
Rank, aName, Count, pData->m_aRequestingPlayer);
911+
"%d. %s COTD %s Points: %d, requested by %s",
912+
Rank, aName, g_Config.m_SvKoMode == 0 ? "gores" : "race", Count, pData->m_aRequestingPlayer);
911913
}
912914
else
913915
{
914916
str_format(paMessages[0], sizeof(paMessages[0]),
915-
"%s has not collected any cotd points so far", pData->m_aName);
917+
"%s has not collected any cotd %s points so far", pData->m_aName, g_Config.m_SvKoMode == 0 ? "gores" : "race");
916918
}
917919
return false;
918920
}

0 commit comments

Comments
 (0)