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

@@ -3,51 +3,51 @@ using Content.Server.Administration;
using Content.Server.GameTicking;
using Content.Server.Interfaces.GameTicking;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
using Robust.Shared.IoC;
namespace Content.Server.Commands.GameTicking
{
[AdminCommand(AdminFlags.Server)]
class DelayStartCommand : IClientCommand
class DelayStartCommand : IConsoleCommand
{
public string Command => "delaystart";
public string Description => "Delays the round start.";
public string Help => $"Usage: {Command} <seconds>\nPauses/Resumes the countdown if no argument is provided.";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var ticker = IoCManager.Resolve<IGameTicker>();
if (ticker.RunLevel != GameRunLevel.PreRoundLobby)
{
shell.SendText(player, "This can only be executed while the game is in the pre-round lobby.");
shell.WriteLine("This can only be executed while the game is in the pre-round lobby.");
return;
}
if (args.Length == 0)
{
var paused = ticker.TogglePause();
shell.SendText(player, paused ? "Paused the countdown." : "Resumed the countdown.");
shell.WriteLine(paused ? "Paused the countdown." : "Resumed the countdown.");
return;
}
if (args.Length != 1)
{
shell.SendText(player, "Need zero or one arguments.");
shell.WriteLine("Need zero or one arguments.");
return;
}
if (!uint.TryParse(args[0], out var seconds) || seconds == 0)
{
shell.SendText(player, $"{args[0]} isn't a valid amount of seconds.");
shell.WriteLine($"{args[0]} isn't a valid amount of seconds.");
return;
}
var time = TimeSpan.FromSeconds(seconds);
if (!ticker.DelayStart(time))
{
shell.SendText(player, "An unknown error has occurred.");
shell.WriteLine("An unknown error has occurred.");
}
}
}

View File

@@ -3,26 +3,26 @@ using Content.Server.Administration;
using Content.Server.GameTicking;
using Content.Server.Interfaces.GameTicking;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
using Robust.Shared.IoC;
namespace Content.Server.Commands.GameTicking
{
[AdminCommand(AdminFlags.Server)]
class EndRoundCommand : IClientCommand
class EndRoundCommand : IConsoleCommand
{
public string Command => "endround";
public string Description => "Ends the round and moves the server to PostRound.";
public string Help => String.Empty;
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var ticker = IoCManager.Resolve<IGameTicker>();
if (ticker.RunLevel != GameRunLevel.InRound)
{
shell.SendText(player, "This can only be executed while the game is in a round.");
shell.WriteLine("This can only be executed while the game is in a round.");
return;
}

View File

@@ -2,43 +2,43 @@
using Content.Server.GameTicking;
using Content.Server.Interfaces.GameTicking;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
using Robust.Shared.IoC;
namespace Content.Server.Commands.GameTicking
{
[AdminCommand(AdminFlags.Server)]
class ForcePresetCommand : IClientCommand
class ForcePresetCommand : IConsoleCommand
{
public string Command => "forcepreset";
public string Description => "Forces a specific game preset to start for the current lobby.";
public string Help => $"Usage: {Command} <preset>";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var ticker = IoCManager.Resolve<IGameTicker>();
if (ticker.RunLevel != GameRunLevel.PreRoundLobby)
{
shell.SendText(player, "This can only be executed while the game is in the pre-round lobby.");
shell.WriteLine("This can only be executed while the game is in the pre-round lobby.");
return;
}
if (args.Length != 1)
{
shell.SendText(player, "Need exactly one argument.");
shell.WriteLine("Need exactly one argument.");
return;
}
var name = args[0];
if (!ticker.TryGetPreset(name, out var type))
{
shell.SendText(player, $"No preset exists with name {name}.");
shell.WriteLine($"No preset exists with name {name}.");
return;
}
ticker.SetStartPreset(type, true);
shell.SendText(player, $"Forced the game to start with preset {name}.");
shell.WriteLine($"Forced the game to start with preset {name}.");
}
}
}

View File

@@ -4,8 +4,8 @@ using Content.Server.Administration;
using Content.Server.Interfaces.GameTicking;
using Content.Shared;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
using Robust.Shared.Interfaces.Configuration;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
@@ -13,12 +13,12 @@ using Robust.Shared.Localization;
namespace Content.Server.Commands.GameTicking
{
[AdminCommand(AdminFlags.Server)]
public class GoLobbyCommand : IClientCommand
public class GoLobbyCommand : IConsoleCommand
{
public string Command => "golobby";
public string Description => "Enables the lobby and restarts the round.";
public string Help => $"Usage: {Command} / {Command} <preset>";
public void Execute(IConsoleShell shell, IPlayerSession? player, string[] args)
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
Type? preset = null;
var presetName = string.Join(" ", args);
@@ -29,7 +29,7 @@ namespace Content.Server.Commands.GameTicking
{
if (!ticker.TryGetPreset(presetName, out preset))
{
shell.SendText(player, $"No preset found with name {presetName}");
shell.WriteLine($"No preset found with name {presetName}");
return;
}
}
@@ -44,7 +44,7 @@ namespace Content.Server.Commands.GameTicking
ticker.SetStartPreset(preset);
}
shell.SendText(player, $"Enabling the lobby and restarting the round.{(preset == null ? "" : $"\nPreset set to {presetName}")}");
shell.WriteLine($"Enabling the lobby and restarting the round.{(preset == null ? "" : $"\nPreset set to {presetName}")}");
}
}
}

View File

@@ -1,17 +1,17 @@
using System.Collections.Generic;
using System.Collections.Generic;
using Content.Server.Administration;
using Content.Server.GameTicking;
using Content.Server.Interfaces.GameTicking;
using Content.Shared.Roles;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Server.Commands.GameTicking
{
[AnyCommand]
class JoinGameCommand : IClientCommand
class JoinGameCommand : IConsoleCommand
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
@@ -23,8 +23,9 @@ namespace Content.Server.Commands.GameTicking
{
IoCManager.InjectDependencies(this);
}
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
var output = string.Join(".", args);
if (player == null)
{
@@ -34,7 +35,7 @@ namespace Content.Server.Commands.GameTicking
var ticker = IoCManager.Resolve<IGameTicker>();
if (ticker.RunLevel == GameRunLevel.PreRoundLobby)
{
shell.SendText(player, "Round has not started.");
shell.WriteLine("Round has not started.");
return;
}
else if(ticker.RunLevel == GameRunLevel.InRound)
@@ -45,7 +46,7 @@ namespace Content.Server.Commands.GameTicking
if(positions.GetValueOrDefault(ID, 0) == 0) //n < 0 is treated as infinite
{
var jobPrototype = _prototypeManager.Index<JobPrototype>(ID);
shell.SendText(player, $"{jobPrototype.Name} has no available slots.");
shell.WriteLine($"{jobPrototype.Name} has no available slots.");
return;
}
ticker.MakeJoinGame(player, args[0].ToString());
@@ -55,4 +56,4 @@ namespace Content.Server.Commands.GameTicking
ticker.MakeJoinGame(player, null);
}
}
}
}

View File

@@ -1,9 +1,9 @@
using System.Linq;
using System.Linq;
using Content.Server.Administration;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Server.Interfaces.Timing;
using Robust.Shared.Console;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Utility;
@@ -11,17 +11,18 @@ using Robust.Shared.Utility;
namespace Content.Server.Commands.GameTicking
{
[AdminCommand(AdminFlags.Server | AdminFlags.Mapping)]
class MappingCommand : IClientCommand
class MappingCommand : IConsoleCommand
{
public string Command => "mapping";
public string Description => "Creates and teleports you to a new uninitialized map for mapping.";
public string Help => $"Usage: {Command} <mapname> / {Command} <id> <mapname>";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
if (player == null)
{
shell.SendText(player, "Only players can use this command");
shell.WriteLine("Only players can use this command");
return;
}
@@ -34,7 +35,7 @@ namespace Content.Server.Commands.GameTicking
case 1:
if (player.AttachedEntity == null)
{
shell.SendText(player, "The map name argument cannot be omitted if you have no entity.");
shell.WriteLine("The map name argument cannot be omitted if you have no entity.");
return;
}
@@ -44,7 +45,7 @@ namespace Content.Server.Commands.GameTicking
case 2:
if (!int.TryParse(args[0], out var id))
{
shell.SendText(player, $"{args[0]} is not a valid integer.");
shell.WriteLine($"{args[0]} is not a valid integer.");
return;
}
@@ -52,21 +53,21 @@ namespace Content.Server.Commands.GameTicking
mapName = args[1];
break;
default:
shell.SendText(player, Help);
shell.WriteLine(Help);
return;
}
shell.ExecuteCommand(player, $"addmap {mapId} false");
shell.ExecuteCommand(player, $"loadbp {mapId} \"{CommandParsing.Escape(mapName)}\" true");
shell.ExecuteCommand(player, "aghost");
shell.ExecuteCommand(player, $"tp 0 0 {mapId}");
shell.ExecuteCommand($"addmap {mapId} false");
shell.ExecuteCommand($"loadbp {mapId} \"{CommandParsing.Escape(mapName)}\" true");
shell.ExecuteCommand("aghost");
shell.ExecuteCommand($"tp 0 0 {mapId}");
var newGrid = mapManager.GetAllGrids().OrderByDescending(g => (int) g.Index).First();
var pauseManager = IoCManager.Resolve<IPauseManager>();
pauseManager.SetMapPaused(newGrid.ParentMapId, true);
shell.SendText(player, $"Created unloaded map from file {mapName} with id {mapId}. Use \"savebp {newGrid.Index} foo.yml\" to save the new grid as a map.");
shell.WriteLine($"Created unloaded map from file {mapName} with id {mapId}. Use \"savebp {newGrid.Index} foo.yml\" to save the new grid as a map.");
}
}
}

View File

@@ -2,20 +2,20 @@
using Content.Server.Administration;
using Content.Server.Interfaces.GameTicking;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
using Robust.Shared.IoC;
namespace Content.Server.Commands.GameTicking
{
[AdminCommand(AdminFlags.Server)]
public class NewRoundCommand : IClientCommand
public class NewRoundCommand : IConsoleCommand
{
public string Command => "restartround";
public string Description => "Moves the server from PostRound to a new PreRoundLobby.";
public string Help => String.Empty;
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var ticker = IoCManager.Resolve<IGameTicker>();
ticker.RestartRound();

View File

@@ -1,20 +1,21 @@
using Content.Server.Administration;
using Content.Server.Administration;
using Content.Server.Interfaces.GameTicking;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
using Robust.Shared.IoC;
namespace Content.Server.Commands.GameTicking
{
[AnyCommand]
class ObserveCommand : IClientCommand
class ObserveCommand : IConsoleCommand
{
public string Command => "observe";
public string Description => "";
public string Help => "";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
if (player == null)
{
return;
@@ -24,4 +25,4 @@ namespace Content.Server.Commands.GameTicking
ticker.MakeObserve(player);
}
}
}
}

View File

@@ -1,23 +1,24 @@
using Content.Server.Interfaces.GameTicking;
using Content.Server.Interfaces.GameTicking;
using Content.Server.Players;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
using Robust.Shared.IoC;
using Robust.Shared.Network;
namespace Content.Server.Commands.GameTicking
{
class RespawnCommand : IClientCommand
class RespawnCommand : IConsoleCommand
{
public string Command => "respawn";
public string Description => "Respawns a player, kicking them back to the lobby.";
public string Help => "respawn [player]";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
if (args.Length > 1)
{
shell.SendText(player, "Must provide <= 1 argument.");
shell.WriteLine("Must provide <= 1 argument.");
return;
}
@@ -29,7 +30,7 @@ namespace Content.Server.Commands.GameTicking
{
if (player == null)
{
shell.SendText((IPlayerSession)null, "If not a player, an argument must be given.");
shell.WriteLine("If not a player, an argument must be given.");
return;
}
@@ -37,7 +38,7 @@ namespace Content.Server.Commands.GameTicking
}
else if (!playerMgr.TryGetUserId(args[0], out userId))
{
shell.SendText(player, "Unknown player");
shell.WriteLine("Unknown player");
return;
}
@@ -45,17 +46,16 @@ namespace Content.Server.Commands.GameTicking
{
if (!playerMgr.TryGetPlayerData(userId, out var data))
{
shell.SendText(player, "Unknown player");
shell.WriteLine("Unknown player");
return;
}
data.ContentData().WipeMind();
shell.SendText(player,
"Player is not currently online, but they will respawn if they come back online");
shell.WriteLine("Player is not currently online, but they will respawn if they come back online");
return;
}
ticker.Respawn(targetPlayer);
}
}
}
}

View File

@@ -1,24 +1,24 @@
using Content.Server.Administration;
using Content.Server.Interfaces.GameTicking;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
using Robust.Shared.IoC;
namespace Content.Server.Commands.GameTicking
{
[AdminCommand(AdminFlags.Server)]
class SetGamePresetCommand : IClientCommand
class SetGamePresetCommand : IConsoleCommand
{
public string Command => "setgamepreset";
public string Description => "";
public string Help => "";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.SendText(player, "Need exactly one argument.");
shell.WriteLine("Need exactly one argument.");
return;
}

View File

@@ -3,26 +3,26 @@ using Content.Server.Administration;
using Content.Server.GameTicking;
using Content.Server.Interfaces.GameTicking;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
using Robust.Shared.IoC;
namespace Content.Server.Commands.GameTicking
{
[AdminCommand(AdminFlags.Server)]
class StartRoundCommand : IClientCommand
class StartRoundCommand : IConsoleCommand
{
public string Command => "startround";
public string Description => "Ends PreRoundLobby state and starts the round.";
public string Help => String.Empty;
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var ticker = IoCManager.Resolve<IGameTicker>();
if (ticker.RunLevel != GameRunLevel.PreRoundLobby)
{
shell.SendText(player, "This can only be executed while the game is in the pre-round lobby.");
shell.WriteLine("This can only be executed while the game is in the pre-round lobby.");
return;
}

View File

@@ -1,8 +1,8 @@
using Content.Server.Administration;
using Content.Server.Administration;
using Content.Shared.Administration;
using Content.Shared.Maps;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
@@ -12,15 +12,16 @@ using Robust.Shared.Map;
namespace Content.Server.Commands.GameTicking
{
[AdminCommand(AdminFlags.Mapping)]
class TileWallsCommand : IClientCommand
class TileWallsCommand : IConsoleCommand
{
// ReSharper disable once StringLiteralTypo
public string Command => "tilewalls";
public string Description => "Puts an underplating tile below every wall on a grid.";
public string Help => $"Usage: {Command} <gridId> | {Command}";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
GridId gridId;
switch (args.Length)
@@ -28,7 +29,7 @@ namespace Content.Server.Commands.GameTicking
case 0:
if (player?.AttachedEntity == null)
{
shell.SendText((IPlayerSession) null, "Only a player can run this command.");
shell.WriteLine("Only a player can run this command.");
return;
}
@@ -37,28 +38,28 @@ namespace Content.Server.Commands.GameTicking
case 1:
if (!int.TryParse(args[0], out var id))
{
shell.SendText(player, $"{args[0]} is not a valid integer.");
shell.WriteLine($"{args[0]} is not a valid integer.");
return;
}
gridId = new GridId(id);
break;
default:
shell.SendText(player, Help);
shell.WriteLine(Help);
return;
}
var mapManager = IoCManager.Resolve<IMapManager>();
if (!mapManager.TryGetGrid(gridId, out var grid))
{
shell.SendText(player, $"No grid exists with id {gridId}");
shell.WriteLine($"No grid exists with id {gridId}");
return;
}
var entityManager = IoCManager.Resolve<IEntityManager>();
if (!entityManager.TryGetEntity(grid.GridEntityId, out var gridEntity))
{
shell.SendText(player, $"Grid {gridId} doesn't have an associated grid entity.");
shell.WriteLine($"Grid {gridId} doesn't have an associated grid entity.");
return;
}
@@ -106,7 +107,7 @@ namespace Content.Server.Commands.GameTicking
changed++;
}
shell.SendText(player, $"Changed {changed} tiles.");
shell.WriteLine($"Changed {changed} tiles.");
}
}
}

View File

@@ -1,24 +1,24 @@
using Content.Server.Administration;
using Content.Server.Interfaces.GameTicking;
using Content.Shared.Administration;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
using Robust.Shared.IoC;
namespace Content.Server.Commands.GameTicking
{
[AdminCommand(AdminFlags.Server)]
class ToggleDisallowLateJoinCommand : IClientCommand
class ToggleDisallowLateJoinCommand : IConsoleCommand
{
public string Command => "toggledisallowlatejoin";
public string Description => "Allows or disallows latejoining during mid-game.";
public string Help => $"Usage: {Command} <disallow>";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.SendText(player, "Need exactly one argument.");
shell.WriteLine("Need exactly one argument.");
return;
}
@@ -27,11 +27,11 @@ namespace Content.Server.Commands.GameTicking
if (bool.TryParse(args[0], out var result))
{
ticker.ToggleDisallowLateJoin(bool.Parse(args[0]));
shell.SendText(player, result ? "Late joining has been disabled." : "Late joining has been enabled.");
shell.WriteLine(result ? "Late joining has been disabled." : "Late joining has been enabled.");
}
else
{
shell.SendText(player, "Invalid argument.");
shell.WriteLine("Invalid argument.");
}
}
}

View File

@@ -1,20 +1,21 @@
using Content.Server.Administration;
using Content.Server.Administration;
using Content.Server.Interfaces.GameTicking;
using Robust.Server.Interfaces.Console;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Console;
using Robust.Shared.IoC;
namespace Content.Server.Commands.GameTicking
{
[AnyCommand]
class ToggleReadyCommand : IClientCommand
class ToggleReadyCommand : IConsoleCommand
{
public string Command => "toggleready";
public string Description => "";
public string Help => "";
public void Execute(IConsoleShell shell, IPlayerSession player, string[] args)
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var player = shell.Player as IPlayerSession;
if (player == null)
{
return;
@@ -24,4 +25,4 @@ namespace Content.Server.Commands.GameTicking
ticker.ToggleReady(player, bool.Parse(args[0]));
}
}
}
}