Skip to main content

ClientCommandHandler

A class in Root.Township, the global namespace.

Server side handler for one remote console connection: reads framed commands from the socket on its own thread, runs console commands and streams log output back. Created by ClientHandler.

Constructors​

MemberWhat it is
ClientCommandHandler(Socket socketToClient, UserInfoWithPermissions userInfo)Creates a ClientCommandHandler from socketToClient and userInfo.

Fields​

9 private and internal fields
MemberWhat it is
private Dictionary<RemoteConsoleCommandType, HandleCommand> commandHandlersHandlers by command type: console command and mod upload are added in the constructor.
private ClientCommandHandler.ReceivedMessage currentMessageThe message being read from the socket, reused for each message.
private bool hasClosedSet by Close to stop the receive loop.
private static Logger loggerNLog logger for this class.
private byte[] receiveBufferBuffer for raw socket reads.
private Thread receiveThreadBackground thread running ReceiveConsoleInput.
private byte[] sendBufferBuffer for outgoing log messages.
private Socket socketToClientThe remote console client's socket.
private UserInfoWithPermissions userInfoThe connected user and their permissions, used in logs.

Events​

MemberWhat it is
event Action DisconnectedRaised when the remote console connection closes.

Methods​

MemberWhat it is
void AddHandler(RemoteConsoleCommandType type, HandleCommand handler)Registers the handler for a remote console command type.
void Close()Stops receiving, unhooks the log stream and closes the socket.
8 private and internal methods
MemberWhat it is
private void EndSend(IAsyncResult result)Completes an async socket send.
private void Handle(int size, byte messageType, byte[] data)Looks up and runs the handler for a received message type; logs an error for unknown types.
private void HandleConsoleCommand(byte[] buffer, int received)Decodes a command string and runs it through CommandService on the main thread.
private void HandleConsoleLog(LogEventInfo logInfo)Serialises a log event and sends it to the remote console.
private void HandleModUpload(byte[] buffer, int received)Writes uploaded C# text to UploadedMod.cs in the mods folder.
private void HandleReceivedCommand(byte[] data, int packetLength)Feeds received bytes into the current message and processes each complete message.
private void ReceiveConsoleInput()Receive loop run on receiveThread; ends when the socket closes, then raises Disconnected.
private void SendBuffer(RemoteConsoleResponseType type, int length)Writes the length and response type header into sendBuffer and sends it.

Used in​

Members of other types that take, return or hold a ClientCommandHandler: