do not respawn inactive players

This commit is contained in:
Vinzenz Schroeter 2024-05-02 21:27:56 +02:00 committed by RobbersDaughter
parent cd12ab7bde
commit abad2c95c8
11 changed files with 91 additions and 48 deletions

View file

@ -4,6 +4,8 @@ namespace TanksServer.Models;
internal sealed class Player : IEquatable<Player>
{
private int _openConnections;
public required string Name { get; init; }
[JsonIgnore] public PlayerControls Controls { get; } = new();
@ -12,6 +14,8 @@ internal sealed class Player : IEquatable<Player>
public DateTime LastInput { get; set; } = DateTime.Now;
public int OpenConnections => _openConnections;
public override bool Equals(object? obj) => obj is Player p && Equals(p);
public bool Equals(Player? other) => other?.Name == Name;
@ -21,4 +25,8 @@ internal sealed class Player : IEquatable<Player>
public static bool operator ==(Player? left, Player? right) => Equals(left, right);
public static bool operator !=(Player? left, Player? right) => !Equals(left, right);
internal void IncrementConnectionCount() => Interlocked.Increment(ref _openConnections);
internal void DecrementConnectionCount() => Interlocked.Decrement(ref _openConnections);
}

View file

@ -11,5 +11,6 @@ internal record struct PlayerInfo(
string Name,
Scores Scores,
string Controls,
TankInfo? Tank
TankInfo? Tank,
int OpenConnections
);