Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Content/Commands/DedservAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion Content/Tools/Gameplay/FastForward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions Content/Tools/Gameplay/Godmode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions Content/Tools/Gameplay/InfiniteReach.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions Content/Tools/Gameplay/Noclip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion Content/Tools/Map/MapTeleport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions Content/Tools/Visualization/Floodlight.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
{
Expand Down
5 changes: 4 additions & 1 deletion Content/Tools/Visualization/FreeCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions Content/Tools/Visualization/Hitboxes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HitboxWindow>();
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<HitboxWindow>();
Expand Down
21 changes: 21 additions & 0 deletions Core/Systems/PermissionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ internal class PermissionHandler : ModSystem
/// </summary>
public static List<int> visualAdmins = new();

/// <summary>
/// Resets all tools for a player who is not an admin.
/// </summary>
/// <param name="player">The player to reset tools for.</param>
public static void ResetToolsForNonAdmin(Player player)
{
if (Main.netMode == NetmodeID.Server)
return;

foreach (Tool tool in ModContent.GetContent<Tool>())
{
tool.ResetForNonAdmin(player);
}
}

/// <summary>
/// Determines if a player can use tools or not, based on their netmode and admin status.
/// </summary>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down
8 changes: 8 additions & 0 deletions Core/Systems/ToolSystem/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ public abstract class Tool : ModType
/// </summary>
public virtual bool SyncOnClientJoint => true;

/// <summary>
/// Resets cheat abilities (e.g godmode) for non-admin players.
/// </summary>
/// <param name="player"></param>
public virtual void ResetForNonAdmin(Player player)
{
}

/// <summary>
/// What happens when the user activates this tool, either by clicking on it or using it's hotkey.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion DragonLens.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<Reference Update="$(tMLSteamPath)\Libraries\FNA\1.0.0\FNA.dll" Publicize="true" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AssGen" OutputItemType="Analyzer" ReferenceOutputAssembly="false" Version="3.0.0" />
<PackageReference Include="AssGen" Version="3.0.1" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<Reference Include="StructureHelper">
Expand Down
24 changes: 20 additions & 4 deletions Localization/Themes/ru-RU_Mods.DragonLens.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
24 changes: 20 additions & 4 deletions Localization/Themes/zh-Hans_Mods.DragonLens.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
displayName = DragonLens
author = ScalarVector & Tomat & HeartPlusUp & QuestionMark
version = 1.10
version = 1.11
dllReferences = StructureHelper
Loading