From 68157481be2ae01c78504766bb76ff44a0e9b274 Mon Sep 17 00:00:00 2001 From: Edo Date: Sat, 4 Mar 2023 17:40:28 +0000 Subject: [PATCH] Add IP Whitelist for rcon, add msg to gsc meth (#804) --- src/Components/Modules/Network.hpp | 4 ++-- src/Components/Modules/PlayerMovement.cpp | 17 +------------- src/Components/Modules/RCon.cpp | 27 +++++++++++++++++++++++ src/Components/Modules/RCon.hpp | 2 ++ src/Components/Modules/Weapon.cpp | 1 + 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/Components/Modules/Network.hpp b/src/Components/Modules/Network.hpp index 9c55a014..9f62839b 100644 --- a/src/Components/Modules/Network.hpp +++ b/src/Components/Modules/Network.hpp @@ -94,8 +94,8 @@ namespace Components template <> struct std::hash { - std::size_t operator()(const Components::Network::Address& k) const noexcept + std::size_t operator()(const Components::Network::Address& x) const noexcept { - return std::hash()(k.getString()); + return std::hash()(*reinterpret_cast(&x.getIP().bytes[0])) ^ std::hash()(x.getPort()); } }; diff --git a/src/Components/Modules/PlayerMovement.cpp b/src/Components/Modules/PlayerMovement.cpp index c624d908..7bd2f77f 100644 --- a/src/Components/Modules/PlayerMovement.cpp +++ b/src/Components/Modules/PlayerMovement.cpp @@ -115,23 +115,8 @@ namespace Components // Do not bounce if BGBounces is 0 jle noBounce - - push eax - - mov eax, BGBouncesAllAngles - mov eax, dword ptr [eax + 0x10] - test eax, eax - - pop eax - - // Do not apply all angles patch if BGBouncesAllAngles is 0 - jle regularBounce - - push 0x4B1B7D - ret - + // Bounce - regularBounce: push 0x4B1B34 ret diff --git a/src/Components/Modules/RCon.cpp b/src/Components/Modules/RCon.cpp index b5a29b17..66714b8f 100644 --- a/src/Components/Modules/RCon.cpp +++ b/src/Components/Modules/RCon.cpp @@ -8,6 +8,8 @@ namespace Components { std::unordered_map RCon::RateLimit; + std::vector RCon::RconAddresses; + RCon::Container RCon::RconContainer; Utils::Cryptography::ECC::Key RCon::RconKey; @@ -76,6 +78,24 @@ namespace Components Network::SendCommand(target, "rconRequest"); } }); + + Command::AddSV("RconWhitelistAdd", [](Command::Params* params) + { + if (params->size() < 2) + { + Logger::Print("Usage: %s \n", params->get(0)); + return; + } + + Network::Address address(params->get(1)); + std::hash hashFn; + const auto hash = hashFn(address); + + if (address.isValid() && std::ranges::find(RconAddresses, hash) == RconAddresses.end()) + { + RconAddresses.push_back(hash); + } + }); } bool RCon::IsRateLimitCheckDisabled() @@ -180,6 +200,13 @@ namespace Components Network::OnClientPacket("rcon", [](const Network::Address& address, [[maybe_unused]] const std::string& data) { + std::hash hashFn; + const auto hash = hashFn(address); + if (!RconAddresses.empty() && std::ranges::find(RconAddresses, hash) != RconAddresses.end()) + { + return; + } + const auto time = Game::Sys_Milliseconds(); if (!IsRateLimitCheckDisabled() && !RateLimitCheck(address, time)) { diff --git a/src/Components/Modules/RCon.hpp b/src/Components/Modules/RCon.hpp index adcca588..907592c6 100644 --- a/src/Components/Modules/RCon.hpp +++ b/src/Components/Modules/RCon.hpp @@ -31,6 +31,8 @@ namespace Components static std::unordered_map RateLimit; + static std::vector RconAddresses; + static Container RconContainer; static Utils::Cryptography::ECC::Key RconKey; diff --git a/src/Components/Modules/Weapon.cpp b/src/Components/Modules/Weapon.cpp index 0c427986..15b9847d 100644 --- a/src/Components/Modules/Weapon.cpp +++ b/src/Components/Modules/Weapon.cpp @@ -557,6 +557,7 @@ namespace Components auto* ps = &ent->client->ps; if (!Game::BG_IsWeaponValid(ps, index)) { + Game::Scr_Error(Utils::String::VA("invalid InitialWeaponRaise: %s", weapon)); return; }