Exemple #1
0
        // Token: 0x06000144 RID: 324 RVA: 0x000087A0 File Offset: 0x000069A0
        private void AsyncReceive(object state)
        {
            for (;;)
            {
                byte[] array;
                lock (this._readBuffers)
                {
                    if (this._readBuffers.Count == 0)
                    {
                        lock (this._readingPacketsLock)
                        {
                            this._readingPackets = false;
                        }
                        break;
                    }
                    array = this._readBuffers.Dequeue();
                }
                this._readableDataLen += array.Length;
                bool flag3 = true;
                while (flag3)
                {
                    switch (this._receiveState)
                    {
                    case Client.ReceiveType.Header:
                        if (this._readableDataLen >= this.HEADER_SIZE)
                        {
                            int num = this._appendHeader ? (this.HEADER_SIZE - this._tempHeaderOffset) : this.HEADER_SIZE;
                            try
                            {
                                if (this._appendHeader)
                                {
                                    try
                                    {
                                        Array.Copy(array, this._readOffset, this._tempHeader, this._tempHeaderOffset, num);
                                    }
                                    catch (Exception ex)
                                    {
                                        flag3 = false;
                                        this.OnClientFail(ex);
                                        break;
                                    }
                                    this._payloadLen       = BitConverter.ToInt32(this._tempHeader, 0);
                                    this._tempHeaderOffset = 0;
                                    this._appendHeader     = false;
                                }
                                else
                                {
                                    this._payloadLen = BitConverter.ToInt32(array, this._readOffset);
                                }
                                if (this._payloadLen <= 0 || this._payloadLen > this.MAX_PACKET_SIZE)
                                {
                                    throw new Exception("invalid header");
                                }
                            }
                            catch (Exception)
                            {
                                flag3 = false;
                                this.Disconnect();
                                break;
                            }
                            this._readableDataLen -= num;
                            this._readOffset      += num;
                            this._receiveState     = Client.ReceiveType.Payload;
                        }
                        else
                        {
                            try
                            {
                                Array.Copy(array, this._readOffset, this._tempHeader, this._tempHeaderOffset, this._readableDataLen);
                            }
                            catch (Exception ex2)
                            {
                                flag3 = false;
                                this.OnClientFail(ex2);
                                break;
                            }
                            this._tempHeaderOffset += this._readableDataLen;
                            this._appendHeader      = true;
                            flag3 = false;
                        }
                        break;

                    case Client.ReceiveType.Payload:
                    {
                        if (this._payloadBuffer == null || this._payloadBuffer.Length != this._payloadLen)
                        {
                            this._payloadBuffer = new byte[this._payloadLen];
                        }
                        int num2 = (this._writeOffset + this._readableDataLen >= this._payloadLen) ? (this._payloadLen - this._writeOffset) : this._readableDataLen;
                        try
                        {
                            Array.Copy(array, this._readOffset, this._payloadBuffer, this._writeOffset, num2);
                        }
                        catch (Exception ex3)
                        {
                            flag3 = false;
                            this.OnClientFail(ex3);
                            break;
                        }
                        this._writeOffset     += num2;
                        this._readOffset      += num2;
                        this._readableDataLen -= num2;
                        if (this._writeOffset == this._payloadLen)
                        {
                            bool flag4;
                            if (!(flag4 = (this._payloadBuffer.Length == 0)))
                            {
                                this._payloadBuffer = GClass18.smethod_6(this._payloadBuffer);
                                flag4 = (this._payloadBuffer.Length == 0);
                            }
                            if (!flag4)
                            {
                                try
                                {
                                    this._payloadBuffer = SafeQuickLZ.Decompress(this._payloadBuffer);
                                }
                                catch (Exception)
                                {
                                    flag3 = false;
                                    this.Disconnect();
                                    break;
                                }
                                flag4 = (this._payloadBuffer.Length == 0);
                            }
                            if (flag4)
                            {
                                flag3 = false;
                                this.Disconnect();
                                break;
                            }
                            using (MemoryStream memoryStream = new MemoryStream(this._payloadBuffer))
                            {
                                try
                                {
                                    IPacket packet = (IPacket)this._serializer.Deserialize(memoryStream);
                                    this.OnClientRead(packet);
                                }
                                catch (Exception ex4)
                                {
                                    flag3 = false;
                                    this.OnClientFail(ex4);
                                    break;
                                }
                            }
                            this._receiveState  = Client.ReceiveType.Header;
                            this._payloadBuffer = null;
                            this._payloadLen    = 0;
                            this._writeOffset   = 0;
                        }
                        if (this._readableDataLen == 0)
                        {
                            flag3 = false;
                        }
                        break;
                    }
                    }
                }
                if (this._receiveState == Client.ReceiveType.Header)
                {
                    this._writeOffset = 0;
                }
                this._readOffset      = 0;
                this._readableDataLen = 0;
            }
        }
Exemple #2
0
 // Token: 0x060001A6 RID: 422 RVA: 0x00002C7F File Offset: 0x00000E7F
 public static string smethod_5(string input)
 {
     //先将编码base64转换然后 进入GClass18.smethod_6()函数 最后进行utf-8编码得到字符串
     return(Encoding.UTF8.GetString(GClass18.smethod_6(Convert.FromBase64String(input))));
 }