[server] Rename PixelCommand to PixelMessage, along with all associated namespaces. Also add HandshakeRequestMessaage class.

This commit is contained in:
Starbeamrainbowlabs 2017-03-04 12:43:46 +00:00
parent 0c669012b6
commit 007a5beeaf
5 changed files with 39 additions and 10 deletions

View file

@ -54,7 +54,7 @@ namespace PixelHub.Server
/// Sends the given command to the remote PixelBot. /// Sends the given command to the remote PixelBot.
/// </summary> /// </summary>
/// <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(PixelMessage command)
{ {
byte[] message = command.AsCompiledCommand(); byte[] message = command.AsCompiledCommand();
await client.GetStream().WriteAsync(message, 0, message.Length); await client.GetStream().WriteAsync(message, 0, message.Length);

View file

@ -40,15 +40,15 @@
<Compile Include="SBRL.Utilities\ForgetTask.cs" /> <Compile Include="SBRL.Utilities\ForgetTask.cs" />
<Compile Include="SBRL.Utilities\Utilities.cs" /> <Compile Include="SBRL.Utilities\Utilities.cs" />
<Compile Include="SBRL.Utilities\PrefixedWriter.cs" /> <Compile Include="SBRL.Utilities\PrefixedWriter.cs" />
<Compile Include="PixelCommand.cs" />
<Compile Include="PixelBot.cs" /> <Compile Include="PixelBot.cs" />
<Compile Include="NetTools.cs" /> <Compile Include="NetTools.cs" />
<Compile Include="PixelCommands\ResetCommand.cs" /> <Compile Include="PixelMessage.cs" />
<Compile Include="PixelCommands\HandshakeRequestCommand.cs" /> <Compile Include="PixelMessages\HandshakeRequestMessage.cs" />
<Compile Include="PixelMessages\ResetMessage.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>
<Folder Include="SBRL.Utilities\" /> <Folder Include="SBRL.Utilities\" />
<Folder Include="PixelCommands\" /> <Folder Include="PixelMessages\" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -34,7 +34,7 @@ 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 abstract class PixelCommand public abstract class PixelMessage
{ {
/// <summary> /// <summary>
/// A random number generator. Useful for generating default message ids. /// A random number generator. Useful for generating default message ids.
@ -95,7 +95,7 @@ namespace PixelHub
/// </summary> /// </summary>
public abstract byte[] Payload { get; protected set; } public abstract byte[] Payload { get; protected set; }
public PixelCommand() public PixelMessage()
{ {
byte[] rawMessageId = new byte[sizeof(uint)]; byte[] rawMessageId = new byte[sizeof(uint)];
rand.NextBytes(rawMessageId); rand.NextBytes(rawMessageId);

View file

@ -0,0 +1,29 @@
using System;
using System.Text;
namespace PixelHub.Server.PixelMessages
{
public class HandshakeRequestMessage : PixelMessage
{
/// <summary>
/// The type of PixelBot the client thinks it is. Rather like a user-agent string actually.
/// </summary>
public string PixelBotType = string.Empty;
public override byte[] Payload {
get {
return Encoding.UTF8.GetBytes(PixelBotType);
}
protected set {
PixelBotType = Encoding.UTF8.GetString(value);
}
}
public new MessageTypes MessageType { get; private set; } = MessageTypes.HandshakeRequest;
public HandshakeRequestMessage()
{
}
}
}

View file

@ -1,12 +1,12 @@
using System; using System;
namespace PixelHub.Server.PixelCommands namespace PixelHub.Server.PixelMessages
{ {
/// <summary> /// <summary>
/// Hard-resets the PixelBot. Useful if something has gone wrong, or to reset it's internal state. /// Hard-resets the PixelBot. Useful if something has gone wrong, or to reset it's internal state.
/// Note that this will cause the PixelBot to drop it's connection! /// Note that this will cause the PixelBot to drop it's connection!
/// </summary> /// </summary>
public class ResetCommand : PixelCommand public class ResetMessage : PixelMessage
{ {
public override byte[] Payload { public override byte[] Payload {
get { get {
@ -19,7 +19,7 @@ namespace PixelHub.Server.PixelCommands
public new MessageTypes MessageType { get; private set; } = MessageTypes.Reset; public new MessageTypes MessageType { get; private set; } = MessageTypes.Reset;
public ResetCommand() public ResetMessage()
{ {
} }