示例#1
0
        public async Task <IActionResult> GetRconPlayers(Guid id)
        {
            var gameServerDto = await _gameServersRepository.GetGameServer(id);

            var canViewLiveRcon = await _authorizationService.AuthorizeAsync(User, gameServerDto, AuthPolicies.ViewLiveRcon);

            if (!canViewLiveRcon.Succeeded)
            {
                return(Unauthorized());
            }

            var portalGameServerStatusDto = await _gameServerStatusRepository.GetStatus(id, TimeSpan.FromSeconds(15));

            return(Json(new
            {
                data = portalGameServerStatusDto.Players
            }));
        }
        public override async Task HandleChatMessage(Guid serverId, string name, string guid, string message, ChatType chatType)
        {
            if (!IsMatchingCommand(message))
            {
                return;
            }

            if (!name.Contains(">XI<"))
            {
                return;
            }

            var server = await _gameServersRepository.GetGameServer(serverId);

            var gameServerStatus = await _gameServerStatusRepository.GetStatus(serverId, TimeSpan.Zero);

            var targetName = name;

            if (gameServerStatus != null)
            {
                var splits = message.Replace("!fu", "").Trim().Split(' ');
                if (splits.Any())
                {
                    var potentialTarget = splits.First().ToLower();
                    var potentialMatch  = gameServerStatus.Players.Where(p => p.Name.ToLower().Contains(potentialTarget)).ToList();

                    if (potentialMatch.Count == 1)
                    {
                        targetName = potentialMatch.First().Name;
                    }
                }
            }

            _logger.LogInformation("FuckYou initiated for {name} on {server}", name, server.Title);

            var responseMessage = GenerateResponseMessage(targetName);

            _logger.LogInformation("Executing FuckYou response '{response}' for {name} on {server}", responseMessage, name, server.Title);

            var rconClient = _rconClientFactory.CreateInstance(server.GameType, server.ServerId, server.Hostname, server.QueryPort, server.RconPassword);
            await rconClient.Say(responseMessage);
        }
示例#3
0
        // ReSharper disable once UnusedMember.Global
        public async Task RunUpdateGameServerStatus([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger log)
        {
            log.LogDebug($"Start RunUpdateGameServerStatus @ {DateTime.UtcNow}");

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            _playerIngest.OverrideLogger(log);

            var servers = await _legacyContext.GameServers.AsQueryable().Where(server => server.ShowOnPortalServerList).ToListAsync();

            foreach (var server in servers)
            {
                log.LogDebug($"Updating game server status for {server.Title}");

                try
                {
                    var model = await _gameServerStatusRepository.GetStatus(server.ServerId, TimeSpan.FromMinutes(-1));

                    if (model == null)
                    {
                        log.LogWarning($"Failed to update game server status for {server.Title}");
                        continue;
                    }

                    log.LogInformation($"{model.ServerName} is online running {model.Map} with {model.PlayerCount} players connected");

                    await _gameServerStatusStatsRepository.UpdateEntry(new GameServerStatusStatsDto
                    {
                        ServerId    = server.ServerId,
                        GameType    = server.GameType,
                        PlayerCount = model.PlayerCount,
                        MapName     = model.Map
                    });

                    var playerGuid = string.Empty;
                    try
                    {
                        foreach (var player in model.Players)
                        {
                            playerGuid = player.Guid;
                            await _playerIngest.IngestData(server.GameType, player.Guid, player.Name, player.IpAddress);
                        }
                    }
                    catch (Exception ex)
                    {
                        log.LogError(ex, "Failed to ingest player data for guid: {Guid}", playerGuid);
                    }
                }
                catch (Exception ex)
                {
                    log.LogError(ex, "Failed to get game server status for {Title}", server.Title);
                }
            }

            foreach (var gameServerStatus in await _gameServerStatusRepository.GetAllStatusModels(new Servers.Models.GameServerStatusFilterModel(), TimeSpan.Zero))
            {
                var server = servers.SingleOrDefault(server => server.ServerId == gameServerStatus.ServerId);

                if (server == null)
                {
                    log.LogInformation($"Removing game server status as server is no longer being queried {gameServerStatus.ServerName}");
                    await _gameServerStatusRepository.DeleteStatusModel(gameServerStatus);

                    await _gameServerStatusStatsRepository.DeleteGameServerStatusStats(gameServerStatus.ServerId);
                }
            }

            stopWatch.Stop();
            log.LogDebug($"Stop RunUpdateGameServerStatus @ {DateTime.UtcNow} after {stopWatch.ElapsedMilliseconds} milliseconds");
        }
示例#4
0
        public override async Task HandleChatMessage(Guid serverId, string name, string guid, string message, ChatType chatType)
        {
            if (!IsMatchingCommand(message))
            {
                return;
            }

            var server = await _gameServersRepository.GetGameServer(serverId);

            var gameServerStatus = await _gameServerStatusRepository.GetStatus(serverId, TimeSpan.Zero);

            if (gameServerStatus == null)
            {
                _logger.LogWarning("Could not process !like for {name} as the game server status is null for {serverId}", name, serverId);
                return;
            }

            var statusPlayer = gameServerStatus.Players.SingleOrDefault(p => p.Guid == guid);

            if (statusPlayer == null)
            {
                _logger.LogWarning("Could not process !like for {name} as the status player is null for {guid}", name, guid);
                return;
            }

            var databasePlayer = await _playersRepository.GetPlayer(gameServerStatus.GameType, guid);

            if (databasePlayer == null)
            {
                _logger.LogWarning("Could not process !like for {name} as player is null for {guid}", name, guid);
                return;
            }

            var rconClient = _rconClientFactory.CreateInstance(server.GameType, server.ServerId, server.Hostname, server.QueryPort, server.RconPassword);
            var like       = !message.ToLower().Contains("!dislike");

            var mapPopularityDto = await _mapPopularityRepository.GetMapPopularity(gameServerStatus.GameType, gameServerStatus.Map);

            if (mapPopularityDto == null)
            {
                mapPopularityDto = new MapPopularityDto
                {
                    GameType = gameServerStatus.GameType,
                    MapName  = gameServerStatus.Map,
                    MapVotes = new List <MapPopularityVoteDto>
                    {
                        new MapPopularityVoteDto
                        {
                            ServerId    = gameServerStatus.ServerId,
                            ServerName  = gameServerStatus.ServerName,
                            PlayerId    = databasePlayer.PlayerId,
                            PlayerName  = name,
                            ModName     = gameServerStatus.Mod,
                            PlayerCount = gameServerStatus.PlayerCount,
                            Updated     = DateTime.UtcNow,
                            Like        = like
                        }
                    }
                };

                await _mapPopularityRepository.UpdateMapPopularity(mapPopularityDto);
            }
            else
            {
                var existing = mapPopularityDto.MapVotes.SingleOrDefault(mp => mp.PlayerId == databasePlayer.PlayerId && mp.ModName == gameServerStatus.Mod && mp.ServerId == gameServerStatus.ServerId);
                if (existing == null)
                {
                    mapPopularityDto.MapVotes.Add(new MapPopularityVoteDto
                    {
                        ServerId    = gameServerStatus.ServerId,
                        ServerName  = gameServerStatus.ServerName,
                        PlayerId    = databasePlayer.PlayerId,
                        PlayerName  = name,
                        ModName     = gameServerStatus.Mod,
                        PlayerCount = gameServerStatus.PlayerCount,
                        Updated     = DateTime.UtcNow,
                        Like        = like
                    });

                    await _mapPopularityRepository.UpdateMapPopularity(mapPopularityDto);
                }
                else
                {
                    existing.Updated = DateTime.UtcNow;
                    existing.Like    = like;

                    await _mapPopularityRepository.UpdateMapPopularity(mapPopularityDto);
                }
            }

            var globalMessage = $"^6{name} ^2likes ^6this map - thanks for the feedback!";

            if (!like)
            {
                globalMessage = $"^6{name} ^1dislikes ^6this map - thanks for the feedback!";
            }

            var totalLikes    = mapPopularityDto.MapVotes.Count(mv => mv.ServerId == gameServerStatus.ServerId && mv.ModName == gameServerStatus.Mod && mv.Like);
            var totalDislikes = mapPopularityDto.MapVotes.Count(mv => mv.ServerId == gameServerStatus.ServerId && mv.ModName == gameServerStatus.Mod && mv.Like == false);

            var overall = $"^6Overall there are ^2{totalLikes} likes ^6and ^1{totalDislikes} dislikes ^6for this map";

            await rconClient.Say(globalMessage);

            await rconClient.Say(overall);
        }