Files
crystall-punk-14/Content.Server/GameTicking/Commands/ObserveCommand.cs

53 lines
1.6 KiB
C#
Raw Permalink Normal View History

using Content.Server.Administration.Managers;
using Content.Shared.Administration;
2022-08-14 12:54:49 -07:00
using Content.Shared.GameTicking;
using Robust.Shared.Console;
2021-06-09 22:19:39 +02:00
namespace Content.Server.GameTicking.Commands
{
[AnyCommand]
sealed class ObserveCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _e = default!;
[Dependency] private readonly IAdminManager _adminManager = default!;
public string Command => "observe";
public string Description => "";
public string Help => "";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (shell.Player is not { } player)
{
shell.WriteError(Loc.GetString("shell-cannot-run-command-from-server"));
return;
}
var ticker = _e.System<GameTicker>();
2021-12-21 21:23:29 +01:00
if (ticker.RunLevel == GameRunLevel.PreRoundLobby)
{
shell.WriteError("Wait until the round starts.");
return;
}
var isAdminCommand = args.Length > 0 && args[0].ToLower() == "admin";
if (!isAdminCommand && _adminManager.IsAdmin(player))
{
_adminManager.DeAdmin(player);
}
2022-08-14 12:54:49 -07:00
if (ticker.PlayerGameStatuses.TryGetValue(player.UserId, out var status) &&
status != PlayerGameStatus.JoinedGame)
{
2023-06-21 13:04:07 +12:00
ticker.JoinAsObserver(player);
2022-08-14 12:54:49 -07:00
}
else
2022-08-14 12:54:49 -07:00
{
shell.WriteError($"{player.Name} is not in the lobby. This incident will be reported.");
2022-08-14 12:54:49 -07:00
}
}
}
}