]> git.deb.at Git - rhonda/impostor.git/commitdiff
Fixes issue #84, ban ips caught cheating
authorAeonLucid <aeonlucid@outlook.com>
Sun, 25 Oct 2020 22:05:23 +0000 (23:05 +0100)
committerAeonLucid <aeonlucid@outlook.com>
Sun, 25 Oct 2020 22:05:23 +0000 (23:05 +0100)
src/Impostor.Api/Games/IGame.cs
src/Impostor.Server/Net/Client.cs
src/Impostor.Server/Net/State/ClientPlayer.cs
src/Impostor.Server/Net/State/Game.Api.cs
src/Impostor.Server/Net/State/Game.State.cs

index 1460adcece9d3305a46e2c2f2b76484d1e43cde0..ab42371cb40597327c951660bb065da193cc032b 100644 (file)
@@ -34,6 +34,17 @@ namespace Impostor.Api.Games
 
         IClientPlayer GetClientPlayer(int clientId);
 
+        /// <summary>
+        ///     Adds an <see cref="IPAddress"/> to the ban list of this game.
+        ///     Prevents all future joins from this <see cref="IPAddress"/>.
+        ///
+        ///     This does not kick the player with that <see cref="IPAddress"/> from the lobby.
+        /// </summary>
+        /// <param name="ipAddress">
+        ///     The <see cref="IPAddress"/> to ban.
+        /// </param>
+        void BanIp(IPAddress ipAddress);
+
         /// <summary>
         ///     Syncs the internal <see cref="GameOptionsData"/> to all players.
         ///     Necessary to do if you modified it, otherwise it won't be used.
index 8c0ffcd2b296194386d0a15deffe68af1178c24e..b6fe4f0307b9b32ba79c083028e2481bc113567b 100644 (file)
@@ -172,6 +172,8 @@ namespace Impostor.Server.Net
                     }
                     catch (ImpostorCheatException e)
                     {
+                        Player.Game.BanIp(Connection.EndPoint.Address);
+
                         await DisconnectAsync(DisconnectReason.Hacking, e.Message);
                     }
 
index 5f2dc93e09c5677420ab4c206872db59b499c24d..9e7d80562596f1a9593835358d713488912ec4d0 100644 (file)
@@ -11,8 +11,7 @@ namespace Impostor.Server.Net.State
     internal partial class ClientPlayer : IClientPlayer
     {
         private readonly ILogger<ClientPlayer> _logger;
-
-        private Timer _spawnTimeout;
+        private readonly Timer _spawnTimeout;
 
         public ClientPlayer(ILogger<ClientPlayer> logger, ClientBase client, Game game)
         {
index 2a5ec4a2b3e10c8ec129596d26caf77f22e6c4ef..194df87c20f14c6ea868e112f69a0c11efd0f219 100644 (file)
@@ -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))
index 8b22030d573cc7243070b8ed0f71b6aa288fc6f3..e51b2f79cffef37ec5bd9f7f63c83b722f3c0c77 100644 (file)
@@ -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));