From a4dd4828cf585a5534c7ecc86aeb43484c924d00 Mon Sep 17 00:00:00 2001 From: AJCM-git <60196617+AJCM-git@users.noreply.github.com> Date: Thu, 28 Dec 2023 20:32:46 -0400 Subject: [PATCH] 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 --- Content.Server/Access/AddAccessLogCommand.cs | 42 +++++++++++++++++++ .../Components/AccessReaderComponent.cs | 13 +++++- .../Access/Systems/AccessReaderSystem.cs | 11 +++-- .../en-US/commands/toolshed-commands.ftl | 2 + 4 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 Content.Server/Access/AddAccessLogCommand.cs diff --git a/Content.Server/Access/AddAccessLogCommand.cs b/Content.Server/Access/AddAccessLogCommand.cs new file mode 100644 index 0000000000..8b3aebb16b --- /dev/null +++ b/Content.Server/Access/AddAccessLogCommand.cs @@ -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 accessor) + { + var accessReader = EnsureComp(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 accessor) + { + AddAccessLog(ctx, input, seconds, accessor); + } +} diff --git a/Content.Shared/Access/Components/AccessReaderComponent.cs b/Content.Shared/Access/Components/AccessReaderComponent.cs index 815e6b4c65..5dd45b21c3 100644 --- a/Content.Shared/Access/Components/AccessReaderComponent.cs +++ b/Content.Shared/Access/Components/AccessReaderComponent.cs @@ -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 diff --git a/Content.Shared/Access/Systems/AccessReaderSystem.cs b/Content.Shared/Access/Systems/AccessReaderSystem.cs index 2735b7166b..c5bceb4899 100644 --- a/Content.Shared/Access/Systems/AccessReaderSystem.cs +++ b/Content.Shared/Access/Systems/AccessReaderSystem.cs @@ -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 /// The accessor to log private void LogAccess(Entity ent, EntityUid accessor) { + if (IsPaused(ent)) + return; + if (ent.Comp.AccessLog.Count >= ent.Comp.AccessLogLimit) ent.Comp.AccessLog.Dequeue(); diff --git a/Resources/Locale/en-US/commands/toolshed-commands.ftl b/Resources/Locale/en-US/commands/toolshed-commands.ftl index 29c8190d6e..3747712aa2 100644 --- a/Resources/Locale/en-US/commands/toolshed-commands.ftl +++ b/Resources/Locale/en-US/commands/toolshed-commands.ftl @@ -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. -- 2.51.2