Esempio n. 1
0
        /// <summary>
        /// Bans the early quitter.
        /// </summary>
        /// <param name="player">The player.</param>
        private async Task BanEarlyQuitter(string player)
        {
            // User already banned by admin (or by another module); do nothing
            if (_bansDb.UserAlreadyBanned(player))
            {
                Log.Write(string.Format(
                              "{0} already existed in ban database; skipping early quit ban.",
                              player), _logClassType, _logPrefix);
                return;
            }
            // Do the ban
            var expirationDate = ExpirationDateGenerator.GenerateExpirationDate(_banTime, _banTimeScale);

            _bansDb.AddUserToDb(player, "earlyQuitMod", DateTime.Now, expirationDate, BanType.AddedByEarlyQuit);

            await
            _sst.QlCommands.QlCmdSay(
                string.Format(
                    "^5[EARLYQUIT]^7 ^3{0}^7 has quit too many games early and is now banned until:^1 {1}",
                    player, expirationDate.ToString("G", DateTimeFormatInfo.InvariantInfo)), false);

            // The player might have not actually disconnected but spectated instead, so kickban(QL) immediately
            await _sst.QlCommands.CustCmdKickban(player);

            // UI: reflect changes
            _sst.UserInterface.RefreshCurrentBansDataSource();
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the ban.
        /// </summary>
        /// <param name="c">The command argument information.</param>
        /// <returns><c>true</c> if the ban was successfully added, otherwise <c>false</c>.</returns>
        private async Task <bool> AddBan(Cmd c)
        {
            // Kickban user immediately using internal QL command
            await _sst.QlCommands.CustCmdKickban(Helpers.GetArgVal(c, 2));

            if (_banDb.UserAlreadyBanned(Helpers.GetArgVal(c, 2)))
            {
                var deleted = await DeleteIfExpired(Helpers.GetArgVal(c, 2));

                if (deleted)
                {
                    StatusMessage =
                        string.Format("^5[TIMEBAN]^7 A previous ban for^3 {0}^7 has expired. Now removing." +
                                      " Re-add if you wish to re-ban.",
                                      Helpers.GetArgVal(c, 2));
                    await SendServerTell(c, StatusMessage);

                    return(false);
                }

                var banInfo = _banDb.GetBanInfo(Helpers.GetArgVal(c, 2));
                if (banInfo == null)
                {
                    StatusMessage =
                        "^1[ERROR]^3 Unable to retrieve ban information while attempting to add ban.";
                    await SendServerTell(c, StatusMessage);

                    return(false);
                }
                StatusMessage = string.Format(
                    "^5[TIMEBAN]^7 Time-ban already exists for player: ^3{0}^7, who was banned by admin: ^3{1}^7 on ^1{2}^7." +
                    " Ban will expire on: ^2{3}.^7 Use ^3{4}{5} del {0}^7 to remove ban.",
                    Helpers.GetArgVal(c, 2), banInfo.BannedBy,
                    banInfo.BanAddedDate.ToString("G", DateTimeFormatInfo.InvariantInfo),
                    banInfo.BanExpirationDate.ToString("G", DateTimeFormatInfo.InvariantInfo),
                    CommandList.GameCommandPrefix,
                    ((c.FromIrc)
                        ? (string.Format("{0} {1}",
                                         c.CmdName, c.Args[1]))
                        : c.CmdName));

                await SendServerTell(c, StatusMessage);

                return(false);
            }

            // length was already verified to be a double in Eval method
            var length         = double.Parse(Helpers.GetArgVal(c, 3));
            var scale          = Helpers.GetArgVal(c, 4);
            var expirationDate = ExpirationDateGenerator.GenerateExpirationDate(length, scale);

            if (
                _banDb.AddUserToDb(Helpers.GetArgVal(c, 2), c.FromUser, DateTime.Now, expirationDate,
                                   BanType.AddedByAdmin) ==
                UserDbResult.Success)
            {
                StatusMessage = string.Format(
                    "^2[SUCCESS]^7 Added time-ban for player: {0}. Ban will expire in {1} {2} on {3}",
                    Helpers.GetArgVal(c, 2), Math.Truncate(length), scale,
                    expirationDate.ToString("G", DateTimeFormatInfo.InvariantInfo));
                await SendServerSay(c, StatusMessage);

                // UI: reflect changes
                _sst.UserInterface.RefreshCurrentBansDataSource();

                return(true);
            }

            StatusMessage = string.Format(
                "^1[ERROR]^3 An error occurred while attempting to add a time-ban for player:^1 {0}",
                Helpers.GetArgVal(c, 2));
            await SendServerTell(c, StatusMessage);

            return(false);
        }