Иконка ресурса

FREE KickPlayerNames : 1.0.3 1.0.3

Нет прав для скачивания
C#:
using System.Collections.Generic;
using System.Linq;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

#region Changelogs and ToDo
/**********************************************************************
* 1.0.0 :   Initial release
* 1.0.1 :   Added Discord support
*           Added German language file (thx to Autopsie17)
*           Added Russian language file (thx to Jtedal)
* 1.0.2 :   Added French Laguage file (thx to Tanki)
*           Added instantkick (limited to english)
*           Added Delayed kick system
*           Added Delayed kick timer
*           Added Gametip And Chatmsg for the player
*           Player gets reason in his/her own language if language file is made
* 1.0.3     Fix for console NRE
*           
**********************************************************************/
#endregion

namespace Oxide.Plugins
{
    [Info("Kick Player Names" , "Krungh Crow" , "1.0.3")]
    [Description("Prevents players logging in with certain names and kicks them")]

    class KickPlayerNames : CovalencePlugin
    {
        [PluginReference] Plugin DiscordMessages;

        #region Variables
        const string Bypas_Perm = "kickplayernames.bypas";
        bool ActiveTip = false;
        #endregion

        #region Configuration
        void Init()
        {
            if (!LoadConfigVariables())
            {
                Puts("Config file issue detected. Please delete file, or check syntax and fix.");
                return;
            }
            permission.RegisterPermission(Bypas_Perm , this);
        }

        private ConfigData configData;

        class ConfigData
        {
            [JsonProperty(PropertyName = "Discord Webhook")]
            public string DisWebhook = "";
            [JsonProperty(PropertyName = "Discord log")]
            public bool DisUseFancy = false;
            [JsonProperty(PropertyName = "Discord Title")]
            public string DisTitle = "Login detected with Name Phrase :";
            [JsonProperty(PropertyName = "Discord Embed color")]
            public int EmbedColor = 10181046;
            [JsonProperty(PropertyName = "Kick instantly")]
            public bool KickInstantly = false;
            [JsonProperty(PropertyName = "Kick time after login")]
            public float KickTime = 30f;
            [JsonProperty("Blocked name Phrases")]
            public List<string> Names = new List<string>();
        }

        private bool LoadConfigVariables()
        {
            try { configData = Config.ReadObject<ConfigData>(); }
            catch { return false; }
            SaveConf();
            return true;
        }

        protected override void LoadDefaultConfig()
        {
            Puts("Fresh install detected Creating a new config file.");
            configData = new ConfigData
            {
                Names = new List<string>()
                {
                    { "admin" },
                    { "banditcamp" },
                    { "bandit camp" },
                    { ".com" },
                    { ".org" }
                }
            };
            SaveConf();
        }

        void SaveConf() => Config.WriteObject(configData , true);
        #endregion

        #region LanguageAPI
        protected override void LoadDefaultMessages()
        {
            lang.RegisterMessages(new Dictionary<string , string>
            {
                ["KickMessage"] = "Sorry we dont allow the phrase [{0}] you are using in your name.You can rename yourself and you will be welcome to join our server again." ,
            } , this , "en");

            lang.RegisterMessages(new Dictionary<string , string>
            {
                ["KickMessage"] = "Sorry we accepteren de term [{0}] niet in je naam.Als je jezelf beter benaamt ben je weer welkom op de server." ,
            } , this , "nl");

            lang.RegisterMessages(new Dictionary<string , string>
            {
                ["KickMessage"] = "Entschuldigung, das Wort [{0}] ist in deinem Namen nicht erlaubt. Du kannst deinen Namen ändern und bist herzlich eingeladen, unserem Server wieder beizutreten."
            } , this , "de");

            lang.RegisterMessages(new Dictionary<string , string>
            {
                ["KickMessage"] = "К сожалению, мы запрещаем нашим игрокам использовать слово(-а) [{0}] в никнейме. Пожалуйста, отредактируйте свой ник и тогда вы снова сможете подключиться к нашему серверу."
            } , this , "ru");

            lang.RegisterMessages(new Dictionary<string , string>
            {
                ["KickMessage"] = "Désolé, nous n'autorisons pas l'expression [{0}] que vous utilisez dans votre nom. Changez votre nom et vous serez le bienvenue sur notre serveur."
            } , this , "fr");
        }
        #endregion

        #region Hooks
        object CanUserLogin(string name , string id , string ipAddress)
        {
            IPlayer player = players.FindPlayerById(id);
            if (player != null && permission.UserHasPermission(player.Id , Bypas_Perm)) return true;
            var Blacklist = configData.Names.ToList();
            if (name != null)
            {
                foreach (var BadName in Blacklist)
                {
                    if (name.ToLower().Contains(BadName))
                    {
                        Puts($"{name} ({id}) at {ipAddress} is connecting with [{BadName}] phrase in their name");
                        if (configData.DisUseFancy) SendDiscordFancy(player , BadName);
                        if (configData.KickInstantly == true) return string.Format(lang.GetMessage("KickMessage" , this , id) , BadName);
                        return true;
                    }
                }
            }
            return true;
        }

        void OnPlayerConnected(BasePlayer player)
        {
            if (permission.UserHasPermission(player.UserIDString , Bypas_Perm)) return;
            var Blacklist = configData.Names.ToList();

            foreach (var BadName in Blacklist)
            {
                if (player.displayName.ToLower().Contains(BadName))
                {
                    string msg = string.Format(lang.GetMessage("KickMessage" , this , player.UserIDString) , BadName);
                    player.ChatMessage($"<color=red>{msg}</color>");
                    TIP(player , msg , configData.KickTime);
                    return;
                }
            }
        }

        void TIP(BasePlayer player , string message , float dur)
        {
            if (player == null) return;
            if (!ActiveTip)
            {
                player?.SendConsoleCommand("gametip.hidegametip");
                player.SendConsoleCommand("gametip.showgametip" , message);
                ActiveTip = true;
                timer.Once(dur , () =>
                {
                    player?.SendConsoleCommand("gametip.hidegametip");
                    ActiveTip = false;
                    if (player.IsConnected)
                    {
                        player.Kick(message);
                    }
                });
            }
            else timer.Once(1f , () =>
            {
                TIP(player , message , dur);
            });
        }

        #endregion

        #region Discord

        void SendDiscordFancy(IPlayer player , string msg)
        {
            string WebhookURL = configData.DisWebhook;
            string EmbedTitle = configData.DisTitle;
            int Embedcolor = configData.EmbedColor;//Purple is default
            if (!DiscordMessages || WebhookURL == "")
            {
                Puts("Discordmessages not installed or no webhook provided");
                return;
            }
            object fields = new[]
            {
                new
                {
                    name = $"Player : {player.Name}", value = $"", inline = true
                },
                new
                {
                    name = $"Steam ID : {player.Id}", value = $"https://steamcommunity.com/profiles/{player.Id}/", inline = false
                },
                new
                {
                    name = $"Phrase  : {msg}", value = $"", inline = false
                }
            };

            string json = JsonConvert.SerializeObject(fields);
            DiscordMessages?.Call("API_SendFancyMessage", (string)WebhookURL, (string)EmbedTitle, (int)Embedcolor, json);
        }

        #endregion
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху