2024-03-31 04:05:44 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Content.Server.GameTicking;
|
|
|
|
|
|
using Content.Server.Ghost;
|
|
|
|
|
|
using Content.Server.Mind;
|
2020-10-30 16:06:48 +01:00
|
|
|
|
using Content.Shared.Administration;
|
2021-08-06 00:02:36 -07:00
|
|
|
|
using Content.Shared.Ghost;
|
2023-08-30 21:46:11 -07:00
|
|
|
|
using Content.Shared.Mind;
|
2024-03-31 04:05:44 +02:00
|
|
|
|
using Robust.Server.GameObjects;
|
|
|
|
|
|
using Robust.Server.Player;
|
2021-02-01 16:49:43 -08:00
|
|
|
|
using Robust.Shared.Console;
|
2018-09-20 18:19:04 +02:00
|
|
|
|
|
2024-03-31 04:05:44 +02:00
|
|
|
|
namespace Content.Server.Administration.Commands;
|
|
|
|
|
|
|
|
|
|
|
|
[AdminCommand(AdminFlags.Admin)]
|
2024-07-14 12:25:18 +02:00
|
|
|
|
public sealed class AGhostCommand : LocalizedCommands
|
2018-09-20 18:19:04 +02:00
|
|
|
|
{
|
2024-03-31 04:05:44 +02:00
|
|
|
|
[Dependency] private readonly IEntityManager _entities = default!;
|
|
|
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
|
|
|
|
|
|
|
|
public override string Command => "aghost";
|
|
|
|
|
|
public override string Help => "aghost";
|
|
|
|
|
|
|
|
|
|
|
|
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
2018-09-20 18:19:04 +02:00
|
|
|
|
{
|
2024-03-31 04:05:44 +02:00
|
|
|
|
if (args.Length == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
var names = _playerManager.Sessions.OrderBy(c => c.Name).Select(c => c.Name).ToArray();
|
|
|
|
|
|
return CompletionResult.FromHintOptions(names, LocalizationManager.GetString("shell-argument-username-optional-hint"));
|
|
|
|
|
|
}
|
2021-12-05 18:09:01 +01:00
|
|
|
|
|
2024-03-31 04:05:44 +02:00
|
|
|
|
return CompletionResult.Empty;
|
|
|
|
|
|
}
|
2018-09-20 18:19:04 +02:00
|
|
|
|
|
2024-03-31 04:05:44 +02:00
|
|
|
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (args.Length > 1)
|
2018-09-20 18:19:04 +02:00
|
|
|
|
{
|
2024-03-31 04:05:44 +02:00
|
|
|
|
shell.WriteError(LocalizationManager.GetString("shell-wrong-arguments-number"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var player = shell.Player;
|
|
|
|
|
|
var self = player != null;
|
|
|
|
|
|
if (player == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If you are not a player, you require a player argument.
|
|
|
|
|
|
if (args.Length == 0)
|
2018-09-20 18:19:04 +02:00
|
|
|
|
{
|
2024-03-31 04:05:44 +02:00
|
|
|
|
shell.WriteError(LocalizationManager.GetString("shell-need-exactly-one-argument"));
|
2018-09-20 18:19:04 +02:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-31 04:05:44 +02:00
|
|
|
|
var didFind = _playerManager.TryGetSessionByUsername(args[0], out player);
|
|
|
|
|
|
if (!didFind)
|
2020-08-25 05:37:54 -06:00
|
|
|
|
{
|
2024-03-31 04:05:44 +02:00
|
|
|
|
shell.WriteError(LocalizationManager.GetString("shell-target-player-does-not-exist"));
|
2020-08-25 05:37:54 -06:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-03-31 04:05:44 +02:00
|
|
|
|
}
|
2023-08-28 11:20:31 +02:00
|
|
|
|
|
2024-03-31 04:05:44 +02:00
|
|
|
|
// If you are a player and a username is provided, a lookup is done to find the target player.
|
|
|
|
|
|
if (args.Length == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
var didFind = _playerManager.TryGetSessionByUsername(args[0], out player);
|
|
|
|
|
|
if (!didFind)
|
2018-09-20 18:19:04 +02:00
|
|
|
|
{
|
2024-03-31 04:05:44 +02:00
|
|
|
|
shell.WriteError(LocalizationManager.GetString("shell-target-player-does-not-exist"));
|
|
|
|
|
|
return;
|
2018-09-20 18:19:04 +02:00
|
|
|
|
}
|
2024-03-31 04:05:44 +02:00
|
|
|
|
}
|
2021-01-02 22:11:39 +01:00
|
|
|
|
|
2024-03-31 04:05:44 +02:00
|
|
|
|
var mindSystem = _entities.System<SharedMindSystem>();
|
|
|
|
|
|
var metaDataSystem = _entities.System<MetaDataSystem>();
|
|
|
|
|
|
var ghostSystem = _entities.System<SharedGhostSystem>();
|
|
|
|
|
|
var transformSystem = _entities.System<TransformSystem>();
|
|
|
|
|
|
var gameTicker = _entities.System<GameTicker>();
|
2021-01-02 22:11:39 +01:00
|
|
|
|
|
2024-03-31 04:05:44 +02:00
|
|
|
|
if (!mindSystem.TryGetMind(player, out var mindId, out var mind))
|
|
|
|
|
|
{
|
|
|
|
|
|
shell.WriteError(self
|
|
|
|
|
|
? LocalizationManager.GetString("aghost-no-mind-self")
|
|
|
|
|
|
: LocalizationManager.GetString("aghost-no-mind-other"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2021-10-06 11:56:16 +02:00
|
|
|
|
|
2024-03-31 04:05:44 +02:00
|
|
|
|
if (mind.VisitingEntity != default && _entities.TryGetComponent<GhostComponent>(mind.VisitingEntity, out var oldGhostComponent))
|
|
|
|
|
|
{
|
|
|
|
|
|
mindSystem.UnVisit(mindId, mind);
|
|
|
|
|
|
// If already an admin ghost, then return to body.
|
|
|
|
|
|
if (oldGhostComponent.CanGhostInteract)
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var canReturn = mind.CurrentEntity != null
|
|
|
|
|
|
&& !_entities.HasComponent<GhostComponent>(mind.CurrentEntity);
|
|
|
|
|
|
var coordinates = player!.AttachedEntity != null
|
|
|
|
|
|
? _entities.GetComponent<TransformComponent>(player.AttachedEntity.Value).Coordinates
|
|
|
|
|
|
: gameTicker.GetObserverSpawnPoint();
|
|
|
|
|
|
var ghost = _entities.SpawnEntity(GameTicker.AdminObserverPrototypeName, coordinates);
|
|
|
|
|
|
transformSystem.AttachToGridOrMap(ghost, _entities.GetComponent<TransformComponent>(ghost));
|
|
|
|
|
|
|
|
|
|
|
|
if (canReturn)
|
|
|
|
|
|
{
|
|
|
|
|
|
// TODO: Remove duplication between all this and "GamePreset.OnGhostAttempt()"...
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(mind.CharacterName))
|
|
|
|
|
|
metaDataSystem.SetEntityName(ghost, mind.CharacterName);
|
|
|
|
|
|
else if (!string.IsNullOrWhiteSpace(mind.Session?.Name))
|
|
|
|
|
|
metaDataSystem.SetEntityName(ghost, mind.Session.Name);
|
2021-02-25 06:14:16 +05:00
|
|
|
|
|
2024-03-31 04:05:44 +02:00
|
|
|
|
mindSystem.Visit(mindId, ghost, mind);
|
2018-09-20 18:19:04 +02:00
|
|
|
|
}
|
2024-03-31 04:05:44 +02:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
metaDataSystem.SetEntityName(ghost, player.Name);
|
|
|
|
|
|
mindSystem.TransferTo(mindId, ghost, mind: mind);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var comp = _entities.GetComponent<GhostComponent>(ghost);
|
|
|
|
|
|
ghostSystem.SetCanReturnToBody(comp, canReturn);
|
2018-09-20 18:19:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|