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

FREE RustChat : 1.0 1.0

Нет прав для скачивания
C#:
using ConVar;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using UnityEngine;
namespace Oxide.Plugins {
    /*ПЛАГИН БЫЛ ПОФИКШЕН С ПОМОЩЬЮ ПРОГРАММЫ СКАЧАНОЙ С https://discord.gg/dNGbxafuJn */
    [Info("RustChat", "https://discord.gg/dNGbxafuJn", "1.0")]
    [Description("")]
    public class RustChat : RustPlugin {
        [PluginReference]
        private Plugin WebPanel;
        [PluginReference]
        private Plugin RustMenu;
        [PluginReference]
        private Plugin Clans;
        [PluginReference]
        private Plugin WebPanelV2;
        public static RustChat Instance;
        private int timerIndex = 0;
        private Dictionary<ulong, User> _users = new Dictionary<ulong, User>();
        private Dictionary<ulong, List<string>> lastMessages = new Dictionary<ulong, List<string>>();
#region Configuration
        private ChatConfig chatConfig;
        public class ChatConfig {
            [JsonProperty("Секретный ключ для бота дискорда")]
            public string DiscordToken;
            [JsonProperty("Секретный ключ сообщества вконтакте")]
            public string VkToken;
            [JsonProperty("Секретный ключ сообщества вконтакте с правами appWidget")]
            public string WidgetToken;
            [JsonProperty("ID дискорд канала")]
            public string MuteChannel;
            [JsonProperty("Префиксы")]
            public Dictionary<string, string> ChatPrefix;
            [JsonProperty("Цвета")]
            public Dictionary<string, string[]> ChatColors;
        }
        private ChatConfig GetChatConfig() {
            return new ChatConfig() {
                DiscordToken = "", VkToken = "", WidgetToken = "", MuteChannel = "", ChatPrefix = new Dictionary<string, string>() {
                    [$"rustchat.default"]
                    = "[Игрок]", [$"rustchat.premium"] = "[Премиум]", [$"rustchat.vip"] = "[VIP]", [$"rustchat.deluxe"] = "[Deluxe]", [$"rustchat.godlike"] = "[GODLIKE]", [$"rustchat.namereward"] = "[Фанат]", [$"rustchat.discord"] = "[Discord]", [$"rustchat.discordbooster"] = "[Батя Дискорда]", [$"rustchat.youtube"] = "[YouTube]", [$"rustchat.helper"] = "[Хелпер]", [$"rustchat.moderator"] = "[Модератор]", [$"rustchat.admin"] = "[Администратор]",
                }
                , ChatColors = new Dictionary<string, string[]>() {
                    [$"rustchat.default"]
                    = new string[] {
                        "#FFC000"
                    }
                    , [$"rustchat.premium"] = new string[] {
                        "#55ff8a"
                    }
                    , [$"rustchat.vip"] = new string[] {
                        "#f9ff55"
                    }
                    , [$"rustchat.deluxe"] = new string[] {
                        "#7303c0", "#9002bf", "#a809bf", "#bf17be", "#d325bd", "#de44c2", "#e95dc7", "#f273cd", "#f695d9", "#f9b4e5", "#fbd2ef", "#fdeff9"
                    }
                    , [$"rustchat.godlike"] = new string[] {
                        "#ff0000"
                    }
                    , [$"rustchat.paid1"] = new string[] {
                        "#1e9600", "#52a800", "#7aba00", "#a1cc00", "#c8dd00", "#dcd600", "#eecf00", "#ffc700", "#ffa600", "#ff8200", "#ff5800",
                    }
                    , [$"rustchat.paid2"] = new string[] {
                        "#833ab4", "#b123a4", "#d3008c", "#eb0070", "#f90051", "#fe2941", "#ff412f", "#fe5618", "#fe711b", "#fd8825", "#fd9d33", "#fcb045"
                    }
                    , [$"rustchat.namereward"] = new string[] {
                        "#FFFFFF"
                    }
                    , [$"rustchat.discord"] = new string[] {
                        "#9090ff"
                    }
                    , [$"rustchat.discordbooster"] = new string[] {
                        "#b20a2c", "#c5372a", "#d55627", "#e27326", "#ed9028", "#f0a438", "#f3b74a", "#f6ca5e", "#f6d77c", "#f8e49a", "#fbf0b7", "#fffbd5"
                    }
                    , [$"rustchat.youtube"] = new string[] {
                        "#55aafe"
                    }
                    , [$"rustchat.helper"] = new string[] {
                        "#56E0FB"
                    }
                    , [$"rustchat.moderator"] = new string[] {
                        "#55aaff"
                    }
                    , [$"rustchat.admin"] = new string[] {
                        "#ff0000"
                    }
                    ,
                }
            }
            ;
        }
        protected override void LoadDefaultConfig() {
            Config.WriteObject(GetChatConfig(), true);
        }
        private void Init() {
            chatConfig = Config.ReadObject<ChatConfig>();
        }
#endregion
#region API
        public string BaseUrl = "http://176.118.165.205:1337/api";
        public string RegisterDSUser = "/discord/registerUser?authToken={0}&username={1}&discriminator={2}&userID={3}";
        public string GetDSUser = "/discord/getUser?authToken={0}&memberID={1}&userID={2}";
        public string RegisterVKUser = "/vk/registerUser?authToken={0}&vkID={1}&userID={2}";
        public string GetVKUser = "/vk/getUser?authToken={0}&vkID={1}&userID={2}";
        public string CreateDSMessage = "/discord/createMessage?authToken={0}&memberID={1}";
        public string CreateDSChannelMessage = "/discord/createChannelMessage?authToken={0}&channelID={1}";
        public string CreateVKMessage = "/vk/createMessage?authToken={0}&vkID={1}&message={2}";
        public string BuildEmbedMessage(string apiUrl, Dictionary<string, string> options, string color = "#0099ff") {
            apiUrl += "&color=" + Parse(color);
            if (options.ContainsKey("title")) apiUrl += "&title=" + Parse(options["title"]);
            if (options.ContainsKey("url")) apiUrl += "&url=" + Parse(options["url"]);
            if (options.ContainsKey("author")) apiUrl += "&author=" + Parse(options["author"]);
            if (options.ContainsKey("authorImage")) apiUrl += "&authorImage=" + Parse(options["authorImage"]);
            if (options.ContainsKey("authorUrl")) apiUrl += "&authorUrl=" + Parse(options["authorUrl"]);
            if (options.ContainsKey("description")) apiUrl += "&description=" + Parse(options["description"]);
            if (options.ContainsKey("thumbnail")) apiUrl += "&thumbnail=" + Parse(options["thumbnail"]);
            if (options.ContainsKey("image")) apiUrl += "&image=" + Parse(options["image"]);
            if (options.ContainsKey("timestamp")) apiUrl += "&timestamp=" + Parse(options["timestamp"]);
            if (options.ContainsKey("footerText")) apiUrl += "&footerText=" + Parse(options["footerText"]);
            if (options.ContainsKey("footerImage")) apiUrl += "&footerImage=" + Parse(options["footerImage"]);
            if (options.ContainsKey("fields")) {
                apiUrl += "&fields=";
                foreach (var field in options["fields"].Split(';')) {
                    apiUrl += field + ";";
                }
                apiUrl = apiUrl.Remove(apiUrl.Length - 2);
            }
            return apiUrl;
        }
        public string Parse(string str) {
            return Uri.EscapeDataString(str.Trim('"', '|', ';'));
        }
        public void DoRequest(string url, string args) {
            webrequest.Enqueue(url + args, null, (code, response) => {
                if (code != 200) {
                    PrintError("DoRequest Code: " + code + " Message: " + response != null ? response : "null");
                    return;
                }
            }
            , this);
        }
        public void DoRequest<T>(string url, string args, Action<T> callback = null) {
            webrequest.Enqueue(url + args, null, (code, response) => {
                if (code != 200) {
                    PrintError("DoRequest Code: " + code + " Message: " + response != null ? response : "null");
                    return;
                }
                if (callback != null) {
                    try {
                        T member = JsonConvert.DeserializeObject<T>(response);
                        callback(member);
                    }
                    catch {
                        T member = default(T);
                        callback(member);
                        PrintError("DoRequest DeserializeObject<T> : " + response);
                    }
                }
            }
            , this);
        }
        public class RegisterUserResponse {
            [JsonProperty("response")]
            public string Response {
                get;
                set;
            }
            [JsonProperty("type")]
            public string Type {
                get;
                set;
            }
            [JsonProperty("memberID")]
            public string MemberId {
                get;
                set;
            }
            [JsonProperty("isServerBooster")]
            public int IsServerBooster {
                get;
                set;
            }
            [JsonProperty("code")]
            public string Code {
                get;
                set;
            }
        }
        public class GetUserResponse {
            [JsonProperty("response")]
            public string Response {
                get;
                set;
            }
            [JsonProperty("type")]
            public string Type {
                get;
                set;
            }
            [JsonProperty("memberID")]
            public string MemberId {
                get;
                set;
            }
            [JsonProperty("isServerBooster")]
            public int IsServerBooster {
                get;
                set;
            }
            [JsonProperty("code")]
            public string Code {
                get;
                set;
            }
            [JsonProperty("isAuthed")]
            public int IsAuthed {
                get;
                set;
            }
        }
        public class RegisterUserVkResponse {
            [JsonProperty("response")]
            public string Response {
                get;
                set;
            }
            [JsonProperty("type")]
            public string Type {
                get;
                set;
            }
            [JsonProperty("vkID")]
            public int VkID {
                get;
                set;
            }
            [JsonProperty("code")]
            public string Code {
                get;
                set;
            }
        }
        public class GetUserVkResponse {
            [JsonProperty("response")]
            public string Response {
                get;
                set;
            }
            [JsonProperty("type")]
            public string Type {
                get;
                set;
            }
            [JsonProperty("vkID")]
            public int VkID {
                get;
                set;
            }
            [JsonProperty("code")]
            public string Code {
                get;
                set;
            }
            [JsonProperty("isAuthed")]
            public int IsAuthed {
                get;
                set;
            }
        }
#endregion
        private static readonly Dictionary<string, TimeSpan> _muteReasons = new Dictionary<string, TimeSpan>() {
            ["Антифлуд"]
            = new TimeSpan(0, 0, 3), ["Капс"] = new TimeSpan(0, 1, 0), ["Флуд"] = new TimeSpan(0, 1, 0), ["Мат"] = new TimeSpan(0, 5, 0), ["Реклама"] = new TimeSpan(0, 5, 0), ["Оскорбление игроков"] = new TimeSpan(0, 30, 0), ["Оскорбление администрации"] = new TimeSpan(0, 60, 0), ["Оскорбление семьи"] = new TimeSpan(0, 60, 0), ["Система"] = new TimeSpan(0, 60, 0),
        }
        ;
        private static readonly List<string> _helpData = new List<string>() {
            "Ограничение на количество игроков в команде <color=#FFC000>Два игрока в одной команде</color>", "Собирай монеты и получай кейсы <color=#FFC000>/case</color>", "Открой меню дополнительного крафта <color=#FFC000>/craft</color>", "Для просмотра списка команд и биндов сервера введите <color=#FFC000>/help</color>", "Чтобы получить подарок введите <color=#FFC000>/vk</color>", "Присоединяйся к нашему дискорду и получай подарок <color=#FFC000>/ds</color>", "Вступайте в нашу группу вк и получайте бонусы! <color=#FFC000>https://vk.com/rustland</color>\nЗабрать бонус можно прописав в чате /vk", "Ведётся набор модераторов. Анкету можно заполнить в нашей группе вконтакте <color=#FFC000>https://vk.com/rustland</color>", "Участвуйте в розыгрыше привилегии на вайп в нашем дискорде <color=#FFC000>https://discord.gg/8dmuD3V</color>", "Пожаловаться на читера <color=#FFC000>/report</color>",
        }
        ;
#region Data
        public class User {
            public ulong UserID;
            public string Name;
            public string CachedName;
            public string Prefix;
            public string ColorName;
            public string ColorPrefix;
            public string[] ColorNameArr;
            public string[] ColorPrefixArr;
            public string ColorText;
            public bool IsRenamed;
            public bool IsChatEnabled;
            public bool IsHelpEnabled;
            public ulong LastPM;
            public DateTime LastConnection;
            public DateTime LastMessage;
            public DateTime MuteExpire;
            public int MutePenalties;
            public int MuteCount;
            public List<string> IgnoreList = new List<string>();
            public bool IgnoreAdd(string userID) {
                if (IgnoreList.Contains(userID)) return false;
                IgnoreList.Add(userID);
                return true;
            }
            public bool IgnoreRemove(string userID) {
                if (IgnoreList.Contains(userID) == false) return false;
                IgnoreList.Remove(userID);
                return true;
            }
            public bool Mute(string reason) {
                TimeSpan reasonTime;
                if (DateTime.Now >= MuteExpire && _muteReasons.TryGetValue(reason, out reasonTime)) {
                    MutePenalties++;
                    TimeSpan muteTime = TimeSpan.FromTicks(reasonTime.Ticks * MutePenalties);
                    MuteExpire = DateTime.Now + muteTime;
                    return true;
                }
                return false;
            }
            public bool Mute(TimeSpan muteTime) {
                if (DateTime.Now >= MuteExpire) {
                    MutePenalties++;
                    MuteExpire = DateTime.Now + muteTime;
                    return true;
                }
                return false;
            }
            public List<string> GetAllUserPrefix() {
                return Instance.chatConfig.ChatPrefix.Where(x => Instance.permission.UserHasPermission(UserID.ToString(), x.Key)).Select(x => x.Value).ToList();
            }
            public List<string[]> GetAllUserColors() {
                return Instance.chatConfig.ChatColors.Where(x => Instance.permission.UserHasPermission(UserID.ToString(), x.Key)).Select(x => x.Value).ToList();
            }
        }
        public User GetByID(ulong userID) {
            User user = null;
            if (_users.TryGetValue(userID, out user) == false) {
                BasePlayer player = BasePlayer.FindByID(userID);
                if (player != null) {
                    user = new User() {
                        UserID = userID, Name = player.displayName, CachedName = CleanString(player.net.connection.username), Prefix = chatConfig.ChatPrefix["rustchat.default"], ColorNameArr = chatConfig.ChatColors["rustchat.default"], ColorPrefixArr = chatConfig.ChatColors["rustchat.default"], ColorText = "#FFFFFF", IgnoreList = new List<string>(), IsRenamed = false, IsChatEnabled = true, IsHelpEnabled = true, LastConnection = DateTime.Now, MuteExpire = DateTime.MinValue, LastMessage = DateTime.MinValue, MutePenalties = 0, LastPM = 0UL, MuteCount = 0
                    }
                    ;
                    _users.Add(userID, user);
                }
            }
            return user;
        }
#endregion
#region U'Mod Hooks & WebSocket
        private Timer initTimer;
        protected override void LoadDefaultMessages() {
            lang.RegisterMessages(new Dictionary<string, string> {
                ["TITLE_1"]
                = "Выбрать префикс:", ["TITLE_2"] = "Выбрать цвет префикса:", ["TITLE_3"] = "Выбрать цвет ника:", ["TITLE_4"] = "Отображать чат:", ["TITLE_5"] = "Отображать помощь в чате:", ["TITLE_6"] = "CHAT",
            }
            , this, "ru");
            lang.RegisterMessages(new Dictionary<string, string> {
                ["TITLE_1"]
                = "Choose your prefix:", ["TITLE_2"] = "Choose your prefix color:", ["TITLE_3"] = "Choose your nickname color:", ["TITLE_4"] = "Chat enabled:", ["TITLE_5"] = "Chat help enabled:", ["TITLE_6"] = "ЧАТ",
            }
            , this, "en");
        }
        private void OnServerInitialized() {
            Instance = this;
            for (int i = 0; i < chatConfig.ChatPrefix.Count; i++) permission.RegisterPermission(chatConfig.ChatPrefix.ElementAt(i).Key, this);
            for (int i = 0; i < chatConfig.ChatColors.Count; i++) permission.RegisterPermission(chatConfig.ChatColors.ElementAt(i).Key, this);
            _users = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, User>>("ChatData");
            List<ulong> cacheList = new List<ulong>();
            foreach (var user in _users) {
                if (user.Value.LastConnection.AddDays(14) < DateTime.Now) cacheList.Add(user.Key);
            }
            foreach (var userID in cacheList) {
                _users.Remove(userID);
            }
            timer.Every(120f, () => {
                timerIndex++;
                if (timerIndex >= _helpData.Count) timerIndex = 0;
                foreach (var p in BasePlayer.activePlayerList) {
                    User targetUser = GetByID(p.userID);
                    if (targetUser.IsChatEnabled && targetUser.IsHelpEnabled) {
                        p.SendConsoleCommand("chat.add", new object[] {
                            0, 76561198331571902, "<color=#FFC000>[RUSTLAND]</color> " + _helpData[timerIndex]
                        }
                        );
                        p.SendConsoleCommand("echo " + "<color=#FFC000>[RUSTLAND]</color> " + _helpData[timerIndex]);
                    }
                }
            }
            );
            initTimer = timer.Every(5f, () => {
                if (RustMenu != null) {
                    RustMenu.Call("API_RegisterSubMenu", "SUBMENUSETTINGS", this.Name, "RenderSettings", new Dictionary<string, string>() {
                        ["ru"]
                        = "НАСТРОЙКИ", ["en"] = "SETTINGS"
                    }
                    , "MENUMAIN");
                    if ((bool)RustMenu.Call("API_MenuExist", "MENUMAIN", "SUBMENUSETTINGS")) {
                        initTimer.Destroy();
                    }
                }
            }
            );
            for (int i = 0; i < BasePlayer.activePlayerList.Count; i++) {
                OnPlayerConnected(BasePlayer.activePlayerList[i]);
            }
        }
        private void RenderSettings(Dictionary<string, object> args) {
            BasePlayer player = (BasePlayer)args["player"];
            CuiElementContainer Container = (CuiElementContainer)args["container"];
            string menuName = (string)args["menuName"];
            string subMenuName = (string)args["subMenuName"];
            User user = GetByID(player.userID);
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{-275} {230}", OffsetMax = $"{-75} {300}"
                }
                , Button = {
                    Color = "0 0 0 0", Command = $"",
                }
                , Text = {
                    Text = lang.GetMessage("TITLE_6", this, player.UserIDString), Align = TextAnchor.MiddleLeft, Font = "robotocondensed-bold.ttf", FontSize = 48, Color = "0.91 0.86 0.82 1"
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right");
            Container.Add(new CuiElement {
                Name = "RustMenu" + ".Content" + ".Right" + $".Prefix", Parent = "RustMenu" + ".Content" + ".Right", Components = {
                    new CuiImageComponent {
                        Color = "0 0 0 0",
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{75} {230 - 1 * 45}", OffsetMax = $"{275} {270 - 1 * 45}"
                    }
                    ,
                }
            }
            );
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "0 0", OffsetMin = "40 0", OffsetMax = "160 40"
                }
                , Button = {
                    Color = "0.28 0.25 0.19 0.75", Command = $"", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
                }
                , Text = {
                    Text = user.Prefix, Color = "0.91 0.86 0.82 1", FontSize = 16, Align = TextAnchor.MiddleCenter,
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".Prefix");
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "0 0", OffsetMin = "0 0", OffsetMax = "40 40"
                }
                , Button = {
                    Color = "0.34 0.49 0.18 0.75", Command = $"rustchat.prefix back", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
                }
                , Text = {
                    Text = "<", FontSize = 20, Align = TextAnchor.MiddleCenter,
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".Prefix");
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "0 0", OffsetMin = "160 0", OffsetMax = "200 40"
                }
                , Button = {
                    Color = "0.34 0.49 0.18 0.75", Command = $"rustchat.prefix next", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
                }
                , Text = {
                    Text = ">", FontSize = 20, Align = TextAnchor.MiddleCenter,
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".Prefix");
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = $"0 0.5", AnchorMax = $"0 0.5", OffsetMin = "-350 -20", OffsetMax = "-50 20"
                }
                , Button = {
                    Color = "0 0 0 0", Command = $"",
                }
                , Text = {
                    Text = lang.GetMessage("TITLE_1", this, player.UserIDString), Align = TextAnchor.MiddleLeft, Font = "robotocondensed-bold.ttf", FontSize = 24, Color = "0.91 0.86 0.82 1"
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".Prefix");
            Container.Add(new CuiElement {
                Name = "RustMenu" + ".Content" + ".Right" + $".PrefixColor", Parent = "RustMenu" + ".Content" + ".Right", Components = {
                    new CuiImageComponent {
                        Color = "0 0 0 0",
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{75} {230 - 2 * 45}", OffsetMax = $"{275} {270 - 2 * 45}"
                    }
                    ,
                }
            }
            );
            string prefixColor = string.Empty;
            int value = 1;
            for (int i = 0, j = 0; i < user.Prefix.Length; i++, j += value) {
                if (j == user.ColorPrefixArr.Length) {
                    value = -1;
                    j += value;
                }
                if (j == -1) {
                    value = 1;
                    j += value;
                }
                prefixColor += $"<color={user.ColorPrefixArr[j]}>{user.Prefix[i]}</color>";
            }
            string nameColor = string.Empty;
            value = 1;
            for (int i = 0, j = 0; i < user.Name.Length; i++, j += value) {
                if (j == user.ColorNameArr.Length) {
                    value = -1;
                    j += value;
                }
                if (j == -1) {
                    value = 1;
                    j += value;
                }
                nameColor += $"<color={user.ColorNameArr[j]}>{user.Name[i]}</color>";
            }
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "0 0", OffsetMin = "40 0", OffsetMax = "160 40"
                }
                , Button = {
                    Color = "0.28 0.25 0.19 0.75", Command = $"", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
                }
                , Text = {
                    Text = $"{prefixColor}", Color = "0.91 0.86 0.82 1", FontSize = 16, Align = TextAnchor.MiddleCenter,
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".PrefixColor");
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "0 0", OffsetMin = "0 0", OffsetMax = "40 40"
                }
                , Button = {
                    Color = "0.34 0.49 0.18 0.75", Command = $"rustchat.prefixcolor back", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
                }
                , Text = {
                    Text = "<", FontSize = 20, Align = TextAnchor.MiddleCenter,
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".PrefixColor");
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "0 0", OffsetMin = "160 0", OffsetMax = "200 40"
                }
                , Button = {
                    Color = "0.34 0.49 0.18 0.75", Command = $"rustchat.prefixcolor next", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
                }
                , Text = {
                    Text = ">", FontSize = 20, Align = TextAnchor.MiddleCenter,
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".PrefixColor");
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = $"0 0.5", AnchorMax = $"0 0.5", OffsetMin = "-350 -20", OffsetMax = "-50 20"
                }
                , Button = {
                    Color = "0 0 0 0", Command = $"",
                }
                , Text = {
                    Text = lang.GetMessage("TITLE_2", this, player.UserIDString), Align = TextAnchor.MiddleLeft, Font = "robotocondensed-bold.ttf", FontSize = 24, Color = "0.91 0.86 0.82 1"
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".PrefixColor");
            Container.Add(new CuiElement {
                Name = "RustMenu" + ".Content" + ".Right" + $".NameColor", Parent = "RustMenu" + ".Content" + ".Right", Components = {
                    new CuiImageComponent {
                        Color = "0 0 0 0",
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{75} {230 - 3 * 45}", OffsetMax = $"{275} {270 - 3 * 45}"
                    }
                    ,
                }
            }
            );
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "0 0", OffsetMin = "40 0", OffsetMax = "160 40"
                }
                , Button = {
                    Color = "0.28 0.25 0.19 0.75", Command = $"", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
                }
                , Text = {
                    Text = $"{nameColor}", Color = "0.91 0.86 0.82 1", FontSize = 16, Align = TextAnchor.MiddleCenter,
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".NameColor");
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "0 0", OffsetMin = "0 0", OffsetMax = "40 40"
                }
                , Button = {
                    Color = "0.34 0.49 0.18 0.75", Command = $"rustchat.namecolor back", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
                }
                , Text = {
                    Text = "<", FontSize = 20, Align = TextAnchor.MiddleCenter,
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".NameColor");
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "0 0", OffsetMin = "160 0", OffsetMax = "200 40"
                }
                , Button = {
                    Color = "0.34 0.49 0.18 0.75", Command = $"rustchat.namecolor next", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
                }
                , Text = {
                    Text = ">", FontSize = 20, Align = TextAnchor.MiddleCenter,
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".NameColor");
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = $"0 0.5", AnchorMax = $"0 0.5", OffsetMin = "-350 -20", OffsetMax = "-50 20"
                }
                , Button = {
                    Color = "0 0 0 0", Command = $"",
                }
                , Text = {
                    Text = lang.GetMessage("TITLE_3", this, player.UserIDString), Align = TextAnchor.MiddleLeft, Font = "robotocondensed-bold.ttf", FontSize = 24, Color = "0.91 0.86 0.82 1"
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".NameColor");
            Container.Add(new CuiElement {
                Name = "RustMenu" + ".Content" + ".Right" + $".Chat", Parent = "RustMenu" + ".Content" + ".Right", Components = {
                    new CuiImageComponent {
                        Color = "1 1 1 0.1",
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{235} {230 - 4 * 45}", OffsetMax = $"{275} {270 - 4 * 45}"
                    }
                    ,
                }
            }
            );
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "0 0", OffsetMin = "0 0", OffsetMax = "40 40"
                }
                , Button = {
                    Color = "0 0 0 0", Command = $"rustchat.chatswitch chat", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
                }
                , Text = {
                    Text = user.IsChatEnabled ? "✔️" : "", FontSize = 20, Align = TextAnchor.MiddleCenter,
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".Chat");
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = $"0 0.5", AnchorMax = $"0 0.5", OffsetMin = "-510 -20", OffsetMax = "0 20"
                }
                , Button = {
                    Color = "0 0 0 0", Command = $"",
                }
                , Text = {
                    Text = lang.GetMessage("TITLE_4", this, player.UserIDString), Align = TextAnchor.MiddleLeft, Font = "robotocondensed-bold.ttf", FontSize = 24, Color = "0.91 0.86 0.82 1"
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".Chat");
            Container.Add(new CuiElement {
                Name = "RustMenu" + ".Content" + ".Right" + $".ChatAds", Parent = "RustMenu" + ".Content" + ".Right", Components = {
                    new CuiImageComponent {
                        Color = "1 1 1 0.1",
                    }
                    , new CuiRectTransformComponent {
                        AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = $"{235} {230 - 5 * 45}", OffsetMax = $"{275} {270 - 5 * 45}"
                    }
                    ,
                }
            }
            );
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = "0 0", AnchorMax = "0 0", OffsetMin = "0 0", OffsetMax = "40 40"
                }
                , Button = {
                    Color = "0 0 0 0", Command = $"rustchat.chatswitch help", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"
                }
                , Text = {
                    Text = user.IsHelpEnabled ? "✔️" : "", FontSize = 20, Align = TextAnchor.MiddleCenter,
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".ChatAds");
            Container.Add(new CuiButton {
                RectTransform = {
                    AnchorMin = $"0 0.5", AnchorMax = $"0 0.5", OffsetMin = "-510 -20", OffsetMax = "0 20"
                }
                , Button = {
                    Color = "0 0 0 0", Command = $"",
                }
                , Text = {
                    Text = lang.GetMessage("TITLE_5", this, player.UserIDString), Align = TextAnchor.MiddleLeft, Font = "robotocondensed-bold.ttf", FontSize = 24, Color = "0.91 0.86 0.82 1"
                }
                ,
            }
            , "RustMenu" + ".Content" + ".Right" + $".ChatAds");
        }
        private void OnChatMessage(Dictionary<string, string> packet) {
            string userID = string.Empty;
            string subject = string.Empty;
            if (packet.TryGetValue("userID", out userID)) {
                if (packet.TryGetValue("subject", out subject)) {
                    User user = GetByID(ulong.Parse(userID));
                    string prefix = string.Empty;
                    int value = 1;
                    for (int i = 0, j = 0; i < user.Prefix.Length; i++, j += value) {
                        if (j == user.ColorPrefixArr.Length) {
                            value = -1;
                            j += value;
                        }
                        if (j == -1) {
                            value = 1;
                            j += value;
                        }
                        prefix += $"<color={user.ColorPrefixArr[j]}>{user.Prefix[i]}</color>";
                    }
                    string playerName = string.Empty;
                    value = 1;
                    for (int i = 0, j = 0; i < user.Name.Length; i++, j += value) {
                        if (j == user.ColorNameArr.Length) {
                            value = -1;
                            j += value;
                        }
                        if (j == -1) {
                            value = 1;
                            j += value;
                        }
                        playerName += $"<color={user.ColorNameArr[j]}>{user.Name[i]}</color>";
                    }
                    string clanPrefix = "";
                    if (Clans != null && !string.IsNullOrEmpty((string)Clans.Call("GetClanOf", ulong.Parse(userID)))) {
                        clanPrefix = $"[{(string)Clans.Call("GetClanOf", ulong.Parse(userID))}] ";
                    }
                    subject = $"{prefix} {clanPrefix}{playerName}: <color={user.ColorText}>{subject}</color>";
                    foreach (var p in BasePlayer.activePlayerList) {
                        User targetUser = GetByID(p.userID);
                        if (!targetUser.IgnoreList.Contains(userID) && targetUser.IsChatEnabled) {
                            p.SendConsoleCommand("chat.add", new object[] {
                                0, ulong.Parse(userID), subject
                            }
                            );
                            p.SendConsoleCommand("echo " + subject);
                        }
                    }
                }
            }
        }
        private void OnWebPanelMessage(Dictionary<string, string> packet) {
            string userID = string.Empty;
            string subject = string.Empty;
            if (packet.TryGetValue("userID", out userID)) {
                if (packet.TryGetValue("subject", out subject)) {
                    User user = GetByID(ulong.Parse(userID));
                    string prefix = string.Empty;
                    int value = 1;
                    for (int i = 0, j = 0; i < user.Prefix.Length; i++, j += value) {
                        if (j == user.ColorPrefixArr.Length) {
                            value = -1;
                            j += value;
                        }
                        if (j == -1) {
                            value = 1;
                            j += value;
                        }
                        prefix += $"<color={user.ColorPrefixArr[j]}>{user.Prefix[i]}</color>";
                    }
                    string playerName = string.Empty;
                    value = 1;
                    for (int i = 0, j = 0; i < user.Name.Length; i++, j += value) {
                        if (j == user.ColorNameArr.Length) {
                            value = -1;
                            j += value;
                        }
                        if (j == -1) {
                            value = 1;
                            j += value;
                        }
                        playerName += $"<color={user.ColorNameArr[j]}>{user.Name[i]}</color>";
                    }
                    string clanPrefix = "";
                    if (Clans != null && !string.IsNullOrEmpty((string)Clans.Call("GetClanOf", ulong.Parse(userID)))) {
                        clanPrefix = $"[{(string)Clans.Call("GetClanOf", ulong.Parse(userID))}] ";
                    }
                    subject = $"{prefix} {clanPrefix}{playerName}: <color={user.ColorText}>{subject}</color>";
                    foreach (var p in BasePlayer.activePlayerList) {
                        User targetUser = GetByID(p.userID);
                        if (!targetUser.IgnoreList.Contains(userID) && targetUser.IsChatEnabled) {
                            p.SendConsoleCommand("chat.add", new object[] {
                                0, ulong.Parse(userID), subject
                            }
                            );
                            p.SendConsoleCommand("echo " + subject);
                        }
                    }
                }
            }
        }
        private void OnWebPanelMute(Dictionary<string, string> packet) {
            string targetUserID = packet["userID"];
            string moderatorUserID = packet["moderatorUserID"];
            string reason = packet["reason"];
            User user = GetByID(ulong.Parse(targetUserID));
            if (user != null) {
                if (user.MuteExpire < DateTime.Now) {
                    user.Mute(reason);
                    User moderatorUser = GetByID(ulong.Parse(moderatorUserID));
                    if (moderatorUser != null) {
                        moderatorUser.MuteCount += 1;
                        string msg = $"Модератор чата <color=#FFC000>{moderatorUser.Name}</color> заблокировал чат игроку <color=#FFC000>{user.Name}</color>\nПричина: <color=#FFC000>{reason.ToUpper()}</color>\nПродолжительность: <color=#FFC000>{FormatTime(user.MuteExpire - DateTime.Now)}</color>";
                        foreach (var p in BasePlayer.activePlayerList) {
                            User targetUser = GetByID(p.userID);
                            if (targetUser.IsChatEnabled) {
                                p.SendConsoleCommand("chat.add", new object[] {
                                    0, 76561198331571902, msg
                                }
                                );
                                p.SendConsoleCommand("echo " + msg);
                            }
                        }
                        List<string> _list;
                        lastMessages.TryGetValue(ulong.Parse(targetUserID), out _list);
                        DoRequest(BuildEmbedMessage(BaseUrl + string.Format(CreateDSChannelMessage, chatConfig.DiscordToken, chatConfig.MuteChannel), new Dictionary<string, string>() {
                            ["title"]
                            = $"Игрока замутили на сервере: {ConVar.Server.hostname}", ["author"] = moderatorUser.Name, ["authorUrl"] = "https://steamcommunity.com/profiles/" + moderatorUserID + "/", ["fields"] = $"Игрок:|{user.Name}|true;Причина:|{reason.ToUpper()}|true;Продолжительность:|{FormatTime(user.MuteExpire - DateTime.Now)}|true;Мут №|{moderatorUser.MuteCount}|true;Последние сообщения:|{(_list == null ? "Нет сообщений" : string.Join("\n", _list))}|false;"
                        }
                        , "#7FFF00"), null);
                        if (WebPanel != null) {
                            WebPanel.Call("SendWebPanelMessage", msg);
                            WebPanelV2.Call("SendWebPanelMessage", msg);
                        }
                    }
                }
            }
        }
        private void OnUserGroupRemoved(string id, string groupName) {
            User data = GetByID(ulong.Parse(id));
            if (data != null) {
                string prefixKey = chatConfig.ChatPrefix.Where(x => x.Value == data.Prefix).FirstOrDefault().Key;
                if (!permission.UserHasPermission(id, prefixKey)) data.Prefix = chatConfig.ChatPrefix["rustchat.default"];
                string prefixColorKey = chatConfig.ChatColors.Where(x => x.Value == data.ColorPrefixArr).FirstOrDefault().Key;
                if (!permission.UserHasPermission(id, prefixColorKey)) data.ColorPrefixArr = chatConfig.ChatColors["rustchat.default"];
                string nameColorKey = chatConfig.ChatColors.Where(x => x.Value.SequenceEqual(data.ColorNameArr)).FirstOrDefault().Key;
                if (!permission.UserHasPermission(id, nameColorKey)) data.ColorNameArr = chatConfig.ChatColors["rustchat.default"];
            }
        }
        private void OnPlayerConnected(BasePlayer player) {
            User data = GetByID(player.userID);
            if (data.ColorNameArr == null || data.ColorNameArr.Length == 0) {
                data.ColorNameArr = new string[] {
                    data.ColorName
                }
                ;
            }
            if (data.ColorPrefixArr == null || data.ColorPrefixArr.Length == 0) {
                data.ColorPrefixArr = new string[] {
                    data.ColorPrefix
                }
                ;
            }
            string prefixKey = chatConfig.ChatPrefix.Where(x => x.Value == data.Prefix).FirstOrDefault().Key;
            if (!permission.UserHasPermission(player.UserIDString, prefixKey)) data.Prefix = chatConfig.ChatPrefix["rustchat.default"];
            string prefixColorKey = chatConfig.ChatColors.Where(x => x.Value.SequenceEqual(data.ColorPrefixArr)).FirstOrDefault().Key;
            if (!permission.UserHasPermission(player.UserIDString, prefixColorKey)) data.ColorPrefixArr = chatConfig.ChatColors["rustchat.default"];
            string nameColorKey = chatConfig.ChatColors.Where(x => x.Value.SequenceEqual(data.ColorNameArr)).FirstOrDefault().Key;
            if (!permission.UserHasPermission(player.UserIDString, nameColorKey)) data.ColorNameArr = chatConfig.ChatColors["rustchat.default"];
            if (data.IsRenamed && data.CachedName == CleanString(player.net.connection.username)) {
                player.displayName = data.Name;
                player.net.connection.username = data.Name;
                covalence.Players.FindPlayerById(player.UserIDString).Name = data.Name;
            }
            else {
                data.Name = CleanString(player.net.connection.username);
                data.CachedName = CleanString(player.net.connection.username);
                player.displayName = CleanString(player.net.connection.username);
                covalence.Players.FindPlayerById(player.UserIDString).Name = CleanString(player.net.connection.username);
                data.IsRenamed = false;
            }
            data.LastConnection = DateTime.Now;
        }
        private void Unload() {
            Core.Interface.Oxide.DataFileSystem.WriteObject("ChatData", _users);
        }
        private void OnNewSave() {
            _users = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<ulong, User>>("ChatData");
            foreach (var user in _users) user.Value.MutePenalties = 0;
            Core.Interface.Oxide.DataFileSystem.WriteObject("ChatData", _users);
        }
        private object OnPlayerChat(BasePlayer player, string message, Chat.ChatChannel chatchannel) {
            bool isGlobalChat = Chat.ChatChannel.Global == chatchannel;
            if (message.Length > 255) message.Substring(0, 255);
            User chatUser = GetByID(player.userID);
            if (!chatUser.IsChatEnabled) {
                SendReply(player, $"<color=#FFC000>[RUSTLAND]</color> Чат выключен");
                return true;
            }
            if (chatUser.MuteExpire >= DateTime.Now && isGlobalChat) {
                SendReply(player, $"<color=#FFC000>[RUSTLAND]</color> Вам запрещено писать в чат. До разблокировки осталось {FormatTime(chatUser.MuteExpire.AddSeconds(1) - DateTime.Now)}");
                return true;
            }
            if ((DateTime.Now - chatUser.LastMessage).TotalSeconds < 1) {
                chatUser.Mute("Антифлуд");
                SendReply(player, $"<color=#FFC000>[RUSTLAND]</color> Вам запрещено писать в чат. До разблокировки осталось {FormatTime(chatUser.MuteExpire.AddSeconds(1) - DateTime.Now)}");
                return true;
            }
            var formatedText = StripRichText(message);
            Puts((isGlobalChat ? "[GLOBAL] " : "[TEAM] ") + chatUser.Name + ": " + formatedText);
            bool IsConnected = WebPanel == null ? false : WebPanel.Call<bool>("IsOnline");
            bool IsConnectedV2 = W
// ... [Code preview truncated due to length. Full source in attached file] ...

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