Access logs tweaks and fixes (#23096)
* Fix AccessRecord not serializing correctly on map saves * record struct my beloved * Final tweaks * pro * This is no longer necessary
This commit is contained in:
42
Content.Server/Access/AddAccessLogCommand.cs
Normal file
42
Content.Server/Access/AddAccessLogCommand.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Shared.Toolshed;
|
||||
using Robust.Shared.Toolshed.Syntax;
|
||||
|
||||
namespace Content.Server.Access;
|
||||
|
||||
[ToolshedCommand, AdminCommand(AdminFlags.Mapping)]
|
||||
public sealed class AddAccessLogCommand : ToolshedCommand
|
||||
{
|
||||
[CommandImplementation]
|
||||
public void AddAccessLog(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[CommandArgument] EntityUid input,
|
||||
[CommandArgument] float seconds,
|
||||
[CommandArgument] ValueRef<string> accessor)
|
||||
{
|
||||
var accessReader = EnsureComp<AccessReaderComponent>(input);
|
||||
|
||||
var accessLogCount = accessReader.AccessLog.Count;
|
||||
if (accessLogCount >= accessReader.AccessLogLimit)
|
||||
ctx.WriteLine($"WARNING: Surpassing the limit of the log by {accessLogCount - accessReader.AccessLogLimit+1} entries!");
|
||||
|
||||
var accessTime = TimeSpan.FromSeconds(seconds);
|
||||
var accessName = accessor.Evaluate(ctx)!;
|
||||
accessReader.AccessLog.Enqueue(new AccessRecord(accessTime, accessName));
|
||||
ctx.WriteLine($"Successfully added access log to {input} with this information inside:\n " +
|
||||
$"Time of access: {accessTime}\n " +
|
||||
$"Accessed by: {accessName}");
|
||||
}
|
||||
|
||||
[CommandImplementation]
|
||||
public void AddAccessLogPiped(
|
||||
[CommandInvocationContext] IInvocationContext ctx,
|
||||
[PipedArgument] EntityUid input,
|
||||
[CommandArgument] float seconds,
|
||||
[CommandArgument] ValueRef<string> accessor)
|
||||
{
|
||||
AddAccessLog(ctx, input, seconds, accessor);
|
||||
}
|
||||
}
|
||||
@@ -65,8 +65,17 @@ public sealed partial class AccessReaderComponent : Component
|
||||
public int AccessLogLimit = 20;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public record struct AccessRecord(TimeSpan AccessTime, string Accessor);
|
||||
[DataDefinition, Serializable, NetSerializable]
|
||||
public readonly partial record struct AccessRecord(
|
||||
[property: DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
TimeSpan AccessTime,
|
||||
[property: DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
string Accessor)
|
||||
{
|
||||
public AccessRecord() : this(TimeSpan.Zero, string.Empty)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class AccessReaderComponentState : ComponentState
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.DeviceLinking.Events;
|
||||
using Content.Shared.Emag.Components;
|
||||
@@ -8,8 +10,6 @@ using Content.Shared.PDA;
|
||||
using Content.Shared.StationRecords;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Shared.GameTicking;
|
||||
using Robust.Shared.Collections;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -26,7 +26,7 @@ public sealed class AccessReaderSystem : EntitySystem
|
||||
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
||||
[Dependency] private readonly SharedIdCardSystem _idCardSystem = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
||||
[Dependency] private readonly SharedStationRecordsSystem _records = default!;
|
||||
[Dependency] private readonly SharedStationRecordsSystem _recordsSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -42,7 +42,7 @@ public sealed class AccessReaderSystem : EntitySystem
|
||||
private void OnGetState(EntityUid uid, AccessReaderComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new AccessReaderComponentState(component.Enabled, component.DenyTags, component.AccessLists,
|
||||
_records.Convert(component.AccessKeys), component.AccessLog, component.AccessLogLimit);
|
||||
_recordsSystem.Convert(component.AccessKeys), component.AccessLog, component.AccessLogLimit);
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, AccessReaderComponent component, ref ComponentHandleState args)
|
||||
@@ -348,6 +348,9 @@ public sealed class AccessReaderSystem : EntitySystem
|
||||
/// <param name="accessor">The accessor to log</param>
|
||||
private void LogAccess(Entity<AccessReaderComponent> ent, EntityUid accessor)
|
||||
{
|
||||
if (IsPaused(ent))
|
||||
return;
|
||||
|
||||
if (ent.Comp.AccessLog.Count >= ent.Comp.AccessLogLimit)
|
||||
ent.Comp.AccessLog.Dequeue();
|
||||
|
||||
|
||||
@@ -76,3 +76,5 @@ command-description-mind-get =
|
||||
Grabs the mind from the entity, if any.
|
||||
command-description-mind-control =
|
||||
Assumes control of an entity with the given player.
|
||||
command-description-addaccesslog =
|
||||
Adds an access log to this entity. Do note that this bypasses the log's default limit and pause check.
|
||||
|
||||
Reference in New Issue
Block a user