SuicideCommand.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Content.Server.GameTicking;
  2. using Content.Server.Popups;
  3. using Content.Shared.Administration;
  4. using Content.Shared.Chat;
  5. using Content.Shared.Mind;
  6. using Robust.Shared.Console;
  7. using Robust.Shared.Enums;
  8. namespace Content.Server.Chat.Commands
  9. {
  10. [AnyCommand]
  11. internal sealed class SuicideCommand : IConsoleCommand
  12. {
  13. [Dependency] private readonly IEntityManager _e = default!;
  14. public string Command => "suicide";
  15. public string Description => Loc.GetString("suicide-command-description");
  16. public string Help => Loc.GetString("suicide-command-help-text");
  17. public void Execute(IConsoleShell shell, string argStr, string[] args)
  18. {
  19. if (shell.Player is not { } player)
  20. {
  21. shell.WriteError(Loc.GetString("shell-cannot-run-command-from-server"));
  22. return;
  23. }
  24. if (player.Status != SessionStatus.InGame || player.AttachedEntity == null)
  25. return;
  26. var minds = _e.System<SharedMindSystem>();
  27. // This check also proves mind not-null for at the end when the mob is ghosted.
  28. if (!minds.TryGetMind(player, out var mindId, out var mindComp) ||
  29. mindComp.OwnedEntity is not { Valid: true } victim)
  30. {
  31. shell.WriteLine(Loc.GetString("suicide-command-no-mind"));
  32. return;
  33. }
  34. var suicideSystem = _e.System<SuicideSystem>();
  35. if (_e.HasComponent<AdminFrozenComponent>(victim))
  36. {
  37. var deniedMessage = Loc.GetString("suicide-command-denied");
  38. shell.WriteLine(deniedMessage);
  39. _e.System<PopupSystem>()
  40. .PopupEntity(deniedMessage, victim, victim);
  41. return;
  42. }
  43. if (suicideSystem.Suicide(victim))
  44. return;
  45. shell.WriteLine(Loc.GetString("ghost-command-denied"));
  46. }
  47. }
  48. }