Example #1
0
        /// <summary>
        /// Evaluates the early quit clear command to see if it can be successfully processed.
        /// </summary>
        /// <param name="c">The command argument information.</param>
        /// <returns><c>true</c> if the evaluation was successful, otherwise <c>false</c>.</returns>
        private async Task <bool> EvalEarlyQuitClear(Cmd c)
        {
            if (c.Args.Length != (c.FromIrc ? 5 : 4))
            {
                StatusMessage =
                    string.Format(
                        "^1[ERROR]^3 Usage: {0}{1} {2} clear <name> ^7 - name is without the clan tag",
                        CommandList.GameCommandPrefix, c.CmdName,
                        ((c.FromIrc)
                            ? (string.Format("{0} {1}", c.Args[1],
                                             NameModule))
                            : NameModule));
                await SendServerTell(c, StatusMessage);

                return(false);
            }
            var quitDb = new DbQuits();

            if (!quitDb.UserExistsInDb(Helpers.GetArgVal(c, 3)))
            {
                StatusMessage = string.Format("^1[ERROR] {0}^3 has no early quits.",
                                              Helpers.GetArgVal(c, 3));
                await SendServerTell(c, StatusMessage);

                return(false);
            }
            await ClearEarlyQuits(c, quitDb);

            return(true);
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EarlyQuitHandler"/> class.
 /// </summary>
 public EarlyQuitHandler(SynServerTool sst)
 {
     _sst     = sst;
     _quitsDb = new DbQuits();
     _usersDb = new DbUsers();
     _bansDb  = new DbBans();
     GetConfigData();
 }
Example #3
0
        /// <summary>
        /// Removes a user's ban and removes/resets any other extraneous ban-related database
        /// properties for the user.
        /// </summary>
        /// <param name="banInfo">The ban information.</param>
        /// <param name="updateUi">
        /// if set to <c>true</c> then update relevant datasources in the user interface.
        /// </param>
        /// <returns><c>true</c> if the ban was deleted, otherwise <c>false</c>.</returns>
        /// <remarks>
        /// This method is typically used when access to the user interface is needed and when the
        /// unban command needs to be directly sent to the game. The underlying SST database classes
        /// are not given access to the main SST class.
        /// </remarks>
        public async Task <bool> RemoveBan(BanInfo banInfo, bool updateUi = true)
        {
            if (banInfo == null)
            {
                return(false);
            }
            // If the user was banned for quitting early, then also remove the user from the early
            // quit database when we clear the expired ban
            if (banInfo.BanType == BanType.AddedByEarlyQuit)
            {
                var eQuitDb = new DbQuits();
                eQuitDb.DeleteUserFromDb(banInfo.PlayerName);

                // UI: reflect changes
                if (updateUi)
                {
                    _sst.UserInterface.RefreshCurrentQuittersDataSource();
                }
            }
            // If the user was banned for using too many substitutes in pickup games, reset the
            // sub-used count
            if (banInfo.BanType == BanType.AddedByPickupSubs)
            {
                var pickupDb = new DbPickups();
                pickupDb.ResetSubsUsedCount(banInfo.PlayerName);
            }
            // If the user was banned for too many no-shows in pickup games, reset the user's
            // no-show count
            if (banInfo.BanType == BanType.AddedByPickupNoShows)
            {
                var pickupDb = new DbPickups();
                pickupDb.ResetNoShowCount(banInfo.PlayerName);
            }
            // Remove the ban from the database. This "on-demand" method of removing the ban is
            // preferred instead of using some mechanism such as a timer that would check every X
            // time period; In other words, leave the user banned until he tries to reconnect then
            // silently remove the ban.
            // Note: expired bans are also removed at various points during the bot's existence, for example,
            // they are also removed when admins try to add, list, or check bans with the timeban
            // command or can be removed using the UI.
            _banDb.DeleteUserFromDb(banInfo.PlayerName);

            // remove from QL's external temp kickban system as well
            if (_sst.IsMonitoringServer)
            {
                await _sst.QlCommands.CmdUnban(banInfo.PlayerName);
            }

            // UI: reflect changes
            if (updateUi)
            {
                _sst.UserInterface.RefreshCurrentBansDataSource();
            }

            return(true);
        }
Example #4
0
        /// <summary>
        /// Forgives a given numer of early quits for a user.
        /// </summary>
        /// <param name="c">The command argument information.</param>
        /// <param name="num">The number of quits to forgive.</param>
        /// <param name="player">The player.</param>
        /// <param name="qdb">The quit database.</param>
        private async Task ForgiveEarlyQuits(Cmd c, int num, string player, DbQuits qdb)
        {
            qdb.DecrementUserQuitCount(player, num);

            StatusMessage = string.Format("^5[EARLYQUIT]^7 Forgave^3 {0} ^7of ^3{1}^7's early quits.",
                                          num, player);
            await SendServerSay(c, StatusMessage);

            // UI: reflect changes
            _sst.UserInterface.RefreshCurrentQuittersDataSource();
        }
Example #5
0
        /// <summary>
        /// Clears the early quits for a given user.
        /// </summary>
        /// <param name="c">The command argument information.</param>
        /// <param name="qdb">The quit database.</param>
        private async Task ClearEarlyQuits(Cmd c, DbQuits qdb)
        {
            qdb.DeleteUserFromDb(Helpers.GetArgVal(c, 3));

            StatusMessage = string.Format("^5[EARLYQUIT]^7 Cleared all early quit records for: ^3{0}",
                                          Helpers.GetArgVal(c, 3));
            await SendServerSay(c, StatusMessage);

            // See if there is an early quit-related ban and remove it as well
            await qdb.RemoveQuitRelatedBan(_sst, Helpers.GetArgVal(c, 3));

            // UI: reflect changes
            _sst.UserInterface.RefreshCurrentQuittersDataSource();
            _sst.UserInterface.RefreshCurrentBansDataSource();
        }
Example #6
0
        /// <summary>
        /// Loads the configuration.
        /// </summary>
        public void LoadConfig()
        {
            // Initialize database
            var eq = new DbQuits();

            eq.InitDb();

            var cfg = _configHandler.ReadConfiguration();

            // See if we're dealing with the default values ReSharper disable once CompareOfFloatsByEqualityOperator
            if (cfg.EarlyQuitOptions.banTime == 0 ||
                cfg.EarlyQuitOptions.banTimeScale == string.Empty)
            {
                Active = false;
                return;
            }
            // See if it's a valid scale
            if (!Helpers.ValidTimeScales.Contains(cfg.EarlyQuitOptions.banTimeScale))
            {
                Log.WriteCritical(
                    "Invalid time scale detected. Won't enable. Setting early quit banner defaults.",
                    _logClassType, _logPrefix);

                Active = false;
                cfg.EarlyQuitOptions.SetDefaults();
                _configHandler.WriteConfiguration(cfg);
                return;
            }

            Active          = cfg.EarlyQuitOptions.isActive;
            BanTime         = cfg.EarlyQuitOptions.banTime;
            BanTimeScale    = cfg.EarlyQuitOptions.banTimeScale;
            MaxQuitsAllowed = cfg.EarlyQuitOptions.maxQuitsAllowed;

            Log.Write(string.Format(
                          "Active: {0}, ban time: {1} {2}, max early quits allowed: {3}",
                          (Active ? "YES" : "NO"), BanTime, BanTimeScale, MaxQuitsAllowed), _logClassType, _logPrefix);
        }
Example #7
0
        /// <summary>
        /// Evaluates the early quit forgive command to see if it can be successfully processed.
        /// </summary>
        /// <param name="c">The command argument information.</param>
        /// <returns><c>true</c> if the evaluation was successful, otherwise <c>false</c>.</returns>
        private async Task <bool> EvalEarlyQuitForgive(Cmd c)
        {
            if (c.Args.Length != (c.FromIrc ? 6 : 5))
            {
                StatusMessage = string.Format(
                    "^1[ERROR]^3 Usage: {0}{1} {2} forgive <name> <# of quits> ^7 - name is without the clan" +
                    " tag. # quits is amount to forgive",
                    CommandList.GameCommandPrefix, c.CmdName,
                    ((c.FromIrc)
                        ? (string.Format("{0} {1}", c.Args[1],
                                         NameModule))
                        : NameModule));
                await SendServerTell(c, StatusMessage);

                return(false);
            }
            var quitDb = new DbQuits();

            if (!quitDb.UserExistsInDb(Helpers.GetArgVal(c, 3)))
            {
                StatusMessage = string.Format("^1[ERROR]^7 {0}^3 has no early quits.", Helpers.GetArgVal(c, 3));
                await SendServerTell(c, StatusMessage);

                return(false);
            }
            int numQuitsToForgive;

            if (!int.TryParse(Helpers.GetArgVal(c, 4), out numQuitsToForgive))
            {
                StatusMessage = "^1[ERROR]^3 # of quits must be a number greater than zero!";
                await SendServerTell(c, StatusMessage);

                return(false);
            }
            if (numQuitsToForgive == 0)
            {
                StatusMessage = "^1[ERROR]^3 # of quits must be greater than zero.";
                await SendServerTell(c, StatusMessage);

                return(false);
            }
            var userTotalQuits = quitDb.GetUserQuitCount(Helpers.GetArgVal(c, 3));

            if (numQuitsToForgive >= userTotalQuits)
            {
                StatusMessage =
                    string.Format(
                        "^1[ERROR]^3 {0} has^1 {1}^3 total quits. This would remove all. If that's" +
                        " what you want: ^1{2}{3} {4} clear {0}",
                        Helpers.GetArgVal(c, 3), userTotalQuits,
                        CommandList.GameCommandPrefix, c.CmdName,
                        ((c.FromIrc)
                            ? (string.Format("{0} {1}", c.Args[1],
                                             NameModule))
                            : NameModule));
                await SendServerTell(c, StatusMessage);

                return(false);
            }
            await ForgiveEarlyQuits(c, numQuitsToForgive, Helpers.GetArgVal(c, 3), quitDb);

            return(true);
        }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EarlyQuitCmd"/> class.
 /// </summary>
 /// <param name="sst">The main class.</param>
 public EarlyQuitCmd(SynServerTool sst)
 {
     _sst    = sst;
     _quitDb = new DbQuits();
 }