Files
tbd-station-14/Content.Server/Access/AddAccessLogCommand.cs
AJCM-git a4dd4828cf 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
2023-12-28 19:32:46 -05:00

43 lines
1.6 KiB
C#

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