From 475c2a0b42128769b3d6bb361a6083c6f04e88b7 Mon Sep 17 00:00:00 2001 From: deltanedas <39013340+deltanedas@users.noreply.github.com> Date: Sat, 22 Jun 2024 15:12:58 +0000 Subject: [PATCH] add access reader log wire (#29094) * add LoggingDisabled to AccessReader * add LogWireAction * -m give everything besides high-security door a log wire * make LogAccess public and support string arg * add log when pulsing * m * l --------- Co-authored-by: deltanedas <@deltanedas:kde.org> --- Content.Server/Access/LogWireAction.cs | 74 +++++++++++++++++++ .../Components/AccessReaderComponent.cs | 7 ++ .../Access/Systems/AccessReaderSystem.cs | 25 +++++-- Resources/Locale/en-US/wires/log-wire.ftl | 1 + Resources/Locale/en-US/wires/wire-names.ftl | 1 + Resources/Prototypes/Wires/layouts.yml | 4 + 6 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 Content.Server/Access/LogWireAction.cs create mode 100644 Resources/Locale/en-US/wires/log-wire.ftl diff --git a/Content.Server/Access/LogWireAction.cs b/Content.Server/Access/LogWireAction.cs new file mode 100644 index 0000000000..1e97d5c9d6 --- /dev/null +++ b/Content.Server/Access/LogWireAction.cs @@ -0,0 +1,74 @@ +using Content.Server.Wires; +using Content.Shared.Access; +using Content.Shared.Access.Components; +using Content.Shared.Access.Systems; +using Content.Shared.Emag.Components; +using Content.Shared.Wires; + +namespace Content.Server.Access; + +public sealed partial class LogWireAction : ComponentWireAction +{ + public override Color Color { get; set; } = Color.Blue; + public override string Name { get; set; } = "wire-name-log"; + + [DataField] + public int PulseTimeout = 30; + + [DataField] + public LocId PulseLog = "log-wire-pulse-access-log"; + + private AccessReaderSystem _access = default!; + + public override StatusLightState? GetLightState(Wire wire, AccessReaderComponent comp) + { + return comp.LoggingDisabled ? StatusLightState.Off : StatusLightState.On; + } + + public override object StatusKey => AccessWireActionKey.Status; + + public override void Initialize() + { + base.Initialize(); + + _access = EntityManager.System(); + } + + public override bool Cut(EntityUid user, Wire wire, AccessReaderComponent comp) + { + WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key); + comp.LoggingDisabled = true; + EntityManager.Dirty(wire.Owner, comp); + return true; + } + + public override bool Mend(EntityUid user, Wire wire, AccessReaderComponent comp) + { + comp.LoggingDisabled = false; + return true; + } + + public override void Pulse(EntityUid user, Wire wire, AccessReaderComponent comp) + { + _access.LogAccess((wire.Owner, comp), Loc.GetString(PulseLog)); + comp.LoggingDisabled = true; + WiresSystem.StartWireAction(wire.Owner, PulseTimeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitPulseCancel, wire)); + } + + public override void Update(Wire wire) + { + if (!IsPowered(wire.Owner)) + WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key); + } + + private void AwaitPulseCancel(Wire wire) + { + if (!wire.IsCut && EntityManager.TryGetComponent(wire.Owner, out var comp)) + comp.LoggingDisabled = false; + } + + private enum PulseTimeoutKey : byte + { + Key + } +} diff --git a/Content.Shared/Access/Components/AccessReaderComponent.cs b/Content.Shared/Access/Components/AccessReaderComponent.cs index cbd3f5acd6..903ceab186 100644 --- a/Content.Shared/Access/Components/AccessReaderComponent.cs +++ b/Content.Shared/Access/Components/AccessReaderComponent.cs @@ -65,6 +65,13 @@ public sealed partial class AccessReaderComponent : Component [DataField, ViewVariables(VVAccess.ReadWrite)] public int AccessLogLimit = 20; + /// + /// If true logging on successful access uses will be disabled. + /// Can be set by LOG wire. + /// + [DataField] + public bool LoggingDisabled; + /// /// Whether or not emag interactions have an effect on this. /// diff --git a/Content.Shared/Access/Systems/AccessReaderSystem.cs b/Content.Shared/Access/Systems/AccessReaderSystem.cs index efdbff3bb8..5d1932a959 100644 --- a/Content.Shared/Access/Systems/AccessReaderSystem.cs +++ b/Content.Shared/Access/Systems/AccessReaderSystem.cs @@ -382,18 +382,15 @@ public sealed class AccessReaderSystem : EntitySystem } /// - /// Logs an access + /// Logs an access for a specific entity. /// /// The reader to log the access on /// The accessor to log - private void LogAccess(Entity ent, EntityUid accessor) + public void LogAccess(Entity ent, EntityUid accessor) { - if (IsPaused(ent)) + if (IsPaused(ent) || ent.Comp.LoggingDisabled) return; - if (ent.Comp.AccessLog.Count >= ent.Comp.AccessLogLimit) - ent.Comp.AccessLog.Dequeue(); - string? name = null; if (TryComp(accessor, out var nameIdentifier)) name = nameIdentifier.FullIdentifier; @@ -404,7 +401,21 @@ public sealed class AccessReaderSystem : EntitySystem && idCard.Comp is { BypassLogging: false, FullName: not null }) name = idCard.Comp.FullName; - name ??= Loc.GetString("access-reader-unknown-id"); + LogAccess(ent, name ?? Loc.GetString("access-reader-unknown-id")); + } + + /// + /// Logs an access with a predetermined name + /// + /// The reader to log the access on + /// The name to log as + public void LogAccess(Entity ent, string name) + { + if (IsPaused(ent) || ent.Comp.LoggingDisabled) + return; + + if (ent.Comp.AccessLog.Count >= ent.Comp.AccessLogLimit) + ent.Comp.AccessLog.Dequeue(); var stationTime = _gameTiming.CurTime.Subtract(_gameTicker.RoundStartTimeSpan); ent.Comp.AccessLog.Enqueue(new AccessRecord(stationTime, name)); diff --git a/Resources/Locale/en-US/wires/log-wire.ftl b/Resources/Locale/en-US/wires/log-wire.ftl new file mode 100644 index 0000000000..735816a52d --- /dev/null +++ b/Resources/Locale/en-US/wires/log-wire.ftl @@ -0,0 +1 @@ +log-wire-pulse-access-log = ERROR: Electromagnetic spike detected diff --git a/Resources/Locale/en-US/wires/wire-names.ftl b/Resources/Locale/en-US/wires/wire-names.ftl index 851241f85c..a1ebec9e7d 100644 --- a/Resources/Locale/en-US/wires/wire-names.ftl +++ b/Resources/Locale/en-US/wires/wire-names.ftl @@ -66,3 +66,4 @@ wire-name-bomb-boom = BOOM wire-name-bomb-bolt = BOLT wire-name-speech = SPKR wire-name-listen = MIC +wire-name-log = LOG diff --git a/Resources/Prototypes/Wires/layouts.yml b/Resources/Prototypes/Wires/layouts.yml index 8d6be674e8..3939655707 100644 --- a/Resources/Prototypes/Wires/layouts.yml +++ b/Resources/Prototypes/Wires/layouts.yml @@ -4,6 +4,7 @@ - !type:PowerWireAction - !type:PowerWireAction pulseTimeout: 15 + - !type:LogWireAction - !type:DoorBoltWireAction - !type:DoorBoltLightWireAction - !type:DoorTimingWireAction @@ -57,6 +58,7 @@ wires: - !type:PowerWireAction - !type:AccessWireAction + - !type:LogWireAction - !type:VendingMachineContrabandWireAction - !type:VendingMachineEjectItemWireAction - !type:SpeechWireAction @@ -66,6 +68,7 @@ wires: - !type:PowerWireAction - !type:AccessWireAction + - !type:LogWireAction - !type:AirAlarmPanicWire - !type:AtmosMonitorDeviceNetWire @@ -121,6 +124,7 @@ - !type:PowerWireAction - !type:PowerWireAction pulseTimeout: 15 + - !type:LogWireAction - !type:DoorBoltWireAction - !type:DoorBoltLightWireAction - !type:DoorTimingWireAction