From d612c56aab19b0152caa2fed3ea8fa49eaa52cf8 Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Tue, 10 Jun 2025 21:58:21 -0400 Subject: [PATCH] Forbid string literals for `SharedToolSystem` methods (#38250) * Forbid string literals for ToolSystem methods * Cleanup violations * Sort usings --- Content.Server/Fax/FaxSystem.cs | 16 +++++++++------ Content.Server/Mech/Systems/MechSystem.cs | 14 ++++++++----- Content.Server/Medical/CryoPodSystem.cs | 12 +++++++---- Content.Server/Wires/WiresSystem.cs | 20 +++++++++++-------- .../Tools/Systems/SharedToolSystem.cs | 10 +++++----- 5 files changed, 44 insertions(+), 28 deletions(-) diff --git a/Content.Server/Fax/FaxSystem.cs b/Content.Server/Fax/FaxSystem.cs index 79710e3f97..44a953374e 100644 --- a/Content.Server/Fax/FaxSystem.cs +++ b/Content.Server/Fax/FaxSystem.cs @@ -5,29 +5,31 @@ using Content.Server.DeviceNetwork.Systems; using Content.Server.Popups; using Content.Server.Power.Components; using Content.Server.Tools; -using Content.Shared.UserInterface; using Content.Shared.Administration.Logs; using Content.Shared.Containers.ItemSlots; using Content.Shared.Database; using Content.Shared.DeviceNetwork; +using Content.Shared.DeviceNetwork.Components; using Content.Shared.DeviceNetwork.Events; using Content.Shared.Emag.Systems; using Content.Shared.Fax; -using Content.Shared.Fax.Systems; using Content.Shared.Fax.Components; +using Content.Shared.Fax.Systems; using Content.Shared.Interaction; using Content.Shared.Labels.Components; using Content.Shared.Labels.EntitySystems; using Content.Shared.Mobs.Components; +using Content.Shared.NameModifier.Components; using Content.Shared.Paper; +using Content.Shared.Power; +using Content.Shared.Tools; +using Content.Shared.UserInterface; using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.Audio.Systems; using Robust.Shared.Containers; using Robust.Shared.Player; -using Content.Shared.NameModifier.Components; -using Content.Shared.Power; -using Content.Shared.DeviceNetwork.Components; +using Robust.Shared.Prototypes; namespace Content.Server.Fax; @@ -50,6 +52,8 @@ public sealed class FaxSystem : EntitySystem [Dependency] private readonly FaxecuteSystem _faxecute = default!; [Dependency] private readonly EmagSystem _emag = default!; + private static readonly ProtoId ScrewingQuality = "Screwing"; + private const string PaperSlotId = "Paper"; public override void Initialize() @@ -209,7 +213,7 @@ public sealed class FaxSystem : EntitySystem { if (args.Handled || !TryComp(args.User, out var actor) || - !_toolSystem.HasQuality(args.Used, "Screwing")) // Screwing because Pulsing already used by device linking + !_toolSystem.HasQuality(args.Used, ScrewingQuality)) // Screwing because Pulsing already used by device linking return; _quickDialog.OpenDialog(actor.PlayerSession, diff --git a/Content.Server/Mech/Systems/MechSystem.cs b/Content.Server/Mech/Systems/MechSystem.cs index 9da96a76f8..7b0c2f6472 100644 --- a/Content.Server/Mech/Systems/MechSystem.cs +++ b/Content.Server/Mech/Systems/MechSystem.cs @@ -1,5 +1,6 @@ using System.Linq; using Content.Server.Atmos.EntitySystems; +using Content.Server.Body.Systems; using Content.Server.Mech.Components; using Content.Server.Power.Components; using Content.Server.Power.EntitySystems; @@ -13,16 +14,17 @@ using Content.Shared.Mech.Components; using Content.Shared.Mech.EntitySystems; using Content.Shared.Movement.Events; using Content.Shared.Popups; +using Content.Shared.Tools; using Content.Shared.Tools.Components; -using Content.Shared.Verbs; -using Content.Shared.Wires; -using Content.Server.Body.Systems; using Content.Shared.Tools.Systems; +using Content.Shared.Verbs; +using Content.Shared.Whitelist; +using Content.Shared.Wires; using Robust.Server.Containers; using Robust.Server.GameObjects; using Robust.Shared.Containers; using Robust.Shared.Player; -using Content.Shared.Whitelist; +using Robust.Shared.Prototypes; namespace Content.Server.Mech.Systems; @@ -40,6 +42,8 @@ public sealed partial class MechSystem : SharedMechSystem [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!; [Dependency] private readonly SharedToolSystem _toolSystem = default!; + private static readonly ProtoId PryingQuality = "Prying"; + /// public override void Initialize() { @@ -91,7 +95,7 @@ public sealed partial class MechSystem : SharedMechSystem return; } - if (_toolSystem.HasQuality(args.Used, "Prying") && component.BatterySlot.ContainedEntity != null) + if (_toolSystem.HasQuality(args.Used, PryingQuality) && component.BatterySlot.ContainedEntity != null) { var doAfterEventArgs = new DoAfterArgs(EntityManager, args.User, component.BatteryRemovalDelay, new RemoveBatteryEvent(), uid, target: uid, used: args.Target) diff --git a/Content.Server/Medical/CryoPodSystem.cs b/Content.Server/Medical/CryoPodSystem.cs index 15fe2a69cf..8dd0330a27 100644 --- a/Content.Server/Medical/CryoPodSystem.cs +++ b/Content.Server/Medical/CryoPodSystem.cs @@ -9,12 +9,11 @@ using Content.Server.NodeContainer.EntitySystems; using Content.Server.NodeContainer.NodeGroups; using Content.Server.NodeContainer.Nodes; using Content.Server.Temperature.Components; -using Content.Shared.Chemistry.EntitySystems; using Content.Shared.Atmos; -using Content.Shared.UserInterface; using Content.Shared.Chemistry; using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Components.SolutionManager; +using Content.Shared.Chemistry.EntitySystems; using Content.Shared.Climbing.Systems; using Content.Shared.Containers.ItemSlots; using Content.Shared.Database; @@ -26,11 +25,14 @@ using Content.Shared.Interaction; using Content.Shared.Medical.Cryogenics; using Content.Shared.MedicalScanner; using Content.Shared.Power; +using Content.Shared.Tools; +using Content.Shared.Tools.Systems; +using Content.Shared.UserInterface; using Content.Shared.Verbs; using Robust.Server.GameObjects; using Robust.Shared.Containers; +using Robust.Shared.Prototypes; using Robust.Shared.Timing; -using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem; namespace Content.Server.Medical; @@ -51,6 +53,8 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem [Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly NodeContainerSystem _nodeContainer = default!; + private static readonly ProtoId PryingQuality = "Prying"; + public override void Initialize() { base.Initialize(); @@ -211,7 +215,7 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem if (args.Handled || !entity.Comp.Locked || entity.Comp.BodyContainer.ContainedEntity == null) return; - args.Handled = _toolSystem.UseTool(args.Used, args.User, entity.Owner, entity.Comp.PryDelay, "Prying", new CryoPodPryFinished()); + args.Handled = _toolSystem.UseTool(args.Used, args.User, entity.Owner, entity.Comp.PryDelay, PryingQuality, new CryoPodPryFinished()); } private void OnExamined(Entity entity, ref ExaminedEvent args) diff --git a/Content.Server/Wires/WiresSystem.cs b/Content.Server/Wires/WiresSystem.cs index 397b199ecb..7f382e15bb 100644 --- a/Content.Server/Wires/WiresSystem.cs +++ b/Content.Server/Wires/WiresSystem.cs @@ -10,6 +10,7 @@ using Content.Shared.Hands.Components; using Content.Shared.Interaction; using Content.Shared.Popups; using Content.Shared.Power; +using Content.Shared.Tools; using Content.Shared.Tools.Components; using Content.Shared.Wires; using Robust.Server.GameObjects; @@ -29,6 +30,9 @@ public sealed class WiresSystem : SharedWiresSystem [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly ConstructionSystem _construction = default!; + private static readonly ProtoId CuttingQuality = "Cutting"; + private static readonly ProtoId PulsingQuality = "Pulsing"; + // This is where all the wire layouts are stored. [ViewVariables] private readonly Dictionary _layouts = new(); @@ -443,8 +447,8 @@ public sealed class WiresSystem : SharedWiresSystem if (!IsPanelOpen(uid)) return; - if (Tool.HasQuality(args.Used, "Cutting", tool) || - Tool.HasQuality(args.Used, "Pulsing", tool)) + if (Tool.HasQuality(args.Used, CuttingQuality, tool) || + Tool.HasQuality(args.Used, PulsingQuality, tool)) { if (TryComp(args.User, out ActorComponent? actor)) { @@ -623,7 +627,7 @@ public sealed class WiresSystem : SharedWiresSystem switch (action) { case WiresAction.Cut: - if (!Tool.HasQuality(toolEntity, "Cutting", tool)) + if (!Tool.HasQuality(toolEntity, CuttingQuality, tool)) { _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user); return; @@ -637,7 +641,7 @@ public sealed class WiresSystem : SharedWiresSystem break; case WiresAction.Mend: - if (!Tool.HasQuality(toolEntity, "Cutting", tool)) + if (!Tool.HasQuality(toolEntity, CuttingQuality, tool)) { _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user); return; @@ -651,7 +655,7 @@ public sealed class WiresSystem : SharedWiresSystem break; case WiresAction.Pulse: - if (!Tool.HasQuality(toolEntity, "Pulsing", tool)) + if (!Tool.HasQuality(toolEntity, PulsingQuality, tool)) { _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-multitool"), user); return; @@ -710,7 +714,7 @@ public sealed class WiresSystem : SharedWiresSystem switch (action) { case WiresAction.Cut: - if (!Tool.HasQuality(toolEntity, "Cutting", tool)) + if (!Tool.HasQuality(toolEntity, CuttingQuality, tool)) { _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user); break; @@ -731,7 +735,7 @@ public sealed class WiresSystem : SharedWiresSystem UpdateUserInterface(used); break; case WiresAction.Mend: - if (!Tool.HasQuality(toolEntity, "Cutting", tool)) + if (!Tool.HasQuality(toolEntity, CuttingQuality, tool)) { _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user); break; @@ -752,7 +756,7 @@ public sealed class WiresSystem : SharedWiresSystem UpdateUserInterface(used); break; case WiresAction.Pulse: - if (!Tool.HasQuality(toolEntity, "Pulsing", tool)) + if (!Tool.HasQuality(toolEntity, PulsingQuality, tool)) { _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-multitool"), user); break; diff --git a/Content.Shared/Tools/Systems/SharedToolSystem.cs b/Content.Shared/Tools/Systems/SharedToolSystem.cs index 95377d913a..bf98a365e7 100644 --- a/Content.Shared/Tools/Systems/SharedToolSystem.cs +++ b/Content.Shared/Tools/Systems/SharedToolSystem.cs @@ -115,7 +115,7 @@ public abstract partial class SharedToolSystem : EntitySystem EntityUid user, EntityUid? target, float doAfterDelay, - IEnumerable toolQualitiesNeeded, + [ForbidLiteral] IEnumerable toolQualitiesNeeded, DoAfterEvent doAfterEv, float fuel = 0, ToolComponent? toolComponent = null) @@ -153,7 +153,7 @@ public abstract partial class SharedToolSystem : EntitySystem EntityUid user, EntityUid? target, TimeSpan delay, - IEnumerable toolQualitiesNeeded, + [ForbidLiteral] IEnumerable toolQualitiesNeeded, DoAfterEvent doAfterEv, out DoAfterId? id, float fuel = 0, @@ -200,7 +200,7 @@ public abstract partial class SharedToolSystem : EntitySystem EntityUid user, EntityUid? target, float doAfterDelay, - string toolQualityNeeded, + [ForbidLiteral] string toolQualityNeeded, DoAfterEvent doAfterEv, float fuel = 0, ToolComponent? toolComponent = null) @@ -219,7 +219,7 @@ public abstract partial class SharedToolSystem : EntitySystem /// /// Whether a tool entity has the specified quality or not. /// - public bool HasQuality(EntityUid uid, string quality, ToolComponent? tool = null) + public bool HasQuality(EntityUid uid, [ForbidLiteral] string quality, ToolComponent? tool = null) { return Resolve(uid, ref tool, false) && tool.Qualities.Contains(quality); } @@ -228,7 +228,7 @@ public abstract partial class SharedToolSystem : EntitySystem /// Whether a tool entity has all specified qualities or not. /// [PublicAPI] - public bool HasAllQualities(EntityUid uid, IEnumerable qualities, ToolComponent? tool = null) + public bool HasAllQualities(EntityUid uid, [ForbidLiteral] IEnumerable qualities, ToolComponent? tool = null) { return Resolve(uid, ref tool, false) && tool.Qualities.ContainsAll(qualities); }