From d4ed1310d20ce4e89ee2c9949c0dac1f2c4cbce8 Mon Sep 17 00:00:00 2001 From: def Date: Thu, 13 Apr 2017 09:33:26 +0200 Subject: [PATCH] Configurable rate limit for SQL queries --- src/engine/shared/config_variables.h | 1 + src/game/server/ddracechat.cpp | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 2fb486942..5d4fe7b0f 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -231,6 +231,7 @@ MACRO_CONFIG_INT(SvSaveGames, sv_savegames, 1, 0, 1, CFGFLAG_SERVER, "Enables sa MACRO_CONFIG_INT(SvSaveGamesDelay, sv_savegames_delay, 60, 0, 10000, CFGFLAG_SERVER, "Delay in seconds for loading a savegame") MACRO_CONFIG_STR(SvSqlFailureFile, sv_sql_failure_file, 64, "failed_sql.sql", CFGFLAG_SERVER, "File to store failed Sql-Inserts (ranks)") +MACRO_CONFIG_INT(SvSqlQueriesDelay, sv_sql_queries_delay, 1, 0, 20, CFGFLAG_SERVER, "Delay in seconds between SQL queries of a single player") #endif MACRO_CONFIG_INT(SvDDRaceRules, sv_ddrace_rules, 1, 0, 1, CFGFLAG_SERVER, "Whether the default mod rules are displayed or not") diff --git a/src/game/server/ddracechat.cpp b/src/game/server/ddracechat.cpp index 2b4c5b93a..8eb584db5 100644 --- a/src/game/server/ddracechat.cpp +++ b/src/game/server/ddracechat.cpp @@ -341,7 +341,7 @@ void CGameContext::ConTeamTop5(IConsole::IResult *pResult, void *pUserData) #if defined(CONF_SQL) if(pSelf->m_apPlayers[pResult->m_ClientID] && g_Config.m_SvUseSQL) - if(pSelf->m_apPlayers[pResult->m_ClientID]->m_LastSQLQuery + pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) + if(pSelf->m_apPlayers[pResult->m_ClientID]->m_LastSQLQuery + g_Config.m_SvSqlQueriesDelay * pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) return; #endif @@ -372,7 +372,7 @@ void CGameContext::ConTop5(IConsole::IResult *pResult, void *pUserData) #if defined(CONF_SQL) if(pSelf->m_apPlayers[pResult->m_ClientID] && g_Config.m_SvUseSQL) - if(pSelf->m_apPlayers[pResult->m_ClientID]->m_LastSQLQuery + pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) + if(pSelf->m_apPlayers[pResult->m_ClientID]->m_LastSQLQuery + g_Config.m_SvSqlQueriesDelay * pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) return; #endif @@ -403,7 +403,7 @@ void CGameContext::ConTimes(IConsole::IResult *pResult, void *pUserData) #if defined(CONF_SQL) if(pSelf->m_apPlayers[pResult->m_ClientID] && g_Config.m_SvUseSQL) - if(pSelf->m_apPlayers[pResult->m_ClientID]->m_LastSQLQuery + pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) + if(pSelf->m_apPlayers[pResult->m_ClientID]->m_LastSQLQuery + g_Config.m_SvSqlQueriesDelay * pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) return; #endif @@ -495,7 +495,7 @@ void CGameContext::ConMap(IConsole::IResult *pResult, void *pUserData) #if defined(CONF_SQL) if(g_Config.m_SvUseSQL) - if(pPlayer->m_LastSQLQuery + pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) + if(pPlayer->m_LastSQLQuery + g_Config.m_SvSqlQueriesDelay * pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) return; #endif @@ -519,7 +519,7 @@ void CGameContext::ConMapInfo(IConsole::IResult *pResult, void *pUserData) #if defined(CONF_SQL) if(g_Config.m_SvUseSQL) - if(pPlayer->m_LastSQLQuery + pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) + if(pPlayer->m_LastSQLQuery + g_Config.m_SvSqlQueriesDelay * pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) return; #endif @@ -581,7 +581,7 @@ void CGameContext::ConSave(IConsole::IResult *pResult, void *pUserData) } if(g_Config.m_SvUseSQL) - if(pPlayer->m_LastSQLQuery + pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) + if(pPlayer->m_LastSQLQuery + g_Config.m_SvSqlQueriesDelay * pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) return; int Team = ((CGameControllerDDRace*) pSelf->m_pController)->m_Teams.m_Core.Team(pResult->m_ClientID); @@ -636,7 +636,7 @@ void CGameContext::ConLoad(IConsole::IResult *pResult, void *pUserData) } if(g_Config.m_SvUseSQL) - if(pPlayer->m_LastSQLQuery + pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) + if(pPlayer->m_LastSQLQuery + g_Config.m_SvSqlQueriesDelay * pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) return; #endif @@ -663,7 +663,7 @@ void CGameContext::ConTeamRank(IConsole::IResult *pResult, void *pUserData) #if defined(CONF_SQL) if(g_Config.m_SvUseSQL) - if(pPlayer->m_LastSQLQuery + pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) + if(pPlayer->m_LastSQLQuery + g_Config.m_SvSqlQueriesDelay * pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) return; #endif @@ -698,7 +698,7 @@ void CGameContext::ConRank(IConsole::IResult *pResult, void *pUserData) #if defined(CONF_SQL) if(g_Config.m_SvUseSQL) - if(pPlayer->m_LastSQLQuery + pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) + if(pPlayer->m_LastSQLQuery + g_Config.m_SvSqlQueriesDelay * pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) return; #endif @@ -1402,7 +1402,7 @@ void CGameContext::ConPoints(IConsole::IResult *pResult, void *pUserData) return; if(pSelf->m_apPlayers[pResult->m_ClientID] && g_Config.m_SvUseSQL) - if(pSelf->m_apPlayers[pResult->m_ClientID]->m_LastSQLQuery + pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) + if(pSelf->m_apPlayers[pResult->m_ClientID]->m_LastSQLQuery + g_Config.m_SvSqlQueriesDelay * pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) return; CPlayer *pPlayer = pSelf->m_apPlayers[pResult->m_ClientID]; @@ -1435,7 +1435,7 @@ void CGameContext::ConTopPoints(IConsole::IResult *pResult, void *pUserData) return; if(pSelf->m_apPlayers[pResult->m_ClientID] && g_Config.m_SvUseSQL) - if(pSelf->m_apPlayers[pResult->m_ClientID]->m_LastSQLQuery + pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) + if(pSelf->m_apPlayers[pResult->m_ClientID]->m_LastSQLQuery + g_Config.m_SvSqlQueriesDelay * pSelf->Server()->TickSpeed() >= pSelf->Server()->Tick()) return; if (g_Config.m_SvHideScore)