/// <summary> /// Query the game server and get the server info and players /// </summary> /// <param name="gameServer"></param> /// <returns></returns> public async Task <ServerStatsWrapper> UpdateServerQueryStatsAsync(GameServer gameServer) { _logger.LogDebug("Updating query stats for server {id}", gameServer.Id); var query = _gameQueryFactory.GetQueryProtocol(gameServer); var players = await query.GetServerPlayersAsync(); var serverInfo = await query.GetServerInfoAsync(); var statsWrapper = new ServerStatsWrapper(serverInfo, players, gameServer.Id); _mediator.Publish(new ServerStatsUpdateNotification(statsWrapper)); return(statsWrapper); }
public async Task <ServerStatsWrapper> Handle(QueryServerCommand request, CancellationToken cancellationToken) { _logger.LogDebug($"Running Handler QueryGameServerHandler"); var statsWrapper = new ServerStatsWrapper() { gameServerId = request.gameServerId }; var gameServer = _repository.Single(DataItemPolicy <GameServer> .ById(request.gameServerId)); if (gameServer == null) { _logger.LogError($"Unable to located game server with ID {request.gameServerId}"); return(statsWrapper); } var query = _gameQueryFactory.GetQueryProtocol(gameServer); statsWrapper.players = await query.GetServerPlayersAsync(); statsWrapper.serverInfo = await query.GetServerInfoAsync(); return(statsWrapper); }