Skip to content

Commit

Permalink
Add simple ping toleration to murder player check
Browse files Browse the repository at this point in the history
  • Loading branch information
js6pak committed Apr 11, 2021
1 parent a56eed2 commit f43577b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Impostor.Api/Net/IHazelConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public interface IHazelConnection
/// </summary>
IClient? Client { get; set; }

/// <summary>
/// Gets the average ping of the client.
/// </summary>
float AveragePing { get; }

/// <summary>
/// Sends a message writer to the connection.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Impostor.Server/Net/Hazel/HazelConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public HazelConnection(Connection innerConnection, ILogger<HazelConnection> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ private async ValueTask<bool> HandleMurderPlayer(ClientPlayer sender, IInnerPlay
}
}

PlayerInfo.LastMurder = _dateTimeProvider.UtcNow;
PlayerInfo.LastMurder = _dateTimeProvider.UtcNow - TimeSpan.FromMilliseconds(sender.Client.Connection.AveragePing);

if (target != null && !target.PlayerInfo.IsDead)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit f43577b

Please sign in to comment.