This repository has been archived on 2026-07-13. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
servicepoint-tanks/TanksServer/Services/TankManager.cs
2024-04-07 21:09:36 +02:00

25 lines
730 B
C#

using System.Collections;
using Microsoft.Extensions.Logging;
using TanksServer.Models;
namespace TanksServer.Services;
internal sealed class TankManager(ILogger<TankManager> logger) : IEnumerable<Tank>
{
private readonly ConcurrentDictionary<Tank, byte> _tanks = new();
public void Add(Tank tank)
{
logger.LogInformation("Tank added for player {}", tank.Owner.Id);
_tanks.TryAdd(tank, 0);
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public IEnumerator<Tank> GetEnumerator() => _tanks.Keys.GetEnumerator();
public void Remove(Tank tank)
{
logger.LogInformation("Tank removed for player {}", tank.Owner.Id);
_tanks.Remove(tank, out _);
}
}