From 111fb9f037070e699b052a3610dc10bec9054d99 Mon Sep 17 00:00:00 2001 From: Hual Date: Tue, 21 Nov 2023 13:06:53 +0200 Subject: [PATCH] Synchronize bans so multiple players are banned at once --- .../LegacyNetwork/legacy_network_impl.cpp | 23 +++++++++++++++++++ .../LegacyNetwork/legacy_network_impl.hpp | 3 +++ 2 files changed, 26 insertions(+) diff --git a/Server/Components/LegacyNetwork/legacy_network_impl.cpp b/Server/Components/LegacyNetwork/legacy_network_impl.cpp index d253215bd..ca5cab50c 100644 --- a/Server/Components/LegacyNetwork/legacy_network_impl.cpp +++ b/Server/Components/LegacyNetwork/legacy_network_impl.cpp @@ -586,12 +586,35 @@ void RakNetLegacyNetwork::RPCHook(RakNet::RPCParameters* rpcParams, void* extra) #endif } +void RakNetLegacyNetwork::synchronizeBans() +{ + char addr[22] = { 0 }; + unsigned short port; + for (IPlayer* player : core->getPlayers().entries()) + { + const PeerNetworkData& netData = player->getNetworkData(); + if (netData.network != this) + { + continue; + } + + const PeerNetworkData::NetworkID& nid = netData.networkID; + const RakNet::PlayerID rid { unsigned(nid.address.v4), nid.port }; + rakNetServer.GetPlayerIPFromID(rid, addr, &port); + if (rakNetServer.IsBanned(addr)) + { + player->kick(); + } + } +} + void RakNetLegacyNetwork::ban(const BanEntry& entry, Milliseconds expire) { // Only support ipv4 if (entry.address != StringView("127.0.0.1")) { rakNetServer.AddToBanList(entry.address.data(), expire.count()); + synchronizeBans(); } } diff --git a/Server/Components/LegacyNetwork/legacy_network_impl.hpp b/Server/Components/LegacyNetwork/legacy_network_impl.hpp index 009d508f4..07195fe50 100644 --- a/Server/Components/LegacyNetwork/legacy_network_impl.hpp +++ b/Server/Components/LegacyNetwork/legacy_network_impl.hpp @@ -357,6 +357,9 @@ class RakNetLegacyNetwork final : public Network, public CoreEventHandler, publi void handlePreConnectPacketData(int playerIndex); + /// Synchronize players after banning an IP, kicking any that match the banned IP + void synchronizeBans(); + NetworkStats getStatistics(IPlayer* player = nullptr) override; unsigned getPing(const IPlayer& peer) override