2using System.Collections.Generic;
3using System.Net.Sockets;
5using System.Threading.Tasks;
54 Func<BadNetworkConsoleClient, IBadNetworkConsoleClientCommandParser> parserFactory)
83 Func<BadNetworkConsoleClient, IBadNetworkConsoleClientCommandParser> parserFactory)
171 Console.WriteLine(wp.Message);
175 Console.Write(wp.Message);
179 Console.BackgroundColor = cs.
Color;
183 Console.ForegroundColor = cs.
Color;
206 byte[] len =
new byte[
sizeof(int)];
207 NetworkStream stream =
m_Client.GetStream();
208 int read = stream.Read(len, 0, len.Length);
210 if (read != len.Length)
215 byte[] packet =
new byte[BitConverter.ToInt32(len, 0)];
216 read = stream.Read(packet, 0, packet.Length);
218 if (read != packet.Length)
236 NetworkStream str =
m_Client.GetStream();
237 List<byte> packetData =
new List<byte>();
239 packetData.AddRange(BitConverter.GetBytes(packetBytes.Length));
240 packetData.AddRange(packetBytes);
241 str.Write(packetData.ToArray(), 0, packetData.Count);
251 List<byte> packet =
new List<byte>();
252 packet.AddRange(BitConverter.GetBytes(packetData.Length));
253 packet.AddRange(packetData);
256 .Write(packet.ToArray(), 0, packet.Count);
264 DateTime lastHeartBeat = DateTime.Now;
268 Task<string> task = Task.Run(Console.ReadLine);
275 lastHeartBeat = DateTime.Now;
286 string message = task.Result ??
"client::disconnect";
288 if (message.StartsWith(
"client::"))
290 string cmd = message.Substring(
"client::".Length);
296 lastHeartBeat = DateTime.Now;
298 List<byte> packet =
new List<byte>();
299 packet.AddRange(BitConverter.GetBytes(packetData.Length));
300 packet.AddRange(packetData);
303 .Write(packet.ToArray(), 0, packet.Count);
Wrapper class for the console abstraction.
static void WriteLine(string str)
Writes a string to the console and appends a newline.
Exception that is thrown when the remote console encounters an error.
The Default Command Parser for the Remote Console Client.
void AddCommand(Func< BadNetworkConsoleClient, BadNetworkConsoleClientCommand > command)
Adds a Command to the Command List.
Implements the Client for the Remote Console.
bool m_ExitRequested
If true the client will exit.
static int ConsoleReadInputSleep
The Interval in which packets are read from the server.
readonly string m_Address
The Address of the Remote Console.
Thread? m_ReadThread
The Read Thread.
void ProcessPacket(BadConsolePacket packet)
Processes the given Packet.
readonly int m_Port
The Port of the Remote Console.
void Start()
Starts the Client.
static IBadNetworkConsoleClientCommandParser DefaultParserFactory(BadNetworkConsoleClient client)
The Default Parser Factory.
readonly IBadNetworkConsoleClientCommandParser m_Parser
The Parser.
static int ConsoleWriteSleep
The Interval in which packets are sent to the server.
BadNetworkConsoleClient(TcpClient client, Func< BadNetworkConsoleClient, IBadNetworkConsoleClientCommandParser > parserFactory)
Creates a new Client from the given TcpClient.
void Stop()
Stops the Client.
static int HeartBeatSendInterval
The Interval in which the Heartbeat is sent.
void Write()
The Write Thread.
BadNetworkConsoleClient(string address, int port, Func< BadNetworkConsoleClient, IBadNetworkConsoleClientCommandParser > parserFactory)
Creates a new Client from the given Address and Port.
BadNetworkConsoleClient(string address, int port)
Creates a new Client from the given Address and Port.
BadNetworkConsoleClient(TcpClient client)
Creates a new Client from the given TcpClient.
readonly TcpClient m_Client
The TCP Client.
void Read()
The Read Thread.
void SendHeartBeat()
Sends a Heartbeat to the Server.
Commands that disconnects the client from the server.
Command that lists all commands available to the user.
Gets used to clear the console on the client.
Gets used to change the color of the console.
ConsoleColor Color
The Color to change to.
Gets used to disconnect the client and the server.
override byte[] Serialize()
static readonly BadConsoleDisconnectPacket Packet
Static Instance of this Packet.
Gets used to send a HeartBeat to the client.
static readonly BadConsoleHeartBeatPacket Packet
Static Instance of this Packet.
override byte[] Serialize()
Gets used as handshake between the client and the server.
int HeartBeatInterval
The Heartbeat interval that the server uses.
Implements the base class for all BadConsole Packets.
static BadConsolePacket Deserialize(byte[] data)
Deserializes a BadConsolePacket from the given data.
Gets used to send a Read Result to the server.
override byte[] Serialize()
Gets sent to the client to write a message to the console.
Used to parse commands on the client.
void ExecuteCommand(string command)
Executes a command on the client.
Contains Console Commands for the Remote Console Client.
Contains the Console Client Implementation for the Remote Console Abstraction over TCP.
Contains the network packets for the remote console.