Fix access wires emagging machines (#14471)

* Fix access wires emagging machines

* comment

* le fix
This commit is contained in:
Nemanja
2023-03-13 22:55:18 -04:00
committed by GitHub
parent 73efa95662
commit 89d3875cde
3 changed files with 33 additions and 17 deletions

View File

@@ -16,27 +16,33 @@ public sealed class AccessWireAction : ComponentWireAction<AccessReaderComponent
public override StatusLightState? GetLightState(Wire wire, AccessReaderComponent comp) public override StatusLightState? GetLightState(Wire wire, AccessReaderComponent comp)
{ {
return EntityManager.HasComponent<EmaggedComponent>(comp.Owner) ? StatusLightState.On : StatusLightState.Off; return comp.Enabled ? StatusLightState.On : StatusLightState.Off;
} }
public override object StatusKey { get; } = AccessWireActionKey.Status; public override object StatusKey => AccessWireActionKey.Status;
public override bool Cut(EntityUid user, Wire wire, AccessReaderComponent comp) public override bool Cut(EntityUid user, Wire wire, AccessReaderComponent comp)
{ {
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key); WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
EntityManager.EnsureComponent<EmaggedComponent>(comp.Owner); comp.Enabled = false;
EntityManager.Dirty(comp);
return true; return true;
} }
public override bool Mend(EntityUid user, Wire wire, AccessReaderComponent comp) public override bool Mend(EntityUid user, Wire wire, AccessReaderComponent comp)
{ {
EntityManager.RemoveComponent<EmaggedComponent>(comp.Owner); if (!EntityManager.HasComponent<EmaggedComponent>(wire.Owner))
{
comp.Enabled = true;
EntityManager.Dirty(comp);
}
return true; return true;
} }
public override void Pulse(EntityUid user, Wire wire, AccessReaderComponent comp) public override void Pulse(EntityUid user, Wire wire, AccessReaderComponent comp)
{ {
EntityManager.EnsureComponent<EmaggedComponent>(comp.Owner); comp.Enabled = false;
EntityManager.Dirty(comp);
WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitPulseCancel, wire)); WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitPulseCancel, wire));
} }
@@ -52,10 +58,10 @@ public sealed class AccessWireAction : ComponentWireAction<AccessReaderComponent
{ {
if (!wire.IsCut) if (!wire.IsCut)
{ {
// check is still here incase you somehow TOCTOU it into unemagging something it shouldn't if (EntityManager.TryGetComponent<AccessReaderComponent>(wire.Owner, out var access) && !EntityManager.HasComponent<EmaggedComponent>(wire.Owner))
if (EntityManager.TryGetComponent<AccessReaderComponent>(wire.Owner, out var access))
{ {
EntityManager.RemoveComponent<EmaggedComponent>(wire.Owner); access.Enabled = true;
EntityManager.Dirty(access);
} }
} }
} }

View File

@@ -13,6 +13,13 @@ namespace Content.Shared.Access.Components;
[RegisterComponent, NetworkedComponent] [RegisterComponent, NetworkedComponent]
public sealed class AccessReaderComponent : Component public sealed class AccessReaderComponent : Component
{ {
/// <summary>
/// Whether or not the accessreader is enabled.
/// If not, it will always let people through.
/// </summary>
[DataField("enabled")]
public bool Enabled = true;
/// <summary> /// <summary>
/// The set of tags that will automatically deny an allowed check, if any of them are present. /// The set of tags that will automatically deny an allowed check, if any of them are present.
/// </summary> /// </summary>
@@ -36,14 +43,17 @@ public sealed class AccessReaderComponent : Component
[Serializable, NetSerializable] [Serializable, NetSerializable]
public sealed class AccessReaderComponentState : ComponentState public sealed class AccessReaderComponentState : ComponentState
{ {
public bool Enabled;
public HashSet<string> DenyTags; public HashSet<string> DenyTags;
public List<HashSet<string>> AccessLists; public List<HashSet<string>> AccessLists;
public HashSet<StationRecordKey> AccessKeys; public HashSet<StationRecordKey> AccessKeys;
public AccessReaderComponentState(HashSet<string> denyTags, List<HashSet<string>> accessLists, HashSet<StationRecordKey> accessKeys) public AccessReaderComponentState(bool enabled, HashSet<string> denyTags, List<HashSet<string>> accessLists, HashSet<StationRecordKey> accessKeys)
{ {
Enabled = enabled;
DenyTags = denyTags; DenyTags = denyTags;
AccessLists = accessLists; AccessLists = accessLists;
AccessKeys = accessKeys; AccessKeys = accessKeys;

View File

@@ -32,7 +32,7 @@ namespace Content.Shared.Access.Systems
private void OnGetState(EntityUid uid, AccessReaderComponent component, ref ComponentGetState args) private void OnGetState(EntityUid uid, AccessReaderComponent component, ref ComponentGetState args)
{ {
args.State = new AccessReaderComponentState(component.DenyTags, component.AccessLists, args.State = new AccessReaderComponentState(component.Enabled, component.DenyTags, component.AccessLists,
component.AccessKeys); component.AccessKeys);
} }
@@ -40,6 +40,7 @@ namespace Content.Shared.Access.Systems
{ {
if (args.Current is not AccessReaderComponentState state) if (args.Current is not AccessReaderComponentState state)
return; return;
component.Enabled = state.Enabled;
component.AccessKeys = new (state.AccessKeys); component.AccessKeys = new (state.AccessKeys);
component.AccessLists = new (state.AccessLists); component.AccessLists = new (state.AccessLists);
component.DenyTags = new (state.DenyTags); component.DenyTags = new (state.DenyTags);
@@ -67,8 +68,9 @@ namespace Content.Shared.Access.Systems
private void OnEmagged(EntityUid uid, AccessReaderComponent reader, ref GotEmaggedEvent args) private void OnEmagged(EntityUid uid, AccessReaderComponent reader, ref GotEmaggedEvent args)
{ {
// no fancy conditions
args.Handled = true; args.Handled = true;
reader.Enabled = false;
Dirty(reader);
} }
/// <summary> /// <summary>
@@ -95,6 +97,10 @@ namespace Content.Shared.Access.Systems
{ {
var allEnts = FindPotentialAccessItems(entity); var allEnts = FindPotentialAccessItems(entity);
// Access reader is totally disabled, so access is always allowed.
if (!reader.Enabled)
return true;
if (AreAccessTagsAllowed(FindAccessTags(entity, allEnts), reader)) if (AreAccessTagsAllowed(FindAccessTags(entity, allEnts), reader))
return true; return true;
@@ -111,12 +117,6 @@ namespace Content.Shared.Access.Systems
/// <param name="reader">An access reader to check against</param> /// <param name="reader">An access reader to check against</param>
public bool AreAccessTagsAllowed(ICollection<string> accessTags, AccessReaderComponent reader) public bool AreAccessTagsAllowed(ICollection<string> accessTags, AccessReaderComponent reader)
{ {
if (HasComp<EmaggedComponent>(reader.Owner))
{
// Access reader is totally disabled, so access is always allowed.
return true;
}
if (reader.DenyTags.Overlaps(accessTags)) if (reader.DenyTags.Overlaps(accessTags))
{ {
// Sec owned by cargo. // Sec owned by cargo.