do not respawn inactive players
This commit is contained in:
		
							parent
							
								
									c73240a1c5
								
							
						
					
					
						commit
						6c9775fbfe
					
				
					 11 changed files with 91 additions and 48 deletions
				
			
		| 
						 | 
				
			
			@ -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);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,5 +11,6 @@ internal record struct PlayerInfo(
 | 
			
		|||
    string Name,
 | 
			
		||||
    Scores Scores,
 | 
			
		||||
    string Controls,
 | 
			
		||||
    TankInfo? Tank
 | 
			
		||||
    TankInfo? Tank,
 | 
			
		||||
    int OpenConnections
 | 
			
		||||
);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue