Beispiel #1
0
        // Unregister Net Notify.
        public void UnsubscribeNetNotify(ushort protocol, DataReplyDelegate func)
        {
            List <DataReplyDelegate> funcs;

            if (mNetHandlers.TryGetValue(protocol, out funcs))
            {
                funcs.Remove(func);
            }
        }
Beispiel #2
0
        // Register Net Notify.
        public void SubscribeNetNotify(ushort protocol, DataReplyDelegate func)
        {
            List <DataReplyDelegate> funcs;

            if (!mNetHandlers.TryGetValue(protocol, out funcs))
            {
                funcs = new List <DataReplyDelegate>();
                mNetHandlers.Add(protocol, funcs);
            }

            if (!funcs.Contains(func))
            {
                funcs.Add(func);
            }
        }
Beispiel #3
0
        //[LuaExport]
        public void SubscribeLuaNetNotify(ushort protocol, DataReplyDelegate func)
        {
            if (mLuaNetHandlers == null)
            {
                mLuaNetHandlers = new Dictionary <ushort, List <DataReplyDelegate> >();
                mLuaNetHandlers.Clear();
            }

            List <DataReplyDelegate> funcs;

            if (!mLuaNetHandlers.TryGetValue(protocol, out funcs))
            {
                funcs = new List <DataReplyDelegate>();
                mLuaNetHandlers.Add(protocol, funcs);
            }

            if (!funcs.Contains(func))
            {
                funcs.Add(func);
            }
        }
Beispiel #4
0
        public void ProcessServerData(ushort protocol, byte[] data)
        {
#if UNITY_EDITOR
            if (GlobalConfig.Instance.IsDebugMode)
            {
                GameDebug.Log("S------>C: " + protocol);
            }
#endif
#if UNITY_STANDALONE_WIN
            PackRecorder.RecordRecvPack(protocol, data);
#elif TEST_HOST && UNITY_ANDROID
            var pack_recorder = xc.Game.Instance.PackRecorder;
            if (!pack_recorder.NotRecordDict.ContainsKey(protocol))
            {
                GameDebug.Log("S------>C: " + protocol);
            }
#endif
            //处理错误信息
            if (protocol == NetMsg.MSG_SYS_ERROR)
            {
                S2CSysError errReport = S2CPackBase.DeserializePack <S2CSysError>(data);

                xc.ui.ugui.UIManager.Instance.ShowWaitScreen(false);

                switch (errReport.err_code)
                {
                case ErrorCode.ERR_QUEUE_MAX:    // 服务器人数达到上限后,会马上断开网络
                {
                    mQueueMax = true;
                }
                break;

                case ErrorCode.ERR_ACCOUNT_LOGIN_AGAIN:    // 顶号之后,会马上断开网络
                {
                    mLoginConflict = true;
                    string notice = DBErrorCode.GetErrorString((uint)ErrorCode.ERR_ACCOUNT_LOGIN_AGAIN);
                    if (!string.IsNullOrEmpty(notice))
                    {
                        mLoginConflictNotice = notice;
                    }
                }
                break;

                case ErrorCode.ERR_SERVER_MANTAIN:    // 服务器维护
                {
                    mMaintainServer = true;
                    string notice = DBErrorCode.GetErrorString((uint)ErrorCode.ERR_SERVER_MANTAIN);
                    if (!string.IsNullOrEmpty(notice))
                    {
                        mMaintainServerNotice = notice;
                    }
                }
                break;

                default:
                {
                    string content = "";

                    // 错误码为0时,直接使用服务端发送过来的错误信息
                    if (errReport.err_code == 0)
                    {
                        if (errReport.err_msg == null)
                        {
                            content = xc.TextHelper.GetConstText("CODE_TEXT_LOCALIZATION_35") + errReport.err_code;
                        }
                        else
                        {
                            content = System.Text.Encoding.UTF8.GetString(errReport.err_msg);
                        }
                    }
                    else
                    {
                        DBErrorCode           db        = (DBErrorCode)DBManager.GetInstance().GetDB(typeof(DBErrorCode).Name);
                        DBErrorCode.ErrorInfo errorInfo = db.GetErrorInfo(errReport.err_code);
                        if (errorInfo == null)
                        {
                            content = xc.TextHelper.GetConstText("CODE_TEXT_LOCALIZATION_35") + errReport.err_code;
                        }
                        else
                        {
                            content = errorInfo.mDesc;
                        }
                    }

                    if (errReport.@params != null && [email protected] > 0)
                    {
                        int paramsCount = [email protected];
                        if (paramsCount == 1)
                        {
                            content = string.Format(content, System.Text.Encoding.UTF8.GetString(errReport.@params[0]));
                        }
                        else if (paramsCount == 2)
                        {
                            content = string.Format(content, System.Text.Encoding.UTF8.GetString(errReport.@params[0]), System.Text.Encoding.UTF8.GetString(errReport.@params[1]));
                        }
                        else if (paramsCount == 3)
                        {
                            content = string.Format(content, System.Text.Encoding.UTF8.GetString(errReport.@params[0]), System.Text.Encoding.UTF8.GetString(errReport.@params[1]), System.Text.Encoding.UTF8.GetString(errReport.@params[2]));
                        }
                        else
                        {
                            GameDebug.LogError("MSG_SYS_ERROR 参数过多!!!");
                        }
                    }

                    string log = string.Format(xc.TextHelper.GetConstText("CODE_TEXT_LOCALIZATION_36"), content);
                    UINotice.GetInstance().ShowMessage(content);
                    ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_SYS_ERROR, new CEventBaseArgs(errReport.err_code));
                    GameDebug.LogWarning(log);
                    break;
                }
                }
                return;
            }
            //处理Debug信息
            else if (protocol == NetMsg.MSG_SYS_DEBUG)
            {
                S2CSysDebug msg = S2CPackBase.DeserializePack <S2CSysDebug>(data);

                xc.ui.ugui.UIManager.Instance.ShowWaitScreen(false);

                string content = System.Text.Encoding.UTF8.GetString(msg.err);
                string log     = string.Format(xc.TextHelper.GetConstText("CODE_TEXT_LOCALIZATION_37"), content);
                //UINotice.GetInstance().ShowMessage(content);
                GameDebug.LogWarning(log);
            }
            // 登录验证失败
            else if (protocol == NetMsg.MSG_ACC_LOGIN_FAIL)
            {
                S2CAccLoginFail loginFail = S2CPackBase.DeserializePack <S2CAccLoginFail>(data);
                uint            reason    = loginFail.reason;
                if (reason != 1)
                {
                    UIWidgetHelp.GetInstance().ShowNoticeDlg(xc.ui.ugui.UINoticeWindow.EWindowType.WT_OK, xc.TextHelper.GetConstText("CODE_TEXT_LOCALIZATION_38"), OnClickSDKRelogin, null);
                }

                return;
            }

            bool process = false;
            List <DataReplyDelegate> funcs;
            if (mNetHandlers.TryGetValue(protocol, out funcs))
            {
                // Broacast the net notify.
                for (int i = 0; i < funcs.Count; ++i)
                {
                    DataReplyDelegate func = funcs [i];
                    func(protocol, data);

                    // 这里不再catch异常,不然有报错不好找
                    //try
                    //{
                    //    func(protocol, data);
                    //}
                    //catch (System.Exception e)
                    //{
                    //    GameDebug.LogError("Protocol " + protocol + " error: " + e.Message);
                    //}
                }
                process = true;
            }

            if (mLuaNetHandlers != null)
            {
                if (mLuaNetHandlers.TryGetValue(protocol, out funcs))
                {
                    // Broacast the net notify.
                    for (int i = 0; i < funcs.Count; ++i)
                    {
                        DataReplyDelegate func = funcs[i];
                        try
                        {
                            func(protocol, data);
                        }
                        catch (System.Exception e)
                        {
                            GameDebug.LogError("Protocol " + protocol + " error: " + e.Message);
                        }
                    }
                    process = true;
                }
            }

            if (process == false)
            {
                GameDebug.Log("未处理的协议:" + protocol);
            }
        }