using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Robust.Shared.Player;
using Robust.Shared.Reflection;
using Robust.Shared.Utility;
namespace Robust.Shared.Console
{
///
/// A delegate that is called when the command is executed inside a shell.
///
/// The console shell that executed this command.
/// Unparsed text of the complete command with arguments.
/// An array of all the parsed arguments.
public delegate void ConCommandCallback(IConsoleShell shell, string argStr, string[] args);
///
/// Called to fetch completions for a console command. See for details.
///
public delegate CompletionResult ConCommandCompletionCallback(IConsoleShell shell, string[] args);
///
/// Called to fetch completions for a console command (async). See for details.
///
public delegate ValueTask ConCommandCompletionAsyncCallback(IConsoleShell shell, string[] args, string argStr);
public delegate void ConAnyCommandCallback(IConsoleShell shell, string commandName, string argStr, string[] args);
///
/// 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.
///
[NotContentImplementable]
public interface IConsoleHost
{
///
/// Is the shell running on the client?
///
bool IsClient => !IsServer;
///
/// Is the shell running on the server?
///
bool IsServer { get; }
///
/// The local shell of the peer that is always available.
///
IConsoleShell LocalShell { get; }
///
/// A map of (commandName -> ICommand) of every registered command in the shell.
///
IReadOnlyDictionary AvailableCommands { get; }
///
/// Invoked before any console command is executed.
///
event ConAnyCommandCallback AnyCommandExecuted;
event EventHandler ClearText;
///
/// Scans all loaded assemblies for console commands and registers them. This will NOT sync with connected clients, and
/// should only be used during server initialization.
///
void LoadConsoleCommands();
///
/// Check whether a console command is hidden.
///
///
bool IsCommandHidden(IConsoleCommand command);
#region RegisterCommand
///
/// Registers a console command into the console system. This is an alternative to
/// creating an class.
///
/// A string as identifier for this command.
/// Short one sentence description of the command.
/// Command format string.
///
/// Callback to invoke when this command is executed.
///
void RegisterCommand(
string command,
string description,
string help,
ConCommandCallback callback,
bool requireServerOrSingleplayer = false);
///
/// Registers a console command into the console system. This is an alternative to
/// creating an class.
///
/// A string as identifier for this command.
/// Short one sentence description of the command.
/// Command format string.
///
/// Callback to invoke when this command is executed.
///
///
/// Callback to fetch completions with.
///
void RegisterCommand(
string command,
string description,
string help,
ConCommandCallback callback,
ConCommandCompletionCallback completionCallback,
bool requireServerOrSingleplayer = false);
///
/// Registers a console command into the console system. This is an alternative to
/// creating an class.
///
/// A string as identifier for this command.
/// Short one sentence description of the command.
/// Command format string.
///
/// Callback to invoke when this command is executed.
///
///
/// Callback to fetch completions with (async variant).
///
void RegisterCommand(
string command,
string description,
string help,
ConCommandCallback callback,
ConCommandCompletionAsyncCallback completionCallback,
bool requireServerOrSingleplayer = false);
///
/// Registers a console command into the console system. This is an alternative to creating an class. This override will try to automatically resolve localized help & description
/// strings based on the command name.
///
/// A string as identifier for this command.
///
/// Callback to invoke when this command is executed.
///
void RegisterCommand(
string command,
ConCommandCallback callback,
bool requireServerOrSingleplayer = false);
///
/// Registers a console command into the console system. This is an alternative to creating an class. This override will try to automatically resolve localized help & description
/// strings based on the command name.
///
/// A string as identifier for this command.
///
/// Callback to invoke when this command is executed.
///
///
/// Callback to fetch completions with.
///
void RegisterCommand(
string command,
ConCommandCallback callback,
ConCommandCompletionCallback completionCallback,
bool requireServerOrSingleplayer = false);
///
/// Registers a console command into the console system. This is an alternative to creating an class. This override will try to automatically resolve localized help & description
/// strings based on the command name.
///
/// A string as identifier for this command.
///
/// Callback to invoke when this command is executed.
///
///
/// Callback to fetch completions with (async variant).
///
void RegisterCommand(
string command,
ConCommandCallback callback,
ConCommandCompletionAsyncCallback completionCallback,
bool requireServerOrSingleplayer = false);
///
/// Register an existing console command instance directly.
///
///
/// For this to be useful, the command has to be somehow excluded from automatic registration,
/// such as by using the .
///
/// The command to register.
///
void RegisterCommand(IConsoleCommand command);
///
/// Begin a region for registering many console commands in one go.
/// The region can be ended with .
///
///
/// Commands registered inside this region temporarily suppress some updating
/// logic that would cause significant wasted work. This logic runs when the region is ended instead.
///
void BeginRegistrationRegion();
///
/// End a registration region started with .
///
void EndRegistrationRegion();
#endregion
///
/// Unregisters a console command that has been registered previously with .
/// If the specified command was registered automatically or isn't registered at all, the method will throw.
///
/// The string identifier for the command.
void UnregisterCommand(string command);
///
/// Returns the console shell for a given active session.
///
///
/// On the client this will always return the local shell, on the server this will return the shell of the active
/// session.
///
/// Session to get the shell of.
/// Shell of the specified session.
IConsoleShell GetSessionShell(ICommonSession session);
///
/// Execute a command string immediately on the local shell, bypassing the command buffer completely.
///
/// Command string to execute.
void ExecuteCommand(string command);
///
/// Appends a command into the end of the command buffer on the local shell.
///
///
/// This command will be ran *sometime* in the future, depending on how many waits are in the buffer.
///
/// Command string to execute.
void AppendCommand(string command);
///
/// Inserts a command into the front of the command buffer on the local shell.
///
///
/// This command will preempt the next command executed in the command buffer.
///
/// Command string to execute.
void InsertCommand(string command);
///
/// Processes any contents of the command buffer on the local shell. This needs to be called regularly (once a tick),
/// inside the simulation. Pausing the server should prevent the buffer from being processed.
///
void CommandBufferExecute();
///
/// Executes a command string on this specific session shell. If the command does not exist, the command will be forwarded
/// to the
/// remote shell.
///
/// Session of the client to execute the command.
/// command line string to execute.
void ExecuteCommand(ICommonSession? session, string command);
///
/// Executes the command string on the remote peer. This is mainly used to forward commands from the client to the server.
/// If there is no remote peer (this is a local shell), this function does nothing.
///
/// Session of the remote peer to execute the command on.
/// Command line string to execute at the remote endpoint.
void RemoteExecuteCommand(ICommonSession? session, string command);
///
/// Sends a text string to the remote session.
///
///
/// Remote session to send the text message to. If this is null, the text is sent to the local
/// console.
///
/// Text message to send.
void WriteLine(ICommonSession? session, string text);
void WriteLine(ICommonSession? session, FormattedMessage msg);
///
/// Sends a foreground colored text string to the remote session.
///
///
/// Remote session to send the text message to. If this is null, the text is sent to the local
/// console.
///
/// Text message to send.
void WriteError(ICommonSession? session, string text);
///
/// Removes all text from the local console.
///
void ClearLocalConsole();
}
internal interface IConsoleHostInternal : IConsoleHost
{
///
/// Is this command executed on the server?
/// Always true when ran from server, true for server-proxy commands on the client.
///
bool IsCmdServer(IConsoleCommand cmd);
}
}