Use construction graphs for hacking protections (#20265)
This commit is contained in:
@@ -6,14 +6,11 @@ namespace Content.Shared.Wires;
|
||||
|
||||
public abstract class SharedWiresSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<WiresPanelComponent, ExaminedEvent>(OnExamine);
|
||||
SubscribeLocalEvent<WiresPanelComponent, WeldableAttemptEvent>(OnWeldableAttempt);
|
||||
}
|
||||
|
||||
private void OnExamine(EntityUid uid, WiresPanelComponent component, ExaminedEvent args)
|
||||
@@ -26,21 +23,11 @@ public abstract class SharedWiresSystem : EntitySystem
|
||||
{
|
||||
args.PushMarkup(Loc.GetString("wires-panel-component-on-examine-open"));
|
||||
|
||||
if (_prototypeManager.TryIndex<WiresPanelSecurityLevelPrototype>(component.CurrentSecurityLevelID, out var securityLevelPrototype) &&
|
||||
securityLevelPrototype.Examine != null)
|
||||
if (TryComp<WiresPanelSecurityComponent>(uid, out var wiresPanelSecurity) &&
|
||||
wiresPanelSecurity.Examine != null)
|
||||
{
|
||||
args.PushMarkup(Loc.GetString(securityLevelPrototype.Examine));
|
||||
args.PushMarkup(Loc.GetString(wiresPanelSecurity.Examine));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnWeldableAttempt(EntityUid uid, WiresPanelComponent component, WeldableAttemptEvent args)
|
||||
{
|
||||
if (component.Open &&
|
||||
_prototypeManager.TryIndex<WiresPanelSecurityLevelPrototype>(component.CurrentSecurityLevelID, out var securityLevelPrototype) &&
|
||||
!securityLevelPrototype.WeldingAllowed)
|
||||
{
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,14 +27,6 @@ public sealed partial class WiresPanelComponent : Component
|
||||
|
||||
[DataField("screwdriverCloseSound")]
|
||||
public SoundSpecifier ScrewdriverCloseSound = new SoundPathSpecifier("/Audio/Machines/screwdriverclose.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// This prototype describes the current security features of the wire panel
|
||||
/// </summary>
|
||||
[DataField("securityLevel")]
|
||||
[ValidatePrototypeId<WiresPanelSecurityLevelPrototype>]
|
||||
[AutoNetworkedField]
|
||||
public string CurrentSecurityLevelID = "Level0";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
50
Content.Shared/Wires/WiresPanelSecurityComponent.cs
Normal file
50
Content.Shared/Wires/WiresPanelSecurityComponent.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Wires;
|
||||
|
||||
/// <summary>
|
||||
/// Allows hacking protections to a be added to an entity.
|
||||
/// These safeguards are determined via a construction graph,
|
||||
/// so the entity requires <cref="ConstructionComponent"/> for this to function
|
||||
/// </summary>
|
||||
[NetworkedComponent, RegisterComponent]
|
||||
[Access(typeof(SharedWiresSystem))]
|
||||
[AutoGenerateComponentState]
|
||||
public sealed partial class WiresPanelSecurityComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// A verbal description of the wire panel's current security level
|
||||
/// </summary>
|
||||
[DataField("examine")]
|
||||
[AutoNetworkedField]
|
||||
public string? Examine = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the wiring is accessible to hackers or not
|
||||
/// </summary>
|
||||
[DataField("wiresAccessible")]
|
||||
[AutoNetworkedField]
|
||||
public bool WiresAccessible = true;
|
||||
|
||||
/// <summary>
|
||||
/// Name of the construction graph node that the entity will start on
|
||||
/// </summary>
|
||||
[DataField("securityLevel")]
|
||||
[AutoNetworkedField]
|
||||
public string SecurityLevel = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This event gets raised when security settings on a wires panel change
|
||||
/// </summary>
|
||||
public sealed class WiresPanelSecurityEvent : EntityEventArgs
|
||||
{
|
||||
public readonly string? Examine;
|
||||
public readonly bool WiresAccessible;
|
||||
|
||||
public WiresPanelSecurityEvent(string? examine, bool wiresAccessible)
|
||||
{
|
||||
Examine = examine;
|
||||
WiresAccessible = wiresAccessible;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Shared.Wires;
|
||||
|
||||
[Prototype("WiresPanelSecurityLevel")]
|
||||
public sealed class WiresPanelSecurityLevelPrototype : IPrototype
|
||||
{
|
||||
[IdDataField]
|
||||
public string ID { get; private set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// A verbal description of the wire panel's current security level
|
||||
/// </summary>
|
||||
[DataField("examine")]
|
||||
public string? Examine = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the wiring is accessible to hackers or not
|
||||
/// </summary>
|
||||
[DataField("wiresAccessible")]
|
||||
public bool WiresAccessible = true;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the device can be welded shut or not
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Should be set false when you need to weld/unweld something to/from the wire panel
|
||||
/// </remarks>
|
||||
[DataField("weldingAllowed")]
|
||||
public bool WeldingAllowed = true;
|
||||
}
|
||||
Reference in New Issue
Block a user