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.
- Listed in Global namespace: C to D
- Nested types
ReceivedMessage
Constructors
| Member | What it is |
|---|---|
ClientCommandHandler(Socket socketToClient, UserInfoWithPermissions userInfo) | Creates a ClientCommandHandler from socketToClient and userInfo. |
Fields
9 private and internal fields
| Member | What it is |
|---|---|
private Dictionary<RemoteConsoleCommandType, HandleCommand> commandHandlers | Handlers by command type: console command and mod upload are added in the constructor. |
private ClientCommandHandler.ReceivedMessage currentMessage | The message being read from the socket, reused for each message. |
private bool hasClosed | Set by Close to stop the receive loop. |
private static Logger logger | NLog logger for this class. |
private byte[] receiveBuffer | Buffer for raw socket reads. |
private Thread receiveThread | Background thread running ReceiveConsoleInput. |
private byte[] sendBuffer | Buffer for outgoing log messages. |
private Socket socketToClient | The remote console client's socket. |
private UserInfoWithPermissions userInfo | The connected user and their permissions, used in logs. |
Events
| Member | What it is |
|---|---|
event Action Disconnected | Raised when the remote console connection closes. |
Methods
| Member | What 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
| Member | What 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: