ShowRulesCommand.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Content.Server.Administration;
  2. using Content.Shared.Administration;
  3. using Content.Shared.CCVar;
  4. using Content.Shared.Info;
  5. using Robust.Server.Player;
  6. using Robust.Shared.Configuration;
  7. using Robust.Shared.Console;
  8. using Robust.Shared.Network;
  9. namespace Content.Server.Info;
  10. [AdminCommand(AdminFlags.Admin)]
  11. public sealed class ShowRulesCommand : IConsoleCommand
  12. {
  13. [Dependency] private readonly INetManager _net = default!;
  14. [Dependency] private readonly IConfigurationManager _configuration = default!;
  15. [Dependency] private readonly IPlayerManager _player = default!;
  16. public string Command => "showrules";
  17. public string Description => "Opens the rules popup for the specified player.";
  18. public string Help => "showrules <username> [seconds]";
  19. public async void Execute(IConsoleShell shell, string argStr, string[] args)
  20. {
  21. string target;
  22. float seconds;
  23. switch (args.Length)
  24. {
  25. case 1:
  26. {
  27. target = args[0];
  28. seconds = _configuration.GetCVar(CCVars.RulesWaitTime);
  29. break;
  30. }
  31. case 2:
  32. {
  33. if (!float.TryParse(args[1], out seconds))
  34. {
  35. shell.WriteError($"{args[1]} is not a valid amount of seconds.\n{Help}");
  36. return;
  37. }
  38. target = args[0];
  39. break;
  40. }
  41. default:
  42. {
  43. shell.WriteLine(Help);
  44. return;
  45. }
  46. }
  47. if (!_player.TryGetSessionByUsername(target, out var player))
  48. {
  49. shell.WriteError("Unable to find a player with that name.");
  50. return;
  51. }
  52. var coreRules = _configuration.GetCVar(CCVars.RulesFile);
  53. var message = new SendRulesInformationMessage { PopupTime = seconds, CoreRules = coreRules, ShouldShowRules = true};
  54. _net.ServerSendMessage(message, player.Channel);
  55. }
  56. }