From 069b1763dd0e3c1f0f1446992d0a8041086ffebb Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Mon, 4 Feb 2019 20:46:42 +0100 Subject: [PATCH] Add autoban depending on client version --- src/engine/shared/config_variables.h | 2 ++ src/game/server/gamecontext.cpp | 29 ++++++++++++++++++++++++++++ src/game/server/gamecontext.h | 1 + 3 files changed, 32 insertions(+) diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 7906e51e2..8385e2493 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -359,6 +359,8 @@ MACRO_CONFIG_INT(SvSoloServer, sv_solo_server, 0, 0, 1, CFGFLAG_SERVER|CFGFLAG_G MACRO_CONFIG_STR(SvClientSuggestion, sv_client_suggestion, 128, "Get DDNet client from DDNet.tw to use all features on DDNet!", CFGFLAG_SERVER, "Broadcast to display to players without DDNet client") MACRO_CONFIG_STR(SvClientSuggestionOld, sv_client_suggestion_old, 128, "Your DDNet client is old, update it on DDNet.tw!", CFGFLAG_SERVER, "Broadcast to display to players with an old version of DDNet client") MACRO_CONFIG_STR(SvClientSuggestionBot, sv_client_suggestion_bot, 128, "Your client has bots and can be remotely controlled!\nPlease use another client like DDNet client from DDNet.tw", CFGFLAG_SERVER, "Broadcast to display to players with a known botting client") +MACRO_CONFIG_STR(SvBotVersionNumbers, sv_bot_version_numbers, 128, "99001;99002", CFGFLAG_SERVER, "Semicolon seperated list of known bot clients to be punished by (sv_bot_punishment)") +MACRO_CONFIG_INT(SvBotPunishment, sv_bot_punishment, 1, 0, 1024, CFGFLAG_SERVER, "0 - Disable, 1 - kick, >1 ban in minutes") // netlimit MACRO_CONFIG_INT(SvNetlimit, sv_netlimit, 0, 0, 10000, CFGFLAG_SERVER, "Netlimit: Maximum amount of traffic a client is allowed to use (in kb/s)") diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 76a90b611..48ab57384 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -1800,6 +1800,16 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) //tell known bot clients that they're botting and we know it if (((Version >= 15 && Version < 100) || Version == 502) && g_Config.m_SvClientSuggestionBot[0] != '\0') SendBroadcast(g_Config.m_SvClientSuggestionBot, ClientID); + //autoban known bot versions + if(g_Config.m_SvBotPunishment && isBotVersion(Version)) + { + char aBuf[128]; + if(g_Config.m_SvBotPunishment == 1) + str_format(aBuf, sizeof(aBuf), "kick %d bot client", ClientID); + else + str_format(aBuf, sizeof(aBuf), "ban %d %d %s", ClientID, g_Config.m_SvBotPunishment, "bot client"); + Console()->ExecuteLine(aBuf); + } } else if (MsgID == NETMSGTYPE_CL_SHOWOTHERS) { @@ -3550,6 +3560,25 @@ void CGameContext::Converse(int ClientID, char *pStr) } } +bool CGameContext::isBotVersion(int Version) +{ + char aVersion[16]; + str_format(aVersion, sizeof(aVersion), "%d", Version); + char aVersions[sizeof(g_Config.m_SvBotVersionNumbers)]; + str_copy(aVersions, g_Config.m_SvBotVersionNumbers, sizeof(aVersions)); + char *p = strtok(aVersions, ";");; + + while(p) + { + if(!str_comp(p, aVersion)) + { + return true; + } + p = strtok(NULL, ";"); + } + return false; +} + void CGameContext::List(int ClientID, const char *pFilter) { int Total = 0; diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index bc6a1b639..27a9c7893 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -389,6 +389,7 @@ private: void Whisper(int ClientID, char *pStr); void WhisperID(int ClientID, int VictimID, char *pMessage); void Converse(int ClientID, char *pStr); + bool isBotVersion(int Version); public: CLayers *Layers() { return &m_Layers; }