AddAccessLogCommand.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. using Content.Server.Administration;
  2. using Content.Shared.Access.Components;
  3. using Content.Shared.Administration;
  4. using Robust.Shared.Toolshed;
  5. using Robust.Shared.Toolshed.Syntax;
  6. namespace Content.Server.Access;
  7. [ToolshedCommand, AdminCommand(AdminFlags.Mapping)]
  8. public sealed class AddAccessLogCommand : ToolshedCommand
  9. {
  10. [CommandImplementation]
  11. public void AddAccessLog(IInvocationContext ctx, EntityUid input, float seconds, string accessor)
  12. {
  13. var accessReader = EnsureComp<AccessReaderComponent>(input);
  14. var accessLogCount = accessReader.AccessLog.Count;
  15. if (accessLogCount >= accessReader.AccessLogLimit)
  16. ctx.WriteLine($"WARNING: Surpassing the limit of the log by {accessLogCount - accessReader.AccessLogLimit+1} entries!");
  17. var accessTime = TimeSpan.FromSeconds(seconds);
  18. accessReader.AccessLog.Enqueue(new AccessRecord(accessTime, accessor));
  19. ctx.WriteLine($"Successfully added access log to {input} with this information inside:\n " +
  20. $"Time of access: {accessTime}\n " +
  21. $"Accessed by: {accessor}");
  22. }
  23. [CommandImplementation]
  24. public void AddAccessLogPiped(IInvocationContext ctx, [PipedArgument] EntityUid input, float seconds, string accessor)
  25. {
  26. AddAccessLog(ctx, input, seconds, accessor);
  27. }
  28. }