diff --git a/Content/Commands/DedservAdmin.cs b/Content/Commands/DedservAdmin.cs index 8a1d47e..c1ad820 100644 --- a/Content/Commands/DedservAdmin.cs +++ b/Content/Commands/DedservAdmin.cs @@ -26,7 +26,7 @@ public override void Action(CommandCaller caller, string input, string[] args) throw new UsageException("You must provide a players name!"); } - string name = input[(Command.Length + 1)..]; + string name = input[(Command.Length + 1)..].ToLower(); Player player = Main.player.FirstOrDefault(n => n.name.ToLower() == name); diff --git a/Content/Tools/Gameplay/FastForward.cs b/Content/Tools/Gameplay/FastForward.cs index 70cf093..92446b7 100644 --- a/Content/Tools/Gameplay/FastForward.cs +++ b/Content/Tools/Gameplay/FastForward.cs @@ -13,7 +13,10 @@ internal class FastForward : Tool public override string IconKey => "FastForward"; public override bool HasRightClick => true; - + public override void ResetForNonAdmin(Player player) + { + speedup = 0; + } public override void OnActivate() { if (Main.netMode != NetmodeID.SinglePlayer) diff --git a/Content/Tools/Gameplay/Godmode.cs b/Content/Tools/Gameplay/Godmode.cs index 11f0073..b1796c0 100644 --- a/Content/Tools/Gameplay/Godmode.cs +++ b/Content/Tools/Gameplay/Godmode.cs @@ -17,6 +17,12 @@ internal class Godmode : Tool public override bool HasRightClick => true; + public override void ResetForNonAdmin(Player player) + { + godMode = false; + dogMode = false; + } + public override void OnActivate() { godMode = !godMode; diff --git a/Content/Tools/Gameplay/InfiniteReach.cs b/Content/Tools/Gameplay/InfiniteReach.cs index 777cb45..7d9e0d2 100644 --- a/Content/Tools/Gameplay/InfiniteReach.cs +++ b/Content/Tools/Gameplay/InfiniteReach.cs @@ -12,6 +12,11 @@ internal class InfiniteReach : Tool public override string IconKey => "InfiniteReach"; + public override void ResetForNonAdmin(Player player) + { + active = false; + } + public override void OnActivate() { active = !active; diff --git a/Content/Tools/Gameplay/Noclip.cs b/Content/Tools/Gameplay/Noclip.cs index 967e44a..dce5689 100644 --- a/Content/Tools/Gameplay/Noclip.cs +++ b/Content/Tools/Gameplay/Noclip.cs @@ -3,6 +3,7 @@ using DragonLens.Core.Systems.ThemeSystem; using DragonLens.Core.Systems.ToolSystem; using DragonLens.Helpers; +using System; using System.IO; using Terraria.ID; @@ -26,6 +27,10 @@ public bool Active public override string IconKey => "Noclip"; + public override void ResetForNonAdmin(Player player) + { + Active = false; + } public override void OnActivate() { Active = !Active; diff --git a/Content/Tools/Map/MapTeleport.cs b/Content/Tools/Map/MapTeleport.cs index 0cfca20..f78bbd7 100644 --- a/Content/Tools/Map/MapTeleport.cs +++ b/Content/Tools/Map/MapTeleport.cs @@ -14,7 +14,10 @@ internal class MapTeleport : Tool public static bool active = true; public override string IconKey => "MapTeleport"; - + public override void ResetForNonAdmin(Player player) + { + active = false; + } public override void OnActivate() { active = !active; diff --git a/Content/Tools/Visualization/Floodlight.cs b/Content/Tools/Visualization/Floodlight.cs index f83fc25..f4cd48b 100644 --- a/Content/Tools/Visualization/Floodlight.cs +++ b/Content/Tools/Visualization/Floodlight.cs @@ -1,6 +1,7 @@ using DragonLens.Core.Systems.ThemeSystem; using DragonLens.Core.Systems.ToolSystem; using DragonLens.Helpers; +using System; using Terraria.ModLoader.IO; namespace DragonLens.Content.Tools.Visualization @@ -12,6 +13,10 @@ internal class Floodlight : Tool public override string IconKey => "Lighting"; public override bool HasRightClick => true; + public override void ResetForNonAdmin(Player player) + { + strength = 0f; + } public override void OnActivate() { diff --git a/Content/Tools/Visualization/FreeCamera.cs b/Content/Tools/Visualization/FreeCamera.cs index b693c35..c6ad92e 100644 --- a/Content/Tools/Visualization/FreeCamera.cs +++ b/Content/Tools/Visualization/FreeCamera.cs @@ -11,7 +11,10 @@ internal class FreeCamera : Tool public static Vector2 freeCameraPos; public override string IconKey => "FreeCamera"; - + public override void ResetForNonAdmin(Player player) + { + active = false; + } public override void OnActivate() { active = !active; diff --git a/Content/Tools/Visualization/Hitboxes.cs b/Content/Tools/Visualization/Hitboxes.cs index b7dcec1..3738c73 100644 --- a/Content/Tools/Visualization/Hitboxes.cs +++ b/Content/Tools/Visualization/Hitboxes.cs @@ -15,6 +15,21 @@ internal class Hitboxes : Tool { public override string IconKey => "Hitboxes"; + public override void ResetForNonAdmin(Player player) + { + // Hide the hitbox window entirely for non-admins + HitboxWindow state = UILoader.GetUIState(); + state.visible = false; + + // Also force all options to "none" so no boxes are drawn + state.NPCOption?.boxState = HitboxOption.BoxType.none; + state.ProjectileOption?.boxState = HitboxOption.BoxType.none; + state.PlayerOption?.boxState = HitboxOption.BoxType.none; + state.ItemOption?.boxState = HitboxOption.BoxType.none; + state.MeleeOption?.boxState = HitboxOption.BoxType.none; + state.TileEntityOption?.boxState = HitboxOption.BoxType.none; + } + public override void OnActivate() { HitboxWindow state = UILoader.GetUIState(); diff --git a/Core/Systems/PermissionHandler.cs b/Core/Systems/PermissionHandler.cs index 8ac67d8..693e767 100644 --- a/Core/Systems/PermissionHandler.cs +++ b/Core/Systems/PermissionHandler.cs @@ -29,6 +29,21 @@ internal class PermissionHandler : ModSystem /// public static List visualAdmins = new(); + /// + /// Resets all tools for a player who is not an admin. + /// + /// The player to reset tools for. + public static void ResetToolsForNonAdmin(Player player) + { + if (Main.netMode == NetmodeID.Server) + return; + + foreach (Tool tool in ModContent.GetContent()) + { + tool.ResetForNonAdmin(player); + } + } + /// /// Determines if a player can use tools or not, based on their netmode and admin status. /// @@ -196,6 +211,9 @@ public static void HandlePacket(BinaryReader reader, int whoAmI) item.Visible = false; } + + // Client loses admin permissions -> reset all tools + ResetToolsForNonAdmin(Main.LocalPlayer); } } else if (operation == 2) //Sync visual only @@ -354,6 +372,9 @@ public override void OnEnterWorld() // Send an admin list sync request on enteri packet.Write("AdminUpdate"); packet.Write(2); packet.Send(); + + // Client enters world -> reset all tools + PermissionHandler.ResetToolsForNonAdmin(Player); } if (Netplay.Connection.Socket.GetRemoteAddress().IsLocalHost()) // The host is automatically an admin! diff --git a/Core/Systems/ToolSystem/Tool.cs b/Core/Systems/ToolSystem/Tool.cs index 2d4a222..175cc36 100644 --- a/Core/Systems/ToolSystem/Tool.cs +++ b/Core/Systems/ToolSystem/Tool.cs @@ -62,6 +62,14 @@ public abstract class Tool : ModType /// public virtual bool SyncOnClientJoint => true; + /// + /// Resets cheat abilities (e.g godmode) for non-admin players. + /// + /// + public virtual void ResetForNonAdmin(Player player) + { + } + /// /// What happens when the user activates this tool, either by clicking on it or using it's hotkey. /// diff --git a/DragonLens.csproj b/DragonLens.csproj index 1a066fa..7212969 100644 --- a/DragonLens.csproj +++ b/DragonLens.csproj @@ -30,7 +30,7 @@ - + diff --git a/Localization/Themes/ru-RU_Mods.DragonLens.hjson b/Localization/Themes/ru-RU_Mods.DragonLens.hjson index 5376157..42e369a 100644 --- a/Localization/Themes/ru-RU_Mods.DragonLens.hjson +++ b/Localization/Themes/ru-RU_Mods.DragonLens.hjson @@ -60,14 +60,30 @@ Configs: { BoxStyle: { Tooltip: "" - simple.Label: "{$Mods.DragonLens.BoxStyle.simple}" - vanilla.Label: "{$Mods.DragonLens.BoxStyle.vanilla}" + + simple: { + Label: "{$Mods.DragonLens.BoxStyle.simple}" + // Tooltip: "" + } + + vanilla: { + Label: "{$Mods.DragonLens.BoxStyle.vanilla}" + // Tooltip: "" + } } IconStyle: { Tooltip: "" - basic.Label: "{$Mods.DragonLens.IconStyle.basic}" - HEROs.Label: "{$Mods.DragonLens.IconStyle.HEROs}" + + basic: { + Label: "{$Mods.DragonLens.IconStyle.basic}" + // Tooltip: "" + } + + HEROs: { + Label: "{$Mods.DragonLens.IconStyle.HEROs}" + // Tooltip: "" + } } ToolConfig: { diff --git a/Localization/Themes/zh-Hans_Mods.DragonLens.hjson b/Localization/Themes/zh-Hans_Mods.DragonLens.hjson index 599885b..24f98ad 100644 --- a/Localization/Themes/zh-Hans_Mods.DragonLens.hjson +++ b/Localization/Themes/zh-Hans_Mods.DragonLens.hjson @@ -60,14 +60,30 @@ Configs: { BoxStyle: { // Tooltip: "" - // simple.Label: "{$Mods.DragonLens.BoxStyle.simple}" - // vanilla.Label: "{$Mods.DragonLens.BoxStyle.vanilla}" + + simple: { + // Label: "{$Mods.DragonLens.BoxStyle.simple}" + // Tooltip: "" + } + + vanilla: { + // Label: "{$Mods.DragonLens.BoxStyle.vanilla}" + // Tooltip: "" + } } IconStyle: { // Tooltip: "" - // basic.Label: "{$Mods.DragonLens.IconStyle.basic}" - // HEROs.Label: "{$Mods.DragonLens.IconStyle.HEROs}" + + basic: { + // Label: "{$Mods.DragonLens.IconStyle.basic}" + // Tooltip: "" + } + + HEROs: { + // Label: "{$Mods.DragonLens.IconStyle.HEROs}" + // Tooltip: "" + } } ToolConfig: { diff --git a/build.txt b/build.txt index 4cf0e52..498945f 100644 --- a/build.txt +++ b/build.txt @@ -1,4 +1,4 @@ displayName = DragonLens author = ScalarVector & Tomat & HeartPlusUp & QuestionMark -version = 1.10 +version = 1.11 dllReferences = StructureHelper \ No newline at end of file