From 1e68ac22c7d7c191f05e6f86b7847c2b4f885340 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 2 Dec 2017 14:25:33 -0700 Subject: [PATCH 1/6] Remove superadmin customization config options --- TShockAPI/ConfigFile.cs | 12 ------------ TShockAPI/Group.cs | 10 +++++----- 2 files changed, 5 insertions(+), 17 deletions(-) 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/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 = ""; } /// From 3a8aa7fa29388e0e8dddb2ec5d731adddfeb3c1f Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 2 Dec 2017 14:28:12 -0700 Subject: [PATCH 2/6] Brilliant idea: Remove unused code instead of leaving it there. --- TShockAPI/TSPlayer.cs | 5 ----- 1 file changed, 5 deletions(-) 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. /// From 0bbd128f13368c23e9c72f490fbb53b7e8500559 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 2 Dec 2017 15:06:32 -0700 Subject: [PATCH 3/6] Implement /su command & default group owner /su elevates you to superadmin for 10 minutes. Account creation instructions tell you to use the "owner" group. If you fail to run a command but have the su permission, you're told that you can override it. Fixes #1505 --- TShockAPI/Commands.cs | 35 ++++++++++++++++++++++++++++++++--- TShockAPI/DB/GroupManager.cs | 2 ++ TShockAPI/Permissions.cs | 3 +++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 493aa956..8ebee559 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -311,6 +311,10 @@ 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.userinfo, GrabUserUserInfo, "userinfo", "ui") { HelpText = "Shows information about a player." @@ -685,6 +689,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}su to temporarily become Super Admin, which can run this command.", Specifier); + } } else if (!cmd.AllowServer && !player.RealPlayer) { @@ -1814,6 +1822,27 @@ 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 @@ -4842,10 +4871,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/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/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.")] From fdca4421383939e6beca1fe2d17338717c1365e0 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 2 Dec 2017 15:15:31 -0700 Subject: [PATCH 4/6] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecbd7138..76764b0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added a warning notifying users of the minimum memory required to run TShock (@bartico6) * Added /group rename to allow changing group names (@ColinBohn, @ProfessorXZ) * Added /region rename and OnRegionRenamed hook (@koneko-nyan, @deadsurgeon42) +* 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. If a user has the tshock.su permission, they're informed that they have access to /su if they can't run a command as a result from their degraded permission set. Finally, /su is implemented such that a 10 minute timeout will occur preventing people from just camping with it on. (@hakusaro) ## TShock 4.3.24 From d972f60fa058536896d3cce744eb9d16378655c8 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 2 Dec 2017 17:17:20 -0700 Subject: [PATCH 5/6] Add /sudo command. Usage: /sudo /command. Works on the same basis as /su (requires tshock.su). Replaces message that /su should be used for a one off command. --- TShockAPI/Commands.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 8ebee559..7e180f3c 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -315,6 +315,10 @@ namespace TShockAPI { 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." @@ -691,7 +695,7 @@ namespace TShockAPI player.SendErrorMessage("You do not have access to this command."); if (player.HasPermission(Permissions.su)) { - player.SendInfoMessage("You can use {0}su to temporarily become Super Admin, which can run this command.", Specifier); + player.SendInfoMessage("You can use '{0}sudo {0}{1}' to override this check.", Specifier, cmdText); } } else if (!cmd.AllowServer && !player.RealPlayer) @@ -1847,6 +1851,23 @@ namespace TShockAPI #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); From 6ee5ddf12ed94c6d29c9f3062b2b5780cfa48afc Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sat, 2 Dec 2017 17:19:23 -0700 Subject: [PATCH 6/6] Update changelog to point to /sudo --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76764b0e..11c6aad5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * Added a warning notifying users of the minimum memory required to run TShock (@bartico6) * Added /group rename to allow changing group names (@ColinBohn, @ProfessorXZ) * Added /region rename and OnRegionRenamed hook (@koneko-nyan, @deadsurgeon42) -* 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. If a user has the tshock.su permission, they're informed that they have access to /su if they can't run a command as a result from their degraded permission set. Finally, /su is implemented such that a 10 minute timeout will occur preventing people from just camping with it on. (@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