Esempio n. 1
0
        /// <summary>
        /// 解析消息并进行消息分发
        /// </summary>
        /// <param name="protocol">要解析的消息</param>
        public void ParseMessage(ProtocolBase protocol, int deep = 0)
        {
            var t = (MessageType)protocol.getByte();

            switch (t)
            {
            case MessageType.Init:
                _isConnect         = true;
                _time              = UnityEngine.Time.realtimeSinceStartup;
                ServerCon.clientId = protocol.getByte();
                Debug.Log("clientID:" + ServerCon.clientId);
                break;

            case MessageType.Frame:
                inputCenter.ReceiveStep(protocol);
                break;

            case MessageType.RandomSeed:
                random = new IDG.Random((ushort)protocol.getInt32());
                foreach (var m in gameManagers)
                {
                    m.Init(this);
                }
                break;

            case MessageType.Ping:
                TimeSpan ts = DateTime.Now - m_dtLastPingTime;
                m_nPing          = (int)(ts.TotalMilliseconds);
                m_dtLastPingTime = DateTime.Now;
                m_nPingMsgNum--;
                break;

            case MessageType.BattleEnd:
                break;

            case MessageType.end:
                break;

            default:
                Debug.LogError("消息解析错误 未解析类型" + t);
                return;
            }

            if (t != MessageType.end && deep < 5)
            {
                ParseMessage(protocol, deep + 1);
            }
            else
            {
            }

            if (protocol.Length > 0)
            {
                Debug.LogError("剩余未解析" + protocol.Length);
            }
        }
        /// <summary>
        /// 解析消息并进行消息分发
        /// </summary>
        /// <param name="protocol">要解析的消息</param>
        public void ParseMessage(ProtocolBase protocol, int deep = 0)
        {
            var t = (MessageType)protocol.getByte();

            //          Debug.Log("parseMessage" + t);
            //Debug.Log(DateTime.Now.ToString() + ":" + DateTime.Now.Millisecond+"MessageType: " + (MessageType)t);
            switch (t)
            {
            case MessageType.Init:
                ServerCon.clientId = protocol.getByte();


                Debug.Log("clientID:" + ServerCon.clientId);
                break;

            case MessageType.Frame:
                inputCenter.ReceiveStep(protocol);
                break;

            case MessageType.RandomSeed:
                random = new IDG.Random((ushort)protocol.getInt32());
                //    Debug.LogError("randomSeedTest "+random.next()) ;
                foreach (var m in gameManagers)
                {
                    m.Init(this);
                }
                break;

            case MessageType.end:
                break;

            default:
                Debug.LogError("消息解析错误 未解析类型" + t);
                return;
            }
            if (t != MessageType.end && deep < 5)
            {
                ParseMessage(protocol, deep + 1);
                //     Debug.LogError("继续解析"+deep);
            }
            else
            {
                //     Debug.LogError("解析结束" );
            }
            if (protocol.Length > 0)
            {
                Debug.LogError("剩余未解析" + protocol.Length);
                //ParseMessage(protocol);
            }
        }