Files
tbd-station-14/Content.Server/Roles/AddRoleCommand.cs
Kara db1dfc8958 Command perm modifications (#11273)
* Command perm modifications

* actually not this one

* string
2022-09-14 19:02:38 -05:00

61 lines
1.8 KiB
C#

using Content.Server.Administration;
using Content.Server.Players;
using Content.Shared.Administration;
using Content.Shared.Roles;
using Robust.Server.Player;
using Robust.Shared.Console;
using Robust.Shared.Prototypes;
using System.Linq;
namespace Content.Server.Roles
{
[AdminCommand(AdminFlags.Admin)]
public sealed class AddRoleCommand : IConsoleCommand
{
public string Command => "addrole";
public string Description => "Adds a role to a player's mind.";
public string Help => "addrole <session ID> <role>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteLine("Expected exactly 2 arguments.");
return;
}
var mgr = IoCManager.Resolve<IPlayerManager>();
if (!mgr.TryGetPlayerDataByUsername(args[0], out var data))
{
shell.WriteLine("Can't find that mind");
return;
}
var mind = data.ContentData()?.Mind;
if (mind == null)
{
shell.WriteLine("Can't find that mind");
return;
}
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
if (!prototypeManager.TryIndex<JobPrototype>(args[1], out var jobPrototype))
{
shell.WriteLine("Can't find that role");
return;
}
if (mind.AllRoles.Any(r => r.Name == jobPrototype.Name))
{
shell.WriteLine("Mind already has that role");
return;
}
var role = new Job(mind, jobPrototype!);
mind.AddRole(role);
}
}
}