diff --git a/CHANGELOG.md b/CHANGELOG.md index 534e143b..05ff1fe8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added /region rename and OnRegionRenamed hook (@koneko-nyan, @deadsurgeon42) * Rebuilt /ban add. New syntax is /ban add [time] [reason] where target is the target online player, offline player, or IP; where time is the time format or 0 for permanent; and where [reason] is the reason. (@hakusaro) * Removed /ban addip and /ban addtemp. Now covered under /ban add. (@hakusaro) +* Added /su, which temporarily elevates players with the tshock.su permission to super admin. In addition added, a new group, owner, that is suggested for new users to setup TShock with as opposed to superadmin. Finally, /su is implemented such that a 10 minute timeout will occur preventing people from just camping with it on. (@hakusaro) +* Added /sudo, which runs a command as the superadmin group. If a user fails to execute a command but can sudo, they'll be told that they can override the permission check with sudo. Much better than just telling them to run /su and then re-run the command. (@hakusaro) ## TShock 4.3.24 * Updated OpenTerraria API to 1.3.5.3 (@DeathCradle) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 26ed7fc5..630927e3 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -312,6 +312,14 @@ namespace TShockAPI { HelpText = "Temporarily sets another player's group." }); + add(new Command(Permissions.su, SubstituteUser, "su") + { + HelpText = "Temporarily elevates you to Super Admin." + }); + add(new Command(Permissions.su, SubstituteUserDo, "sudo") + { + HelpText = "Executes a command as the super admin." + }); add(new Command(Permissions.userinfo, GrabUserUserInfo, "userinfo", "ui") { HelpText = "Shows information about a player." @@ -686,6 +694,10 @@ namespace TShockAPI { TShock.Utils.SendLogs(string.Format("{0} tried to execute {1}{2}.", player.Name, Specifier, cmdText), Color.PaleVioletRed, player); player.SendErrorMessage("You do not have access to this command."); + if (player.HasPermission(Permissions.su)) + { + player.SendInfoMessage("You can use '{0}sudo {0}{1}' to override this check.", Specifier, cmdText); + } } else if (!cmd.AllowServer && !player.RealPlayer) { @@ -1813,10 +1825,48 @@ namespace TShockAPI } } + private static void SubstituteUser(CommandArgs args) + { + + if (args.Player.tempGroup != null) + { + args.Player.tempGroup = null; + args.Player.tempGroupTimer.Stop(); + args.Player.SendSuccessMessage("Your previous permission set has been restored."); + return; + } + else + { + args.Player.tempGroup = new SuperAdminGroup(); + args.Player.tempGroupTimer = new System.Timers.Timer(600 * 1000); + args.Player.tempGroupTimer.Elapsed += args.Player.TempGroupTimerElapsed; + args.Player.tempGroupTimer.Start(); + args.Player.SendSuccessMessage("Your account has been elevated to Super Admin for 10 minutes."); + return; + } + } + #endregion Player Management Commands #region Server Maintenence Commands + // Executes a command as a superuser if you have sudo rights. + private static void SubstituteUserDo(CommandArgs args) + { + if (args.Parameters.Count == 0) + { + args.Player.SendErrorMessage("Usage: /sudo [command]."); + args.Player.SendErrorMessage("Example: /sudo /ban add Shank 2d Hacking."); + return; + } + + string replacementCommand = String.Join(" ", args.Parameters); + args.Player.tempGroup = new SuperAdminGroup(); + HandleCommand(args.Player, replacementCommand); + args.Player.tempGroup = null; + return; + } + private static void Broadcast(CommandArgs args) { string message = string.Join(" ", args.Parameters); @@ -4841,10 +4891,10 @@ namespace TShockAPI if (args.Player.Group.Name != "superadmin") args.Player.tempGroup = new SuperAdminGroup(); - args.Player.SendInfoMessage("Superadmin has been temporarily given to you. It will be removed on logout."); + args.Player.SendInfoMessage("Temporary system access has been given to you, so you can run one command."); args.Player.SendInfoMessage("Please use the following to create a permanent account for you."); - args.Player.SendInfoMessage("{0}user add superadmin", Specifier); - args.Player.SendInfoMessage("Creates: with the password as part of the superadmin group."); + args.Player.SendInfoMessage("{0}user add owner", Specifier); + args.Player.SendInfoMessage("Creates: with the password as part of the owner group."); args.Player.SendInfoMessage("Please use {0}login after this process.", Specifier); args.Player.SendInfoMessage("If you understand, please {0}login now, and then type {0}auth.", Specifier); return; diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs index e5fa3320..5cfed41b 100644 --- a/TShockAPI/ConfigFile.cs +++ b/TShockAPI/ConfigFile.cs @@ -78,18 +78,6 @@ namespace TShockAPI [Description("Disables any building / placing of blocks.")] public bool DisableBuild; - /// SuperAdminChatRGB - The chat color for the superadmin group. - [Description("#.#.# = Red/Blue/Green - RGB Colors for the Admin Chat Color. Max value: 255.")] - public int[] SuperAdminChatRGB = { 255, 0, 0 }; - - /// SuperAdminChatPrefix - The superadmin chat prefix. - [Description("Super admin group chat prefix.")] - public string SuperAdminChatPrefix = "(Admin) "; - - /// SuperAdminChatSuffix - The superadmin chat suffix. - [Description("Super admin group chat suffix.")] - public string SuperAdminChatSuffix = ""; - /// BackupInterval - The backup frequency in minutes. [Description("Backup frequency in minutes. So, a value of 60 = 60 minutes. Backups are stored in the \\tshock\\backups folder.")] public int BackupInterval; diff --git a/TShockAPI/DB/GroupManager.cs b/TShockAPI/DB/GroupManager.cs index 7d4f5a1b..9da13b9e 100644 --- a/TShockAPI/DB/GroupManager.cs +++ b/TShockAPI/DB/GroupManager.cs @@ -77,6 +77,8 @@ namespace TShockAPI.DB string.Join(",", Permissions.maintenance, "tshock.cfg.*", "tshock.world.*", Permissions.butcher, Permissions.item, Permissions.give, Permissions.heal, Permissions.immunetoban, Permissions.usebanneditem)); + AddDefaultGroup("owner", "trustedadmin", string.Join(",", Permissions.su)); + AddDefaultGroup("vip", "default", string.Join(",", Permissions.reservedslot)); } diff --git a/TShockAPI/Group.cs b/TShockAPI/Group.cs index 1eb5d48f..448f8442 100644 --- a/TShockAPI/Group.cs +++ b/TShockAPI/Group.cs @@ -340,11 +340,11 @@ namespace TShockAPI public SuperAdminGroup() : base("superadmin") { - R = (byte)TShock.Config.SuperAdminChatRGB[0]; - G = (byte)TShock.Config.SuperAdminChatRGB[1]; - B = (byte)TShock.Config.SuperAdminChatRGB[2]; - Prefix = TShock.Config.SuperAdminChatPrefix; - Suffix = TShock.Config.SuperAdminChatSuffix; + R = (byte)255; + G = (byte)255; + B = (byte)255; + Prefix = "(Super Admin) "; + Suffix = ""; } /// diff --git a/TShockAPI/Permissions.cs b/TShockAPI/Permissions.cs index 95eb6153..37340e48 100644 --- a/TShockAPI/Permissions.cs +++ b/TShockAPI/Permissions.cs @@ -221,6 +221,9 @@ namespace TShockAPI [Description("Meant for super admins only.")] public static readonly string user = "tshock.superadmin.user"; + [Description("Allows a user to elevate to superadmin for 10 minutes.")] + public static readonly string su = "tshock.su"; + // tshock.tp nodes [Description("User can teleport *everyone* to them.")] diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 8f7b831e..e2eedd1a 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -549,11 +549,6 @@ namespace TShockAPI get { return (int)(Y / 16); } } - /// - /// Unused. - /// - public bool TpLock; - /// /// Checks if the player has any inventory slots available. ///