JoinGameCommand.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using Content.Server.Administration.Managers;
  2. using Content.Server.Station.Systems;
  3. using Content.Shared.Administration;
  4. using Content.Shared.CCVar;
  5. using Content.Shared.GameTicking;
  6. using Content.Shared.Roles;
  7. using Robust.Shared.Configuration;
  8. using Robust.Shared.Console;
  9. using Robust.Shared.Prototypes;
  10. namespace Content.Server.GameTicking.Commands
  11. {
  12. [AnyCommand]
  13. sealed class JoinGameCommand : IConsoleCommand
  14. {
  15. [Dependency] private readonly IEntityManager _entManager = default!;
  16. [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
  17. [Dependency] private readonly IAdminManager _adminManager = default!;
  18. [Dependency] private readonly IConfigurationManager _cfg = default!;
  19. public string Command => "joingame";
  20. public string Description => "";
  21. public string Help => "";
  22. public JoinGameCommand()
  23. {
  24. IoCManager.InjectDependencies(this);
  25. }
  26. public void Execute(IConsoleShell shell, string argStr, string[] args)
  27. {
  28. if (args.Length != 2)
  29. {
  30. shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
  31. return;
  32. }
  33. var player = shell.Player;
  34. if (player == null)
  35. {
  36. return;
  37. }
  38. var ticker = _entManager.System<GameTicker>();
  39. var stationJobs = _entManager.System<StationJobsSystem>();
  40. if (ticker.PlayerGameStatuses.TryGetValue(player.UserId, out var status) && status == PlayerGameStatus.JoinedGame)
  41. {
  42. Logger.InfoS("security", $"{player.Name} ({player.UserId}) attempted to latejoin while in-game.");
  43. shell.WriteError($"{player.Name} is not in the lobby. This incident will be reported.");
  44. return;
  45. }
  46. if (ticker.RunLevel == GameRunLevel.PreRoundLobby)
  47. {
  48. shell.WriteLine("Round has not started.");
  49. return;
  50. }
  51. else if (ticker.RunLevel == GameRunLevel.InRound)
  52. {
  53. string id = args[0];
  54. if (!int.TryParse(args[1], out var sid))
  55. {
  56. shell.WriteError(Loc.GetString("shell-argument-must-be-number"));
  57. }
  58. var station = _entManager.GetEntity(new NetEntity(sid));
  59. var jobPrototype = _prototypeManager.Index<JobPrototype>(id);
  60. if (stationJobs.TryGetJobSlot(station, jobPrototype, out var slots) == false || slots == 0)
  61. {
  62. shell.WriteLine($"{jobPrototype.LocalizedName} has no available slots.");
  63. return;
  64. }
  65. if (_adminManager.IsAdmin(player) && _cfg.GetCVar(CCVars.AdminDeadminOnJoin))
  66. {
  67. _adminManager.DeAdmin(player);
  68. }
  69. ticker.MakeJoinGame(player, station, id);
  70. return;
  71. }
  72. ticker.MakeJoinGame(player, EntityUid.Invalid);
  73. }
  74. }
  75. }