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

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

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

            var rconClient = _rconClientFactory.CreateInstance(
                gameServerDto.GameType,
                gameServerDto.ServerId,
                gameServerDto.Hostname,
                gameServerDto.QueryPort,
                gameServerDto.RconPassword);

            var result = await rconClient.Restart();

            return(Json(new
            {
                Success = true,
                Message = result
            }));
        }
Beispiel #2
0
        public void Configure(GameType gameType, Guid serverId, string hostname, int queryPort, string rconPassword)
        {
            QueryClient = _queryClientFactory.CreateInstance(gameType, hostname, queryPort);

            if (!string.IsNullOrWhiteSpace(rconPassword))
            {
                RconClient = _rconClientFactory.CreateInstance(gameType, serverId, hostname, queryPort, rconPassword);
            }

            _gameType         = gameType;
            _serverIdentifier = serverId;
            _hostname         = hostname;
            _queryPort        = queryPort;
        }
        public override async Task HandleChatMessage(Guid serverId, string name, string guid, string message, ChatType chatType)
        {
            if (!IsMatchingCommand(message))
            {
                return;
            }

            if (name != "Sitting-Duc>XI<")
            {
                return;
            }

            var server = await _gameServersRepository.GetGameServer(serverId);

            var rconClient = _rconClientFactory.CreateInstance(server.GameType, server.ServerId, server.Hostname, server.QueryPort, server.RconPassword);
            await rconClient.Say("^5Sitting-Duc ^2is the greatest!");
        }
        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);
        }
Beispiel #5
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);
        }