Ejemplo n.º 1
0
        public async Task <IActionResult> Index()
        {
            var sessionGeoLocationDto =
                _httpContext.HttpContext.Session.GetObjectFromJson <LookupAddressResponse>(UserLocationSessionKey);

            if (sessionGeoLocationDto != null)
            {
                return(View(sessionGeoLocationDto));
            }

            var address = GetUsersIpForLookup();

            LookupAddressResponse lookupAddressResponse;

            try
            {
                lookupAddressResponse = await _geoLocationClient.LookupAddress(address.ToString());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error retrieving geo-location data for {address}", address);
                return(Error());
            }

            _httpContext.HttpContext.Session.SetObjectAsJson(UserLocationSessionKey, lookupAddressResponse);

            return(View(lookupAddressResponse));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            var sessionGeoLocationDto =
                _httpContext.HttpContext.Session.GetObjectFromJson <LookupAddressResponse>(UserLocationSessionKey);

            if (sessionGeoLocationDto != null)
            {
                return(View(sessionGeoLocationDto));
            }

            var address = GetUsersIpForLookup();

            var lookupAddressResponse = await _geoLocationClient.LookupAddress(address.ToString());

            if (lookupAddressResponse == null)
            {
                return(Error());
            }
            else if (!lookupAddressResponse.Success)
            {
                return(Error(lookupAddressResponse.ErrorMessage));
            }
            else
            {
                _httpContext.HttpContext.Session.SetObjectAsJson(UserLocationSessionKey, lookupAddressResponse);

                return(View(lookupAddressResponse));
            }
        }
        private async Task <PortalGameServerStatusDto> RefreshGameServerStatus(Guid serverId)
        {
            try
            {
                var server = await _gameServersRepository.GetGameServer(serverId);

                var gameServerStatusHelper = _gameServerClientFactory.GetGameServerStatusHelper(server.GameType, server.ServerId, server.Hostname, server.QueryPort, server.RconPassword);

                var gameServerStatus = await gameServerStatusHelper.GetServerStatus();

                if (gameServerStatus == null)
                {
                    return(null);
                }

                var model = new PortalGameServerStatusDto
                {
                    ServerId    = serverId,
                    GameType    = server.GameType,
                    Hostname    = server.Hostname,
                    QueryPort   = server.QueryPort,
                    MaxPlayers  = gameServerStatus.MaxPlayers,
                    ServerName  = gameServerStatus.ServerName,
                    Map         = gameServerStatus.Map,
                    Mod         = gameServerStatus.Mod,
                    PlayerCount = gameServerStatus.PlayerCount
                };

                var players = new List <PortalGameServerPlayerDto>();

                foreach (var player in gameServerStatus.Players)
                {
                    var playerDto = new PortalGameServerPlayerDto
                    {
                        Num       = player.Num,
                        Guid      = player.Guid,
                        Name      = player.Name,
                        IpAddress = player.IpAddress,
                        Score     = player.Score,
                        Rate      = player.Rate
                    };

                    if (!string.IsNullOrWhiteSpace(player.IpAddress))
                    {
                        var geoLocationResponse = await _geoLocationClient.LookupAddress(playerDto.IpAddress);

                        if (geoLocationResponse.Success)
                        {
                            playerDto.GeoLocation = geoLocationResponse.GeoLocationDto;

                            await _playersLocationsRepository.UpdateEntry(new PlayerLocationDto
                            {
                                GameType    = server.GameType,
                                ServerId    = server.ServerId,
                                ServerName  = gameServerStatus.ServerName,
                                Guid        = player.Guid,
                                PlayerName  = player.Name,
                                GeoLocation = geoLocationResponse.GeoLocationDto
                            });
                        }
                    }

                    players.Add(playerDto);
                }

                model.Players = players;

                await UpdateStatus(serverId, model);

                return(model);
            }
            catch
            {
                return(null);
            }
        }