Skip to content

Commit

Permalink
Merge pull request #776 from openmultiplayer/hual/757
Browse files Browse the repository at this point in the history
Synchronize bans so multiple players are banned at once
  • Loading branch information
Hual authored Nov 24, 2023
2 parents 8829f9f + 111fb9f commit bb83a9f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Server/Components/LegacyNetwork/legacy_network_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
3 changes: 3 additions & 0 deletions Server/Components/LegacyNetwork/legacy_network_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bb83a9f

Please sign in to comment.