{
await Connection.CustomDisconnectAsync(reason, message);
}
+
+ public bool Equals(IClient? other)
+ {
+ return other != null && Id == other.Id;
+ }
+
+ public override bool Equals(object? obj)
+ {
+ return Equals(obj as ClientBase);
+ }
+
+ public override int GetHashCode()
+ {
+ return Id;
+ }
}
}
private readonly IEventManager _eventManager;
private readonly IGameCodeFactory _gameCodeFactory;
private readonly ICompatibilityManager _compatibilityManager;
+ private readonly ConcurrentDictionary<IClient, Game?> _gamesCreatedBy;
public GameManager(
ILogger<GameManager> logger,
_games = new ConcurrentDictionary<int, Game>();
_compatibilityConfig = compatibilityConfig.Value;
_compatibilityManager = compatibilityManager;
+ _gamesCreatedBy = new ConcurrentDictionary<IClient, Game?>();
}
IEnumerable<IGame> IGameManager.Games => _games.Select(kv => kv.Value);
public async ValueTask<IGame?> CreateAsync(IClient? owner, IGameOptions options, GameFilterOptions filterOptions)
{
+ if (owner != null && !_gamesCreatedBy.TryAdd(owner, null))
+ {
+ _logger.LogWarning("Connection {Name}({ClientId}) has tried to create a second game, blocked", owner.Name, owner.Id);
+ return null;
+ }
+
var @event = new GameCreationEvent(this, owner);
await _eventManager.CallAsync(@event);
(success, game) = await TryCreateAsync(options, filterOptions, owner);
}
+ if (owner != null)
+ {
+ _gamesCreatedBy[owner] = game;
+ }
+
if (!success || game == null)
{
throw new ImpostorException("Could not create new game"); // TODO: Fix generic exception.