AdminLogBulk.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Threading.Tasks;
  2. using Content.Server.Administration.Logs;
  3. using Content.Shared.Administration;
  4. using Content.Shared.Database;
  5. using Robust.Shared.Console;
  6. using Robust.Shared.Timing;
  7. namespace Content.Server.Administration.Commands;
  8. #if DEBUG
  9. [AdminCommand(AdminFlags.Host)]
  10. public sealed class AdminLogBulk : IConsoleCommand
  11. {
  12. public string Command => "adminlogbulk";
  13. public string Description => "Adds debug logs to the database.";
  14. public string Help => $"Usage: {Command} <amount> <parallel>";
  15. public void Execute(IConsoleShell shell, string argStr, string[] args)
  16. {
  17. if (shell.Player?.AttachedEntity is not { } entity)
  18. {
  19. shell.WriteError("This command can only be ran by a player with an attached entity.");
  20. return;
  21. }
  22. int amount;
  23. var parallel = false;
  24. switch (args)
  25. {
  26. case {Length: 1} when int.TryParse(args[0], out amount):
  27. case {Length: 2} when int.TryParse(args[0], out amount) &&
  28. bool.TryParse(args[1], out parallel):
  29. break;
  30. default:
  31. shell.WriteError(Help);
  32. return;
  33. }
  34. var logManager = IoCManager.Resolve<IAdminLogManager>();
  35. var stopwatch = new Stopwatch();
  36. stopwatch.Start();
  37. if (parallel)
  38. {
  39. Parallel.For(0, amount, _ =>
  40. {
  41. logManager.Add(LogType.Unknown, $"Debug log added by {entity:Player}");
  42. });
  43. }
  44. else
  45. {
  46. for (var i = 0; i < amount; i++)
  47. {
  48. logManager.Add(LogType.Unknown, $"Debug log added by {entity:Player}");
  49. }
  50. }
  51. shell.WriteLine($"Added {amount} logs in {stopwatch.Elapsed.TotalMilliseconds} ms");
  52. }
  53. }
  54. #endif