Exemplo n.º 1
0
        public bool MatchesWarningPoint(int warnings)
        {
            WarningPoint p = GetAllWarningPoints().FirstOrDefault(point => warnings == point.WarningsToTrigger);

            if (p == null)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        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);
            }
        }