Console Unify API Changes (#3059)

* Remove unused IChatCommand.

* Lots of refactoring into a shared context.

* Removed ICommonSession from server concmd Execute.

* Added argStr parameter to concmd execute.

* The execute function of client concmds now returns void, use the new shell.RemoteExecuteCommand function to forward commands.

* Finally move shells and commands into shared.

* Console commands can now be registered directly without a class in a shared context.

* Engine API Changes.

* Repair rebase damage.

* Update Submodule.
This commit is contained in:
Acruid
2021-02-01 16:49:43 -08:00
committed by GitHub
parent 80ad2ef5b7
commit 8b5d66050a
119 changed files with 820 additions and 796 deletions

View File

@@ -1,8 +1,9 @@
#nullable enable
#nullable enable
using Content.Server.Administration;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
namespace Content.Server.Commands.Damage
{
@@ -13,15 +14,16 @@ namespace Content.Server.Commands.Damage
public override string Description => "Adds a damage flag to your entity or another.";
public override string Help => $"Usage: {Command} <flag> / {Command} <entityUid> <flag>";
public override void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
if (!TryGetEntity(shell, player, args, true, out var entity, out var flag, out var damageable))
{
return;
}
damageable.AddFlag(flag);
shell.SendText(player, $"Added damage flag {flag} to entity {entity.Name}");
shell.WriteLine($"Added damage flag {flag} to entity {entity.Name}");
}
}
}

View File

@@ -2,21 +2,21 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.GameObjects.Components.Damage;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.Commands.Damage
{
public abstract class DamageFlagCommand : IClientCommand
public abstract class DamageFlagCommand : IConsoleCommand
{
public abstract string Command { get; }
public abstract string Description { get; }
public abstract string Help { get; }
public abstract void Execute(IConsoleShell shell, IPlayerSession? player, string[] args);
public abstract void Execute(IConsoleShell shell, string argStr, string[] args);
public bool TryGetEntity(
IConsoleShell shell,
@@ -41,19 +41,19 @@ namespace Content.Server.Commands.Damage
{
if (player == null)
{
shell.SendText(player, "An entity needs to be specified when the command isn't used by a player.");
shell.WriteLine("An entity needs to be specified when the command isn't used by a player.");
return false;
}
if (player.AttachedEntity == null)
{
shell.SendText(player, "An entity needs to be specified when you aren't attached to an entity.");
shell.WriteLine("An entity needs to be specified when you aren't attached to an entity.");
return false;
}
if (!Enum.TryParse(args[0], true, out parsedFlag))
{
shell.SendText(player, $"{args[0]} is not a valid damage flag.");
shell.WriteLine($"{args[0]} is not a valid damage flag.");
return false;
}
@@ -65,44 +65,44 @@ namespace Content.Server.Commands.Damage
{
if (!EntityUid.TryParse(args[0], out var id))
{
shell.SendText(player, $"{args[0]} isn't a valid entity id.");
shell.WriteLine($"{args[0]} isn't a valid entity id.");
return false;
}
var entityManager = IoCManager.Resolve<IEntityManager>();
if (!entityManager.TryGetEntity(id, out parsedEntity))
{
shell.SendText(player, $"No entity found with id {id}.");
shell.WriteLine($"No entity found with id {id}.");
return false;
}
if (!Enum.TryParse(args[1], true, out parsedFlag))
{
shell.SendText(player, $"{args[1]} is not a valid damage flag.");
shell.WriteLine($"{args[1]} is not a valid damage flag.");
return false;
}
break;
}
default:
shell.SendText(player, Help);
shell.WriteLine(Help);
return false;
}
if (!parsedEntity.TryGetComponent(out parsedDamageable))
{
shell.SendText(player, $"Entity {parsedEntity.Name} doesn't have a {nameof(IDamageableComponent)}");
shell.WriteLine($"Entity {parsedEntity.Name} doesn't have a {nameof(IDamageableComponent)}");
return false;
}
if (parsedDamageable.HasFlag(parsedFlag) && adding)
{
shell.SendText(player, $"Entity {parsedEntity.Name} already has damage flag {parsedFlag}.");
shell.WriteLine($"Entity {parsedEntity.Name} already has damage flag {parsedFlag}.");
return false;
}
else if (!parsedDamageable.HasFlag(parsedFlag) && !adding)
{
shell.SendText(player, $"Entity {parsedEntity.Name} doesn't have damage flag {parsedFlag}.");
shell.WriteLine($"Entity {parsedEntity.Name} doesn't have damage flag {parsedFlag}.");
return false;
}

View File

@@ -1,9 +1,9 @@
#nullable enable
#nullable enable
using Content.Server.Administration;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
@@ -12,14 +12,15 @@ using Robust.Shared.IoC;
namespace Content.Server.Commands.Damage
{
[AdminCommand(AdminFlags.Admin)]
public class GodModeCommand : IClientCommand
public class GodModeCommand : IConsoleCommand
{
public string Command => "godmode";
public string Description => "Makes your entity or another invulnerable to almost anything. May have irreversible changes.";
public string Help => $"Usage: {Command} / {Command} <entityUid>";
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
IEntity entity;
switch (args.Length)
@@ -27,13 +28,13 @@ namespace Content.Server.Commands.Damage
case 0:
if (player == null)
{
shell.SendText(player, "An entity needs to be specified when the command isn't used by a player.");
shell.WriteLine("An entity needs to be specified when the command isn't used by a player.");
return;
}
if (player.AttachedEntity == null)
{
shell.SendText(player, "An entity needs to be specified when you aren't attached to an entity.");
shell.WriteLine("An entity needs to be specified when you aren't attached to an entity.");
return;
}
@@ -42,28 +43,28 @@ namespace Content.Server.Commands.Damage
case 1:
if (!EntityUid.TryParse(args[0], out var id))
{
shell.SendText(player, $"{args[0]} isn't a valid entity id.");
shell.WriteLine($"{args[0]} isn't a valid entity id.");
return;
}
var entityManager = IoCManager.Resolve<IEntityManager>();
if (!entityManager.TryGetEntity(id, out var parsedEntity))
{
shell.SendText(player, $"No entity found with id {id}.");
shell.WriteLine($"No entity found with id {id}.");
return;
}
entity = parsedEntity;
break;
default:
shell.SendText(player, Help);
shell.WriteLine(Help);
return;
}
var godmodeSystem = EntitySystem.Get<GodmodeSystem>();
var enabled = godmodeSystem.ToggleGodmode(entity);
shell.SendText(player, enabled
shell.WriteLine(enabled
? $"Enabled godmode for entity {entity.Name} with id {entity.Uid}"
: $"Disabled godmode for entity {entity.Name} with id {entity.Uid}");
}

View File

@@ -1,8 +1,9 @@
#nullable enable
#nullable enable
using Content.Server.Administration;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
namespace Content.Server.Commands.Damage
{
@@ -13,15 +14,16 @@ namespace Content.Server.Commands.Damage
public override string Description => "Removes a damage flag from your entity or another.";
public override string Help => $"Usage: {Command} <flag> / {Command} <entityUid> <flag>";
public override void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
if (!TryGetEntity(shell, player, args, false, out var entity, out var flag, out var damageable))
{
return;
}
damageable.RemoveFlag(flag);
shell.SendText(player, $"Removed damage flag {flag} from entity {entity.Name}");
shell.WriteLine($"Removed damage flag {flag} from entity {entity.Name}");
}
}
}