示例#1
0
    public void ProcessMsg(DGPKG msg)
    {
//		Debug.Log("Start ProcessMsg");
        // 通过模块注册消息响应函数处理
        if (msg == null)
        {
            return;
        }

//		Debug.Log("ProcessMsg : " + (msg != null));
        if (msg.header.seq == 0)
        {
            NotifyMsgHandleMgr.Instance.HandleMsg(msg);
        }
        else
        {
            MsgInfo info = GetMsgInfo((int)msg.header.seq);
            if (info == null) // 最大的可能是,seq对应的响应来了多次(因为在目前的消息重发机制下,客户端可能会将具有同一seq的请求重发多次)
            {
                RemoveAlreadySentMsgBySeq(msg.header.seq);
            }
            else
            {
                RemoveAlreadySentMsg(info);

                //ssGame.NetDelay = Time.realtimeSinceStartup*1000 - msg.stHead.dwClientTime;
                if (info.Callback != null)
                {
                    if (msg.header != null && msg.body != null)
                    {
//                        Debug.Log("ProcessMsg : " + msg.header.msg_full_name);
                        //Debug.Log("ProcessMsg here GetType: " + msg.body.GetType());
                        //Debug.Log("ProcessMsg rsper: " + info.Callback.Target);
                        string fullName = msg.header.msg_full_name;
                        string typeName = msg.body.GetType().FullName;
                        if (fullName == typeName)
                        {
                            info.Callback(CSMsgResult.NoError, msg);
                        }
                        else
                        {
                            Debug.LogError(string.Format("{0} != {1}", fullName, typeName));
                        }
                        info.Reset();
                    }
                }
            }

            // 只要还有尚未被响应的请求,这里就不主动解锁
            if (!IsAnyRequestNotResponded())
            {
                UnlockScreen();
            }
        }
    }
示例#2
0
 private void RemoveOneTimeoutAreadySentMsg()
 {
     //foreach (MsgInfo msginfo in mCSMsgAlreadySentList)
     for (int i = 0; i < mCSMsgAlreadySentList.Count; i++)
     {
         MsgInfo msginfo = mCSMsgAlreadySentList[i];
         if (msginfo != null && IsMsgTimeout(msginfo))
         {
             Debuger.Log(msginfo.Msg.header.msg_full_name + " : MsgWaitResponseTimeout");
             mCSMsgAlreadySentList.Remove(msginfo);
             if (msginfo.Msg != null && msginfo.Callback != null)
             {
                 msginfo.Callback(CSMsgResult.MsgWaitResponseTimeout, msginfo.Msg);
             }
             return;
         }
     }
 }
示例#3
0
    /// <summary>
    /// 清理登陆状态,关闭Socket,对于之前没有处理的消息统一回调
    /// </summary>
    /// <param name="result"></param>
    public void HandleNetworkError(CSMsgResult result, int errorCode = 0, bool showTips = true)
    {
        mShowErrTips = false;
        for (int i = 0; i < kCSMsgCallArrayLength; i++)
        {
            MsgInfo info = GetMsgInfo(i);
            if (info != null && info.Callback != null)
            {
                try
                {
                    info.Callback(result, null);
                }
                catch (Exception)
                {
                }
                RemoveAlreadySentMsg(info);
                RemoveWaitSendMsg(info);
                info.Reset();

                UnlockScreen();
            }
        }
        string msgContent = string.Empty;

        switch (result)
        {
        case CSMsgResult.MsgTimeOut:
            msgContent = LoginMgr.Instance.SvrHost + "MsgTimeOut";
            break;

        case CSMsgResult.NetworkError:
        {
            msgContent = LoginMgr.Instance.SvrHost + "NetworkErrorWithCode :" + errorCode;
        }
        break;

        case CSMsgResult.InternalError:
            msgContent = LoginMgr.Instance.SvrHost + "InternalError";
            break;
        }

        Debug.LogError(msgContent);
    }
示例#4
0
 private void RemoveOneTimeoutWaitSendMsg()
 {
     //foreach (MsgInfo msginfo in mCSMsgWaitSendList)
     for (int i = 0; i < mCSMsgWaitSendList.Count; i++)
     {
         MsgInfo msginfo = mCSMsgWaitSendList[i];
         if (msginfo != null && IsMsgTimeout(msginfo))
         {
             Debuger.Log(msginfo.Msg.header.msg_full_name + " : MsgWaitSendTimeout");
             mCSMsgWaitSendList.Remove(msginfo);
             try
             {
                 msginfo.Callback(CSMsgResult.MsgWaitSendTimeout, msginfo.Msg);
             }
             catch (Exception)
             {
             }
             return;
         }
     }
 }