BattleNet.RealmServer.BuildPacket C# (CSharp) Method

BuildPacket() public method

public BuildPacket ( byte command ) : byte[]
command byte
return byte[]
        public override byte[] BuildPacket(byte command, params IEnumerable<byte>[] args)
        {
            List<byte> packet = new List<byte>();

            List<byte> packetArray = new List<byte>();
            foreach (IEnumerable<byte> a in args)
            {
                packetArray.AddRange(a);
            }

            UInt16 arrayCount = (UInt16)(packetArray.Count + 3);
            packet.AddRange(BitConverter.GetBytes(arrayCount));
            packet.Add((byte)command);
            packet.AddRange(packetArray);

            byte[] bytes = new byte[arrayCount];
            packet.CopyTo(bytes);
            return bytes;
        }

Usage Example

 // MCP Functions
 public void JoinGame()
 {
     m_mcp.Write(m_mcp.BuildPacket(0x04, BitConverter.GetBytes(GameRequestId), System.Text.Encoding.ASCII.GetBytes(GameName), GenericServer.zero, System.Text.Encoding.ASCII.GetBytes(GamePassword), GenericServer.zero));
 }