Browse Source

Create initial message sending framework

master
Starbeamrainbowlabs 4 years ago
parent
commit
ea7d72ab4a
2 changed files with 25 additions and 2 deletions
  1. +3
    -1
      PixelHub-Server/PixelHub/PixelBot.cs
  2. +22
    -1
      PixelHub-Server/PixelHub/PixelCommand.cs

+ 3
- 1
PixelHub-Server/PixelHub/PixelBot.cs View File

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


+ 22
- 1
PixelHub-Server/PixelHub/PixelCommand.cs View File

@ -34,8 +34,13 @@ namespace PixelHub
/// <summary>
/// Specifies a single command that is to be sent to a PixelBot.
/// </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>
/// The protocol version that this message is written in.
/// </summary>
@ -57,5 +62,21 @@ namespace PixelHub
/// </summary>
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();
}
}
}