Create initial message sending framework

This commit is contained in:
Starbeamrainbowlabs 2017-02-26 20:08:25 +00:00
parent f90e689097
commit ea7d72ab4a
2 changed files with 25 additions and 2 deletions

View file

@ -56,7 +56,9 @@ namespace PixelHub.Server
/// <param name="command">The command to send.</param> /// <param name="command">The command to send.</param>
public async Task Send(PixelCommand command) 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();
} }
} }
} }

View file

@ -34,8 +34,13 @@ namespace PixelHub
/// <summary> /// <summary>
/// Specifies a single command that is to be sent to a PixelBot. /// Specifies a single command that is to be sent to a PixelBot.
/// </summary> /// </summary>
public class PixelCommand public abstract class PixelCommand
{ {
/// <summary>
/// A random number generator. Useful for generating default message ids.
/// </summary>
private static Random rand = new Random();
/// <summary> /// <summary>
/// The protocol version that this message is written in. /// The protocol version that this message is written in.
/// </summary> /// </summary>
@ -57,5 +62,21 @@ namespace PixelHub
/// </summary> /// </summary>
public uint MessageLength = 0; public uint MessageLength = 0;
/// <summary>
/// The payload of the message.
/// </summary>
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();
}
} }
} }