Пример #1
0
        public PrecompiledPacket(List <PacketFromServer> packets)
        {
            if (packets.Count == 0)
            {
                throw new ArgumentException("Empty list");
            }

            using (var ms = new MemoryStream())
                using (var w = new EndianBinaryWriter(EndianBitConverter.Big, ms))
                {
                    foreach (var m in packets)
                    {
                        //Buffer to memory stream
                        if (m.PacketBuffer == null)
                        {
                            m.Prepare();
                        }
                        Packet.WriteVarInt(w, m.PacketBuffer.Length);
                        w.Write(m.PacketBuffer);
                    }
                    w.Flush();
                    SetPacketBuffer(ms.ToArray());
                }
            if (PacketBuffer.Length == 0)
            {
                throw new ArgumentException("Empty compiled packet");
            }
        }
 public void Add(PacketFromServer m)
 {
     //Buffer to memory stream
     if (m.PacketBuffer == null)
     {
         m.Prepare();
     }
     Packet.WriteVarInt(w, m.PacketBuffer.Length);
     w.Write(m.PacketBuffer, 0, m.PacketBuffer.Length);
 }