Toolshed refactor (#33598)

* Content changes for engine toolshed PR

* add contains command

* more permissive commands
This commit is contained in:
Leon Friedrich
2024-12-21 17:45:48 +11:00
committed by GitHub
parent b011dbb61e
commit 06e2bba8ab
19 changed files with 212 additions and 270 deletions

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Reflection;
using Content.Server.Administration.Managers;
using Robust.Shared.Toolshed; using Robust.Shared.Toolshed;
namespace Content.IntegrationTests.Tests.Toolshed; namespace Content.IntegrationTests.Tests.Toolshed;
@@ -10,10 +11,23 @@ public sealed class AdminTest : ToolshedTest
[Test] [Test]
public async Task AllCommandsHavePermissions() public async Task AllCommandsHavePermissions()
{ {
var toolMan = Server.ResolveDependency<ToolshedManager>();
var admin = Server.ResolveDependency<IAdminManager>();
var ignored = new HashSet<Assembly>()
{typeof(LocTest).Assembly, typeof(Robust.UnitTesting.Shared.Toolshed.LocTest).Assembly};
await Server.WaitAssertion(() => await Server.WaitAssertion(() =>
{ {
Assert.That(InvokeCommand("cmd:list where { acmd:perms isnull }", out var res)); Assert.Multiple(() =>
Assert.That((IEnumerable<CommandSpec>) res, Is.Empty, "All commands must have admin permissions set up."); {
foreach (var cmd in toolMan.DefaultEnvironment.AllCommands())
{
if (ignored.Contains(cmd.Cmd.GetType().Assembly))
continue;
Assert.That(admin.TryGetCommandFlags(cmd, out _), $"Command does not have admin permissions set up: {cmd.FullName()}");
}
});
}); });
} }
} }

View File

@@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using Robust.Shared.IoC; using System.Reflection;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Toolshed; using Robust.Shared.Toolshed;
@@ -14,10 +14,27 @@ public sealed class LocTest : ToolshedTest
[Test] [Test]
public async Task AllCommandsHaveDescriptions() public async Task AllCommandsHaveDescriptions()
{ {
var locMan = Server.ResolveDependency<ILocalizationManager>();
var toolMan = Server.ResolveDependency<ToolshedManager>();
var locStrings = new HashSet<string>();
var ignored = new HashSet<Assembly>()
{typeof(LocTest).Assembly, typeof(Robust.UnitTesting.Shared.Toolshed.LocTest).Assembly};
await Server.WaitAssertion(() => await Server.WaitAssertion(() =>
{ {
Assert.That(InvokeCommand("cmd:list where { cmd:descloc loc:tryloc isnull }", out var res)); Assert.Multiple(() =>
Assert.That((IEnumerable<CommandSpec>)res!, Is.Empty, "All commands must have localized descriptions."); {
foreach (var cmd in toolMan.DefaultEnvironment.AllCommands())
{
if (ignored.Contains(cmd.Cmd.GetType().Assembly))
continue;
var descLoc = cmd.DescLocStr();
Assert.That(locStrings.Add(descLoc), $"Duplicate command description key: {descLoc}");
Assert.That(locMan.TryGetString(descLoc, out _), $"Failed to get command description for command {cmd.FullName()}");
}
});
}); });
} }
} }

View File

@@ -74,15 +74,15 @@ public abstract class ToolshedTest : IInvocationContext
return (T) res!; return (T) res!;
} }
protected void ParseCommand(string command, Type? inputType = null, Type? expectedType = null, bool once = false) protected void ParseCommand(string command, Type? inputType = null, Type? expectedType = null)
{ {
var parser = new ParserContext(command, Toolshed); var parser = new ParserContext(command, Toolshed);
var success = CommandRun.TryParse(false, parser, inputType, expectedType, once, out _, out _, out var error); var success = CommandRun.TryParse(parser, inputType, expectedType, out _);
if (error is not null) if (parser.Error is not null)
ReportError(error); ReportError(parser.Error);
if (error is null) if (parser.Error is null)
Assert.That(success, $"Parse failed despite no error being reported. Parsed {command}"); Assert.That(success, $"Parse failed despite no error being reported. Parsed {command}");
} }
@@ -153,11 +153,28 @@ public abstract class ToolshedTest : IInvocationContext
return _errors; return _errors;
} }
public bool HasErrors => _errors.Count > 0;
public void ClearErrors() public void ClearErrors()
{ {
_errors.Clear(); _errors.Clear();
} }
public object? ReadVar(string name)
{
return Variables.GetValueOrDefault(name);
}
public void WriteVar(string name, object? value)
{
Variables[name] = value;
}
public IEnumerable<string> GetVars()
{
return Variables.Keys;
}
public Dictionary<string, object?> Variables { get; } = new(); public Dictionary<string, object?> Variables { get; } = new();
protected void ExpectError(Type err) protected void ExpectError(Type err)

View File

@@ -10,11 +10,7 @@ namespace Content.Server.Access;
public sealed class AddAccessLogCommand : ToolshedCommand public sealed class AddAccessLogCommand : ToolshedCommand
{ {
[CommandImplementation] [CommandImplementation]
public void AddAccessLog( public void AddAccessLog(IInvocationContext ctx, EntityUid input, float seconds, string accessor)
[CommandInvocationContext] IInvocationContext ctx,
[CommandArgument] EntityUid input,
[CommandArgument] float seconds,
[CommandArgument] ValueRef<string> accessor)
{ {
var accessReader = EnsureComp<AccessReaderComponent>(input); var accessReader = EnsureComp<AccessReaderComponent>(input);
@@ -23,19 +19,14 @@ public sealed class AddAccessLogCommand : ToolshedCommand
ctx.WriteLine($"WARNING: Surpassing the limit of the log by {accessLogCount - accessReader.AccessLogLimit+1} entries!"); ctx.WriteLine($"WARNING: Surpassing the limit of the log by {accessLogCount - accessReader.AccessLogLimit+1} entries!");
var accessTime = TimeSpan.FromSeconds(seconds); var accessTime = TimeSpan.FromSeconds(seconds);
var accessName = accessor.Evaluate(ctx)!; accessReader.AccessLog.Enqueue(new AccessRecord(accessTime, accessor));
accessReader.AccessLog.Enqueue(new AccessRecord(accessTime, accessName));
ctx.WriteLine($"Successfully added access log to {input} with this information inside:\n " + ctx.WriteLine($"Successfully added access log to {input} with this information inside:\n " +
$"Time of access: {accessTime}\n " + $"Time of access: {accessTime}\n " +
$"Accessed by: {accessName}"); $"Accessed by: {accessor}");
} }
[CommandImplementation] [CommandImplementation]
public void AddAccessLogPiped( public void AddAccessLogPiped(IInvocationContext ctx, [PipedArgument] EntityUid input, float seconds, string accessor)
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] float seconds,
[CommandArgument] ValueRef<string> accessor)
{ {
AddAccessLog(ctx, input, seconds, accessor); AddAccessLog(ctx, input, seconds, accessor);
} }

View File

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

View File

@@ -23,7 +23,7 @@ public sealed class RejuvenateCommand : ToolshedCommand
} }
[CommandImplementation] [CommandImplementation]
public void Rejuvenate([CommandInvocationContext] IInvocationContext ctx) public void Rejuvenate(IInvocationContext ctx)
{ {
_rejuvenate ??= GetSys<RejuvenateSystem>(); _rejuvenate ??= GetSys<RejuvenateSystem>();
if (ExecutingEntity(ctx) is not { } ent) if (ExecutingEntity(ctx) is not { } ent)

View File

@@ -8,6 +8,7 @@ using Robust.Shared.Toolshed;
using Robust.Shared.Toolshed.Syntax; using Robust.Shared.Toolshed.Syntax;
using Robust.Shared.Toolshed.TypeParsers; using Robust.Shared.Toolshed.TypeParsers;
using System.Linq; using System.Linq;
using Robust.Shared.Prototypes;
namespace Content.Server.Administration.Toolshed; namespace Content.Server.Administration.Toolshed;
@@ -17,48 +18,38 @@ public sealed class SolutionCommand : ToolshedCommand
private SharedSolutionContainerSystem? _solutionContainer; private SharedSolutionContainerSystem? _solutionContainer;
[CommandImplementation("get")] [CommandImplementation("get")]
public SolutionRef? Get( public SolutionRef? Get([PipedArgument] EntityUid input, string name)
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<string> name
)
{ {
_solutionContainer ??= GetSys<SharedSolutionContainerSystem>(); _solutionContainer ??= GetSys<SharedSolutionContainerSystem>();
if (_solutionContainer.TryGetSolution(input, name.Evaluate(ctx)!, out var solution)) if (_solutionContainer.TryGetSolution(input, name, out var solution))
return new SolutionRef(solution.Value); return new SolutionRef(solution.Value);
return null; return null;
} }
[CommandImplementation("get")] [CommandImplementation("get")]
public IEnumerable<SolutionRef> Get( public IEnumerable<SolutionRef> Get([PipedArgument] IEnumerable<EntityUid> input, string name)
[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>(); return input.Select(x => Get(x, name)).Where(x => x is not null).Cast<SolutionRef>();
} }
[CommandImplementation("adjreagent")] [CommandImplementation("adjreagent")]
public SolutionRef AdjReagent( public SolutionRef AdjReagent(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] SolutionRef input, [PipedArgument] SolutionRef input,
[CommandArgument] Prototype<ReagentPrototype> name, ProtoId<ReagentPrototype> proto,
[CommandArgument] ValueRef<FixedPoint2> amountRef FixedPoint2 amount
) )
{ {
_solutionContainer ??= GetSys<SharedSolutionContainerSystem>(); _solutionContainer ??= GetSys<SharedSolutionContainerSystem>();
var amount = amountRef.Evaluate(ctx);
if (amount > 0) if (amount > 0)
{ {
_solutionContainer.TryAddReagent(input.Solution, name.Value.ID, amount, out _); _solutionContainer.TryAddReagent(input.Solution, proto, amount, out _);
} }
else if (amount < 0) else if (amount < 0)
{ {
_solutionContainer.RemoveReagent(input.Solution, name.Value.ID, -amount); _solutionContainer.RemoveReagent(input.Solution, proto, -amount);
} }
return input; return input;
@@ -66,12 +57,11 @@ public sealed class SolutionCommand : ToolshedCommand
[CommandImplementation("adjreagent")] [CommandImplementation("adjreagent")]
public IEnumerable<SolutionRef> AdjReagent( public IEnumerable<SolutionRef> AdjReagent(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] IEnumerable<SolutionRef> input, [PipedArgument] IEnumerable<SolutionRef> input,
[CommandArgument] Prototype<ReagentPrototype> name, ProtoId<ReagentPrototype> name,
[CommandArgument] ValueRef<FixedPoint2> amountRef FixedPoint2 amount
) )
=> input.Select(x => AdjReagent(ctx, x, name, amountRef)); => input.Select(x => AdjReagent(x, name, amount));
} }
public readonly record struct SolutionRef(Entity<SolutionComponent> Solution) public readonly record struct SolutionRef(Entity<SolutionComponent> Solution)

View File

@@ -36,82 +36,50 @@ public sealed class TagCommand : ToolshedCommand
} }
[CommandImplementation("add")] [CommandImplementation("add")]
public EntityUid Add( public EntityUid Add([PipedArgument] EntityUid input, ProtoId<TagPrototype> tag)
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<string, Prototype<TagPrototype>> @ref
)
{ {
_tag ??= GetSys<TagSystem>(); _tag ??= GetSys<TagSystem>();
_tag.AddTag(input, @ref.Evaluate(ctx)!); _tag.AddTag(input, tag);
return input; return input;
} }
[CommandImplementation("add")] [CommandImplementation("add")]
public IEnumerable<EntityUid> Add( public IEnumerable<EntityUid> Add([PipedArgument] IEnumerable<EntityUid> input, ProtoId<TagPrototype> tag)
[CommandInvocationContext] IInvocationContext ctx, => input.Select(x => Add(x, tag));
[PipedArgument] IEnumerable<EntityUid> input,
[CommandArgument] ValueRef<string, Prototype<TagPrototype>> @ref
)
=> input.Select(x => Add(ctx, x, @ref));
[CommandImplementation("rm")] [CommandImplementation("rm")]
public EntityUid Rm( public EntityUid Rm([PipedArgument] EntityUid input, ProtoId<TagPrototype> tag)
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<string, Prototype<TagPrototype>> @ref
)
{ {
_tag ??= GetSys<TagSystem>(); _tag ??= GetSys<TagSystem>();
_tag.RemoveTag(input, @ref.Evaluate(ctx)!); _tag.RemoveTag(input, tag);
return input; return input;
} }
[CommandImplementation("rm")] [CommandImplementation("rm")]
public IEnumerable<EntityUid> Rm( public IEnumerable<EntityUid> Rm([PipedArgument] IEnumerable<EntityUid> input, ProtoId<TagPrototype> tag)
[CommandInvocationContext] IInvocationContext ctx, => input.Select(x => Rm(x, tag));
[PipedArgument] IEnumerable<EntityUid> input,
[CommandArgument] ValueRef<string, Prototype<TagPrototype>> @ref
)
=> input.Select(x => Rm(ctx, x, @ref));
[CommandImplementation("addmany")] [CommandImplementation("addmany")]
public EntityUid AddMany( public EntityUid AddMany([PipedArgument] EntityUid input, IEnumerable<ProtoId<TagPrototype>> tags)
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<IEnumerable<string>, IEnumerable<string>> @ref
)
{ {
_tag ??= GetSys<TagSystem>(); _tag ??= GetSys<TagSystem>();
_tag.AddTags(input, (IEnumerable<ProtoId<TagPrototype>>)@ref.Evaluate(ctx)!); _tag.AddTags(input, tags);
return input; return input;
} }
[CommandImplementation("addmany")] [CommandImplementation("addmany")]
public IEnumerable<EntityUid> AddMany( public IEnumerable<EntityUid> AddMany([PipedArgument] IEnumerable<EntityUid> input, IEnumerable<ProtoId<TagPrototype>> tags)
[CommandInvocationContext] IInvocationContext ctx, => input.Select(x => AddMany(x, tags.ToArray()));
[PipedArgument] IEnumerable<EntityUid> input,
[CommandArgument] ValueRef<IEnumerable<string>, IEnumerable<string>> @ref
)
=> input.Select(x => AddMany(ctx, x, @ref));
[CommandImplementation("rmmany")] [CommandImplementation("rmmany")]
public EntityUid RmMany( public EntityUid RmMany([PipedArgument] EntityUid input, IEnumerable<ProtoId<TagPrototype>> tags)
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<IEnumerable<string>, IEnumerable<string>> @ref
)
{ {
_tag ??= GetSys<TagSystem>(); _tag ??= GetSys<TagSystem>();
_tag.RemoveTags(input, (IEnumerable<ProtoId<TagPrototype>>)@ref.Evaluate(ctx)!); _tag.RemoveTags(input, tags);
return input; return input;
} }
[CommandImplementation("rmmany")] [CommandImplementation("rmmany")]
public IEnumerable<EntityUid> RmMany( public IEnumerable<EntityUid> RmMany([PipedArgument] IEnumerable<EntityUid> input, IEnumerable<ProtoId<TagPrototype>> tags)
[CommandInvocationContext] IInvocationContext ctx, => input.Select(x => RmMany(x, tags.ToArray()));
[PipedArgument] IEnumerable<EntityUid> input,
[CommandArgument] ValueRef<IEnumerable<string>, IEnumerable<string>> @ref
)
=> input.Select(x => RmMany(ctx, x, @ref));
} }

View File

@@ -14,7 +14,7 @@ public sealed class DeleteChatMessageCommand : ToolshedCommand
[Dependency] private readonly IEntitySystemManager _manager = default!; [Dependency] private readonly IEntitySystemManager _manager = default!;
[CommandImplementation("id")] [CommandImplementation("id")]
public void DeleteChatMessage([CommandInvocationContext] IInvocationContext ctx, [CommandArgument] uint messageId) public void DeleteChatMessage(IInvocationContext ctx, uint messageId)
{ {
if (!_manager.GetEntitySystem<ChatRepositorySystem>().Delete(messageId)) if (!_manager.GetEntitySystem<ChatRepositorySystem>().Delete(messageId))
{ {

View File

@@ -14,7 +14,7 @@ public sealed class NukeChatMessagesCommand : ToolshedCommand
[Dependency] private readonly IEntitySystemManager _manager = default!; [Dependency] private readonly IEntitySystemManager _manager = default!;
[CommandImplementation("usernames")] [CommandImplementation("usernames")]
public void Command([CommandInvocationContext] IInvocationContext ctx, [CommandArgument] string usernamesCsv) public void Command(IInvocationContext ctx, string usernamesCsv)
{ {
var usernames = usernamesCsv.Split(','); var usernames = usernamesCsv.Split(',');

View File

@@ -29,19 +29,10 @@ public sealed class MindCommand : ToolshedCommand
} }
[CommandImplementation("control")] [CommandImplementation("control")]
public EntityUid Control( public EntityUid Control(IInvocationContext ctx, [PipedArgument] EntityUid target, ICommonSession player)
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid target,
[CommandArgument] ValueRef<ICommonSession> playerRef)
{ {
_mind ??= GetSys<SharedMindSystem>(); _mind ??= GetSys<SharedMindSystem>();
var player = playerRef.Evaluate(ctx);
if (player is null)
{
ctx.ReportError(new NotForServerConsoleError());
return target;
}
if (!_mind.TryGetMind(player, out var mindId, out var mind)) if (!_mind.TryGetMind(player, out var mindId, out var mind))
{ {

View File

@@ -20,7 +20,7 @@ public sealed class PolymorphCommand : ToolshedCommand
[CommandImplementation] [CommandImplementation]
public EntityUid? Polymorph( public EntityUid? Polymorph(
[PipedArgument] EntityUid input, [PipedArgument] EntityUid input,
[CommandArgument] ProtoId<PolymorphPrototype> protoId ProtoId<PolymorphPrototype> protoId
) )
{ {
_system ??= GetSys<PolymorphSystem>(); _system ??= GetSys<PolymorphSystem>();
@@ -34,7 +34,7 @@ public sealed class PolymorphCommand : ToolshedCommand
[CommandImplementation] [CommandImplementation]
public IEnumerable<EntityUid> Polymorph( public IEnumerable<EntityUid> Polymorph(
[PipedArgument] IEnumerable<EntityUid> input, [PipedArgument] IEnumerable<EntityUid> input,
[CommandArgument] ProtoId<PolymorphPrototype> protoId ProtoId<PolymorphPrototype> protoId
) )
=> input.Select(x => Polymorph(x, protoId)).Where(x => x is not null).Select(x => (EntityUid)x!); => input.Select(x => Polymorph(x, protoId)).Where(x => x is not null).Select(x => (EntityUid)x!);
} }

View File

@@ -30,7 +30,7 @@ public sealed class JobsCommand : ToolshedCommand
=> stations.SelectMany(Jobs); => stations.SelectMany(Jobs);
[CommandImplementation("job")] [CommandImplementation("job")]
public JobSlotRef Job([PipedArgument] EntityUid station, [CommandArgument] Prototype<JobPrototype> job) public JobSlotRef Job([PipedArgument] EntityUid station, Prototype<JobPrototype> job)
{ {
_jobs ??= GetSys<StationJobsSystem>(); _jobs ??= GetSys<StationJobsSystem>();
@@ -38,7 +38,7 @@ public sealed class JobsCommand : ToolshedCommand
} }
[CommandImplementation("job")] [CommandImplementation("job")]
public IEnumerable<JobSlotRef> Job([PipedArgument] IEnumerable<EntityUid> stations, [CommandArgument] Prototype<JobPrototype> job) public IEnumerable<JobSlotRef> Job([PipedArgument] IEnumerable<EntityUid> stations, Prototype<JobPrototype> job)
=> stations.Select(x => Job(x, job)); => stations.Select(x => Job(x, job));
[CommandImplementation("isinfinite")] [CommandImplementation("isinfinite")]
@@ -50,63 +50,41 @@ public sealed class JobsCommand : ToolshedCommand
=> jobs.Select(x => IsInfinite(x, inverted)); => jobs.Select(x => IsInfinite(x, inverted));
[CommandImplementation("adjust")] [CommandImplementation("adjust")]
public JobSlotRef Adjust( public JobSlotRef Adjust([PipedArgument] JobSlotRef @ref, int by)
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] JobSlotRef @ref,
[CommandArgument] ValueRef<int> by
)
{ {
_jobs ??= GetSys<StationJobsSystem>(); _jobs ??= GetSys<StationJobsSystem>();
_jobs.TryAdjustJobSlot(@ref.Station, @ref.Job, by.Evaluate(ctx), true, true); _jobs.TryAdjustJobSlot(@ref.Station, @ref.Job, by, true, true);
return @ref; return @ref;
} }
[CommandImplementation("adjust")] [CommandImplementation("adjust")]
public IEnumerable<JobSlotRef> Adjust( public IEnumerable<JobSlotRef> Adjust([PipedArgument] IEnumerable<JobSlotRef> @ref, int by)
[CommandInvocationContext] IInvocationContext ctx, => @ref.Select(x => Adjust(x, by));
[PipedArgument] IEnumerable<JobSlotRef> @ref,
[CommandArgument] ValueRef<int> by
)
=> @ref.Select(x => Adjust(ctx, x, by));
[CommandImplementation("set")] [CommandImplementation("set")]
public JobSlotRef Set( public JobSlotRef Set([PipedArgument] JobSlotRef @ref, int by)
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] JobSlotRef @ref,
[CommandArgument] ValueRef<int> by
)
{ {
_jobs ??= GetSys<StationJobsSystem>(); _jobs ??= GetSys<StationJobsSystem>();
_jobs.TrySetJobSlot(@ref.Station, @ref.Job, by.Evaluate(ctx), true); _jobs.TrySetJobSlot(@ref.Station, @ref.Job, by, true);
return @ref; return @ref;
} }
[CommandImplementation("set")] [CommandImplementation("set")]
public IEnumerable<JobSlotRef> Set( public IEnumerable<JobSlotRef> Set([PipedArgument] IEnumerable<JobSlotRef> @ref, int by)
[CommandInvocationContext] IInvocationContext ctx, => @ref.Select(x => Set(x, by));
[PipedArgument] IEnumerable<JobSlotRef> @ref,
[CommandArgument] ValueRef<int> by
)
=> @ref.Select(x => Set(ctx, x, by));
[CommandImplementation("amount")] [CommandImplementation("amount")]
public int Amount( public int Amount([PipedArgument] JobSlotRef @ref)
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] JobSlotRef @ref
)
{ {
_jobs ??= GetSys<StationJobsSystem>(); _jobs ??= GetSys<StationJobsSystem>();
_jobs.TryGetJobSlot(@ref.Station, @ref.Job, out var slots); _jobs.TryGetJobSlot(@ref.Station, @ref.Job, out var slots);
return (int)(slots ?? 0); return slots ?? 0;
} }
[CommandImplementation("amount")] [CommandImplementation("amount")]
public IEnumerable<int> Amount( public IEnumerable<int> Amount([PipedArgument] IEnumerable<JobSlotRef> @ref)
[CommandInvocationContext] IInvocationContext ctx, => @ref.Select(Amount);
[PipedArgument] IEnumerable<JobSlotRef> @ref
)
=> @ref.Select(x => Amount(ctx, x));
} }
// Used for Toolshed queries. // Used for Toolshed queries.

View File

@@ -27,7 +27,7 @@ public sealed class StationsCommand : ToolshedCommand
} }
[CommandImplementation("get")] [CommandImplementation("get")]
public EntityUid Get([CommandInvocationContext] IInvocationContext ctx) public EntityUid Get(IInvocationContext ctx)
{ {
_station ??= GetSys<StationSystem>(); _station ??= GetSys<StationSystem>();
@@ -54,7 +54,6 @@ public sealed class StationsCommand : ToolshedCommand
public EntityUid? LargestGrid([PipedArgument] EntityUid input) public EntityUid? LargestGrid([PipedArgument] EntityUid input)
{ {
_station ??= GetSys<StationSystem>(); _station ??= GetSys<StationSystem>();
return _station.GetLargestGrid(Comp<StationDataComponent>(input)); return _station.GetLargestGrid(Comp<StationDataComponent>(input));
} }
@@ -80,46 +79,30 @@ public sealed class StationsCommand : ToolshedCommand
=> input.Select(Config); => input.Select(Config);
[CommandImplementation("addgrid")] [CommandImplementation("addgrid")]
public void AddGrid( public void AddGrid([PipedArgument] EntityUid input, EntityUid grid)
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<EntityUid> grid
)
{ {
_station ??= GetSys<StationSystem>(); _station ??= GetSys<StationSystem>();
_station.AddGridToStation(input, grid);
_station.AddGridToStation(input, grid.Evaluate(ctx));
} }
[CommandImplementation("rmgrid")] [CommandImplementation("rmgrid")]
public void RmGrid( public void RmGrid([PipedArgument] EntityUid input, EntityUid grid)
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<EntityUid> grid
)
{ {
_station ??= GetSys<StationSystem>(); _station ??= GetSys<StationSystem>();
_station.RemoveGridFromStation(input, grid);
_station.RemoveGridFromStation(input, grid.Evaluate(ctx));
} }
[CommandImplementation("rename")] [CommandImplementation("rename")]
public void Rename([CommandInvocationContext] IInvocationContext ctx, public void Rename([PipedArgument] EntityUid input, string name)
[PipedArgument] EntityUid input,
[CommandArgument] ValueRef<string> name
)
{ {
_station ??= GetSys<StationSystem>(); _station ??= GetSys<StationSystem>();
_station.RenameStation(input, name);
_station.RenameStation(input, name.Evaluate(ctx)!);
} }
[CommandImplementation("rerollBounties")] [CommandImplementation("rerollBounties")]
public void RerollBounties([CommandInvocationContext] IInvocationContext ctx, public void RerollBounties([PipedArgument] EntityUid input)
[PipedArgument] EntityUid input)
{ {
_cargo ??= GetSys<CargoSystem>(); _cargo ??= GetSys<CargoSystem>();
_cargo.RerollBountyDatabase(input); _cargo.RerollBountyDatabase(input);
} }
} }

View File

@@ -94,7 +94,7 @@ namespace Content.Server.StationEvents
/// to even exist) so I think it's fine. /// to even exist) so I think it's fine.
/// </remarks> /// </remarks>
[CommandImplementation("simulate")] [CommandImplementation("simulate")]
public IEnumerable<(string, float)> Simulate([CommandArgument] EntityPrototype eventScheduler, [CommandArgument] int rounds, [CommandArgument] int playerCount, [CommandArgument] float roundEndMean, [CommandArgument] float roundEndStdDev) public IEnumerable<(string, float)> Simulate(EntityPrototype eventScheduler, int rounds, int playerCount, float roundEndMean, float roundEndStdDev)
{ {
_stationEvent ??= GetSys<EventManagerSystem>(); _stationEvent ??= GetSys<EventManagerSystem>();
_entityTable ??= GetSys<EntityTableSystem>(); _entityTable ??= GetSys<EntityTableSystem>();
@@ -146,7 +146,7 @@ namespace Content.Server.StationEvents
} }
[CommandImplementation("lsprob")] [CommandImplementation("lsprob")]
public IEnumerable<(string, float)> LsProb([CommandArgument] EntityPrototype eventScheduler) public IEnumerable<(string, float)> LsProb(EntityPrototype eventScheduler)
{ {
_compFac ??= IoCManager.Resolve<IComponentFactory>(); _compFac ??= IoCManager.Resolve<IComponentFactory>();
_stationEvent ??= GetSys<EventManagerSystem>(); _stationEvent ??= GetSys<EventManagerSystem>();
@@ -166,7 +166,7 @@ namespace Content.Server.StationEvents
} }
[CommandImplementation("lsprobtime")] [CommandImplementation("lsprobtime")]
public IEnumerable<(string, float)> LsProbTime([CommandArgument] EntityPrototype eventScheduler, [CommandArgument] float time) public IEnumerable<(string, float)> LsProbTime(EntityPrototype eventScheduler, float time)
{ {
_compFac ??= IoCManager.Resolve<IComponentFactory>(); _compFac ??= IoCManager.Resolve<IComponentFactory>();
_stationEvent ??= GetSys<EventManagerSystem>(); _stationEvent ??= GetSys<EventManagerSystem>();
@@ -188,7 +188,7 @@ namespace Content.Server.StationEvents
} }
[CommandImplementation("prob")] [CommandImplementation("prob")]
public float Prob([CommandArgument] EntityPrototype eventScheduler, [CommandArgument] string eventId) public float Prob(EntityPrototype eventScheduler, string eventId)
{ {
_compFac ??= IoCManager.Resolve<IComponentFactory>(); _compFac ??= IoCManager.Resolve<IComponentFactory>();
_stationEvent ??= GetSys<EventManagerSystem>(); _stationEvent ??= GetSys<EventManagerSystem>();

View File

@@ -22,13 +22,9 @@ public sealed class ACmdCommand : ToolshedCommand
} }
[CommandImplementation("caninvoke")] [CommandImplementation("caninvoke")]
public bool CanInvoke( public bool CanInvoke(IInvocationContext ctx, [PipedArgument] CommandSpec command, ICommonSession player)
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] CommandSpec command,
[CommandArgument] ValueRef<ICommonSession> player
)
{ {
// Deliberately discard the error. // Deliberately discard the error.
return ((IPermissionController) _adminManager).CheckInvokable(command, player.Evaluate(ctx), out var err); return ((IPermissionController) _adminManager).CheckInvokable(command, player, out _);
} }
} }

View File

@@ -15,10 +15,10 @@ public sealed class RunVerbAsCommand : ToolshedCommand
[CommandImplementation] [CommandImplementation]
public IEnumerable<NetEntity> RunVerbAs( public IEnumerable<NetEntity> RunVerbAs(
[CommandInvocationContext] IInvocationContext ctx, IInvocationContext ctx,
[PipedArgument] IEnumerable<NetEntity> input, [PipedArgument] IEnumerable<NetEntity> input,
[CommandArgument] ValueRef<NetEntity> runner, EntityUid runner,
[CommandArgument] string verb string verb
) )
{ {
_verb ??= GetSys<SharedVerbSystem>(); _verb ??= GetSys<SharedVerbSystem>();
@@ -26,17 +26,14 @@ public sealed class RunVerbAsCommand : ToolshedCommand
foreach (var i in input) foreach (var i in input)
{ {
var runnerNet = runner.Evaluate(ctx); if (EntityManager.Deleted(runner) && runner.IsValid())
var runnerEid = EntityManager.GetEntity(runnerNet); ctx.ReportError(new DeadEntity(runner));
if (EntityManager.Deleted(runnerEid) && runnerEid.IsValid())
ctx.ReportError(new DeadEntity(runnerEid));
if (ctx.GetErrors().Any()) if (ctx.GetErrors().Any())
yield break; yield break;
var eId = EntityManager.GetEntity(i); var eId = EntityManager.GetEntity(i);
var verbs = _verb.GetLocalVerbs(eId, runnerEid, Verb.VerbTypes, true); var verbs = _verb.GetLocalVerbs(eId, runner, Verb.VerbTypes, true);
// if the "verb name" is actually a verb-type, try run any verb of that type. // if the "verb name" is actually a verb-type, try run any verb of that type.
var verbType = Verb.VerbTypes.FirstOrDefault(x => x.Name == verb); var verbType = Verb.VerbTypes.FirstOrDefault(x => x.Name == verb);
@@ -45,7 +42,7 @@ public sealed class RunVerbAsCommand : ToolshedCommand
var verbTy = verbs.FirstOrDefault(v => v.GetType() == verbType); var verbTy = verbs.FirstOrDefault(v => v.GetType() == verbType);
if (verbTy != null) if (verbTy != null)
{ {
_verb.ExecuteVerb(verbTy, runnerEid, eId, forced: true); _verb.ExecuteVerb(verbTy, runner, eId, forced: true);
yield return i; yield return i;
} }
} }
@@ -54,7 +51,7 @@ public sealed class RunVerbAsCommand : ToolshedCommand
{ {
if (verbTy.Text.ToLowerInvariant() == verb) if (verbTy.Text.ToLowerInvariant() == verb)
{ {
_verb.ExecuteVerb(verbTy, runnerEid, eId, forced: true); _verb.ExecuteVerb(verbTy, runner, eId, forced: true);
yield return i; yield return i;
} }
} }

View File

@@ -16,7 +16,7 @@ public sealed class VisualizeCommand : ToolshedCommand
[CommandImplementation] [CommandImplementation]
public void VisualizeEntities( public void VisualizeEntities(
[CommandInvocationContext] IInvocationContext ctx, IInvocationContext ctx,
[PipedArgument] IEnumerable<EntityUid> input [PipedArgument] IEnumerable<EntityUid> input
) )
{ {

View File

@@ -6,7 +6,6 @@
- physics - physics
- player - player
- splat - splat
- emplace
- bin - bin
- extremes - extremes
- reduce - reduce
@@ -19,113 +18,88 @@
- iota - iota
- rep - rep
- to - to
- iterate
- Flags: DEBUG - Flags: DEBUG
Commands: Commands:
- comp - comp
- delete - delete
- do - with
- prototyped
- named - named
- paused - paused
- with - emplace
- count - do
- iterate
- select - select
- where - where
- prototyped - count
- types - types
- ecscomp
- actor - actor
- spawn - spawn
- replace
- mappos - mappos
- pos - pos
- tp - tp
- allcomps - allcomps
- replace
- entitysystemupdateorder - entitysystemupdateorder
- mind - mind
- Flags: HOST
Commands:
- methods
- ioc
- Commands:
- fuck - fuck
- ent
- as
- buildinfo
- help
- explain
- cmd
- stopwatch
- self
- search
- isnull
- help
- isempty
- any
- unique
- cd
- ls
- loc
- vars
- '=>' - '=>'
- first
- val
- '+'
- '-'
- '*'
- '/'
- 'min'
- 'max'
- '&'
- '|'
- '^'
- 'neg'
- '<'
- '>'
- '<='
- '>='
- '=='
- '!='
- f
- i
- s
- b
- '+/'
- '-/'
- '*/'
- '//'
- join
- append
- '?' - '?'
- 'or?' - 'or?'
- '??' - '??'
- rng - rng
- 'sum' - self
- sum
- take - take
- curtick - join
- curtime - search
- realtime - first
- servertime - unique
- more - any
- contains
- isnull
- isempty
- cd
- ls
- stopwatch
- append
- min
- max
- average
- '+'
- '-'
- '*'
- '/'
- '%' - '%'
- '%/' - '%/'
- '&~' - '&~'
- '|~' - '|~'
- '^~' - '^~'
- '~' - '~'
- 'abs' - '<'
- 'average' - '>'
- 'bibytecount' - '<='
- 'shortestbitlength' - '>='
- 'countleadzeros' - '=='
- 'counttrailingzeros' - '!='
- 'fpi' - '+/'
- 'fe' - '-/'
- 'ftau' - '*/'
- 'fepsilon' - '//'
- '&'
- '|'
- '^'
- neg
- abs
- bibytecount
- shortestbitlength
- countleadzeros
- counttrailingzeros
- fpi
- fe
- ftau
- fepsilon
- dpi - dpi
- de - de
- dtau - dtau
@@ -181,3 +155,29 @@
- atanpi - atanpi
- pick - pick
- tee - tee
- Flags: HOST
Commands:
- methods
- ioc
- Commands:
- ent
- f
- i
- s
- b
- as
- var
- vars
- val
- help
- explain
- cmd
- buildinfo
- loc
- curtick
- curtime
- realtime
- servertime
- more