From: AeonLucid Date: Sun, 25 Oct 2020 22:05:23 +0000 (+0100) Subject: Fixes issue #84, ban ips caught cheating X-Git-Tag: v1.2.2~74^2~7 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=a6b3cd10f4d3274b606bea5b7d36b5942112c4a6;p=rhonda%2Fimpostor.git Fixes issue #84, ban ips caught cheating --- diff --git a/src/Impostor.Api/Games/IGame.cs b/src/Impostor.Api/Games/IGame.cs index 1460adc..ab42371 100644 --- a/src/Impostor.Api/Games/IGame.cs +++ b/src/Impostor.Api/Games/IGame.cs @@ -34,6 +34,17 @@ namespace Impostor.Api.Games IClientPlayer GetClientPlayer(int clientId); + /// + /// Adds an to the ban list of this game. + /// Prevents all future joins from this . + /// + /// This does not kick the player with that from the lobby. + /// + /// + /// The to ban. + /// + void BanIp(IPAddress ipAddress); + /// /// Syncs the internal to all players. /// Necessary to do if you modified it, otherwise it won't be used. diff --git a/src/Impostor.Server/Net/Client.cs b/src/Impostor.Server/Net/Client.cs index 8c0ffcd..b6fe4f0 100644 --- a/src/Impostor.Server/Net/Client.cs +++ b/src/Impostor.Server/Net/Client.cs @@ -172,6 +172,8 @@ namespace Impostor.Server.Net } catch (ImpostorCheatException e) { + Player.Game.BanIp(Connection.EndPoint.Address); + await DisconnectAsync(DisconnectReason.Hacking, e.Message); } diff --git a/src/Impostor.Server/Net/State/ClientPlayer.cs b/src/Impostor.Server/Net/State/ClientPlayer.cs index 5f2dc93..9e7d805 100644 --- a/src/Impostor.Server/Net/State/ClientPlayer.cs +++ b/src/Impostor.Server/Net/State/ClientPlayer.cs @@ -11,8 +11,7 @@ namespace Impostor.Server.Net.State internal partial class ClientPlayer : IClientPlayer { private readonly ILogger _logger; - - private Timer _spawnTimeout; + private readonly Timer _spawnTimeout; public ClientPlayer(ILogger logger, ClientBase client, Game game) { diff --git a/src/Impostor.Server/Net/State/Game.Api.cs b/src/Impostor.Server/Net/State/Game.Api.cs index 2a5ec4a..194df87 100644 --- a/src/Impostor.Server/Net/State/Game.Api.cs +++ b/src/Impostor.Server/Net/State/Game.Api.cs @@ -1,4 +1,5 @@ using System.IO; +using System.Net; using System.Threading.Tasks; using Impostor.Api.Games; using Impostor.Api.Innersloth; @@ -14,6 +15,11 @@ namespace Impostor.Server.Net.State IGameNet IGame.GameNet => GameNet; + public void BanIp(IPAddress ipAddress) + { + _bannedIps.Add(ipAddress); + } + public async ValueTask SyncSettingsAsync() { using (var writer = StartRpc(Host.Character.NetId, RpcCalls.SyncSettings)) diff --git a/src/Impostor.Server/Net/State/Game.State.cs b/src/Impostor.Server/Net/State/Game.State.cs index 8b22030..e51b2f7 100644 --- a/src/Impostor.Server/Net/State/Game.State.cs +++ b/src/Impostor.Server/Net/State/Game.State.cs @@ -69,7 +69,7 @@ namespace Impostor.Server.Net.State if (isBan && player.Client.Connection != null) { - _bannedIps.Add(player.Client.Connection.EndPoint.Address); + BanIp(player.Client.Connection.EndPoint.Address); } await _eventManager.CallAsync(new PlayerLeftGameEvent(this, player, isBan));