From: AeonLucid Date: Sun, 20 Sep 2020 22:54:32 +0000 (+0200) Subject: Added proper banning based on IPs X-Git-Tag: v1.0.0~8 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=2ba8e1e8a46e7cf808b4216e945a39d704c40ba8;p=rhonda%2Fimpostor.git Added proper banning based on IPs --- diff --git a/src/AmongUs.Server/Net/Game.cs b/src/AmongUs.Server/Net/Game.cs index f1f9015..945a45b 100644 --- a/src/AmongUs.Server/Net/Game.cs +++ b/src/AmongUs.Server/Net/Game.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Concurrent; +using System.Collections.Generic; using System.Linq; +using System.Net; using AmongUs.Server.Data; using AmongUs.Server.Exceptions; using AmongUs.Server.Extensions; @@ -19,18 +21,19 @@ namespace AmongUs.Server.Net private readonly GameManager _gameManager; private readonly ConcurrentDictionary _players; + private readonly HashSet _bannedIps; public Game(GameManager gameManager, int code, GameOptionsData options) { _gameManager = gameManager; _players = new ConcurrentDictionary(); + _bannedIps = new HashSet(); Code = code; CodeStr = GameCode.IntToGameName(code); HostId = -1; GameState = GameStates.NotStarted; Options = options; - } public int Code { get; } @@ -85,6 +88,12 @@ namespace AmongUs.Server.Net public void HandleJoinGame(ClientPlayer sender) { + if (_bannedIps.Contains(sender.Client.Connection.EndPoint.Address)) + { + sender.Client.Connection.Send(new Message1DisconnectReason(DisconnectReason.Banned)); + return; + } + switch (GameState) { case GameStates.NotStarted: @@ -175,6 +184,11 @@ namespace AmongUs.Server.Net if (_players.TryRemove(playerId, out var player)) { player.Game = null; + + if (isBan) + { + _bannedIps.Add(player.Client.Connection.EndPoint.Address); + } } WriteRemovePlayerMessage(message, true, playerId, isBan