]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Access logs tweaks and fixes (#23096)
authorAJCM-git <60196617+AJCM-git@users.noreply.github.com>
Fri, 29 Dec 2023 00:32:46 +0000 (20:32 -0400)
committerGitHub <noreply@github.com>
Fri, 29 Dec 2023 00:32:46 +0000 (19:32 -0500)
* 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 [new file with mode: 0644]
Content.Shared/Access/Components/AccessReaderComponent.cs
Content.Shared/Access/Systems/AccessReaderSystem.cs
Resources/Locale/en-US/commands/toolshed-commands.ftl

diff --git a/Content.Server/Access/AddAccessLogCommand.cs b/Content.Server/Access/AddAccessLogCommand.cs
new file mode 100644 (file)
index 0000000..8b3aebb
--- /dev/null
@@ -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);
+    }
+}
index 815e6b4c658af9e931d3ad95dad5f2544de75912..5dd45b21c313590569ba5c2b01e1ad8812d29a35 100644 (file)
@@ -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
index 2735b7166b24c377df0e90ff1b4ff2b102bd1c76..c5bceb4899f552f2fdbe70aed35ee52e3af5efc0 100644 (file)
@@ -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();
 
index 29c8190d6e258cbca65a98ebcb3f6ab701c837a5..3747712aa275d625e3fe895e081aa5e5c38c4150 100644 (file)
@@ -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.