Esempio n. 1
0
        protected override void ReadBody(ByteReader reader)
        {
            int  count     = reader.ReadByte();
            long totalSize = reader.Length - 2;

            if (totalSize < 1 || count == 0)
            {
                return;
            }

            byte packetSize = reader.ReadByte();

            if (packetSize < 5)
            {
                throw new IOException("Too small packet in batch!");
            }
            byte packetLastID    = reader.ReadByte();
            int  packetLastNetID = reader.ReadInt32();

            byte[] packetData = reader.ReadBytes(packetSize - 5);

            using (var packetWriter = new ByteWriter())
            {
                packetWriter.WriteByte(packetLastID);
                packetWriter.WriteInt32(packetLastNetID);
                packetWriter.WriteBytes(packetData);
                this.Packets.Add(GamePacket.Create(packetWriter.GetBytes()));
            }

            for (int i = 1; i < count; i++)
            {
                byte bitfield = reader.ReadByte();
                if ((bitfield & 1) == 0) //if this is true re-use old packetID
                {
                    packetLastID = reader.ReadByte();
                }
                if ((bitfield & 2) != 0)
                {
                    packetLastNetID += reader.ReadSByte();
                }
                else
                {
                    packetLastNetID = reader.ReadInt32();
                }
                packetSize = (byte)(bitfield >> 2);
                if (packetSize == 63)
                {
                    packetSize = reader.ReadByte();
                }
                packetData = reader.ReadBytes(packetSize);

                using (var packetWriter = new ByteWriter())
                {
                    packetWriter.WriteByte(packetLastID);
                    packetWriter.WriteInt32(packetLastNetID);
                    packetWriter.WriteBytes(packetData);
                    this.Packets.Add(GamePacket.Create(packetWriter.GetBytes()));
                }
            }
        }
Esempio n. 2
0
 public byte[] GetBytes()
 {
     using (var writer = new ByteWriter())
     {
         WriteHeader(writer);
         WriteBody(writer);
         writer.WriteBytes(this.ExtraBytes);
         return(writer.GetBytes());
     }
 }