using UnityEngine; using Rust; using Oxide.Core.Plugins; using System.Collections.Generic; using System; using System.Reflection; using Oxide.Core; using System.Linq; using Oxide.Game.Rust.Cui; namespace Oxide.Plugins { [Info("BanScreen", "MikeHawke", "1.5.1")] [Description("This plugin displays lock out screen when banning")] class BanScreen : RustPlugin { private bool backgroundimage; private string backgroundcolor; private bool Changed; private int messagefontsize; private string text; private string banmsg; private string backgroundimageurl; private int warnfontsize; private string warntext; private bool AcceptButton; private float Seconds; private bool WarnAcceptButton; private float WarnSeconds; void Loaded() { permission.RegisterPermission("BanScreen.usecmd", this); data = Interface.GetMod().DataFileSystem.ReadObject("BanScreenData"); LoadVariables(); } object GetConfig(string menu, string datavalue, object defaultValue) { var data = Config[menu] as Dictionary; if (data == null) { data = new Dictionary(); Config[menu] = data; Changed = true; } object value; if (!data.TryGetValue(datavalue, out value)) { value = defaultValue; data[datavalue] = value; Changed = true; } return value; } #region Methods void Destroy(BasePlayer player, bool all) { CuiHelper.DestroyUi(player, "LCGUI"); } #endregion void LoadVariables() { Seconds = Convert.ToSingle(GetConfig("Ban Acknowledge Button", "Seconds till close if button is false", 10)); AcceptButton = Convert.ToBoolean(GetConfig("Ban Acknowledge Button", "Enabled", true)); WarnSeconds = Convert.ToSingle(GetConfig("Warn Acknowledge Button", "Seconds till close if button is false", 10)); WarnAcceptButton = Convert.ToBoolean(GetConfig("Warn Acknowledge Button", "Enabled", true)); backgroundimageurl = Convert.ToString(GetConfig("Background", "ImageURL", "https://i.ytimg.com/vi/yaqe1qesQ8c/maxresdefault.jpg")); backgroundimage = Convert.ToBoolean(GetConfig("Background", "Enabled", false)); backgroundcolor = Convert.ToString(GetConfig("Background", "Color", "255 0 0 1")); banmsg = Convert.ToString(GetConfig("Messages", "BAN_MESSAGE", "Failed to follow rules")); messagefontsize = Convert.ToInt32(GetConfig("Messages", "FontSize", "22")); text = Convert.ToString(GetConfig("Messages", "BAN_MESSAGES", new List{ "STOP! You have not followed the rules of this server:", "As a result,", "It is the opinion of the staff that you are issued with", "A SERVER BAN", "If you feel the ban is unfair, you may appeal the ban via the following methods", "Discord", "Website", "Note that appeals are at the discretion of the server owner", "And may take up to 48 hours to complete " })); warnfontsize = Convert.ToInt32(GetConfig("WarningMsgs", "FontSize", "22")); warntext = Convert.ToString(GetConfig("WarningMsgs", "LC_MESSAGES", new List{ "STOP!", "This is a warning.", "Continue to not follow the rules and we will issue you", "A SERVER BAN", "Your actions are in violation of the server rules", "If you need to be remided of the rules", "Use /Rules ", "If you continue in this manner you will be removed from the server", "This is your final warning " })); if (Changed) { SaveConfig(); Changed = true; } } protected override void LoadDefaultConfig() { Puts("Creating a new configuration file!"); Config.Clear(); LoadVariables(); } class Data { public List Players = new List{}; } Data data; void Unloaded() { foreach (BasePlayer current in BasePlayer.activePlayerList) { CuiHelper.DestroyUi(current, "LCGUI"); } } void BanUI(BasePlayer player, string msg) { var elements = new CuiElementContainer(); var mainName = elements.Add(new CuiPanel { Image = { Color = backgroundcolor }, RectTransform = { AnchorMin = "0 0", AnchorMax = "1 1" }, CursorEnabled = true }, "Overlay", "BanGUI"); if(backgroundimage == true) { elements.Add(new CuiElement { Parent = "BanGUI", Components = { new CuiRawImageComponent { Url = backgroundimageurl, Sprite = "assets/content/textures/generic/fulltransparent.tga" }, new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" } } }); } var Agree = new CuiButton { Button = { Command = "global.banaccept", Color = "0 255 0 1" }, RectTransform = { AnchorMin = "0.4 0.03", AnchorMax = "0.61 0.17" }, Text = { Text = "Acknowledge", FontSize = 22, Align = TextAnchor.MiddleCenter } }; var Label = new CuiLabel { Text = { Text = $"Warning will close in {Seconds} seconds", FontSize = messagefontsize, Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = "0.4 0.03", AnchorMax = "0.61 0.17" } }; elements.Add( new CuiLabel { Text = { Text = msg, FontSize = messagefontsize, Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = "0 0.20", AnchorMax = "1 0.9" } }, mainName); if(AcceptButton == true) { elements.Add(Agree, mainName); } else { elements.Add(Label, mainName); timer.Once(Seconds,() => { Accepted(player); } ); } CuiHelper.AddUi(player, elements); } void WarnUI(BasePlayer player, string warnmsg) { var elements = new CuiElementContainer(); var mainName = elements.Add(new CuiPanel { Image = { Color = backgroundcolor }, RectTransform = { AnchorMin = "0 0",AnchorMax = "1 1" }, CursorEnabled = true }, "Overlay", "LCGUI"); if(backgroundimage == true) { elements.Add(new CuiElement { Parent = "LCGUI", Components = { new CuiRawImageComponent { Url = backgroundimageurl, Sprite = "assets/content/textures/generic/fulltransparent.tga" }, new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" } } }); } var Agree = new CuiButton{ Button = { Command = "global.LCaccept", Color = "0 255 0 1" }, RectTransform = { AnchorMin = "0.4 0.03", AnchorMax = "0.61 0.17" }, Text = { Text = "Acknowledge", FontSize = 22, Align = TextAnchor.MiddleCenter } }; var Label = new CuiLabel { Text = { Text = $"Warning will close in {WarnSeconds} seconds", FontSize = messagefontsize, Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = "0.4 0.03", AnchorMax = "0.61 0.17" } }; elements.Add(new CuiLabel { Text = { Text = warnmsg, FontSize = warnfontsize, Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = "0 0.20", AnchorMax = "1 0.9" } }, mainName); if(WarnAcceptButton == true) { elements.Add(Agree, mainName); } else { elements.Add(Label, mainName); timer.Once(WarnSeconds,() => { WarAccepted(player); } ); } CuiHelper.AddUi(player, elements); } void Accepted(BasePlayer player) { Player.Ban(player, rust.QuoteSafe(banmsg)); PrintWarning(player.displayName + " Acknowledged the ban screen"); Server.Broadcast(player.displayName + " did not follow the rules and was banned"); } void WarAccepted(BasePlayer player) { if (player == null) return; Destroy(player, true); PrintWarning(player.displayName + " Has seen the Warning screen"); Server.Broadcast(player.displayName + " is on their last warning"); } [ConsoleCommand("LCaccept")] private void LCaccept(ConsoleSystem.Arg arg) { var player = arg.Connection.player as BasePlayer; if (player == null) return; Destroy(player, true); PrintWarning(player.displayName + " Acknowledged the Warning screen"); Server.Broadcast(player.displayName + " is on their last warning"); } [ChatCommand("LastChance")] void cmdLCScreenTo(BasePlayer player, string cmd, string[] args) { if(!permission.UserHasPermission(player.userID.ToString(), "BanScreen.usecmd")) { SendReply(player, "You do not have permission to use this command!"); return; } if(args.Length != 1) { SendReply(player, "Syntax: /LastChance \"target\" "); return; } BasePlayer target = BasePlayer.Find(args[0]); if(target == null) { SendReply(player, "Player not found!"); return; } string warnmsg = ""; foreach(var rule in Config["WarningMsgs", "LC_MESSAGES"] as List) warnmsg = warnmsg + rule.ToString() + "\n \n"; WarnUI(target, warnmsg.ToString()); SendReply(player, "You have displayed the Last Chance screen to " + target.displayName + ""); } [ConsoleCommand("banaccept")] private void banaccept(ConsoleSystem.Arg arg) { BasePlayer player = (BasePlayer)arg.Connection.player; Player.Ban(player, rust.QuoteSafe(banmsg)); PrintWarning(player.displayName + " Acknowledged the ban screen"); Server.Broadcast(player.displayName + " did not follow the rules and was banned"); } [ChatCommand("BanScreen")] void cmdBanScreenTo(BasePlayer player, string cmd, string[] args) { if(!permission.UserHasPermission(player.userID.ToString(), "BanScreen.usecmd")) { SendReply(player, "You do not have permission to use this command!"); return; } if(args.Length != 1) { SendReply(player, "Syntax: /BanScreen \"target\" "); return; } BasePlayer target = BasePlayer.Find(args[0]); if(target == null) { SendReply(player, "Player not found!"); return; } string msg = ""; foreach(var rule in Config["Messages", "BAN_MESSAGES"] as List) msg = msg + rule.ToString() + "\n \n"; BanUI(target, msg.ToString()); SendReply(player, "You have displayed the ban screen to " + target.displayName + ""); } [ConsoleCommand("LastChance")] private void conWarnto(ConsoleSystem.Arg arg) { if (arg.IsAdmin && arg.Args?.Length > 0) { var player = BasePlayer.Find(arg.Args[0]) ?? BasePlayer.FindSleeping(arg.Args[0]); if (player == null) { PrintWarning($"We can't find player with that name/ID! {arg.Args[0]}"); return; } string warnmsg = ""; foreach(var rule in Config["WarningMsgs", "LC_MESSAGES"] as List) warnmsg = warnmsg + rule.ToString() + "\n \n"; WarnUI(player, warnmsg.ToString()); PrintWarning($"Player {arg.Args[0]} was sent the Last Chance screen"); } } [ConsoleCommand("BanScreen")] private void conRuleto(ConsoleSystem.Arg arg) { if (arg.IsAdmin && arg.Args?.Length > 0) { var player = BasePlayer.Find(arg.Args[0]) ?? BasePlayer.FindSleeping(arg.Args[0]); if (player == null) { PrintWarning($"We can't find player with that name/ID! {arg.Args[0]}"); return; } string msg = ""; foreach(var rule in Config["Messages", "BAN_MESSAGES"] as List) msg = msg + rule.ToString() + "\n \n"; BanUI(player, msg.ToString()); PrintWarning($"Player {arg.Args[0]} was sent the ban screen"); } } } }