Ejemplo n.º 1
0
        public bool SendAsync(UnityFrame.CMsg msgData)
        {
            UnityUtility.CTrace.Singleton.debug("发送消息[{0}.{1}.{2}][{3}]", msgData.MsgID.ServerType.ServerType, msgData.MsgID.FuncType.FuncType, msgData.MsgID.MsgNumber, msgData.ToString());

            UnityUtility.CStream stream = new UnityUtility.CStream();
            stream.Write(msgData.MsgID.MsgID);
            if (!msgData.SerializeTo(stream))
            {
                return(false);
            }
            if (!m_netTcpClient.SendAsync(stream))
            {
                //  UnityUtility.CTrace.Singleton.error("发送消息[{0}.{1}.{2}][{3}]", msgData.MsgID.ServerType.ServerType, msgData.MsgID.FuncType.FuncType, msgData.MsgID.MsgNumber, msgData.ToString());
                // return false;
                UnityUtility.CTrace.Singleton.error("发送消息[{0}.{1}.{2}][{3}]Fail", msgData.MsgID.ServerType.ServerType, msgData.MsgID.FuncType.FuncType, msgData.MsgID.MsgNumber, msgData.ToString());
                //CGameClient.LostMsgData = msgData;
                //CGameClient.Singleton.SendMsgReConnectServer();
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        private void CallbackRecvAsync(UnityUtility.CBuffer buffer)
        {
            m_stream.Buffer = buffer;
            uint id = 0;

            if (!m_stream.Read(ref id))
            {
                UnityUtility.CTrace.Singleton.debug("解析消息ID错误");
                m_netTcpClient.Disconnect();
                return;
            }
            UnityFrame.CMsgID msgID   = new UnityFrame.CMsgID(id);
            UnityFrame.CMsg   msgData = CGameClient.Singleton.MsgFactory.CreateMessageByMsgID(msgID);
            if (msgData != null)
            {
                UnityUtility.CTrace.Singleton.debug("解析消息[{0}.{1}.{2}][{3}]", msgID.ServerType.ServerType, msgID.FuncType.FuncType, msgID.MsgNumber, msgData.ToString());

                if (!msgData.SerializeFrom(m_stream))
                {
                    m_netTcpClient.Disconnect();
                    return;
                }
                if (m_stream.Buffer.CanRead)
                {
                    UnityUtility.CTrace.Singleton.error("解析消息ParseMessage[{0}.{1}.{2}]失败,消息还有多余数据", msgID.ServerType.ServerType, msgID.FuncType.FuncType, msgID.MsgNumber);
                    m_netTcpClient.Disconnect();
                    return;
                }
                if (!CGameClient.Singleton.MsgExecMgr.ParseMessage(msgData))
                {
                    UnityUtility.CTrace.Singleton.error("解析消息ParseMessage[{0}.{1}.{2}][{3}]失败", msgID.ServerType.ServerType, msgID.FuncType.FuncType, msgID.MsgNumber, msgData.ToString());
                    m_netTcpClient.Disconnect();
                    return;
                }
            }
            else
            {
                UnityUtility.CTrace.Singleton.error("解析消息ParseMessage[{0}.{1}.{2}]创建消息失败", msgID.ServerType.ServerType, msgID.FuncType.FuncType, msgID.MsgNumber);
                m_netTcpClient.Disconnect();
                return;
            }
        }