Ejemplo n.º 1
0
        /// <summary>
        /// Handles the player connection.
        /// </summary>
        /// <param name="player">The player.</param>
        public async Task HandleIncomingPlayerConnection(string player)
        {
            // "/?" command, regex would otherwise match, so ignore
            if (player.Equals("players show currently", StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            Log.Write("Detected incoming connection for " + player, _logClassType, _logPrefix);

            // Player connections include the clan tag, so we need to remove it
            player = Helpers.GetStrippedName(player);

            _seenDb.UpdateLastSeenDate(player, DateTime.Now);

            if ((Helpers.KeyExists(player, _sst.ServerInfo.CurrentPlayers) &&
                 (!_qlRanksHelper.ShouldSkipEloUpdate(player, _sst.ServerInfo.CurrentPlayers))))
            {
                await HandleEloUpdate(player);
            }

            // If IRC module is active, send the message to the IRC channel
            if (_sst.Mod.Irc.Active && _sst.Mod.Irc.IsConnectedToIrc)
            {
                _sst.Mod.Irc.IrcManager.SendIrcMessage(_sst.Mod.Irc.IrcManager.IrcSettings.ircChannel,
                                                       string.Format("{0} has connected to my QL server.", player));
            }

            // Auto-op if applicable
            await _sst.ServerEventProcessor.AutoOpActiveAdmin(player);

            // Elo limiter kick, if active
            if (_sst.Mod.EloLimit.Active)
            {
                await _sst.Mod.EloLimit.CheckPlayerEloRequirement(player);
            }
            // Account date kick, if active
            if (_sst.Mod.AccountDateLimit.Active)
            {
                await _sst.Mod.AccountDateLimit.RunUserDateCheck(player);
            }
            // Send general info delayed message
            await SendConnectionInfoMessage(player);

            // Pickup module: notify connecting player of the game signup process
            if (_sst.Mod.Pickup.Active)
            {
                await _sst.Mod.Pickup.Manager.NotifyConnectingUser(player);
            }

            // Check for time-bans
            var bManager = new BanManager(_sst);
            await bManager.CheckForBans(player);
        }
Ejemplo n.º 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();
        }