Browse Source

[server] Finish filling in PixelCommand.AsCompiledCommand()

master
Starbeamrainbowlabs 4 years ago
parent
commit
0c669012b6
2 changed files with 21 additions and 0 deletions
  1. +20
    -0
      PixelHub-Server/PixelHub/PixelCommand.cs
  2. +1
    -0
      PixelHub-Server/PixelHub/PixelHub.csproj

+ 20
- 0
PixelHub-Server/PixelHub/PixelCommand.cs View File

@ -73,7 +73,20 @@ namespace PixelHub
public byte[] Header
{
get {
byte[] result = new byte[HeaderSize];
// Fetch all the components needed to build the message header and convert them to byte arrays
byte[] rawProtocolVersion = BitConverter.GetBytes(ProtocolVersion);
byte[] rawMessageType = BitConverter.GetBytes((ushort)MessageType);
byte[] rawMessageId = BitConverter.GetBytes((ushort)MessageId);
byte[] rawMessageLength = BitConverter.GetBytes(Payload.Length);
// Copy the pieces into the correct places
Buffer.BlockCopy(rawProtocolVersion, 0, result, 0, rawProtocolVersion.Length);
Buffer.BlockCopy(rawMessageType, 0, result, 2, rawProtocolVersion.Length);
Buffer.BlockCopy(rawMessageId, 0, result, 4, rawProtocolVersion.Length);
Buffer.BlockCopy(rawMessageLength, 0, result, 8, rawProtocolVersion.Length);
return result;
}
}
@ -89,9 +102,16 @@ namespace PixelHub
MessageId = BitConverter.ToUInt32(rawMessageId, 0);
}
/// <summary>
/// Returns this message in it's raw format that's sent and received over the wire.
/// </summary>
/// <returns>This message, as a byte array.</returns>
public byte[] AsCompiledCommand()
{
byte[] message = new byte[HeaderSize + Payload.Length];
Buffer.BlockCopy(Header, 0, message, 0, HeaderSize);
Buffer.BlockCopy(Payload, 0, message, HeaderSize, Payload.Length);
return message;
}
}
}

+ 1
- 0
PixelHub-Server/PixelHub/PixelHub.csproj View File

@ -44,6 +44,7 @@
<Compile Include="PixelBot.cs" />
<Compile Include="NetTools.cs" />
<Compile Include="PixelCommands\ResetCommand.cs" />
<Compile Include="PixelCommands\HandshakeRequestCommand.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>