2021-11-26 03:02:46 -06:00
|
|
|
using Content.Server.Station;
|
2021-12-13 16:45:49 +11:00
|
|
|
using Content.Shared.Administration;
|
2022-02-28 10:38:36 -06:00
|
|
|
using Content.Shared.GameTicking;
|
2020-12-03 03:40:47 +01:00
|
|
|
using Content.Shared.Roles;
|
2021-11-26 03:02:46 -06:00
|
|
|
using Content.Shared.Station;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.Player;
|
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
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-01 16:49:43 -08:00
|
|
|
var player = shell.Player as IPlayerSession;
|
2021-11-26 03:02:46 -06:00
|
|
|
|
2020-12-03 03:40:47 +01:00
|
|
|
if (player == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-20 10:09:24 +02:00
|
|
|
var ticker = EntitySystem.Get<GameTicker>();
|
2021-11-26 03:02:46 -06:00
|
|
|
var stationSystem = EntitySystem.Get<StationSystem>();
|
2021-11-26 04:03:29 -06:00
|
|
|
|
2022-02-28 10:38:36 -06:00
|
|
|
if (!ticker.PlayersInLobby.ContainsKey(player) || ticker.PlayersInLobby[player] == LobbyPlayerStatus.Observer)
|
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];
|
|
|
|
|
|
|
|
|
|
if (!uint.TryParse(args[1], out var sid))
|
|
|
|
|
{
|
|
|
|
|
shell.WriteError(Loc.GetString("shell-argument-must-be-number"));
|
|
|
|
|
}
|
2020-12-03 03:40:47 +01:00
|
|
|
|
2021-11-26 03:02:46 -06:00
|
|
|
var stationId = new StationId(sid);
|
2021-11-27 00:43:43 -06:00
|
|
|
var jobPrototype = _prototypeManager.Index<JobPrototype>(id);
|
|
|
|
|
if(!stationSystem.IsJobAvailableOnStation(stationId, jobPrototype))
|
2020-12-03 03:40:47 +01:00
|
|
|
{
|
2021-02-01 16:49:43 -08:00
|
|
|
shell.WriteLine($"{jobPrototype.Name} has no available slots.");
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2021-11-26 03:02:46 -06:00
|
|
|
ticker.MakeJoinGame(player, stationId, id);
|
2020-12-03 03:40:47 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-26 03:02:46 -06:00
|
|
|
ticker.MakeJoinGame(player, StationId.Invalid);
|
2020-12-03 03:40:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-02-01 16:49:43 -08:00
|
|
|
}
|