2021-02-02 11:21:16 +00:00
|
|
|
using Content.Server.Players;
|
|
|
|
|
using Content.Shared.Administration;
|
2023-08-30 21:46:11 -07:00
|
|
|
using Content.Shared.Mind;
|
|
|
|
|
using Content.Shared.Mind.Components;
|
2023-10-28 09:59:53 +11:00
|
|
|
using Content.Shared.Players;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.Player;
|
2021-02-02 13:41:21 +01:00
|
|
|
using Robust.Shared.Console;
|
2021-02-02 11:21:16 +00:00
|
|
|
|
|
|
|
|
namespace Content.Server.Administration.Commands
|
|
|
|
|
{
|
|
|
|
|
[AdminCommand(AdminFlags.Admin)]
|
2022-02-16 00:23:23 -07:00
|
|
|
sealed class SetMindCommand : IConsoleCommand
|
2021-02-02 11:21:16 +00:00
|
|
|
{
|
2024-01-03 19:04:31 -05:00
|
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
2023-08-07 19:18:39 +12:00
|
|
|
|
2021-02-02 11:21:16 +00:00
|
|
|
public string Command => "setmind";
|
|
|
|
|
|
2023-06-18 11:33:19 -07:00
|
|
|
public string Description => Loc.GetString("set-mind-command-description", ("requiredComponent", nameof(MindContainerComponent)));
|
2021-02-02 11:21:16 +00:00
|
|
|
|
2021-06-21 02:13:54 +02:00
|
|
|
public string Help => Loc.GetString("set-mind-command-help-text", ("command", Command));
|
2021-02-02 11:21:16 +00:00
|
|
|
|
2021-02-02 13:41:21 +01:00
|
|
|
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
2021-02-02 11:21:16 +00:00
|
|
|
{
|
2023-08-07 19:18:39 +12:00
|
|
|
if (args.Length < 2)
|
2021-02-02 11:21:16 +00:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
shell.WriteLine(Loc.GetString("shell-wrong-arguments-number"));
|
2021-02-02 11:21:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 19:04:31 -05:00
|
|
|
if (!int.TryParse(args[0], out var entInt))
|
2021-02-02 11:21:16 +00:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
shell.WriteLine(Loc.GetString("shell-entity-uid-must-be-number"));
|
2021-02-02 11:21:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-07 19:18:39 +12:00
|
|
|
bool ghostOverride = true;
|
|
|
|
|
if (args.Length > 2)
|
|
|
|
|
{
|
|
|
|
|
ghostOverride = bool.Parse(args[2]);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 19:04:31 -05:00
|
|
|
var nent = new NetEntity(entInt);
|
2021-02-02 11:21:16 +00:00
|
|
|
|
2024-01-03 19:04:31 -05:00
|
|
|
if (!_entManager.TryGetEntity(nent, out var eUid))
|
2021-02-02 11:21:16 +00:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
shell.WriteLine(Loc.GetString("shell-invalid-entity-id"));
|
2021-02-02 11:21:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 19:04:31 -05:00
|
|
|
if (!_entManager.HasComponent<MindContainerComponent>(eUid))
|
2021-02-02 11:21:16 +00:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
shell.WriteLine(Loc.GetString("set-mind-command-target-has-no-mind-message"));
|
2021-02-02 11:21:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!IoCManager.Resolve<IPlayerManager>().TryGetSessionByUsername(args[1], out var session))
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
shell.WriteLine(Loc.GetString("shell-target-player-does-not-exist"));
|
2021-02-02 11:21:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// hm, does player have a mind? if not we may need to give them one
|
|
|
|
|
var playerCData = session.ContentData();
|
|
|
|
|
if (playerCData == null)
|
|
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
shell.WriteLine(Loc.GetString("set-mind-command-target-has-no-content-data-message"));
|
2021-02-02 11:21:16 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 19:04:31 -05:00
|
|
|
var mindSystem = _entManager.System<SharedMindSystem>();
|
|
|
|
|
var metadata = _entManager.GetComponent<MetaDataComponent>(eUid.Value);
|
2023-08-07 19:18:39 +12:00
|
|
|
|
2023-08-28 16:53:24 -07:00
|
|
|
var mind = playerCData.Mind ?? mindSystem.CreateMind(session.UserId, metadata.EntityName);
|
2023-06-18 11:33:19 -07:00
|
|
|
|
2023-08-07 19:18:39 +12:00
|
|
|
mindSystem.TransferTo(mind, eUid, ghostOverride);
|
2021-02-02 11:21:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|