Add IP Whitelist for rcon, add msg to gsc meth (#804)

This commit is contained in:
Edo 2023-03-04 17:40:28 +00:00 committed by GitHub
parent 3a3cf77b06
commit 68157481be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 18 deletions

View File

@ -94,8 +94,8 @@ namespace Components
template <> template <>
struct std::hash<Components::Network::Address> struct std::hash<Components::Network::Address>
{ {
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<std::string>()(k.getString()); return std::hash<std::uint32_t>()(*reinterpret_cast<const std::uint32_t*>(&x.getIP().bytes[0])) ^ std::hash<std::uint16_t>()(x.getPort());
} }
}; };

View File

@ -116,22 +116,7 @@ namespace Components
// Do not bounce if BGBounces is 0 // Do not bounce if BGBounces is 0
jle noBounce 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 // Bounce
regularBounce:
push 0x4B1B34 push 0x4B1B34
ret ret

View File

@ -8,6 +8,8 @@ namespace Components
{ {
std::unordered_map<std::uint32_t, int> RCon::RateLimit; std::unordered_map<std::uint32_t, int> RCon::RateLimit;
std::vector<std::size_t> RCon::RconAddresses;
RCon::Container RCon::RconContainer; RCon::Container RCon::RconContainer;
Utils::Cryptography::ECC::Key RCon::RconKey; Utils::Cryptography::ECC::Key RCon::RconKey;
@ -76,6 +78,24 @@ namespace Components
Network::SendCommand(target, "rconRequest"); Network::SendCommand(target, "rconRequest");
} }
}); });
Command::AddSV("RconWhitelistAdd", [](Command::Params* params)
{
if (params->size() < 2)
{
Logger::Print("Usage: %s <ip-address>\n", params->get(0));
return;
}
Network::Address address(params->get(1));
std::hash<Network::Address> hashFn;
const auto hash = hashFn(address);
if (address.isValid() && std::ranges::find(RconAddresses, hash) == RconAddresses.end())
{
RconAddresses.push_back(hash);
}
});
} }
bool RCon::IsRateLimitCheckDisabled() bool RCon::IsRateLimitCheckDisabled()
@ -180,6 +200,13 @@ namespace Components
Network::OnClientPacket("rcon", [](const Network::Address& address, [[maybe_unused]] const std::string& data) Network::OnClientPacket("rcon", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
{ {
std::hash<Network::Address> hashFn;
const auto hash = hashFn(address);
if (!RconAddresses.empty() && std::ranges::find(RconAddresses, hash) != RconAddresses.end())
{
return;
}
const auto time = Game::Sys_Milliseconds(); const auto time = Game::Sys_Milliseconds();
if (!IsRateLimitCheckDisabled() && !RateLimitCheck(address, time)) if (!IsRateLimitCheckDisabled() && !RateLimitCheck(address, time))
{ {

View File

@ -31,6 +31,8 @@ namespace Components
static std::unordered_map<std::uint32_t, int> RateLimit; static std::unordered_map<std::uint32_t, int> RateLimit;
static std::vector<std::size_t> RconAddresses;
static Container RconContainer; static Container RconContainer;
static Utils::Cryptography::ECC::Key RconKey; static Utils::Cryptography::ECC::Key RconKey;

View File

@ -557,6 +557,7 @@ namespace Components
auto* ps = &ent->client->ps; auto* ps = &ent->client->ps;
if (!Game::BG_IsWeaponValid(ps, index)) if (!Game::BG_IsWeaponValid(ps, index))
{ {
Game::Scr_Error(Utils::String::VA("invalid InitialWeaponRaise: %s", weapon));
return; return;
} }