public async Task TryStart() { using (await _lock.LockAsync()) { if ((_config.userIds.All(id => _clients.Keys.Contains(id)) && _clients.Values.All(client => client.Status == PlayerStatus.Ready) || _config.Public) && _status == ServerStatus.WaitingPlayers) { _status = ServerStatus.Starting; _logger.Log(LogLevel.Trace, "gamesession", "Starting game session.", new { }); await Start(); _logger.Log(LogLevel.Trace, "gamesession", "Game session started.", new { }); var ctx = new GameSessionStartedCtx(_scene, _clients.Select(kvp => new Player(kvp.Value.Peer, kvp.Key))); await _eventHandlers()?.RunEventHandler(eh => eh.GameSessionStarted(ctx), ex => _logger.Log(LogLevel.Error, "gameSession", "An error occured while running gameSession.Started event handlers", ex)); } } }
public async Task TryStart() { using (await _lock.LockAsync()) { if (_config.userIds.All(id => _clients.Keys.Contains(id)) && _clients.Values.All(client => client.Status == PlayerStatus.Ready) && _status == ServerStatus.WaitingPlayers) { _status = ServerStatus.Starting; _logger.Log(LogLevel.Trace, "gamesession", "Starting game session.", new { }); await Start(); var ctx = new GameSessionStartedCtx(_scene, _clients.Select(kvp => new Player(kvp.Value.Peer, kvp.Key))); var handlers = _eventHandlers(); _logger.Log(LogLevel.Info, "gameSession", "Invoking GameStarted", new { h = handlers.Select(h => h.GetType().ToString()) }); await handlers?.RunEventHandler(eh => eh.GameSessionStarted(ctx), ex => _logger.Log(LogLevel.Error, "gameSession", "An error occured while running gameSession.Started event handlers", ex)); _scene.Broadcast("server.started", new GameServerStartMessage { Ip = _ip, Port = _port }); } } }