2024-05-29 06:00:42 +12:00
|
|
|
using Content.Server.Administration.Managers;
|
2022-05-10 13:43:30 -05:00
|
|
|
using Content.Server.Station.Systems;
|
2021-12-13 16:45:49 +11:00
|
|
|
using Content.Shared.Administration;
|
2024-05-29 06:00:42 +12:00
|
|
|
using Content.Shared.CCVar;
|
2022-02-28 10:38:36 -06:00
|
|
|
using Content.Shared.GameTicking;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Content.Shared.Roles;
|
2024-05-29 06:00:42 +12:00
|
|
|
using Robust.Shared.Configuration;
|
2021-02-01 16:49:43 -08:00
|
|
|
using Robust.Shared.Console;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.GameTicking.Commands
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
|
|
|
|
[AnyCommand]
|
2022-02-16 00:23:23 -07:00
|
|
|
sealed class JoinGameCommand : IConsoleCommand
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2023-09-11 09:42:41 +10:00
|
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
2020-12-03 03:40:47 +01:00
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
2024-05-29 06:00:42 +12:00
|
|
|
[Dependency] private readonly IAdminManager _adminManager = default!;
|
|
|
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
2020-12-03 03:40:47 +01:00
|
|
|
|
|
|
|
|
public string Command => "joingame";
|
|
|
|
|
public string Description => "";
|
|
|
|
|
public string Help => "";
|
|
|
|
|
|
|
|
|
|
public JoinGameCommand()
|
|
|
|
|
{
|
|
|
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
|
}
|
2021-02-01 16:49:43 -08:00
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2021-11-26 03:02:46 -06:00
|
|
|
if (args.Length != 2)
|
|
|
|
|
{
|
|
|
|
|
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-28 09:59:53 +11:00
|
|
|
var player = shell.Player;
|
2021-11-26 03:02:46 -06:00
|
|
|
|
2020-12-03 03:40:47 +01:00
|
|
|
if (player == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
var ticker = _entManager.System<GameTicker>();
|
|
|
|
|
var stationJobs = _entManager.System<StationJobsSystem>();
|
2021-11-26 04:03:29 -06:00
|
|
|
|
2022-08-14 12:54:49 -07:00
|
|
|
if (ticker.PlayerGameStatuses.TryGetValue(player.UserId, out var status) && status == PlayerGameStatus.JoinedGame)
|
2021-11-26 04:03:29 -06:00
|
|
|
{
|
2022-02-28 10:46:47 -06:00
|
|
|
Logger.InfoS("security", $"{player.Name} ({player.UserId}) attempted to latejoin while in-game.");
|
2021-11-27 19:28:32 -06:00
|
|
|
shell.WriteError($"{player.Name} is not in the lobby. This incident will be reported.");
|
2021-11-26 04:03:29 -06:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-03 03:40:47 +01:00
|
|
|
if (ticker.RunLevel == GameRunLevel.PreRoundLobby)
|
|
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine("Round has not started.");
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2021-11-26 03:02:46 -06:00
|
|
|
else if (ticker.RunLevel == GameRunLevel.InRound)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2021-11-26 03:02:46 -06:00
|
|
|
string id = args[0];
|
|
|
|
|
|
2022-05-10 13:43:30 -05:00
|
|
|
if (!int.TryParse(args[1], out var sid))
|
2021-11-26 03:02:46 -06:00
|
|
|
{
|
|
|
|
|
shell.WriteError(Loc.GetString("shell-argument-must-be-number"));
|
|
|
|
|
}
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2023-09-11 09:42:41 +10:00
|
|
|
var station = _entManager.GetEntity(new NetEntity(sid));
|
2021-11-27 00:43:43 -06:00
|
|
|
var jobPrototype = _prototypeManager.Index<JobPrototype>(id);
|
2022-05-10 13:43:30 -05:00
|
|
|
if(stationJobs.TryGetJobSlot(station, jobPrototype, out var slots) == false || slots == 0)
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2022-06-28 15:55:05 +03:00
|
|
|
shell.WriteLine($"{jobPrototype.LocalizedName} has no available slots.");
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2024-05-29 06:00:42 +12:00
|
|
|
|
|
|
|
|
if (_adminManager.IsAdmin(player) && _cfg.GetCVar(CCVars.AdminDeadminOnJoin))
|
|
|
|
|
{
|
|
|
|
|
_adminManager.DeAdmin(player);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 13:43:30 -05:00
|
|
|
ticker.MakeJoinGame(player, station, id);
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 13:43:30 -05:00
|
|
|
ticker.MakeJoinGame(player, EntityUid.Invalid);
|
2020-12-03 03:40:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-02-01 16:49:43 -08:00
|
|
|
}
|