Create initial message sending framework
This commit is contained in:
parent
f90e689097
commit
ea7d72ab4a
2 changed files with 25 additions and 2 deletions
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in a new issue