Ejemplo n.º 1
0
        internal void HandleReceivedStream(DataStream ds)
        {
            while (true)
            {
                uint       type;
                uint       len;
                DataStream dataStream;

                if (!ds.TryReadCUInt32(out type))
                {
                    break;
                }
                if (!ds.TryReadCUInt32(out len))
                {
                    break;
                }
                if (!ds.CanRead((int)len))
                {
                    break;
                }

                dataStream          = new DataStream(ds.ReadBytes((int)len));
                dataStream.IsSwaped = true;
                InitializePacket(type, PacketType.ServerPacket, dataStream);

                if (type == 0x00) // Если это контейнер, то читаем из него данные
                {
                    dataStream.Reset();
                    dataStream.IsSwaped = false;

                    while (dataStream.CanRead())
                    {
                        uint       containerType;
                        uint       containerLen;
                        DataStream containerDataStream;
                        PacketType packetType;

                        if (dataStream.ReadCUInt32() == 0x22) // type
                        {
                            dataStream.ReadCUInt32();         // buffer len

                            containerLen        = dataStream.ReadCUInt32() - 2;
                            containerType       = dataStream.ReadWord();
                            containerDataStream = new DataStream(dataStream.ReadBytes((int)containerLen));

                            packetType = PacketType.ServerContainer;
                        }
                        else
                        {
                            containerType                = 0x45;
                            containerDataStream          = dataStream.ReadDataStream();
                            containerDataStream.IsSwaped = true;

                            packetType = PacketType.ServerPacket;
                        }
                        InitializePacket(containerType, packetType, containerDataStream);
                    }
                }
                ds.Flush();
            }
            ds.Reset();
        }