Forbid string literals for SharedToolSystem methods (#38250)

* Forbid string literals for ToolSystem methods

* Cleanup violations

* Sort usings
This commit is contained in:
Tayrtahn
2025-06-10 21:58:21 -04:00
committed by GitHub
parent 58606ca230
commit d612c56aab
5 changed files with 44 additions and 28 deletions

View File

@@ -5,29 +5,31 @@ using Content.Server.DeviceNetwork.Systems;
using Content.Server.Popups; using Content.Server.Popups;
using Content.Server.Power.Components; using Content.Server.Power.Components;
using Content.Server.Tools; using Content.Server.Tools;
using Content.Shared.UserInterface;
using Content.Shared.Administration.Logs; using Content.Shared.Administration.Logs;
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.DeviceNetwork; using Content.Shared.DeviceNetwork;
using Content.Shared.DeviceNetwork.Components;
using Content.Shared.DeviceNetwork.Events; using Content.Shared.DeviceNetwork.Events;
using Content.Shared.Emag.Systems; using Content.Shared.Emag.Systems;
using Content.Shared.Fax; using Content.Shared.Fax;
using Content.Shared.Fax.Systems;
using Content.Shared.Fax.Components; using Content.Shared.Fax.Components;
using Content.Shared.Fax.Systems;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Labels.Components; using Content.Shared.Labels.Components;
using Content.Shared.Labels.EntitySystems; using Content.Shared.Labels.EntitySystems;
using Content.Shared.Mobs.Components; using Content.Shared.Mobs.Components;
using Content.Shared.NameModifier.Components;
using Content.Shared.Paper; using Content.Shared.Paper;
using Content.Shared.Power;
using Content.Shared.Tools;
using Content.Shared.UserInterface;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems; using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.Player; using Robust.Shared.Player;
using Content.Shared.NameModifier.Components; using Robust.Shared.Prototypes;
using Content.Shared.Power;
using Content.Shared.DeviceNetwork.Components;
namespace Content.Server.Fax; namespace Content.Server.Fax;
@@ -50,6 +52,8 @@ public sealed class FaxSystem : EntitySystem
[Dependency] private readonly FaxecuteSystem _faxecute = default!; [Dependency] private readonly FaxecuteSystem _faxecute = default!;
[Dependency] private readonly EmagSystem _emag = default!; [Dependency] private readonly EmagSystem _emag = default!;
private static readonly ProtoId<ToolQualityPrototype> ScrewingQuality = "Screwing";
private const string PaperSlotId = "Paper"; private const string PaperSlotId = "Paper";
public override void Initialize() public override void Initialize()
@@ -209,7 +213,7 @@ public sealed class FaxSystem : EntitySystem
{ {
if (args.Handled || if (args.Handled ||
!TryComp<ActorComponent>(args.User, out var actor) || !TryComp<ActorComponent>(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; return;
_quickDialog.OpenDialog(actor.PlayerSession, _quickDialog.OpenDialog(actor.PlayerSession,

View File

@@ -1,5 +1,6 @@
using System.Linq; using System.Linq;
using Content.Server.Atmos.EntitySystems; using Content.Server.Atmos.EntitySystems;
using Content.Server.Body.Systems;
using Content.Server.Mech.Components; using Content.Server.Mech.Components;
using Content.Server.Power.Components; using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems; using Content.Server.Power.EntitySystems;
@@ -13,16 +14,17 @@ using Content.Shared.Mech.Components;
using Content.Shared.Mech.EntitySystems; using Content.Shared.Mech.EntitySystems;
using Content.Shared.Movement.Events; using Content.Shared.Movement.Events;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Tools;
using Content.Shared.Tools.Components; 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.Tools.Systems;
using Content.Shared.Verbs;
using Content.Shared.Whitelist;
using Content.Shared.Wires;
using Robust.Server.Containers; using Robust.Server.Containers;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.Player; using Robust.Shared.Player;
using Content.Shared.Whitelist; using Robust.Shared.Prototypes;
namespace Content.Server.Mech.Systems; namespace Content.Server.Mech.Systems;
@@ -40,6 +42,8 @@ public sealed partial class MechSystem : SharedMechSystem
[Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!; [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
[Dependency] private readonly SharedToolSystem _toolSystem = default!; [Dependency] private readonly SharedToolSystem _toolSystem = default!;
private static readonly ProtoId<ToolQualityPrototype> PryingQuality = "Prying";
/// <inheritdoc/> /// <inheritdoc/>
public override void Initialize() public override void Initialize()
{ {
@@ -91,7 +95,7 @@ public sealed partial class MechSystem : SharedMechSystem
return; 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, var doAfterEventArgs = new DoAfterArgs(EntityManager, args.User, component.BatteryRemovalDelay,
new RemoveBatteryEvent(), uid, target: uid, used: args.Target) new RemoveBatteryEvent(), uid, target: uid, used: args.Target)

View File

@@ -9,12 +9,11 @@ using Content.Server.NodeContainer.EntitySystems;
using Content.Server.NodeContainer.NodeGroups; using Content.Server.NodeContainer.NodeGroups;
using Content.Server.NodeContainer.Nodes; using Content.Server.NodeContainer.Nodes;
using Content.Server.Temperature.Components; using Content.Server.Temperature.Components;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.UserInterface;
using Content.Shared.Chemistry; using Content.Shared.Chemistry;
using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Components.SolutionManager; using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Climbing.Systems; using Content.Shared.Climbing.Systems;
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using Content.Shared.Database; using Content.Shared.Database;
@@ -26,11 +25,14 @@ using Content.Shared.Interaction;
using Content.Shared.Medical.Cryogenics; using Content.Shared.Medical.Cryogenics;
using Content.Shared.MedicalScanner; using Content.Shared.MedicalScanner;
using Content.Shared.Power; using Content.Shared.Power;
using Content.Shared.Tools;
using Content.Shared.Tools.Systems;
using Content.Shared.UserInterface;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
namespace Content.Server.Medical; namespace Content.Server.Medical;
@@ -51,6 +53,8 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem
[Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly NodeContainerSystem _nodeContainer = default!; [Dependency] private readonly NodeContainerSystem _nodeContainer = default!;
private static readonly ProtoId<ToolQualityPrototype> PryingQuality = "Prying";
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -211,7 +215,7 @@ public sealed partial class CryoPodSystem : SharedCryoPodSystem
if (args.Handled || !entity.Comp.Locked || entity.Comp.BodyContainer.ContainedEntity == null) if (args.Handled || !entity.Comp.Locked || entity.Comp.BodyContainer.ContainedEntity == null)
return; 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<CryoPodComponent> entity, ref ExaminedEvent args) private void OnExamined(Entity<CryoPodComponent> entity, ref ExaminedEvent args)

View File

@@ -10,6 +10,7 @@ using Content.Shared.Hands.Components;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Power; using Content.Shared.Power;
using Content.Shared.Tools;
using Content.Shared.Tools.Components; using Content.Shared.Tools.Components;
using Content.Shared.Wires; using Content.Shared.Wires;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
@@ -29,6 +30,9 @@ public sealed class WiresSystem : SharedWiresSystem
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ConstructionSystem _construction = default!; [Dependency] private readonly ConstructionSystem _construction = default!;
private static readonly ProtoId<ToolQualityPrototype> CuttingQuality = "Cutting";
private static readonly ProtoId<ToolQualityPrototype> PulsingQuality = "Pulsing";
// This is where all the wire layouts are stored. // This is where all the wire layouts are stored.
[ViewVariables] private readonly Dictionary<string, WireLayout> _layouts = new(); [ViewVariables] private readonly Dictionary<string, WireLayout> _layouts = new();
@@ -443,8 +447,8 @@ public sealed class WiresSystem : SharedWiresSystem
if (!IsPanelOpen(uid)) if (!IsPanelOpen(uid))
return; return;
if (Tool.HasQuality(args.Used, "Cutting", tool) || if (Tool.HasQuality(args.Used, CuttingQuality, tool) ||
Tool.HasQuality(args.Used, "Pulsing", tool)) Tool.HasQuality(args.Used, PulsingQuality, tool))
{ {
if (TryComp(args.User, out ActorComponent? actor)) if (TryComp(args.User, out ActorComponent? actor))
{ {
@@ -623,7 +627,7 @@ public sealed class WiresSystem : SharedWiresSystem
switch (action) switch (action)
{ {
case WiresAction.Cut: 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); _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
return; return;
@@ -637,7 +641,7 @@ public sealed class WiresSystem : SharedWiresSystem
break; break;
case WiresAction.Mend: 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); _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
return; return;
@@ -651,7 +655,7 @@ public sealed class WiresSystem : SharedWiresSystem
break; break;
case WiresAction.Pulse: 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); _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-multitool"), user);
return; return;
@@ -710,7 +714,7 @@ public sealed class WiresSystem : SharedWiresSystem
switch (action) switch (action)
{ {
case WiresAction.Cut: 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); _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
break; break;
@@ -731,7 +735,7 @@ public sealed class WiresSystem : SharedWiresSystem
UpdateUserInterface(used); UpdateUserInterface(used);
break; break;
case WiresAction.Mend: 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); _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
break; break;
@@ -752,7 +756,7 @@ public sealed class WiresSystem : SharedWiresSystem
UpdateUserInterface(used); UpdateUserInterface(used);
break; break;
case WiresAction.Pulse: 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); _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-multitool"), user);
break; break;

View File

@@ -115,7 +115,7 @@ public abstract partial class SharedToolSystem : EntitySystem
EntityUid user, EntityUid user,
EntityUid? target, EntityUid? target,
float doAfterDelay, float doAfterDelay,
IEnumerable<string> toolQualitiesNeeded, [ForbidLiteral] IEnumerable<string> toolQualitiesNeeded,
DoAfterEvent doAfterEv, DoAfterEvent doAfterEv,
float fuel = 0, float fuel = 0,
ToolComponent? toolComponent = null) ToolComponent? toolComponent = null)
@@ -153,7 +153,7 @@ public abstract partial class SharedToolSystem : EntitySystem
EntityUid user, EntityUid user,
EntityUid? target, EntityUid? target,
TimeSpan delay, TimeSpan delay,
IEnumerable<string> toolQualitiesNeeded, [ForbidLiteral] IEnumerable<string> toolQualitiesNeeded,
DoAfterEvent doAfterEv, DoAfterEvent doAfterEv,
out DoAfterId? id, out DoAfterId? id,
float fuel = 0, float fuel = 0,
@@ -200,7 +200,7 @@ public abstract partial class SharedToolSystem : EntitySystem
EntityUid user, EntityUid user,
EntityUid? target, EntityUid? target,
float doAfterDelay, float doAfterDelay,
string toolQualityNeeded, [ForbidLiteral] string toolQualityNeeded,
DoAfterEvent doAfterEv, DoAfterEvent doAfterEv,
float fuel = 0, float fuel = 0,
ToolComponent? toolComponent = null) ToolComponent? toolComponent = null)
@@ -219,7 +219,7 @@ public abstract partial class SharedToolSystem : EntitySystem
/// <summary> /// <summary>
/// Whether a tool entity has the specified quality or not. /// Whether a tool entity has the specified quality or not.
/// </summary> /// </summary>
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); 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. /// Whether a tool entity has all specified qualities or not.
/// </summary> /// </summary>
[PublicAPI] [PublicAPI]
public bool HasAllQualities(EntityUid uid, IEnumerable<string> qualities, ToolComponent? tool = null) public bool HasAllQualities(EntityUid uid, [ForbidLiteral] IEnumerable<string> qualities, ToolComponent? tool = null)
{ {
return Resolve(uid, ref tool, false) && tool.Qualities.ContainsAll(qualities); return Resolve(uid, ref tool, false) && tool.Qualities.ContainsAll(qualities);
} }