Skip to main content

ServerConsoleManager

A class in Root.Township, the global namespace.

Singleton that runs the server's admin consoles: a local console window and the remote TCP and WebSocket consoles. It only starts them when the logged-in account has the debug_features permission.

Constructors​

MemberWhat it is
ServerConsoleManager()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

6 private and internal fields
MemberWhat it is
private ServerConsole consoleThe local console window, if open.
private IKeyBoardTriggerHandler keyboardHandlerHandle for the backquote key registration.
private static Logger loggerNLog logger for this class.
private IRemoteConsole remoteConsoleThe TCP remote console.
private IRemoteConsole remoteConsoleWSThe WebSocket remote console.
private IUnityUpdateMethod updateConsoleUpdate loop registration for UpdateConsole.

Properties​

MemberWhat it is
static HashSet<IRemoteConsoleHandler> ConnectedHandlers { get; }Remote console connections currently open.

Events​

MemberWhat it is
static event Action<UserInfoWithPermissions, IRemoteConsoleHandler> ConsoleConnectedFired with the user and handler when a remote console connects.
static event Action<UserInfoWithPermissions, IRemoteConsoleHandler> ConsoleDisconnectedFired with the user and handler when a remote console disconnects.

Methods​

MemberWhat it is
void StartRemoteConsole()Starts the TCP (ServerRemoteConsole) and WebSocket remote consoles, unless already started.
static async Task<bool> ValidateConsoleToken(JwtSecurityToken token)Checks a remote console's JWT. As decompiled, it returns false whenever a server is running (with or without a server_id claim) and true only when none is.
protected override void Awake()Checks permissions now if logged in, and again whenever the login changes.
12 private and internal methods
MemberWhat it is
private void CheckForConsoleStart(Key key)Backquote key handler: opens the local console window if the account has debug_features.
private void CheckPermissions()If the account has debug_features, opens the local console when /console is on the command line, registers the backquote key and starts the remote consoles.
private void CloseConsole(IRemoteConsole console)Closes one remote console and unhooks its events.
private void HandleConsoleConnected(UserInfoWithPermissions user, IRemoteConsoleHandler remoteConsole)Adds the handler to ConnectedHandlers and raises ConsoleConnected.
private void HandleConsoleDisconnected(UserInfoWithPermissions user, IRemoteConsoleHandler remoteConsole)Removes the handler from ConnectedHandlers and raises ConsoleDisconnected.
private async void HandleInput(string command)Runs a line typed in the local console through CommandService and logs the result.
private void OnApplicationQuit()Shuts down all consoles.
private void OnDestroy()Shuts down all consoles.
private void ShutdownConsole()Closes the remote consoles, shuts the local console window and stops its update.
private void StartNewConsole(IRemoteConsole console)Starts a remote console and hooks its connect and disconnect events.
private void StartUp()Opens the local console window, feeds it the server log and registers its input processing on the update loop.
private void UpdateConsole()Processes queued input from the local console each frame.