]> git.deb.at Git - rhonda/impostor.git/commitdiff
Ban kill cooldown bypass (#123)
authorJakub Staroń <kubastaron@hotmail.com>
Thu, 12 Nov 2020 03:04:05 +0000 (04:04 +0100)
committerGitHub <noreply@github.com>
Thu, 12 Nov 2020 03:04:05 +0000 (04:04 +0100)
* Ban kill cooldown bypass

* Fix typo

src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.cs
src/Impostor.Server/Net/Inner/Objects/InnerPlayerInfo.cs

index 7762a7e3112373244e3620c1c169920a345766a9..14b268706308c2db20a732fed18d9134918eb220 100644 (file)
@@ -282,6 +282,13 @@ namespace Impostor.Server.Net.Inner.Objects
                         throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.MurderPlayer)} as crewmate");
                     }
 
+                    if (!sender.Character.PlayerInfo.CanMurder(_game))
+                    {
+                        throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.MurderPlayer)} too fast");
+                    }
+
+                    sender.Character.PlayerInfo.LastMurder = DateTimeOffset.UtcNow;
+
                     var player = reader.ReadNetObject<InnerPlayerControl>(_game);
                     if (!player.PlayerInfo.IsDead)
                     {
index 3982a30b58fe3c1ba839451bfb56f8c239d373bb..cbd3a9d8a030e4e31440132f14e75621f8bc65a1 100644 (file)
@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using Impostor.Api.Games;
 using Impostor.Api.Innersloth;
 using Impostor.Api.Net.Inner.Objects;
 using Impostor.Api.Net.Messages;
@@ -37,6 +38,13 @@ namespace Impostor.Server.Net.Inner.Objects
 
         public List<InnerGameData.TaskInfo> Tasks { get; internal set; }
 
+        public DateTimeOffset LastMurder { get; set; }
+
+        public bool CanMurder(IGame game)
+        {
+            return DateTimeOffset.UtcNow.Subtract(LastMurder).TotalSeconds >= game.Options.KillCooldown;
+        }
+
         public void Serialize(IMessageWriter writer)
         {
             throw new NotImplementedException();
@@ -62,4 +70,4 @@ namespace Impostor.Server.Net.Inner.Objects
             }
         }
     }
-}
\ No newline at end of file
+}