From a7b778977a2c873968e583eff0281f080b979d8a Mon Sep 17 00:00:00 2001 From: def Date: Fri, 11 May 2018 21:57:47 +0200 Subject: [PATCH] Add sv_sql_validservernames (fixes #1123) --- src/engine/shared/config_variables.h | 1 + src/game/server/ddracechat.cpp | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 1346d4da4..6f50ea887 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -230,6 +230,7 @@ MACRO_CONFIG_STR(SvScoreFolder, sv_score_folder, 32, "records", CFGFLAG_SERVER, #if defined(CONF_SQL) MACRO_CONFIG_INT(SvUseSQL, sv_use_sql, 0, 0, 1, CFGFLAG_SERVER, "Enables SQL DB instead of record file") MACRO_CONFIG_STR(SvSqlServerName, sv_sql_servername, 5, "UNK", CFGFLAG_SERVER, "SQL Server name that is inserted into record table") +MACRO_CONFIG_STR(SvSqlValidServerNames, sv_sql_valid_servernames, 64, "UNK", CFGFLAG_SERVER, "Comma seperated list of valid server names for saving a game to ([A-Z][A-Z][A-Z].?") MACRO_CONFIG_INT(SvSaveGames, sv_savegames, 1, 0, 1, CFGFLAG_SERVER, "Enables savegames (/save and /load)") MACRO_CONFIG_INT(SvSaveGamesDelay, sv_savegames_delay, 60, 0, 10000, CFGFLAG_SERVER, "Delay in seconds for loading a savegame") diff --git a/src/game/server/ddracechat.cpp b/src/game/server/ddracechat.cpp index 781976dab..32b60487b 100644 --- a/src/game/server/ddracechat.cpp +++ b/src/game/server/ddracechat.cpp @@ -629,10 +629,29 @@ void CGameContext::ConSave(IConsole::IResult *pResult, void *pUserData) str_copy(aCountry, g_Config.m_SvSqlServerName, sizeof(aCountry)); } - pSelf->Score()->SaveTeam(Team, pCode, pResult->m_ClientID, aCountry); + char aValidServerNames[sizeof(g_Config.m_SvSqlValidServerNames)]; + str_copy(aValidServerNames, g_Config.m_SvSqlValidServerNames, sizeof(aValidServerNames)); + char *p = strtok(aValidServerNames, ",");; + + while(p) + { + if(str_comp(p, aCountry) == 0) + { + pSelf->Score()->SaveTeam(Team, pCode, pResult->m_ClientID, aCountry); + + if(g_Config.m_SvUseSQL) + pPlayer->m_LastSQLQuery = pSelf->Server()->Tick(); + + return; + } + + p = strtok(NULL, ","); + } + + char aBuf[128]; + str_format(aBuf, sizeof(aBuf), "Unknown server name '%s'.", aCountry); + pSelf->SendChatTarget(pResult->m_ClientID, aBuf); - if(g_Config.m_SvUseSQL) - pPlayer->m_LastSQLQuery = pSelf->Server()->Tick(); #endif }