Use construction graphs for hacking protections (#20265)

This commit is contained in:
chromiumboy
2023-10-05 22:15:03 -05:00
committed by GitHub
parent 8eeedb2427
commit acc9c8940b
20 changed files with 363 additions and 581 deletions

View File

@@ -2,6 +2,8 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using Content.Server.Administration.Logs;
using Content.Server.Construction;
using Content.Server.Construction.Components;
using Content.Server.Power.Components;
using Content.Server.UserInterface;
using Content.Shared.Database;
@@ -33,6 +35,7 @@ public sealed class WiresSystem : SharedWiresSystem
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ConstructionSystem _construction = default!;
// This is where all the wire layouts are stored.
[ViewVariables] private readonly Dictionary<string, WireLayout> _layouts = new();
@@ -58,6 +61,7 @@ public sealed class WiresSystem : SharedWiresSystem
SubscribeLocalEvent<WiresComponent, WireDoAfterEvent>(OnDoAfter);
SubscribeLocalEvent<ActivatableUIRequiresPanelComponent, ActivatableUIOpenAttemptEvent>(OnAttemptOpenActivatableUI);
SubscribeLocalEvent<ActivatableUIRequiresPanelComponent, PanelChangedEvent>(OnActivatableUIPanelChanged);
SubscribeLocalEvent<WiresPanelSecurityComponent, WiresPanelSecurityEvent>(SetWiresPanelSecurity);
}
private void SetOrCreateWireLayout(EntityUid uid, WiresComponent? wires = null)
{
@@ -459,8 +463,8 @@ public sealed class WiresSystem : SharedWiresSystem
return;
if (panel.Open &&
_protoMan.TryIndex<WiresPanelSecurityLevelPrototype>(panel.CurrentSecurityLevelID, out var securityLevelPrototype) &&
securityLevelPrototype.WiresAccessible &&
TryComp<WiresPanelSecurityComponent>(uid, out var wiresPanelSecurity) &&
wiresPanelSecurity.WiresAccessible &&
(_toolSystem.HasQuality(args.Used, "Cutting", tool) ||
_toolSystem.HasQuality(args.Used, "Pulsing", tool)))
{
@@ -526,6 +530,14 @@ public sealed class WiresSystem : SharedWiresSystem
if (component.WireSeed == 0)
component.WireSeed = _random.Next(1, int.MaxValue);
// Update the construction graph to make sure that it starts on the node specified by WiresPanelSecurityComponent
if (TryComp<WiresPanelSecurityComponent>(uid, out var wiresPanelSecurity) &&
!string.IsNullOrEmpty(wiresPanelSecurity.SecurityLevel) &&
TryComp<ConstructionComponent>(uid, out var construction))
{
_construction.ChangeNode(uid, null, wiresPanelSecurity.SecurityLevel, true, construction);
}
UpdateUserInterface(uid);
}
#endregion
@@ -656,13 +668,14 @@ public sealed class WiresSystem : SharedWiresSystem
RaiseLocalEvent(uid, ref ev);
}
public void SetWiresPanelSecurityData(EntityUid uid, WiresPanelComponent component, string wiresPanelSecurityLevelID)
public void SetWiresPanelSecurity(EntityUid uid, WiresPanelSecurityComponent component, WiresPanelSecurityEvent args)
{
component.CurrentSecurityLevelID = wiresPanelSecurityLevelID;
component.Examine = args.Examine;
component.WiresAccessible = args.WiresAccessible;
Dirty(uid, component);
if (_protoMan.TryIndex<WiresPanelSecurityLevelPrototype>(component.CurrentSecurityLevelID, out var securityLevelPrototype) &&
securityLevelPrototype.WiresAccessible)
if (!args.WiresAccessible)
{
_uiSystem.TryCloseAll(uid, WiresUiKey.Key);
}