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>
This commit is contained in:
74
Content.Server/Access/LogWireAction.cs
Normal file
74
Content.Server/Access/LogWireAction.cs
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -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));
|
||||
|
||||
1
Resources/Locale/en-US/wires/log-wire.ftl
Normal file
1
Resources/Locale/en-US/wires/log-wire.ftl
Normal file
@@ -0,0 +1 @@
|
||||
log-wire-pulse-access-log = ERROR: Electromagnetic spike detected
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user