Пример #1
0
        /// <summary>
        /// Handles the QLRanks Elo update if necessary.
        /// </summary>
        /// <param name="player">The player.</param>
        private async Task HandleEloUpdate(string player)
        {
            PlayerInfo p;

            if (!_sst.ServerInfo.CurrentPlayers.TryGetValue(player, out p))
            {
                return;
            }
            if (_qlRanksHelper.DoesCachedEloExist(player))
            {
                if (!_qlRanksHelper.IsCachedEloDataOutdated(player))
                {
                    _qlRanksHelper.SetCachedEloData(_sst.ServerInfo.CurrentPlayers, player);
                }
                else
                {
                    Log.Write(
                        string.Format("Outdated cached Elo data found in database for {0}. Will update.",
                                      player), _logClassType, _logPrefix);

                    _qlRanksHelper.CreateNewPlayerEloData(_sst.ServerInfo.CurrentPlayers, player);
                    await
                    _qlRanksHelper.RetrieveEloDataFromApiAsync(_sst.ServerInfo.CurrentPlayers, player);
                }
            }
            else
            {
                _qlRanksHelper.CreateNewPlayerEloData(_sst.ServerInfo.CurrentPlayers, player);
                await
                _qlRanksHelper.RetrieveEloDataFromApiAsync(_sst.ServerInfo.CurrentPlayers, player);
            }
        }
Пример #2
0
        /// <summary>
        /// Handles the player information from the 'players' command and performs various actions
        /// based on the data.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="playersText">The players text.</param>
        /// <remarks>
        /// playersText is sent as an IEnumerable, with each element representing a line of the text
        /// containing the player information from the /players command.
        /// </remarks>
        public async Task HandlePlayersFromPlayersCmd <T>(
            IEnumerable <T> playersText)
        {
            _qlranksToUpdateFromPlayers.Clear();
            var qlranksHelper = new QlRanksHelper();

            foreach (var line in playersText)
            {
                var text           = line.ToString();
                var playerNameOnly =
                    text.Substring(
                        text.LastIndexOf(" ", StringComparison.Ordinal) + 1)
                    .ToLowerInvariant();

                // Try to create the player info (name, clan, id)
                if (!CreatePlayerFromPlayersText(text))
                {
                    return;
                }
                // Set the cached Elo for a player or add to list to be updated
                HandleEloFromPlayersText(qlranksHelper, playerNameOnly);
                // Store user's last seen date
                _seenDb.UpdateLastSeenDate(playerNameOnly, DateTime.Now);
            }
            // Clear
            _sst.QlCommands.ClearBothQlConsoles();

            // Do any necessary Elo updates
            if (_qlranksToUpdateFromPlayers.Any())
            {
                await
                qlranksHelper.RetrieveEloDataFromApiAsync(
                    _sst.ServerInfo.CurrentPlayers, _qlranksToUpdateFromPlayers);
            }
            // If any players should be kicked (i.e. due to a module), then do so, but wait a few
            // (10) seconds since we might have to hit network for retrieval (i.e. QLRanks)
            await Task.Delay(10000);

            await DoRequiredPlayerKicks();
        }
Пример #3
0
        /// <summary>
        /// Removes players from server who do not meet the specified Elo requirements immediately
        /// after enabling the elo limiter.
        /// </summary>
        public async Task BatchRemoveEloPlayers()
        {
            // disable

            var qlrHelper = new QlRanksHelper();
            // First make sure that the elo is correct and fetch if not
            var playersToUpdate = (from player in _sst.ServerInfo.CurrentPlayers
                                   where qlrHelper.PlayerHasInvalidEloData(player.Value)
                                   select player.Key).ToList();

            if (playersToUpdate.Any())
            {
                var qlr =
                    await
                    qlrHelper.RetrieveEloDataFromApiAsync(_sst.ServerInfo.CurrentPlayers, playersToUpdate);

                if (qlr == null)
                {
                    await _sst.QlCommands.QlCmdSay(
                        "^1[ERROR]^7 Unable to retrieve QLRanks data. Elo limit might not be enforced.", false);

                    Log.Write("QLRanks Elo data could not be retrieved. Elo limit might not be enforced.",
                              _logClassType, _logPrefix);
                }
            }
            // Kick the players from the server...
            foreach (var player in _sst.ServerInfo.CurrentPlayers.ToList())
            {
                // Still have invalid elo data...skip.
                if (qlrHelper.PlayerHasInvalidEloData(player.Value))
                {
                    Log.Write(
                        string.Format(
                            "Still have invalid Elo data for player {0}; player won't be evaluated for kicking.",
                            player.Key), _logClassType, _logPrefix);
                    break;
                }
                await KickPlayerIfEloNotMet(player.Key);
            }
        }
Пример #4
0
        /// <summary>
        /// Verify all player elo data.
        /// </summary>
        /// <param name="players">The players.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Unable to verify player Elo data</exception>
        private async Task VerifyElo(Dictionary <string, PlayerInfo> players)
        {
            var update =
                (from player in players
                 where _qlrHelper.PlayerHasInvalidEloData(player.Value)
                 select player.Key).ToList();

            if (update.Any())
            {
                var qlrData =
                    await _qlrHelper.RetrieveEloDataFromApiAsync(_sst.ServerInfo.CurrentPlayers, update);

                if (qlrData == null)
                {
                    await _sst.QlCommands.QlCmdSay(
                        "^1[ERROR]^3 Unable to verify player data. Try again in a few seconds.", false);

                    Log.WriteCritical("Unable to verify player Elo data.", _logClassType, _logPrefix);
                    throw new Exception("Unable to verify player Elo data");
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Gets the missing player Elo values if applicable.
        /// </summary>
        /// <returns><c>true</c> if the ELo values could be retried, otherwise <c>false</c>.</returns>
        private async Task <bool> GetMissingEloVals()
        {
            var qlrHelper       = new QlRanksHelper();
            var playersToUpdate = (from player in _sst.ServerInfo.CurrentPlayers
                                   where qlrHelper.PlayerHasInvalidEloData(player.Value)
                                   select player.Key).ToList();

            if (playersToUpdate.Any())
            {
                var qlr =
                    await
                    qlrHelper.RetrieveEloDataFromApiAsync(_sst.ServerInfo.CurrentPlayers, playersToUpdate);

                if (qlr == null)
                {
                    Log.Write("QLRanks Elo data could not be retrieved when listing server Elos.",
                              _logClassType, _logPrefix);
                    return(false);
                }
            }
            return(true);
        }