Beispiel #1
0
        public override void DataReceived(int TotalLength)
        {
            checked
            {
                switch (this.SocketType)
                {
                case SockType.Chat:
                    if (TotalLength >= 4)
                    {
                        byte[] array = new byte[5];
                        this.PeekData(ref array, 4);
                        if (array[0] == 255)
                        {
                            short  num    = (short)BitConverter.ToUInt16(array, 2);
                            byte[] packet = new byte[(int)(num + 1)];
                            if (TotalLength >= (int)num)
                            {
                                this.GetData(ref packet, (int)num);
                                this.ParsePacket(packet);
                            }
                        }
                    }
                    break;

                case SockType.Realm:
                    if (TotalLength >= 3)
                    {
                        byte[] array = new byte[4];
                        this.PeekData(ref array, 3);
                        short  num    = (short)BitConverter.ToUInt16(array, 0);
                        byte[] packet = new byte[(int)(num + 1)];
                        if (TotalLength >= (int)num)
                        {
                            this.GetData(ref packet, (int)num);
                            this.ParsePacket(packet);
                        }
                    }
                    break;

                case SockType.Game:
                    if (TotalLength >= 2)
                    {
                        byte[] array = new byte[2];
                        if (this.Firstpacket)
                        {
                            this.GetData(ref array, 2);
                            this.Firstpacket = false;
                            this.ParsePacket(array);
                            return;
                        }
                        this.PeekData(ref array, 2);
                        short num2 = (short)Compression.ComputeDataLength(array);
                        if (TotalLength >= (int)num2)
                        {
                            byte[] packet2 = new byte[(int)(num2 + 1)];
                            this.GetData(ref packet2, (int)num2);
                            int    num3   = 24567;
                            byte[] buffer = new byte[num3 + 1];
                            int    num4   = Compression.DecompressPacket(packet2, ref buffer, num3);
                            if (num4 != 0)
                            {
                                List <byte[]> list = Compression.SplitPackets(buffer, num4);
                                if (list != null)
                                {
                                    foreach (var packet in list)
                                    {
                                        this.ParsePacket(packet);
                                    }
                                }
                            }
                        }
                    }
                    break;
                }
            }
        }
Beispiel #2
0
        public static int GetDecompressedPacketSize(byte[] bytes, int offset, int size)
        {
            int num  = (int)bytes[offset];
            int num2 = num;

            if (num2 == 38)
            {
                Compression.lastPacket = num;
                return(Compression.GetChatPacketSize(bytes, offset, size));
            }
            checked
            {
                if (num2 == 91)
                {
                    Compression.lastPacket = num;
                    return((int)BitConverter.ToUInt16(bytes, offset + 1));
                }
                if (num2 == 148)
                {
                    if (size >= 2)
                    {
                        Compression.lastPacket = num;
                        return((int)(6 + bytes[offset + 1] * 3));
                    }
                }
                else if (num2 == 168 || num2 == 170)
                {
                    if (size >= 7)
                    {
                        Compression.lastPacket = num;
                        return((int)bytes[offset + 6]);
                    }
                }
                else if (num2 == 172)
                {
                    if (size >= 13)
                    {
                        Compression.lastPacket = num;
                        return((int)bytes[offset + 12]);
                    }
                }
                else if (num2 == 174)
                {
                    if (size >= 3)
                    {
                        Compression.lastPacket = num;
                        return((int)(3 + BitConverter.ToUInt16(bytes, offset + 1)));
                    }
                }
                else if (num2 == 156 || num2 == 157)
                {
                    if (size >= 3)
                    {
                        Compression.lastPacket = num;
                        return((int)bytes[offset + 2]);
                    }
                }
                else if (num < Compression.PacketSizes.Length)
                {
                    Compression.lastPacket = num;
                    return(Compression.PacketSizes[num]);
                }
                return(-1);
            }
        }