Beispiel #1
0
        /// <summary>
        /// Checks to see if the player meets the elo requirement on connect.
        /// </summary>
        /// <param name="player">The player.</param>
        public async Task CheckPlayerEloRequirement(string player)
        {
            var playerElo = QlRanksHelper.GetEloForGameType(_sst.ServerInfo, player);

            // Likely invalid, skip.
            if (playerElo == 0)
            {
                return;
            }
            await KickPlayerIfEloNotMet(player);
        }
Beispiel #2
0
        /// <summary>
        /// Kicks the player if player does not meet the server's elo requirements.
        /// </summary>
        /// <param name="player">The player.</param>
        private async Task KickPlayerIfEloNotMet(string player)
        {
            // Module values have(n't) been set?
            var hasMaxEloSpecified = MaximumRequiredElo != 0;
            var hasMinEloSpecified = MinimumRequiredElo != 0;

            if (!hasMinEloSpecified)
            {
                return;
            }

            // Elo limits don't apply to SuperUsers or higher
            if (_users.GetUserLevel(player) >= UserLevel.SuperUser)
            {
                return;
            }
            // Can't kick ourselves, though QL doesn't allow it anyway, don't show kick msg.
            if (player.Equals(_sst.AccountName, StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }
            // Get Elo for the current gametype
            var playerElo = QlRanksHelper.GetEloForGameType(_sst.ServerInfo, player);

            // Player Elo is either invalid or we're not in a QLRanks-supported gametype. Abort.
            if (playerElo == 0)
            {
                return;
            }
            // Handle minimum
            if (playerElo < MinimumRequiredElo)
            {
                Log.Write(
                    string.Format("{0}'s {1} Elo is less than minimum required ({2})...Will kick player shortly.",
                                  player,
                                  GameType.ToString().ToUpper(), MinimumRequiredElo), _logClassType, _logPrefix);

                if (_configHandler.ReadConfiguration().EloLimitOptions.showKickSoonMessage)
                {
                    await _sst.QlCommands.QlCmdSay(
                        string.Format(
                            "^3[=> KICK SOON]: ^1{0}^7 ({1} Elo:^1 {2}^7) does not meet this server's Elo requirements. Min:^2 {3} {4}",
                            player, GameType.ToString().ToUpper(), playerElo,
                            MinimumRequiredElo,
                            hasMaxEloSpecified ? string.Format("^7Max:^1 {0}", MaximumRequiredElo) : ""), false);
                }

                // Wait before notifying and kicking, so user's screen doesn't freeze on "awaiting
                // snapshot", especially when connecting
                await
                _sst.QlCommands.QlCmdDelayedTell(
                    string.Format(
                        "^3You will be kicked because your {0} QLRanks Elo (^1{1}^3) doesn't meet this server's requirements. Min: ^1{2} {3}",
                        GameType.ToString().ToUpper(), playerElo, MinimumRequiredElo,
                        hasMaxEloSpecified ? string.Format("^3Max:^1 {0}", MaximumRequiredElo) : ""), player, _kickTellDelaySecs);

                await _sst.QlCommands.CustCmdDelayedKickban(player, (_kickDelaySecs + 2));

                return;
            }
            // Handle range
            if (!hasMaxEloSpecified)
            {
                return;
            }
            if (playerElo <= MaximumRequiredElo)
            {
                return;
            }

            Log.Write(
                string.Format("{0}'s {1} Elo is greater than maximum allowed ({2})...Will kick player shortly.", player,
                              GameType.ToString().ToUpper(), MaximumRequiredElo), _logClassType, _logPrefix);

            if (_configHandler.ReadConfiguration().EloLimitOptions.showKickSoonMessage)
            {
                await _sst.QlCommands.QlCmdSay(
                    string.Format(
                        "^3[=> KICK SOON]: ^1{0}^7 ({1} Elo:^1 {2}^7) does not meet this server's Elo requirements. Min:^2 {3} ^7Max:^1 {4}",
                        player, GameType.ToString().ToUpper(), playerElo,
                        MinimumRequiredElo, MaximumRequiredElo), false);
            }

            await
            _sst.QlCommands.QlCmdDelayedTell(
                string.Format(
                    "^3You will be kicked because your {0} QLRanks Elo (^1{1}^3) doesn't meet this server's requirements. Min: ^1{2}^3 Max: ^1{3}",
                    GameType.ToString().ToUpper(), playerElo, MinimumRequiredElo, MaximumRequiredElo), player, _kickTellDelaySecs);

            await _sst.QlCommands.CustCmdDelayedKickban(player, (_kickDelaySecs + 2));
        }