Beispiel #1
0
        /// <summary>
        /// 解析byte信息为按键数据
        /// </summary>
        /// <param name="message">消息</param>
        public void Parse(ProtocolBase message) {
            Reset();

            midKey = (KeyNum)message.getByte();
            finalKey = (KeyNum)message.getByte();
           // UnityEngine.Debug.LogError("last[" + lastKey + "] mid[" + midKey + "] final[" + finalKey + "]");
        }
Beispiel #2
0
        /// <summary>
        /// 解析byte信息为按键数据
        /// </summary>
        /// <param name="message">消息</param>
        public void Parse(ProtocolBase message)
        {
            Reset();

            midKey   = (KeyNum)message.getByte();
            finalKey = (KeyNum)message.getByte();
        }
        /// <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);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 接收帧消息 并解析消息
        /// </summary>
        /// <param name="protocol">服务器发过来的帧信息</param>
        public void ReceiveStep(ProtocolBase protocol)
        {
            //获取玩家客户端个数
            int length = protocol.getByte();


            _m_serverStep++;
            //    Debug.Log("分布解析:" + protocol.Length);
            for (int i = 0; i < length; i++)
            {
                //解析各个玩家输入
                if (protocol.getBoolean())
                {
                    _m_inputs[i].ReceiveStep(protocol);
                }
            }


            //执行帧调用函数
            for (; _m_clientStep < _m_serverStep; _m_clientStep++)
            {
                if (frameUpdate != null)
                {
                    frameUpdate();
                    client.coroutine.UpdateCoroutine();
                    client.physics.tree.CheckTree();
                }
                this._time += FSClient.deltaTime;
            }
        }
Beispiel #6
0
        /// <summary>
        /// 解析帧信息
        /// </summary>
        /// <param name="message">消息</param>
        public void ReceiveStep(ProtocolBase message)
        {
            frameKey.Parse(message);

            byte len = message.getByte();

            for (byte i = 0; i < len; i++)
            {
                JoyStickKey joy = new JoyStickKey((KeyNum)(message.getByte()), message.getV2());
                if (joySticks.ContainsKey(joy.key))
                {
                    joySticks[joy.key] = joy;
                }
                else
                {
                    joySticks.Add(joy.key, joy);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// 解析帧信息
        /// </summary>
        /// <param name="message">消息</param>
        public void ReceiveStep(ProtocolBase message)
        {
            frameKey.Parse(message);
            //Debug.Log(keyList[InputCenter.Instance.ServerStepIndex]);
            byte len = message.getByte();


            for (byte i = 0; i < len; i++)
            {
                JoyStickKey joy = new JoyStickKey((KeyNum)(message.getByte()), message.getV2());
                //             Debug.LogError("rec+["+joy.key+"]");
                if (joySticks.ContainsKey(joy.key))
                {
                    joySticks[joy.key] = joy;
                }
                else
                {
                    joySticks.Add(joy.key, joy);
                }
            }
        }