From f43577b74580a6303dc9f3ea401690c39e5fe6b5 Mon Sep 17 00:00:00 2001 From: js6pak Date: Sun, 11 Apr 2021 16:05:08 +0200 Subject: [PATCH] Add simple ping toleration to murder player check --- src/Impostor.Api/Net/IHazelConnection.cs | 5 +++++ src/Impostor.Server/Net/Hazel/HazelConnection.cs | 2 ++ src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.cs | 2 +- src/Impostor.Tools.ServerReplay/Mocks/MockHazelConnection.cs | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Impostor.Api/Net/IHazelConnection.cs b/src/Impostor.Api/Net/IHazelConnection.cs index c3ce51e15..09f17c3c1 100644 --- a/src/Impostor.Api/Net/IHazelConnection.cs +++ b/src/Impostor.Api/Net/IHazelConnection.cs @@ -24,6 +24,11 @@ public interface IHazelConnection /// IClient? Client { get; set; } + /// + /// Gets the average ping of the client. + /// + float AveragePing { get; } + /// /// Sends a message writer to the connection. /// diff --git a/src/Impostor.Server/Net/Hazel/HazelConnection.cs b/src/Impostor.Server/Net/Hazel/HazelConnection.cs index c59a91c2d..fab5ff551 100644 --- a/src/Impostor.Server/Net/Hazel/HazelConnection.cs +++ b/src/Impostor.Server/Net/Hazel/HazelConnection.cs @@ -27,6 +27,8 @@ public HazelConnection(Connection innerConnection, ILogger logg public IClient? Client { get; set; } + public float AveragePing => InnerConnection is NetworkConnection networkConnection ? networkConnection.AveragePingMs : 0; + public ValueTask SendAsync(IMessageWriter writer) { return InnerConnection.SendAsync(writer); diff --git a/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.cs b/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.cs index 06191a18f..488e72598 100644 --- a/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.cs +++ b/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.cs @@ -544,7 +544,7 @@ private async ValueTask HandleMurderPlayer(ClientPlayer sender, IInnerPlay } } - PlayerInfo.LastMurder = _dateTimeProvider.UtcNow; + PlayerInfo.LastMurder = _dateTimeProvider.UtcNow - TimeSpan.FromMilliseconds(sender.Client.Connection.AveragePing); if (target != null && !target.PlayerInfo.IsDead) { diff --git a/src/Impostor.Tools.ServerReplay/Mocks/MockHazelConnection.cs b/src/Impostor.Tools.ServerReplay/Mocks/MockHazelConnection.cs index c611c2949..292899aa5 100644 --- a/src/Impostor.Tools.ServerReplay/Mocks/MockHazelConnection.cs +++ b/src/Impostor.Tools.ServerReplay/Mocks/MockHazelConnection.cs @@ -17,6 +17,7 @@ public MockHazelConnection(IPEndPoint endPoint) public IPEndPoint EndPoint { get; } public bool IsConnected { get; } public IClient Client { get; set; } + public float AveragePing => 0; public ValueTask SendAsync(IMessageWriter writer) {