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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user