]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
add access reader log wire (#29094)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Sat, 22 Jun 2024 15:12:58 +0000 (15:12 +0000)
committerGitHub <noreply@github.com>
Sat, 22 Jun 2024 15:12:58 +0000 (01:12 +1000)
* 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 [new file with mode: 0644]
Content.Shared/Access/Components/AccessReaderComponent.cs
Content.Shared/Access/Systems/AccessReaderSystem.cs
Resources/Locale/en-US/wires/log-wire.ftl [new file with mode: 0644]
Resources/Locale/en-US/wires/wire-names.ftl
Resources/Prototypes/Wires/layouts.yml

diff --git a/Content.Server/Access/LogWireAction.cs b/Content.Server/Access/LogWireAction.cs
new file mode 100644 (file)
index 0000000..1e97d5c
--- /dev/null
@@ -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<AccessReaderComponent>
+{
+    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<AccessReaderSystem>();
+    }
+
+    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<AccessReaderComponent>(wire.Owner, out var comp))
+            comp.LoggingDisabled = false;
+    }
+
+    private enum PulseTimeoutKey : byte
+    {
+        Key
+    }
+}
index cbd3f5acd6770bd11e3388783078732fd21a2532..903ceab186d1e03159dc0ca18cdb3337857a6bf3 100644 (file)
@@ -65,6 +65,13 @@ public sealed partial class AccessReaderComponent : Component
     [DataField, ViewVariables(VVAccess.ReadWrite)]
     public int AccessLogLimit = 20;
 
+    /// <summary>
+    /// If true logging on successful access uses will be disabled.
+    /// Can be set by LOG wire.
+    /// </summary>
+    [DataField]
+    public bool LoggingDisabled;
+
     /// <summary>
     /// Whether or not emag interactions have an effect on this.
     /// </summary>
index efdbff3bb88a6b378fc53464ed26b6f02a8020b1..5d1932a959c5a0f3dda38bf2da650a08ff1c8d6c 100644 (file)
@@ -382,18 +382,15 @@ public sealed class AccessReaderSystem : EntitySystem
     }
 
     /// <summary>
-    /// Logs an access
+    /// Logs an access for a specific entity.
     /// </summary>
     /// <param name="ent">The reader to log the access on</param>
     /// <param name="accessor">The accessor to log</param>
-    private void LogAccess(Entity<AccessReaderComponent> ent, EntityUid accessor)
+    public void LogAccess(Entity<AccessReaderComponent> 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<NameIdentifierComponent>(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"));
+    }
+
+    /// <summary>
+    /// Logs an access with a predetermined name
+    /// </summary>
+    /// <param name="ent">The reader to log the access on</param>
+    /// <param name="name">The name to log as</param>
+    public void LogAccess(Entity<AccessReaderComponent> 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 (file)
index 0000000..735816a
--- /dev/null
@@ -0,0 +1 @@
+log-wire-pulse-access-log = ERROR: Electromagnetic spike detected
index 851241f85c1b6c8261c00e8f43cfe8cc9dbbd3b4..a1ebec9e7d3642d3484eae45cf4b00850c79e961 100644 (file)
@@ -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
index 8d6be674e809ffb473cb42554de63c70c5ee21f7..3939655707e103c416b77438c374b60f93a09639 100644 (file)
@@ -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
 
   - !type:PowerWireAction
   - !type:PowerWireAction
     pulseTimeout: 15
+  - !type:LogWireAction
   - !type:DoorBoltWireAction
   - !type:DoorBoltLightWireAction
   - !type:DoorTimingWireAction