From ea7d72ab4aa7b8f84c34be67521fd28e1c0e133f Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sun, 26 Feb 2017 20:08:25 +0000 Subject: [PATCH] Create initial message sending framework --- PixelHub-Server/PixelHub/PixelBot.cs | 4 +++- PixelHub-Server/PixelHub/PixelCommand.cs | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/PixelHub-Server/PixelHub/PixelBot.cs b/PixelHub-Server/PixelHub/PixelBot.cs index 778cc36..a20d11a 100644 --- a/PixelHub-Server/PixelHub/PixelBot.cs +++ b/PixelHub-Server/PixelHub/PixelBot.cs @@ -56,7 +56,9 @@ namespace PixelHub.Server /// The command to send. public async Task Send(PixelCommand command) { - await outgoing.WriteLineAsync(command.AsCompiledCommand()); + byte[] message = command.AsCompiledCommand(); + await client.GetStream().WriteAsync(message, 0, message.Length); + await client.GetStream().FlushAsync(); } } } diff --git a/PixelHub-Server/PixelHub/PixelCommand.cs b/PixelHub-Server/PixelHub/PixelCommand.cs index 719be9e..e240263 100644 --- a/PixelHub-Server/PixelHub/PixelCommand.cs +++ b/PixelHub-Server/PixelHub/PixelCommand.cs @@ -34,8 +34,13 @@ namespace PixelHub /// /// Specifies a single command that is to be sent to a PixelBot. /// - public class PixelCommand + public abstract class PixelCommand { + /// + /// A random number generator. Useful for generating default message ids. + /// + private static Random rand = new Random(); + /// /// The protocol version that this message is written in. /// @@ -57,5 +62,21 @@ namespace PixelHub /// public uint MessageLength = 0; + /// + /// The payload of the message. + /// + public abstract byte[] Payload { get; } + + public PixelCommand() + { + byte[] rawMessageId = new byte[sizeof(uint)]; + rand.NextBytes(rawMessageId); + MessageId = BitConverter.ToUInt32(rawMessageId, 0); + } + + public byte[] AsCompiledCommand() + { + throw new NotImplementedException(); + } } } \ No newline at end of file