protected override void Load()
        {
            WarningUtilities.Log("AdminWarnings has Loaded!");
            Instance = this;

            util.RemoveExpiredWarnings(1000);
            WarningLogger.Init();
        }
Exemple #2
0
    public static AbstractLogger GetChainOfLoggers()
    {
        AbstractLogger error   = new DebugLogger(AbstractLogger.Error);
        AbstractLogger warning = new WarningLogger(AbstractLogger.Warning);
        AbstractLogger debug   = new ErrorLogger(AbstractLogger.Debug);

        error.SetNextLogger(warning);
        warning.SetNextLogger(debug);

        return(error);
    }
Exemple #3
0
        public static void Main()
        {
            var logger        = new OutputLogger();
            var warningLogger = new WarningLogger(logger);
            var errorLogger   = new ErrorLogger(new UpperCaseLoggerDecorator(logger));

            const string message = "decorator works!";

            logger.Log(message);
            warningLogger.Log(message);
            errorLogger.Log(message);
        }
Exemple #4
0
 public void Execute(IRocketPlayer caller, string[] command)
 {
     WarningLogger.ClearWarningLogs();
     WarningUtilities.SendMessage(caller, WarningsPlugin.Instance.Translate("cleared_logs"));
 }
 internal void LogWarning(string message) => WarningLogger?.Invoke(message);
        public void WarnPlayer(IRocketPlayer caller, UnturnedPlayer Player, string reason, bool reasonIncluded)
        {
            bool          actionTaken = false;
            PlayerWarning pData       = GetPlayerData(Player);

            pData.Warnings += 1;
            Save();

            if (MatchesWarningPoint(pData.Warnings))
            {
                WarningPoint point = GetWarningPoint(pData.Warnings);

                if (!string.IsNullOrEmpty(point.ConsoleCommand))
                {
                    string cmd = ConsoleCommandHelper.FormatConsoleCommandString(point.ConsoleCommand.ToLower(), Player);
                    CommandWindow.input.onInputText(cmd);
                    logger.Log(WarningsPlugin.Instance.Translate("console_command", cmd, Player.DisplayName, point.WarningsToTrigger));
                }
                else if (point.KickPlayer)
                {
                    if (reasonIncluded)
                    {
                        KickPlayer(Player, reason, pData.Warnings);
                        LogWarning(WarningsPlugin.Instance.Translate("console_player_kicked_reason", GetPlayerName(caller), Player.DisplayName, reason));
                    }
                    else
                    {
                        KickPlayer(Player, pData.Warnings);
                        LogWarning(WarningsPlugin.Instance.Translate("console_player_kicked", GetPlayerName(caller), Player.DisplayName));
                    }
                    actionTaken = true;

                    if (GetConfigAnnouceMessageServerWide())
                    {
                        UnturnedChat.Say(WarningsPlugin.Instance.Translate("public_player_kicked", Player.DisplayName, pData.Warnings), GetMessageColor());
                    }
                }
                else if (point.BanPlayer)
                {
                    if (reasonIncluded)
                    {
                        BanPlayer(Player, reason, pData.Warnings, point.BanLengthSeconds, caller);
                        LogWarning(WarningsPlugin.Instance.Translate("console_player_banned_reason", GetPlayerName(caller), Player.DisplayName, point.BanLengthSeconds, reason));
                    }
                    else
                    {
                        BanPlayer(Player, pData.Warnings, point.BanLengthSeconds, caller);
                        LogWarning(WarningsPlugin.Instance.Translate("console_player_banned", GetPlayerName(caller), Player.DisplayName, point.BanLengthSeconds));
                    }
                    actionTaken = true;

                    if (GetConfigAnnouceMessageServerWide())
                    {
                        UnturnedChat.Say(WarningsPlugin.Instance.Translate("public_player_banned", Player.DisplayName, pData.Warnings, point.BanLengthSeconds), GetMessageColor());
                    }
                }
            }

            if (!actionTaken)
            {
                if (WarningsPlugin.Instance.Configuration.Instance.AnnouceWarningsServerWide)
                {
                    PublicWarnPlayer(Player, pData, reason, reasonIncluded);
                }
                else
                {
                    PrivateWarnPlayer(Player, pData, reason, reasonIncluded);
                }

                LogWarning(WarningsPlugin.Instance.Translate("console_player_warning", GetPlayerName(caller), Player.DisplayName, pData.Warnings));
            }

            var allWarningPoints = GetAllWarningPoints();

            if (pData.Warnings >= allWarningPoints[allWarningPoints.Count - 1].WarningsToTrigger)
            {
                RemovePlayerData(pData);
                Save();
            }

            if (caller is ConsolePlayer)
            {
                WarningLogger.LogWarning(0.ToString(), "*Console*", Player, reason);
            }
            else
            {
                WarningLogger.LogWarning((UnturnedPlayer)caller, Player, reason);
            }
        }