1
0

GhostCommand.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Content.Server.Popups;
  2. using Content.Shared.Administration;
  3. using Content.Shared.GameTicking;
  4. using Content.Shared.Mind;
  5. using Robust.Shared.Console;
  6. using Content.Server.GameTicking;
  7. namespace Content.Server.Ghost
  8. {
  9. [AnyCommand]
  10. public sealed class GhostCommand : IConsoleCommand
  11. {
  12. [Dependency] private readonly IEntityManager _entities = default!;
  13. public string Command => "ghost";
  14. public string Description => Loc.GetString("ghost-command-description");
  15. public string Help => Loc.GetString("ghost-command-help-text");
  16. public void Execute(IConsoleShell shell, string argStr, string[] args)
  17. {
  18. var player = shell.Player;
  19. if (player == null)
  20. {
  21. shell.WriteLine(Loc.GetString("ghost-command-no-session"));
  22. return;
  23. }
  24. var gameTicker = _entities.System<GameTicker>();
  25. if (!gameTicker.PlayerGameStatuses.TryGetValue(player.UserId, out var playerStatus) ||
  26. playerStatus is not PlayerGameStatus.JoinedGame)
  27. {
  28. shell.WriteLine(Loc.GetString("ghost-command-error-lobby"));
  29. return;
  30. }
  31. if (player.AttachedEntity is { Valid: true } frozen &&
  32. _entities.HasComponent<AdminFrozenComponent>(frozen))
  33. {
  34. var deniedMessage = Loc.GetString("ghost-command-denied");
  35. shell.WriteLine(deniedMessage);
  36. _entities.System<PopupSystem>()
  37. .PopupEntity(deniedMessage, frozen, frozen);
  38. return;
  39. }
  40. var minds = _entities.System<SharedMindSystem>();
  41. if (!minds.TryGetMind(player, out var mindId, out var mind))
  42. {
  43. mindId = minds.CreateMind(player.UserId);
  44. mind = _entities.GetComponent<MindComponent>(mindId);
  45. }
  46. if (!_entities.System<GhostSystem>().OnGhostAttempt(mindId, true, true, mind: mind))
  47. {
  48. shell.WriteLine(Loc.GetString("ghost-command-denied"));
  49. }
  50. }
  51. }
  52. }