* ogh

* i should save my work

* ogh

* hhcdfhjbghshbxdfhghshc
- lots of bugs in parsing still
- invocation is a stub

* expr parsing works

* awawa

* Saving work

* Improve APIs a bit all around, add shortcuts.

* awa

* awa

* AAAAAA

* save work

* Move shit to engine

* lord

* bql is kill

* forgot the fucking bike rack

* bql is kill for real

* pjb will kill me

* aughfhbdj

* adgddf

* gdsgvfvxshngfgh

* b

* hfsjhghj

* a

* tf you mean i have to document it

* follow C# standards

* Assorted cleanup and documentation pass, minor bugfix in ValueRefParser.

* Start porting old commands, remove that pesky prefix in favor of integrating with the shell.

* bw

* Fix valueref up a bit, improve autocomplete for it.

* awa

* fix tests

* git shut up

* Arithmetic commands.

* parse improvements

* Update engine.

---------

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
This commit is contained in:
Moony
2023-08-02 16:09:08 -05:00
committed by GitHub
parent ad61c21c01
commit e2b22a4cd8
48 changed files with 1204 additions and 793 deletions

View File

@@ -12,7 +12,6 @@ namespace Content.Server.Administration
/// </remarks>
/// <seealso cref="AnyCommandAttribute"/>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
[BaseTypeRequired(typeof(IConsoleCommand))]
[MeansImplicitUse]
public sealed class AdminCommandAttribute : Attribute
{

View File

@@ -1,47 +0,0 @@
using System.Linq;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Spawn)]
sealed class DeleteEntitiesWithComponent : IConsoleCommand
{
public string Command => "deleteewc";
public string Description => Loc.GetString("delete-entities-with-component-command-description");
public string Help => Loc.GetString("delete-entities-with-component-command-help-text");
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 1)
{
shell.WriteLine(Help);
return;
}
var factory = IoCManager.Resolve<IComponentFactory>();
var components = new List<Type>();
foreach (var arg in args)
{
components.Add(factory.GetRegistration(arg).Type);
}
var entityManager = IoCManager.Resolve<IEntityManager>();
var entitiesWithComponents = components.Select(c => entityManager.GetAllComponents(c).Select(x => x.Uid));
var entitiesWithAllComponents = entitiesWithComponents.Skip(1).Aggregate(new HashSet<EntityUid>(entitiesWithComponents.First()), (h, e) => { h.IntersectWith(e); return h; });
var count = 0;
foreach (var entity in entitiesWithAllComponents)
{
entityManager.DeleteEntity(entity);
count += 1;
}
shell.WriteLine(Loc.GetString("delete-entities-with-component-command-deleted-components",("count", count)));
}
}
}

View File

@@ -1,36 +0,0 @@
using System.Linq;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Spawn)]
public sealed class DeleteEntitiesWithId : IConsoleCommand
{
public string Command => "deleteewi";
public string Description => "Deletes entities with the specified prototype ID.";
public string Help => $"Usage: {Command} <prototypeID>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.WriteLine(Help);
return;
}
var id = args[0].ToLower();
var entityManager = IoCManager.Resolve<IEntityManager>();
var entities = entityManager.GetEntities().Where(e => entityManager.GetComponent<MetaDataComponent>(e).EntityPrototype?.ID.ToLower() == id);
var i = 0;
foreach (var entity in entities)
{
entityManager.DeleteEntity(entity);
i++;
}
shell.WriteLine($"Deleted all entities with id {id}. Occurrences: {i}");
}
}
}

View File

@@ -1,39 +0,0 @@
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Spawn)]
public sealed class DeleteEntityCommand : IConsoleCommand
{
public string Command => "deleteentity";
public string Description => "Deletes an entity with the given id.";
public string Help => $"Usage: {Command} <id>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.WriteLine($"Invalid amount of arguments.\n{Help}");
return;
}
if (!EntityUid.TryParse(args[0], out var id))
{
shell.WriteLine($"{args[0]} is not a valid entity id.");
return;
}
var entityManager = IoCManager.Resolve<IEntityManager>();
if (!entityManager.EntityExists(id))
{
shell.WriteLine($"No entity found with id {id}.");
return;
}
entityManager.DeleteEntity(id);
shell.WriteLine($"Deleted entity with id {id}.");
}
}
}

View File

@@ -1,68 +0,0 @@
using System.Linq;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Mapping)]
public sealed class FindEntitiesWithComponents : IConsoleCommand
{
public string Command => "findentitieswithcomponents";
public string Description => "Finds entities with all of the specified components.";
public string Help => $"{Command} <componentName1> <componentName2>...";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length == 0)
{
shell.WriteLine($"Invalid amount of arguments: {args.Length}.\n{Help}");
return;
}
var components = new List<Type>();
var componentFactory = IoCManager.Resolve<IComponentFactory>();
var invalidArgs = new List<string>();
foreach (var arg in args)
{
if (!componentFactory.TryGetRegistration(arg, out var registration))
{
invalidArgs.Add(arg);
continue;
}
components.Add(registration.Type);
}
if (invalidArgs.Count > 0)
{
shell.WriteLine($"No component found for component names: {string.Join(", ", invalidArgs)}");
return;
}
var entityManager = IoCManager.Resolve<IEntityManager>();
var entityIds = new HashSet<string>();
var entitiesWithComponents = components.Select(c => entityManager.GetAllComponents(c).Select(x => x.Uid)).ToArray();
var entitiesWithAllComponents = entitiesWithComponents.Skip(1).Aggregate(new HashSet<EntityUid>(entitiesWithComponents.First()), (h, e) => { h.IntersectWith(e); return h; });
foreach (var entity in entitiesWithAllComponents)
{
if (entityManager.GetComponent<MetaDataComponent>(entity).EntityPrototype is not { } prototypeId)
{
continue;
}
entityIds.Add(prototypeId.ID);
}
if (entityIds.Count == 0)
{
shell.WriteLine($"No entities found with components {string.Join(", ", args)}.");
return;
}
shell.WriteLine($"{entityIds.Count} entities found:\n{string.Join("\n", entityIds)}");
}
}
}

View File

@@ -1,48 +0,0 @@
using Content.Shared.Administration;
using Content.Shared.Rejuvenate;
using Robust.Server.Player;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Admin)]
public sealed class RejuvenateCommand : IConsoleCommand
{
public string Command => "rejuvenate";
public string Description => Loc.GetString("rejuvenate-command-description");
public string Help => Loc.GetString("rejuvenate-command-help-text");
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 1 && shell.Player is IPlayerSession player) //Try to heal the users mob if applicable
{
shell.WriteLine(Loc.GetString("rejuvenate-command-self-heal-message"));
if (player.AttachedEntity == null)
{
shell.WriteLine(Loc.GetString("rejuvenate-command-no-entity-attached-message"));
return;
}
PerformRejuvenate(player.AttachedEntity.Value);
}
var entityManager = IoCManager.Resolve<IEntityManager>();
foreach (var arg in args)
{
if (!EntityUid.TryParse(arg, out var entity) || !entityManager.EntityExists(entity))
{
shell.WriteLine(Loc.GetString("shell-could-not-find-entity",("entity", arg)));
continue;
}
PerformRejuvenate(entity);
}
}
public static void PerformRejuvenate(EntityUid target)
{
var entityManager = IoCManager.Resolve<IEntityManager>();
entityManager.EventBus.RaiseLocalEvent(target, new RejuvenateEvent());
}
}
}

View File

@@ -1,84 +0,0 @@
using Content.Server.Commands;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Administration;
using Content.Shared.Roles;
using Robust.Shared.Console;
using Robust.Shared.Prototypes;
namespace Content.Server.Administration.Commands.Station;
[AdminCommand(AdminFlags.Round)]
public sealed class AdjustStationJobCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IEntitySystemManager _entSysManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public string Command => "adjstationjob";
public string Description => "Adjust the job manifest on a station.";
public string Help => "adjstationjob <station id> <job id> <amount>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 3)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
var stationJobs = _entSysManager.GetEntitySystem<StationJobsSystem>();
if (!EntityUid.TryParse(args[0], out var station) || !_entityManager.HasComponent<StationDataComponent>(station))
{
shell.WriteError(Loc.GetString("shell-argument-station-id-invalid", ("index", 1)));
return;
}
if (!_prototypeManager.TryIndex<JobPrototype>(args[1], out var job))
{
shell.WriteError(Loc.GetString("shell-argument-must-be-prototype",
("index", 2), ("prototypeName", nameof(JobPrototype))));
return;
}
if (!int.TryParse(args[2], out var amount) || amount < -1)
{
shell.WriteError(Loc.GetString("shell-argument-number-must-be-between",
("index", 3), ("lower", -1), ("upper", int.MaxValue)));
return;
}
if (amount == -1)
{
stationJobs.MakeJobUnlimited(station, job);
return;
}
stationJobs.TrySetJobSlot(station, job, amount, true);
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var options = ContentCompletionHelper.StationIds(_entityManager);
return CompletionResult.FromHintOptions(options, "<station id>");
}
if (args.Length == 2)
{
var options = CompletionHelper.PrototypeIDs<JobPrototype>();
return CompletionResult.FromHintOptions(options, "<job id>");
}
if (args.Length == 3)
{
return CompletionResult.FromHint("<amount>");
}
return CompletionResult.Empty;
}
}

View File

@@ -1,55 +0,0 @@
using Content.Server.Commands;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands.Station;
[AdminCommand(AdminFlags.Admin)]
public sealed class ListStationJobsCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IEntitySystemManager _entSysManager = default!;
public string Command => "lsstationjobs";
public string Description => "Lists all jobs on the given station.";
public string Help => "lsstationjobs <station id>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
var stationSystem = _entSysManager.GetEntitySystem<StationSystem>();
var stationJobs = _entSysManager.GetEntitySystem<StationJobsSystem>();
if (!EntityUid.TryParse(args[0], out var station) || !_entityManager.HasComponent<StationJobsComponent>(station))
{
shell.WriteError(Loc.GetString("shell-argument-station-id-invalid", ("index", 1)));
return;
}
foreach (var (job, amount) in stationJobs.GetJobs(station))
{
var amountText = amount is null ? "Infinite" : amount.ToString();
shell.WriteLine($"{job}: {amountText}");
}
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var options = ContentCompletionHelper.StationIds(_entityManager);
return CompletionResult.FromHintOptions(options, "<station id>");
}
return CompletionResult.Empty;
}
}

View File

@@ -1,29 +0,0 @@
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands.Station;
[AdminCommand(AdminFlags.Admin)]
public sealed class ListStationsCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public string Command => "lsstations";
public string Description => "List all active stations";
public string Help => "lsstations";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var query = _entityManager.EntityQueryEnumerator<StationDataComponent>();
while (query.MoveNext(out var station, out _))
{
var name = _entityManager.GetComponent<MetaDataComponent>(station).EntityName;
shell.WriteLine($"{station, -10} | {name}");
}
}
}

View File

@@ -1,55 +0,0 @@
using Content.Server.Commands;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Administration;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands.Station;
[AdminCommand(AdminFlags.Admin)]
public sealed class RenameStationCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IEntitySystemManager _entSysManager = default!;
public string Command => "renamestation";
public string Description => "Renames the given station";
public string Help => "renamestation <station id> <name>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
var stationSystem = _entSysManager.GetEntitySystem<StationSystem>();
if (!EntityUid.TryParse(args[0], out var station) || !_entityManager.HasComponent<StationDataComponent>(station))
{
shell.WriteError(Loc.GetString("shell-argument-station-id-invalid", ("index", 1)));
return;
}
stationSystem.RenameStation(station, args[1]);
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
var options = ContentCompletionHelper.StationIds(_entityManager);
return CompletionResult.FromHintOptions(options, "<station id>");
}
if (args.Length == 2)
{
return CompletionResult.FromHint("<name>");
}
return CompletionResult.Empty;
}
}

View File

@@ -1,113 +0,0 @@
using Content.Shared.Administration;
using Content.Shared.Tag;
using Robust.Shared.Console;
namespace Content.Server.Administration.Commands
{
[AdminCommand(AdminFlags.Debug)]
public sealed class AddTagCommand : LocalizedCommands
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Command => "addtag";
public override string Description => Loc.GetString("addtag-command-description");
public override string Help => Loc.GetString("addtag-command-help");
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
if (!EntityUid.TryParse(args[0], out var entityUid))
{
shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
return;
}
if (!_entityManager.TrySystem(out TagSystem? tagSystem))
return;
_entityManager.EnsureComponent<TagComponent>(entityUid);
if (tagSystem.TryAddTag(entityUid, args[1]))
{
shell.WriteLine(Loc.GetString("addtag-command-success", ("tag", args[1]), ("target", entityUid)));
}
else
{
shell.WriteError(Loc.GetString("addtag-command-fail", ("tag", args[1]), ("target", entityUid)));
}
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
return CompletionResult.FromHint(Loc.GetString("shell-argument-uid"));
}
if (args.Length == 2)
{
return CompletionResult.FromHintOptions(CompletionHelper.PrototypeIDs<TagPrototype>(),
Loc.GetString("tag-command-arg-tag"));
}
return CompletionResult.Empty;
}
}
[AdminCommand(AdminFlags.Debug)]
public sealed class RemoveTagCommand : LocalizedCommands
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Command => "removetag";
public override string Description => Loc.GetString("removetag-command-description");
public override string Help => Loc.GetString("removetag-command-help");
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}
if (!EntityUid.TryParse(args[0], out var entityUid))
{
shell.WriteError(Loc.GetString("shell-entity-uid-must-be-number"));
return;
}
if (!_entityManager.TrySystem(out TagSystem? tagSystem))
return;
if (tagSystem.RemoveTag(entityUid, args[1]))
{
shell.WriteLine(Loc.GetString("removetag-command-success", ("tag", args[1]), ("target", entityUid)));
}
else
{
shell.WriteError(Loc.GetString("removetag-command-fail", ("tag", args[1]), ("target", entityUid)));
}
}
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
return CompletionResult.FromHint(Loc.GetString("shell-argument-uid"));
}
if (args.Length == 2&& EntityUid.TryParse(args[0], out var entityUid) && _entityManager.TryGetComponent(entityUid, out TagComponent? tagComponent))
{
return CompletionResult.FromHintOptions(tagComponent.Tags,
Loc.GetString("tag-command-arg-tag"));
}
return CompletionResult.Empty;
}
}
}

View File

@@ -1,3 +1,4 @@
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
@@ -12,7 +13,11 @@ using Robust.Shared.Configuration;
using Robust.Shared.Console;
using Robust.Shared.ContentPack;
using Robust.Shared.Enums;
using Robust.Shared.Map;
using Robust.Shared.Network;
using Robust.Shared.Players;
using Robust.Shared.Toolshed;
using Robust.Shared.Toolshed.Errors;
using Robust.Shared.Utility;
@@ -28,6 +33,7 @@ namespace Content.Server.Administration.Managers
[Dependency] private readonly IResourceManager _res = default!;
[Dependency] private readonly IServerConsoleHost _consoleHost = default!;
[Dependency] private readonly IChatManager _chat = default!;
[Dependency] private readonly ToolshedManager _toolshed = default!;
private readonly Dictionary<IPlayerSession, AdminReg> _admins = new();
private readonly HashSet<NetUserId> _promotedPlayers = new();
@@ -41,6 +47,7 @@ namespace Content.Server.Administration.Managers
public IEnumerable<IPlayerSession> AllAdmins => _admins.Select(p => p.Key);
private readonly AdminCommandPermissions _commandPermissions = new();
private readonly AdminCommandPermissions _toolshedCommandPermissions = new();
public bool IsAdmin(IPlayerSession session, bool includeDeAdmin = false)
{
@@ -196,11 +203,37 @@ namespace Content.Server.Administration.Managers
}
}
foreach (var spec in _toolshed.AllCommands())
{
var (isAvail, flagsReq) = GetRequiredFlag(spec.Cmd);
if (!isAvail)
{
continue;
}
if (flagsReq.Length != 0)
{
_toolshedCommandPermissions.AdminCommands.TryAdd(spec.Cmd.Name, flagsReq);
}
else
{
_toolshedCommandPermissions.AnyCommands.Add(spec.Cmd.Name);
}
}
// Load flags for engine commands, since those don't have the attributes.
if (_res.TryContentFileRead(new ResPath("/engineCommandPerms.yml"), out var efs))
{
_commandPermissions.LoadPermissionsFromStream(efs);
}
if (_res.TryContentFileRead(new ResPath("/toolshedEngineCommandPerms.yml"), out var toolshedPerms))
{
_toolshedCommandPermissions.LoadPermissionsFromStream(toolshedPerms);
}
_toolshed.ActivePermissionController = this;
}
public void PromoteHost(IPlayerSession player)
@@ -366,6 +399,26 @@ namespace Content.Server.Administration.Managers
return Equals(addr, System.Net.IPAddress.Loopback) || Equals(addr, System.Net.IPAddress.IPv6Loopback);
}
public bool TryGetCommandFlags(CommandSpec command, out AdminFlags[]? flags)
{
var cmdName = command.Cmd.Name;
if (_toolshedCommandPermissions.AnyCommands.Contains(cmdName))
{
// Anybody can use this command.
flags = null;
return true;
}
if (_toolshedCommandPermissions.AdminCommands.TryGetValue(cmdName, out flags))
{
return true;
}
flags = null;
return false;
}
public bool CanCommand(IPlayerSession session, string cmdName)
{
if (_commandPermissions.AnyCommands.Contains(cmdName))
@@ -398,7 +451,51 @@ namespace Content.Server.Administration.Managers
return false;
}
private static (bool isAvail, AdminFlags[] flagsReq) GetRequiredFlag(IConsoleCommand cmd)
public bool CheckInvokable(CommandSpec command, ICommonSession? user, out IConError? error)
{
if (user is null)
{
error = null;
return true; // Server console.
}
var name = command.Cmd.Name;
if (!TryGetCommandFlags(command, out var flags))
{
// Command is missing permissions.
error = new CommandPermissionsUnassignedError(command);
return false;
}
if (flags is null)
{
// Anyone can execute this.
error = null;
return true;
}
var data = GetAdminData((IPlayerSession)user);
if (data == null)
{
// Player isn't an admin.
error = new NoPermissionError(command);
return false;
}
foreach (var flag in flags)
{
if (data.HasFlag(flag))
{
error = null;
return true;
}
}
error = new NoPermissionError(command);
return false;
}
private static (bool isAvail, AdminFlags[] flagsReq) GetRequiredFlag(object cmd)
{
MemberInfo type = cmd.GetType();
@@ -472,3 +569,28 @@ namespace Content.Server.Administration.Managers
}
}
}
public record struct CommandPermissionsUnassignedError(CommandSpec Command) : IConError
{
public FormattedMessage DescribeInner()
{
return FormattedMessage.FromMarkup($"The command {Command.FullName()} is missing permission flags and cannot be executed.");
}
public string? Expression { get; set; }
public Vector2i? IssueSpan { get; set; }
public StackTrace? Trace { get; set; }
}
public record struct NoPermissionError(CommandSpec Command) : IConError
{
public FormattedMessage DescribeInner()
{
return FormattedMessage.FromMarkup($"You do not have permission to execute {Command.FullName()}");
}
public string? Expression { get; set; }
public Vector2i? IssueSpan { get; set; }
public StackTrace? Trace { get; set; }
}

View File

@@ -1,6 +1,7 @@
using Content.Shared.Administration;
using Content.Shared.Administration.Managers;
using Robust.Server.Player;
using Robust.Shared.Toolshed;
namespace Content.Server.Administration.Managers
@@ -87,5 +88,7 @@ namespace Content.Server.Administration.Managers
void Initialize();
void PromoteHost(IPlayerSession player);
bool TryGetCommandFlags(CommandSpec command, out AdminFlags[]? flags);
}
}

View File

@@ -117,7 +117,7 @@ public sealed partial class AdminVerbSystem
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/AdminActions/rejuvenate.png")),
Act = () =>
{
RejuvenateCommand.PerformRejuvenate(args.Target);
_rejuvenate.PerformRejuvenate(args.Target);
},
Impact = LogImpact.Extreme,
Message = Loc.GetString("admin-trick-rejuvenate-description"),

View File

@@ -1,3 +1,4 @@
using System.Linq;
using Content.Server.Administration.Commands;
using Content.Server.Administration.Logs;
using Content.Server.Administration.Managers;
@@ -31,6 +32,7 @@ using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Toolshed;
using Robust.Shared.Utility;
using static Content.Shared.Configurable.ConfigurationComponent;
@@ -55,6 +57,8 @@ namespace Content.Server.Administration.Systems
[Dependency] private readonly PrayerSystem _prayerSystem = default!;
[Dependency] private readonly EuiManager _eui = default!;
[Dependency] private readonly MindSystem _mindSystem = default!;
[Dependency] private readonly ToolshedManager _toolshed = default!;
[Dependency] private readonly RejuvenateSystem _rejuvenate = default!;
private readonly Dictionary<IPlayerSession, EditSolutionsEui> _openSolutionUis = new();
@@ -78,6 +82,14 @@ namespace Content.Server.Administration.Systems
if (_adminManager.IsAdmin(player))
{
Verb mark = new();
mark.Text = Loc.GetString("toolshed-verb-mark");
mark.Message = Loc.GetString("toolshed-verb-mark-description");
mark.Category = VerbCategory.Admin;
mark.Act = () => _toolshed.InvokeCommand(player, "=> $marked", Enumerable.Repeat(args.Target, 1), out _);
mark.Impact = LogImpact.Low;
args.Verbs.Add(mark);
if (TryComp(args.Target, out ActorComponent? targetActor))
{
// AdminHelp
@@ -188,8 +200,6 @@ namespace Content.Server.Administration.Systems
Category = VerbCategory.Admin,
Act = () =>
{
if (!TryComp<ActorComponent>(args.Target, out var actor)) return;
_console.ExecuteCommand(player, $"respawn {actor.PlayerSession.Name}");
},
ConfirmationPopup = true,
@@ -229,7 +239,7 @@ namespace Content.Server.Administration.Systems
Text = Loc.GetString("rejuvenate-verb-get-data-text"),
Category = VerbCategory.Debug,
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/rejuvenate.svg.192dpi.png")),
Act = () => RejuvenateCommand.PerformRejuvenate(args.Target),
Act = () => _rejuvenate.PerformRejuvenate(args.Target),
Impact = LogImpact.Medium
};
args.Verbs.Add(verb);
@@ -247,11 +257,11 @@ namespace Content.Server.Administration.Systems
Act = () =>
{
MakeSentientCommand.MakeSentient(args.Target, EntityManager);
var mind = player.ContentData()?.Mind;
if (mind == null)
return;
_mindSystem.TransferTo(mind, args.Target, ghostCheckOverride: true);
},
Impact = LogImpact.High,

View File

@@ -0,0 +1,11 @@
using Content.Shared.Rejuvenate;
namespace Content.Server.Administration.Systems;
public sealed class RejuvenateSystem : EntitySystem
{
public void PerformRejuvenate(EntityUid target)
{
RaiseLocalEvent(target, new RejuvenateEvent());
}
}

View File

@@ -0,0 +1,24 @@
using Content.Server.Administration.Managers;
using Content.Shared.Administration;
using Robust.Server.Player;
using Robust.Shared.Toolshed;
namespace Content.Server.Administration.Toolshed;
[ToolshedCommand, AdminCommand(AdminFlags.Admin)]
public sealed class AdminsCommand : ToolshedCommand
{
[Dependency] private readonly IAdminManager _admin = default!;
[CommandImplementation("active")]
public IEnumerable<IPlayerSession> Active()
{
return _admin.ActiveAdmins;
}
[CommandImplementation("all")]
public IEnumerable<IPlayerSession> All()
{
return _admin.AllAdmins;
}
}

View File

@@ -0,0 +1,16 @@
using Content.Shared.Administration;
using Robust.Shared.Toolshed;
namespace Content.Server.Administration.Toolshed;
[ToolshedCommand, AnyCommand]
public sealed class MarkedCommand : ToolshedCommand
{
[CommandImplementation]
public IEnumerable<EntityUid> Marked([CommandInvocationContext] IInvocationContext ctx)
{
var res = (IEnumerable<EntityUid>?)ctx.ReadVar("marked");
res ??= Array.Empty<EntityUid>();
return res;
}
}

View File

@@ -0,0 +1,22 @@
using Content.Server.Administration.Systems;
using Content.Shared.Administration;
using Robust.Shared.Toolshed;
namespace Content.Server.Administration.Toolshed;
[ToolshedCommand, AdminCommand(AdminFlags.Admin)]
public sealed class RejuvenateCommand : ToolshedCommand
{
private RejuvenateSystem? _rejuvenate;
[CommandImplementation]
public IEnumerable<EntityUid> Rejuvenate([PipedArgument] IEnumerable<EntityUid> input)
{
_rejuvenate ??= GetSys<RejuvenateSystem>();
foreach (var i in input)
{
_rejuvenate.PerformRejuvenate(i);
yield return i;
}
}
}

View File

@@ -0,0 +1,49 @@
using System.Linq;
using Content.Server.Chemistry.EntitySystems;
using Content.Shared.Administration;
using Content.Shared.Chemistry.Components;
using Robust.Shared.Toolshed;
using Robust.Shared.Toolshed.Syntax;
namespace Content.Server.Administration.Toolshed;
[ToolshedCommand, AdminCommand(AdminFlags.Debug)]
public sealed class SolutionCommand : ToolshedCommand
{
private SolutionContainerSystem? _solutionContainer;
[CommandImplementation("get")]
public SolutionRef? Get(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<string> name
)
{
_solutionContainer ??= GetSys<SolutionContainerSystem>();
_solutionContainer.TryGetSolution(input, name.Evaluate(ctx)!, out var solution);
if (solution is not null)
return new SolutionRef(input, solution);
return null;
}
[CommandImplementation("get")]
public IEnumerable<SolutionRef> Get(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] IEnumerable<EntityUid> input,
[CommandArgument] ValueRef<string> name
)
{
return input.Select(x => Get(ctx, x, name)).Where(x => x is not null).Cast<SolutionRef>();
}
}
public readonly record struct SolutionRef(EntityUid Owner, Solution Solution)
{
public override string ToString()
{
return $"{Owner} {Solution}";
}
}

View File

@@ -0,0 +1,106 @@
using System.Linq;
using Content.Shared.Administration;
using Content.Shared.Tag;
using Robust.Shared.Toolshed;
using Robust.Shared.Toolshed.Syntax;
using Robust.Shared.Toolshed.TypeParsers;
namespace Content.Server.Administration.Toolshed;
[ToolshedCommand, AdminCommand(AdminFlags.Debug)]
public sealed class TagCommand : ToolshedCommand
{
private TagSystem? _tag;
[CommandImplementation("list")]
public IEnumerable<string> List([PipedArgument] IEnumerable<EntityUid> ent)
{
return ent.SelectMany(x =>
{
if (TryComp<TagComponent>(x, out var tags))
// Note: Cast is required for C# to figure out the type signature.
return (IEnumerable<string>)tags.Tags;
return Array.Empty<string>();
});
}
[CommandImplementation("add")]
public EntityUid Add(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<string, Prototype<TagPrototype>> @ref
)
{
_tag ??= GetSys<TagSystem>();
_tag.AddTag(input, @ref.Evaluate(ctx)!);
return input;
}
[CommandImplementation("add")]
public IEnumerable<EntityUid> Add(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] IEnumerable<EntityUid> input,
[CommandArgument] ValueRef<string, Prototype<TagPrototype>> @ref
)
=> input.Select(x => Add(ctx, x, @ref));
[CommandImplementation("rm")]
public EntityUid Rm(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<string, Prototype<TagPrototype>> @ref
)
{
_tag ??= GetSys<TagSystem>();
_tag.RemoveTag(input, @ref.Evaluate(ctx)!);
return input;
}
[CommandImplementation("rm")]
public IEnumerable<EntityUid> Rm(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] IEnumerable<EntityUid> input,
[CommandArgument] ValueRef<string, Prototype<TagPrototype>> @ref
)
=> input.Select(x => Rm(ctx, x, @ref));
[CommandImplementation("addmany")]
public EntityUid AddMany(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<IEnumerable<string>, IEnumerable<string>> @ref
)
{
_tag ??= GetSys<TagSystem>();
_tag.AddTags(input, @ref.Evaluate(ctx)!);
return input;
}
[CommandImplementation("addmany")]
public IEnumerable<EntityUid> AddMany(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] IEnumerable<EntityUid> input,
[CommandArgument] ValueRef<IEnumerable<string>, IEnumerable<string>> @ref
)
=> input.Select(x => AddMany(ctx, x, @ref));
[CommandImplementation("rmmany")]
public EntityUid RmMany(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<IEnumerable<string>, IEnumerable<string>> @ref
)
{
_tag ??= GetSys<TagSystem>();
_tag.RemoveTags(input, @ref.Evaluate(ctx)!);
return input;
}
[CommandImplementation("rmmany")]
public IEnumerable<EntityUid> RmMany(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] IEnumerable<EntityUid> input,
[CommandArgument] ValueRef<IEnumerable<string>, IEnumerable<string>> @ref
)
=> input.Select(x => RmMany(ctx, x, @ref));
}