Ejemplo n.º 1
0
        private Variant _UnpackFullTypePackage(ByteArray d)
        {
            Variant variant = null;
            bool    flag    = d.bytesAvailable < 1;
            Variant result;

            if (flag)
            {
                result = variant;
            }
            else
            {
                uint num   = (uint)d.readUnsignedByte();
                uint num2  = num & 15u;
                bool flag2 = num2 == 0u;
                if (flag2)
                {
                    variant = new Variant((num & 16u) > 0u);
                }
                else
                {
                    bool flag3 = num2 == 1u;
                    if (flag3)
                    {
                        bool flag4 = (num & 16u) > 0u;
                        uint num3  = num >> 5;
                        bool flag5 = flag4;
                        if (flag5)
                        {
                            bool flag6 = num3 == 2u;
                            if (flag6)
                            {
                                variant = new Variant(d.readInt());
                            }
                            else
                            {
                                bool flag7 = num3 == 1u;
                                if (flag7)
                                {
                                    variant = new Variant(d.readShort());
                                }
                                else
                                {
                                    bool flag8 = num3 == 0u;
                                    if (flag8)
                                    {
                                        variant = new Variant(d.readByte());
                                    }
                                    else
                                    {
                                        bool flag9 = num3 == 3u;
                                        if (flag9)
                                        {
                                            variant = new Variant((long)((ulong)d.readUnsignedInt() + (ulong)((long)d.readInt() * 4294967296L)));
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            bool flag10 = num3 == 2u;
                            if (flag10)
                            {
                                variant = new Variant(d.readUnsignedInt());
                            }
                            else
                            {
                                bool flag11 = num3 == 1u;
                                if (flag11)
                                {
                                    variant = new Variant(d.readUnsignedShort());
                                }
                                else
                                {
                                    bool flag12 = num3 == 0u;
                                    if (flag12)
                                    {
                                        variant = new Variant(d.readUnsignedByte());
                                    }
                                    else
                                    {
                                        bool flag13 = num3 == 3u;
                                        if (flag13)
                                        {
                                            variant = new Variant((long)((ulong)d.readUnsignedInt() + (ulong)((long)d.readInt() * 4294967296L)));
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        bool flag14 = num2 == 2u;
                        if (flag14)
                        {
                            uint num3 = num >> 5;
                            uint num4 = num3;
                            if (num4 != 2u)
                            {
                                if (num4 == 3u)
                                {
                                    variant = new Variant(d.readDouble());
                                }
                            }
                            else
                            {
                                variant = new Variant(d.readFloat());
                            }
                        }
                        else
                        {
                            bool flag15 = num2 == 3u;
                            if (flag15)
                            {
                                uint num5 = (uint)d.readUnsignedByte();
                                uint num6 = (uint)d.readUnsignedShort();
                                int  num7 = (int)((num6 << 16 | num5 << 8 | num) >> 4);
                                variant = new Variant(d.readUTF8Bytes(num7));
                            }
                            else
                            {
                                bool flag16 = num2 == 4u;
                                if (flag16)
                                {
                                    uint num5 = (uint)d.readUnsignedByte();
                                    uint num6 = (uint)d.readUnsignedShort();
                                    int  num7 = (int)((num6 << 16 | num5 << 8 | num) >> 4);
                                    variant = new Variant();
                                    variant.setToDct();
                                    for (int i = 0; i < num7; i++)
                                    {
                                        int    len    = (int)d.readUnsignedByte();
                                        string text   = d.readUTF8Bytes(len);
                                        int    num8   = text.LastIndexOf("\0");
                                        bool   flag17 = num8 != -1;
                                        if (flag17)
                                        {
                                            text = text.Substring(0, num8);
                                        }
                                        variant[text] = this._UnpackFullTypePackage(d);
                                        bool isStr = variant[text].isStr;
                                        if (isStr)
                                        {
                                            int  num9   = variant[text]._str.LastIndexOf("\0");
                                            bool flag18 = num9 != -1;
                                            if (flag18)
                                            {
                                                string text2 = variant[text]._str.Substring(0, num9);
                                                variant[text] = variant[text]._str.Substring(0, num9);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    bool flag19 = num2 == 5u;
                                    if (flag19)
                                    {
                                        uint num5 = (uint)d.readUnsignedByte();
                                        uint num6 = (uint)d.readUnsignedShort();
                                        int  num7 = (int)((num6 << 16 | num5 << 8 | num) >> 4);
                                        variant = new Variant();
                                        variant.setToArray();
                                        for (int j = 0; j < num7; j++)
                                        {
                                            variant.pushBack(this._UnpackFullTypePackage(d));
                                        }
                                    }
                                    else
                                    {
                                        bool flag20 = num2 == 6u;
                                        if (flag20)
                                        {
                                            uint      num5      = (uint)d.readUnsignedByte();
                                            uint      num6      = (uint)d.readUnsignedShort();
                                            int       num7      = (int)((num6 << 16 | num5 << 8 | num) >> 4);
                                            ByteArray byteArray = new ByteArray();
                                            d.readBytes(byteArray, 0, num7);
                                            variant = new Variant(byteArray);
                                        }
                                        else
                                        {
                                            bool flag21 = num2 == 7u;
                                            if (flag21)
                                            {
                                                uint num5 = (uint)d.readUnsignedByte();
                                                uint num6 = (uint)d.readUnsignedShort();
                                                int  num7 = (int)((num6 << 16 | num5 << 8 | num) >> 4);
                                                variant = new Variant();
                                                variant.setToIntkeyDct();
                                                for (int k = 0; k < num7; k++)
                                                {
                                                    int idx = d.readInt();
                                                    variant[idx] = this._UnpackFullTypePackage(d);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                result = variant;
            }
            return(result);
        }
Ejemplo n.º 2
0
        public Variant parseXML(byte[] bytes, string path)
        {
            Variant variant = null;
            bool    flag    = bytes[0] == 78 && bytes[1] == 105 && bytes[2] == 99;
            Variant result;

            if (flag)
            {
                byte[] array = new byte[bytes.Length - 14];
                for (int i = 14; i < bytes.Length; i++)
                {
                    array[i - 14] = bytes[i];
                }
                ByteArray byteArray = new ByteArray(array);
                byteArray.uncompress();
                variant = this._UnpackFullTypePackage(byteArray);
            }
            else
            {
                MemoryStream memoryStream = new MemoryStream(bytes);
                XmlReader    xmlReader    = XmlReader.Create(memoryStream, new XmlReaderSettings
                {
                    IgnoreComments = true,
                    IgnoreProcessingInstructions = true,
                    IgnoreWhitespace             = true,
                    ValidationType   = ValidationType.None,
                    ValidationFlags  = XmlSchemaValidationFlags.None,
                    ProhibitDtd      = true,
                    ConformanceLevel = ConformanceLevel.Document
                });
                Stack <Variant> stack = new Stack <Variant>();
                try
                {
                    while (xmlReader.Read())
                    {
                        bool flag2 = xmlReader.NodeType == XmlNodeType.Element;
                        if (flag2)
                        {
                            Variant variant2 = Variant.alloc();
                            bool    flag3    = stack.Count > 0;
                            if (flag3)
                            {
                                Variant variant3 = stack.Peek();
                                bool    flag4    = !variant3.ContainsKey(xmlReader.Name);
                                if (flag4)
                                {
                                    variant3[xmlReader.Name] = Variant.alloc();
                                }
                                variant3[xmlReader.Name].pushBack(variant2);
                            }
                            else
                            {
                                variant = variant2;
                            }
                            bool flag5 = !xmlReader.IsEmptyElement;
                            if (flag5)
                            {
                                stack.Push(variant2);
                            }
                            while (xmlReader.MoveToNextAttribute())
                            {
                                variant2[xmlReader.Name] = new Variant(xmlReader.Value);
                            }
                        }
                        else
                        {
                            bool flag6 = xmlReader.NodeType == XmlNodeType.EndElement;
                            if (flag6)
                            {
                                stack.Pop();
                            }
                        }
                    }
                }
                catch (Exception var_19_1CC)
                {
                    DebugTrace.add(Define.DebugTrace.DTT_ERR, string.Concat(new object[]
                    {
                        "[Parse XML error] File: ",
                        path,
                        " Line: ",
                        xmlReader.Settings.LineNumberOffset,
                        " Col: ",
                        xmlReader.Settings.LinePositionOffset
                    }));
                    result = null;
                    return(result);
                }
                xmlReader.Close();
                memoryStream.Close();
            }
            result = variant;
            return(result);
        }
Ejemplo n.º 3
0
        private void _full_type_pacakge_cb_fn(Variant pkg_data, ByteArray tmp)
        {
            bool flag = ConnectionImpl.s_bShowNetLog;

            if (flag)
            {
                Debug.Log("底层 full_type接收到消息包 -- ID " + pkg_data.dump());
            }
            bool flag2 = pkg_data["cmd"]._uint == 1u;

            if (flag2)
            {
                bool flag3 = tmp != null;
                if (flag3)
                {
                    string text = AssetManagerImpl.UPDATE_DOWN_PATH + "pl_" + this._protocal_version.ToString() + ".qsmsg";
                    AssetManagerImpl.preparePath(text);
                    FileStream fileStream = new FileStream(text, FileMode.Create);
                    fileStream.Write(tmp.data, 0, tmp.length);
                    fileStream.Flush();
                    fileStream.Close();
                    Debug.Log("写入服务器消息文件 " + text);
                }
                bool flag4 = this._pack.InitRPCPackageDescribe(pkg_data);
                if (flag4)
                {
                    this._cb.onServerVersionRecv();
                }
                else
                {
                    uint num = (uint)this._recvBuffer.readUnsignedShort();
                    this._cb.onError("RPC_PROTOCAL_ERROR");
                }
            }
            else
            {
                bool flag5 = pkg_data["cmd"]._uint == 2u;
                if (flag5)
                {
                    try
                    {
                        this._server_version   = pkg_data["data"]["sver"]._uint;
                        this._protocal_version = pkg_data["data"]["rpcver"]._uint;
                    }
                    catch (Exception ex)
                    {
                        this._cb.onError("SERVER_VERSION_ERROR" + ex.Message);
                        return;
                    }
                    this._config_versions = pkg_data["data"];
                    Debug.Log("当前_server_version版本号:" + this._server_version.ToString());
                    Debug.Log("当前_protocal_version版本号:" + this._protocal_version.ToString());
                    string path  = AssetManagerImpl.UPDATE_DOWN_PATH + "pl_" + this._protocal_version.ToString() + ".qsmsg";
                    bool   flag6 = File.Exists(path) && false;
                    if (flag6)
                    {
                        Debug.Log("加载消息描述 ---------------- 本地加载.............");
                        new URLReqImpl
                        {
                            dataFormat = "binary",
                            url        = "pl_" + this._protocal_version.ToString() + ".qsmsg"
                        }.load(delegate(IURLReq local_r, object local_ret)
                        {
                            byte[] array      = local_ret as byte[];
                            Variant pkg_data2 = this._pack.UnpackFullTypePackage(array, array.Length);
                            this._full_type_pacakge_cb_fn(pkg_data2, null);
                        }, null, delegate(IURLReq local_r, string err)
                        {
                            this._get_protocal_desc(this._protocal_version);
                        });
                    }
                    else
                    {
                        this._get_protocal_desc(this._protocal_version);
                    }
                }
                else
                {
                    this._cb.onFullTPKG(pkg_data["cmd"]._uint, pkg_data["data"]);
                }
            }
        }
Ejemplo n.º 4
0
        public void onProcess()
        {
            bool flag = !this._sock.Connected;

            if (flag)
            {
                bool isConnected = this._isConnected;
                if (isConnected)
                {
                    this._isConnected = false;
                    this._cb.onConnectionClose();
                }
            }
            else
            {
                bool isConnecting = this._isConnecting;
                if (isConnecting)
                {
                    this._isConnecting = false;
                    this._isConnected  = true;
                    this._cb.onConnect();
                    Variant variant = new Variant();
                    variant["uid"]  = this._uid;
                    variant["tkn"]  = this._token;
                    variant["clnt"] = this._clnt;
                    this.PSendTPKG(2u, variant);
                }
                long tickMillisec = CCTime.getTickMillisec();
                bool flag2        = tickMillisec - this._last_hb_send_time > (long)((ulong)this._hb_interval_val);
                if (flag2)
                {
                    bool connected = this._sock.Connected;
                    if (connected)
                    {
                        this._last_hbs_time_ms = tickMillisec;
                        ByteArray byteArray = new ByteArray();
                        byteArray.writeByte((sbyte)this._make_sgn_pkg_header(0u));
                        byteArray.writeUnsignedInt((uint)(this._last_server_tm_ms + (ulong)(this._last_hbs_time_ms - this._last_hbr_time_ms)));
                        this._flushData(byteArray);
                        byteArray.length        = 0;
                        this._last_hb_send_time = tickMillisec;
                    }
                }
                try
                {
                    bool flag3 = this._sock.Available > 0;
                    if (flag3)
                    {
                        bool flag4 = this._recvBuffer.position > 0;
                        if (flag4)
                        {
                            this._recvBuffer.skip(this._recvBuffer.position);
                            this._recvBuffer.position = 0;
                        }
                        this._recvBuffer.capcity = this._recvBuffer.length + this._sock.Available + 4096;
                        int num = this._sock.Receive(this._recvBuffer.data, this._recvBuffer.length, this._sock.Available, SocketFlags.None);
                        this._recvBuffer.length = this._recvBuffer.length + num;
                        this._tryUnpackPackage();
                    }
                }
                catch (SocketException ex)
                {
                    bool flag5 = ex.ErrorCode != 10035;
                    if (flag5)
                    {
                        this._cb.onError(ex.Message);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        protected void _tryUnpackPackage()
        {
            int num = 0;

            while (this._recvBuffer.bytesAvailable > 0)
            {
                ByteArray byteArray = new ByteArray();
                num++;
                uint num2 = (uint)this._recvBuffer.readUnsignedByte();
                uint num3 = num2 & 192u;
                bool flag = num3 == 0u;
                if (flag)
                {
                    bool flag2 = num2 == 0u;
                    if (flag2)
                    {
                        bool flag3 = this._recvBuffer.bytesAvailable < 4;
                        if (flag3)
                        {
                            this._recvBuffer.position--;
                            break;
                        }
                        this._last_server_tm_ms = (ulong)this._recvBuffer.readUnsignedInt();
                        this._last_hbr_time_ms  = CCTime.getTickMillisec();
                        this._latency_ms        = this._last_hbr_time_ms - this._last_hbs_time_ms;
                        bool flag4 = this._min_last_server_tm_ms == 0uL;
                        if (flag4)
                        {
                            this._min_last_server_tm_ms = this._last_server_tm_ms;
                            this._min_last_hbr_time_ms  = this._last_hbr_time_ms;
                            this._min_latency_ms        = this._latency_ms;
                        }
                        bool flag5 = this._latency_ms < this._min_latency_ms;
                        if (flag5)
                        {
                            this._min_last_server_tm_ms = this._last_server_tm_ms;
                            this._min_last_hbr_time_ms  = this._last_hbr_time_ms;
                            this._min_latency_ms        = this._latency_ms;
                        }
                        this._cb.onHBRecv();
                    }
                }
                else
                {
                    bool flag6 = num3 == 64u;
                    if (flag6)
                    {
                        bool flag7 = this._recvBuffer.bytesAvailable < 1;
                        if (flag7)
                        {
                            this._recvBuffer.position--;
                            break;
                        }
                        uint num4 = (num2 & 31u) << 8;
                        num4 |= (uint)this._recvBuffer.readUnsignedByte();
                        bool flag8 = (long)this._recvBuffer.bytesAvailable < (long)((ulong)(num4 - 2u));
                        if (flag8)
                        {
                            this._recvBuffer.position -= 2;
                            break;
                        }
                        this._recvBuffer.readBytes(byteArray, 0, (int)(num4 - 2u));
                        bool flag9 = this._is_pkg_compressed(num2);
                        if (flag9)
                        {
                            byteArray.uncompress();
                        }
                        Variant pkg_data = this._pack.UnpackRPCPackage(byteArray.data, byteArray.length);
                        this._rpc_package_cb_fn(pkg_data, byteArray);
                    }
                    else
                    {
                        bool flag10 = num3 == 128u;
                        if (flag10)
                        {
                            bool flag11 = this._recvBuffer.bytesAvailable < 3;
                            if (flag11)
                            {
                                this._recvBuffer.position--;
                                break;
                            }
                            uint num4 = (num2 & 31u) << 24;
                            num4 |= (uint)this._recvBuffer.readUnsignedByte();
                            num4 |= (uint)((uint)this._recvBuffer.readUnsignedShort() << 8);
                            bool flag12 = (long)this._recvBuffer.bytesAvailable < (long)((ulong)(num4 - 4u));
                            if (flag12)
                            {
                                this._recvBuffer.position -= 4;
                                break;
                            }
                            this._recvBuffer.readBytes(byteArray, 0, (int)(num4 - 4u));
                            bool flag13 = this._is_pkg_compressed(num2);
                            if (flag13)
                            {
                                byteArray.uncompress();
                            }
                            Variant pkg_data = this._pack.UnpackTypePackage(byteArray.data, byteArray.length);
                            this._type_package_cb_fn(pkg_data, byteArray);
                        }
                        else
                        {
                            bool flag14 = num3 == 192u;
                            if (!flag14)
                            {
                                break;
                            }
                            bool flag15 = this._recvBuffer.bytesAvailable < 3;
                            if (flag15)
                            {
                                this._recvBuffer.position--;
                                break;
                            }
                            uint num4 = (num2 & 31u) << 24;
                            num4 |= (uint)this._recvBuffer.readUnsignedByte();
                            num4 |= (uint)((uint)this._recvBuffer.readUnsignedShort() << 8);
                            bool flag16 = (long)this._recvBuffer.bytesAvailable < (long)((ulong)(num4 - 4u));
                            if (flag16)
                            {
                                this._recvBuffer.position -= 4;
                                break;
                            }
                            this._recvBuffer.readBytes(byteArray, 0, (int)(num4 - 4u));
                            bool flag17 = this._is_pkg_compressed(num2);
                            if (flag17)
                            {
                                byteArray.uncompress();
                            }
                            Variant pkg_data = this._pack.UnpackFullTypePackage(byteArray.data, byteArray.length);
                            this._full_type_pacakge_cb_fn(pkg_data, byteArray);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
 protected void _flushData(ByteArray d)
 {
     this._sock.Send(d.data, d.length, SocketFlags.None);
 }