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:
AJCM-git
2023-12-28 20:32:46 -04:00
committed by GitHub
parent 6699059da1
commit a4dd4828cf
4 changed files with 62 additions and 6 deletions

View 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);
}
}