diff --git a/src/Components/Modules/RCon.cpp b/src/Components/Modules/RCon.cpp index dfa8ffd6..369556ae 100644 --- a/src/Components/Modules/RCon.cpp +++ b/src/Components/Modules/RCon.cpp @@ -15,6 +15,7 @@ namespace Components Dvar::Var RCon::RconPassword; Dvar::Var RCon::RconLogRequests; + Dvar::Var RCon::RconTimeout; void RCon::AddCommands() { @@ -77,6 +78,16 @@ namespace Components }); } + bool RCon::IsRateLimitCheckDisabled() + { + static std::optional flag; + if (!flag.has_value()) + { + flag.emplace(Flags::HasFlag("disable-rate-limit-check")); + } + return flag.value(); + } + bool RCon::RateLimitCheck(const Network::Address& address, const int time) { const auto ip = address.getIP(); @@ -88,8 +99,7 @@ namespace Components const auto lastTime = RateLimit[ip.full]; - // Only one request every 500ms - if (lastTime && (time - lastTime) < 500) + if (lastTime && (time - lastTime) < RconTimeout.get()) { return false; // Flooding } @@ -103,7 +113,7 @@ namespace Components for (auto i = RateLimit.begin(); i != RateLimit.end();) { // No longer at risk of flooding, remove - if ((time - i->second) > 500) + if ((time - i->second) > RconTimeout.get()) { i = RateLimit.erase(i); } @@ -164,13 +174,14 @@ namespace Components Events::OnDvarInit([] { RconPassword = Dvar::Register("rcon_password", "", Game::DVAR_NONE, "The password for rcon"); - RconLogRequests = Dvar::Register("rcon_log_requests", false, Game::DVAR_NONE, "Print remote commands in the output log"); + RconLogRequests = Dvar::Register("rcon_log_requests", false, Game::DVAR_NONE, "Print remote commands in log"); + RconTimeout = Dvar::Register("rcon_timeout", 500, 500, 10000, Game::DVAR_NONE, ""); }); Network::OnClientPacket("rcon", [](const Network::Address& address, [[maybe_unused]] const std::string& data) { const auto time = Game::Sys_Milliseconds(); - if (!RateLimitCheck(address, time)) + if (!IsRateLimitCheckDisabled() && !RateLimitCheck(address, time)) { return; } diff --git a/src/Components/Modules/RCon.hpp b/src/Components/Modules/RCon.hpp index 22c8cfc0..adcca588 100644 --- a/src/Components/Modules/RCon.hpp +++ b/src/Components/Modules/RCon.hpp @@ -38,9 +38,11 @@ namespace Components static Dvar::Var RconPassword; static Dvar::Var RconLogRequests; + static Dvar::Var RconTimeout; static void AddCommands(); + static bool IsRateLimitCheckDisabled(); static bool RateLimitCheck(const Network::Address& address, int time); static void RateLimitCleanup(int time); };