--- /dev/null
+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
+ }
+}
}
/// <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;
&& 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));
- !type:PowerWireAction
- !type:PowerWireAction
pulseTimeout: 15
+ - !type:LogWireAction
- !type:DoorBoltWireAction
- !type:DoorBoltLightWireAction
- !type:DoorTimingWireAction
wires:
- !type:PowerWireAction
- !type:AccessWireAction
+ - !type:LogWireAction
- !type:VendingMachineContrabandWireAction
- !type:VendingMachineEjectItemWireAction
- !type:SpeechWireAction
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