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

@@ -1,27 +0,0 @@
using Content.Server.Wires;
using Content.Shared.Construction;
using Content.Shared.Wires;
using JetBrains.Annotations;
namespace Content.Server.Construction.Completions;
[UsedImplicitly]
[DataDefinition]
public sealed partial class ChangeWiresPanelSecurityLevel : IGraphAction
{
[DataField("level")]
[ValidatePrototypeId<WiresPanelSecurityLevelPrototype>]
public string WiresPanelSecurityLevelID = "Level0";
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
{
if (WiresPanelSecurityLevelID == null)
return;
if (entityManager.TryGetComponent(uid, out WiresPanelComponent? wiresPanel)
&& entityManager.TrySystem(out WiresSystem? wiresSystem))
{
wiresSystem.SetWiresPanelSecurityData(uid, wiresPanel, WiresPanelSecurityLevelID);
}
}
}

View File

@@ -0,0 +1,35 @@
using Content.Shared.Construction;
using Content.Shared.Wires;
using JetBrains.Annotations;
namespace Content.Server.Construction.Completions;
/// <summary>
/// This graph action is used to set values on entities with the <see cref="WiresPanelSecurityComponent"/>
/// </summary>
[UsedImplicitly]
[DataDefinition]
public sealed partial class SetWiresPanelSecurity : IGraphAction
{
/// <summary>
/// Sets the Examine field on the entity's <see cref="WiresPanelSecurityComponent"/>
/// </summary>
[DataField("examine")]
public string Examine = string.Empty;
/// <summary>
/// Sets the WiresAccessible field on the entity's <see cref="WiresPanelSecurityComponent"/>
/// </summary>
[DataField("wiresAccessible")]
public bool WiresAccessible = true;
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
{
if (entityManager.TryGetComponent(uid, out WiresPanelSecurityComponent? _))
{
var ev = new WiresPanelSecurityEvent(Examine, WiresAccessible);
entityManager.EventBus.RaiseLocalEvent(uid, ev);
}
}
}

View File

@@ -0,0 +1,43 @@
using Content.Shared.Construction;
using JetBrains.Annotations;
using Content.Shared.Doors.Components;
using Content.Shared.Examine;
using YamlDotNet.Core.Tokens;
using Content.Shared.Tag;
namespace Content.Server.Construction.Conditions
{
/// <summary>
/// This condition checks whether if an entity with the <see cref="TagComponent"/> possesses a specific tag
/// </summary>
[UsedImplicitly]
[DataDefinition]
public sealed partial class HasTag : IGraphCondition
{
/// <summary>
/// The tag the entity is being checked for
/// </summary>
[DataField("tag")]
public string Tag { get; private set; }
public bool Condition(EntityUid uid, IEntityManager entityManager)
{
if (!entityManager.TrySystem<TagSystem>(out var tagSystem))
return false;
return tagSystem.HasTag(uid, Tag);
}
public bool DoExamine(ExaminedEvent args)
{
return false;
}
public IEnumerable<ConstructionGuideEntry> GenerateGuideEntry()
{
yield return new ConstructionGuideEntry()
{
};
}
}
}

View File

@@ -8,6 +8,7 @@ using Content.Shared.Database;
using Robust.Server.Containers;
using Robust.Shared.Containers;
using Robust.Shared.Prototypes;
using System.Linq;
namespace Content.Server.Construction
{
@@ -298,9 +299,23 @@ namespace Content.Server.Construction
throw new Exception("Missing construction components");
}
// Exit if the new entity's prototype is the same as the original, or the prototype is invalid
if (newEntity == metaData.EntityPrototype?.ID || !_prototypeManager.HasIndex<EntityPrototype>(newEntity))
return null;
// [Optional] Exit if the new entity's prototype is a parent of the original
// E.g., if an entity with the 'AirlockCommand' prototype was to be replaced with a new entity that
// had the 'Airlock' prototype, and DoNotReplaceInheritingEntities was true, the code block would
// exit here because 'AirlockCommand' is derived from 'Airlock'
if (GetCurrentNode(uid, construction)?.DoNotReplaceInheritingEntities == true &&
metaData.EntityPrototype?.ID != null)
{
var parents = _prototypeManager.EnumerateParents<EntityPrototype>(metaData.EntityPrototype.ID)?.ToList();
if (parents != null && parents.Any(x => x.ID == newEntity))
return null;
}
// Optional resolves.
Resolve(uid, ref containerManager, false);

View File

@@ -12,6 +12,7 @@ using Content.Shared.Interaction;
using Content.Shared.Prying.Systems;
using Content.Shared.Radio.EntitySystems;
using Content.Shared.Tools.Components;
using Content.Shared.Tools.Systems;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Utility;
@@ -38,7 +39,7 @@ namespace Content.Server.Construction
// Event handling. Add your subscriptions here! Just make sure they're all handled by EnqueueEvent.
SubscribeLocalEvent<ConstructionComponent, InteractUsingEvent>(EnqueueEvent,
new []{typeof(AnchorableSystem), typeof(PryingSystem) },
new []{typeof(AnchorableSystem), typeof(PryingSystem), typeof(WeldableSystem)},
new []{typeof(EncryptionKeySystem)});
SubscribeLocalEvent<ConstructionComponent, OnTemperatureChangeEvent>(EnqueueEvent);
SubscribeLocalEvent<ConstructionComponent, PartAssemblyPartInsertedEvent>(EnqueueEvent);