Command "setmind", so admins can forcibly relocate other players. (#3067)
Y'all just know an admin is going to abuse this like Make Sentient/Control Mob, but oh well
This commit is contained in:
82
Content.Server/Administration/Commands/SetMindCommand.cs
Normal file
82
Content.Server/Administration/Commands/SetMindCommand.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Server.Players;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Interfaces.Console;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Server.Administration.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Admin)]
|
||||
class SetMindCommand : IClientCommand
|
||||
{
|
||||
public string Command => "setmind";
|
||||
|
||||
public string Description => Loc.GetString("Transfers a mind to the specified entity. The entity must have a MindComponent.");
|
||||
|
||||
public string Help => Loc.GetString("Usage: {0} <entityUid> <username>", Command);
|
||||
|
||||
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
|
||||
{
|
||||
if (args.Length != 2)
|
||||
{
|
||||
shell.SendText(player, Loc.GetString("Wrong number of arguments."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!int.TryParse(args[0], out var entityUid))
|
||||
{
|
||||
shell.SendText(player, Loc.GetString("EntityUid must be a number."));
|
||||
return;
|
||||
}
|
||||
|
||||
var entityManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
var eUid = new EntityUid(entityUid);
|
||||
|
||||
if (!eUid.IsValid() || !entityManager.EntityExists(eUid))
|
||||
{
|
||||
shell.SendText(player, Loc.GetString("Invalid entity ID."));
|
||||
return;
|
||||
}
|
||||
|
||||
var target = entityManager.GetEntity(eUid);
|
||||
|
||||
if (!target.TryGetComponent<MindComponent>(out var mindComponent))
|
||||
{
|
||||
shell.SendText(player, Loc.GetString("Target entity does not have a mind (did you forget to make sentient?)"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IoCManager.Resolve<IPlayerManager>().TryGetSessionByUsername(args[1], out var session))
|
||||
{
|
||||
shell.SendText(player, Loc.GetString("Target player does not exist"));
|
||||
return;
|
||||
}
|
||||
|
||||
// hm, does player have a mind? if not we may need to give them one
|
||||
var playerCData = session.ContentData();
|
||||
if (playerCData == null)
|
||||
{
|
||||
shell.SendText(player, Loc.GetString("Target player does not have content data (wtf?)"));
|
||||
return;
|
||||
}
|
||||
|
||||
var mind = playerCData.Mind;
|
||||
if (mind == null)
|
||||
{
|
||||
mind = new Mind(session.UserId)
|
||||
{
|
||||
CharacterName = target.Name
|
||||
};
|
||||
playerCData.Mind = mind;
|
||||
}
|
||||
mind.TransferTo(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user