1
0

ObserveCommand.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Content.Server.Administration.Managers;
  2. using Content.Shared.Administration;
  3. using Content.Shared.GameTicking;
  4. using Robust.Shared.Console;
  5. namespace Content.Server.GameTicking.Commands
  6. {
  7. [AnyCommand]
  8. sealed class ObserveCommand : IConsoleCommand
  9. {
  10. [Dependency] private readonly IEntityManager _e = default!;
  11. [Dependency] private readonly IAdminManager _adminManager = default!;
  12. public string Command => "observe";
  13. public string Description => "";
  14. public string Help => "";
  15. public void Execute(IConsoleShell shell, string argStr, string[] args)
  16. {
  17. if (shell.Player is not { } player)
  18. {
  19. shell.WriteError(Loc.GetString("shell-cannot-run-command-from-server"));
  20. return;
  21. }
  22. var ticker = _e.System<GameTicker>();
  23. if (ticker.RunLevel == GameRunLevel.PreRoundLobby)
  24. {
  25. shell.WriteError("Wait until the round starts.");
  26. return;
  27. }
  28. var isAdminCommand = args.Length > 0 && args[0].ToLower() == "admin";
  29. if (!isAdminCommand && _adminManager.IsAdmin(player))
  30. {
  31. _adminManager.DeAdmin(player);
  32. }
  33. if (ticker.PlayerGameStatuses.TryGetValue(player.UserId, out var status) &&
  34. status != PlayerGameStatus.JoinedGame)
  35. {
  36. ticker.JoinAsObserver(player);
  37. }
  38. else
  39. {
  40. shell.WriteError($"{player.Name} is not in the lobby. This incident will be reported.");
  41. }
  42. }
  43. }
  44. }