mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Add AnyCommandExecuted callback to IConsoleHost.
Intended use case here is for content to listen to ConCmds for AFK detection.
This commit is contained in:
@@ -83,6 +83,8 @@ namespace Robust.Client.Console
|
||||
OutputText(text, true, true);
|
||||
}
|
||||
|
||||
public override event ConAnyCommandCallback? AnyCommandExecuted;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ExecuteCommand(ICommonSession? session, string command)
|
||||
{
|
||||
@@ -103,7 +105,11 @@ namespace Robust.Client.Console
|
||||
{
|
||||
var command1 = AvailableCommands[commandName];
|
||||
args.RemoveAt(0);
|
||||
command1.Execute(new ConsoleShell(this, null), command, args.ToArray());
|
||||
var shell = new ConsoleShell(this, null);
|
||||
var cmdArgs = args.ToArray();
|
||||
|
||||
AnyCommandExecuted?.Invoke(shell, commandName, command, cmdArgs);
|
||||
command1.Execute(shell, command, cmdArgs);
|
||||
}
|
||||
else
|
||||
WriteError(null, "Unknown command: " + commandName);
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace Robust.Server.Console
|
||||
[Dependency] private readonly IPlayerManager _players = default!;
|
||||
[Dependency] private readonly ISystemConsoleManager _systemConsole = default!;
|
||||
|
||||
public override event ConAnyCommandCallback? AnyCommandExecuted;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ExecuteCommand(ICommonSession? session, string command)
|
||||
{
|
||||
@@ -87,20 +89,22 @@ namespace Robust.Server.Console
|
||||
|
||||
if (AvailableCommands.TryGetValue(cmdName, out var conCmd)) // command registered
|
||||
{
|
||||
args.RemoveAt(0);
|
||||
var cmdArgs = args.ToArray();
|
||||
if (shell.Player != null) // remote client
|
||||
{
|
||||
if (_groupController.CanCommand((IPlayerSession) shell.Player, cmdName)) // client has permission
|
||||
{
|
||||
args.RemoveAt(0);
|
||||
conCmd.Execute(shell, command, args.ToArray());
|
||||
AnyCommandExecuted?.Invoke(shell, cmdName, command, cmdArgs);
|
||||
conCmd.Execute(shell, command, cmdArgs);
|
||||
}
|
||||
else
|
||||
shell.WriteError($"Unknown command: '{cmdName}'");
|
||||
}
|
||||
else // system console
|
||||
{
|
||||
args.RemoveAt(0);
|
||||
conCmd.Execute(shell, command, args.ToArray());
|
||||
AnyCommandExecuted?.Invoke(shell, cmdName, command, cmdArgs);
|
||||
conCmd.Execute(shell, command, cmdArgs);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -30,6 +30,8 @@ namespace Robust.Shared.Console
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyDictionary<string, IConsoleCommand> RegisteredCommands => AvailableCommands;
|
||||
|
||||
public abstract event ConAnyCommandCallback? AnyCommandExecuted;
|
||||
|
||||
protected ConsoleHost()
|
||||
{
|
||||
LocalShell = new ConsoleShell(this, null);
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace Robust.Shared.Console
|
||||
/// <param name="args">An array of all the parsed arguments.</param>
|
||||
public delegate void ConCommandCallback(IConsoleShell shell, string argStr, string[] args);
|
||||
|
||||
public delegate void ConAnyCommandCallback(IConsoleShell shell, string commandName, string argStr, string[] args);
|
||||
|
||||
/// <summary>
|
||||
/// The console host exists as a singleton subsystem that provides all of the features of the console API.
|
||||
/// It will register console commands, spawn console shells and execute command strings.
|
||||
@@ -38,7 +40,10 @@ namespace Robust.Shared.Console
|
||||
/// </summary>
|
||||
IReadOnlyDictionary<string, IConsoleCommand> RegisteredCommands { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Invoked before any console command is executed.
|
||||
/// </summary>
|
||||
event ConAnyCommandCallback AnyCommandExecuted;
|
||||
event EventHandler ClearText;
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user