Exemple #1
0
        /// <summary>
        /// 判断本地玩家的护送任务状态
        /// </summary>
        /// <param name="showTips"></param>
        /// <returns></returns>
        public static bool CheckLocalPlayerEscortTaskState(bool showTips = true)
        {
            if (TaskHelper.LocalPlayerIsInEscortTaskState() == true)
            {
                if (showTips == true)
                {
                    UINotice.Instance.ShowMessage(DBErrorCode.GetErrorString((uint)ErrorCode.ERR_TASK_ESCORT_DOING));
                }
                return(false);
            }

            return(true);
        }
Exemple #2
0
        void HandleServerData(ushort protocol, byte[] data)
        {
            switch (protocol)
            {
            case NetMsg.MSG_TEAM_INFO:
            {
                S2CTeamInfo pack = S2CPackBase.DeserializePack <S2CTeamInfo>(data);

                // 如果是新创建的队伍
                if (TeamId == 0 && pack.team_info.team_id > 0)
                {
                    RemoveAllBeInvitedInfos();
                }

                TeamId         = pack.team_info.team_id;
                LeaderId       = pack.team_info.leader_id;
                TargetId       = pack.team_info.target_id;
                TargetMinLevel = pack.team_info.min_lv;
                TargetMaxLevel = pack.team_info.max_lv;
                TeamMembers    = pack.team_info.members;
                if (pack.team_info.auto_match == 0)
                {
                    mIsAutoMatchingPlayer = false;
                }
                else
                {
                    mIsAutoMatchingPlayer = true;
                }
                mIsAutoMatchingTeam = false;

                ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_INFO_CHANGED, new CEventBaseArgs(pack.auto_build));
                ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_AUTO_MATCHING_STATE_CHANGED, null);

                UpdateMembersTeamIcon(null);

                break;
            }

            case NetMsg.MSG_TEAM_LIST:
            {
                S2CTeamList pack = S2CPackBase.DeserializePack <S2CTeamList>(data);

                break;
            }

            case NetMsg.MSG_TEAM_APPLY:
            {
                S2CTeamApply pack = S2CPackBase.DeserializePack <S2CTeamApply>(data);

                if (pack.result == 1)
                {
                    UINotice.Instance.ShowMessage(DBConstText.GetText("TEAM_APPLY_SUCCESS"));
                }
                else
                {
                    UINotice.Instance.ShowMessage(DBConstText.GetText("TEAM_APPLY_FAIL"));
                }

                break;
            }

            case NetMsg.MSG_TEAM_APPLY_INFO:
            {
                S2CTeamApplyInfo pack = S2CPackBase.DeserializePack <S2CTeamApplyInfo>(data);

                foreach (PkgTeamUserIntro applyInfo in pack.apply_list)
                {
                    if (IsInApllyList(applyInfo.brief.uuid) == false)
                    {
                        ApplyList.Add(applyInfo);
                    }
                }

                if (IsAutoAgree == true && SceneHelp.Instance.IsInWildInstance() == true)
                {
                    List <uint> uuids = new List <uint>();
                    uuids.Clear();
                    foreach (PkgTeamUserIntro apply in ApplyList)
                    {
                        uuids.Add(apply.brief.uuid);
                    }
                    HandleApply(1, uuids);
                }
                else
                {
                    ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_APPLY_INFO_CHANGED, null);
                }

                break;
            }

            case NetMsg.MSG_TEAM_ADD_MEMBER:
            {
                S2CTeamAddMember pack = S2CPackBase.DeserializePack <S2CTeamAddMember>(data);

                if (HaveMember(pack.member.brief.uuid) == false)
                {
                    TeamMembers.Add(pack.member);

                    ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_INFO_CHANGED, null);

                    // 在申请列表里面删除该玩家
                    RemoveApplyInfo(pack.member.brief.uuid);
                }

                break;
            }

            case NetMsg.MSG_TEAM_LEAVE:
            {
                S2CTeamLeave pack = S2CPackBase.DeserializePack <S2CTeamLeave>(data);

                if (pack.uuid == Game.Instance.LocalPlayerID.obj_idx)
                {
                    if (pack.reason == 1)
                    {
                        ApplyList.Clear();
                        ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_APPLY_INFO_CHANGED, null);

                        if (TeamMembers.Count == 1)
                        {
                            if (HaveTeam == true)
                            {
                                UINotice.Instance.ShowMessage(DBConstText.GetText("TEAM_DISMISS_TIPS"));
                            }
                        }
                        else
                        {
                            if (HaveTeam == true)
                            {
                                string msg = DBConstText.GetText("TEAM_ME_LEAVE_TIPS");
                                //ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_SYSTEM_MESSAGE_SHOW, new CEventBaseArgs(msg));
                                UINotice.Instance.ShowMessage(msg);
                            }
                        }
                    }
                    else
                    {
                        if (HaveTeam == true)
                        {
                            string msg = DBConstText.GetText("TEAM_ME_EXPEL_TIPS");
                            //ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_SYSTEM_MESSAGE_SHOW, new CEventBaseArgs(msg));
                            UINotice.Instance.ShowMessage(msg);
                        }
                    }

                    List <PkgTeamMember> tempMembers = new List <PkgTeamMember>(TeamMembers);

                    TeamId         = 0;
                    LeaderId       = 0;
                    TargetType     = 1;
                    TargetId       = 0;
                    TargetMinLevel = 0;
                    TargetMaxLevel = 0;
                    TeamMembers.Clear();

                    ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_INFO_CHANGED, null);

                    UpdateMembersTeamIcon(tempMembers);
                }
                else
                {
                    PkgTeamMember leaveMember = GetMember(pack.uuid);
                    if (leaveMember != null)
                    {
                        TeamMembers.Remove(leaveMember);

                        ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_INFO_CHANGED, null);

                        string msg = "";
                        if (pack.reason == 1)
                        {
                            msg = string.Format(DBConstText.GetText("TEAM_LEAVE_TIPS"), System.Text.Encoding.UTF8.GetString(leaveMember.brief.name));
                            UINotice.Instance.ShowMessage(msg);
                        }
                        else
                        {
                            msg = string.Format(DBConstText.GetText("TEAM_EXPEL_TIPS"), System.Text.Encoding.UTF8.GetString(leaveMember.brief.name));
                            UINotice.Instance.ShowMessage(msg);
                        }
                        ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_SYSTEM_MESSAGE_SHOW, new CEventBaseArgs(msg));
                    }
                }

                if (IsAutoAgree == true && SceneHelp.Instance.IsInWildInstance() == true)
                {
                    List <uint> uuids = new List <uint>();
                    uuids.Clear();
                    foreach (PkgTeamUserIntro apply in ApplyList)
                    {
                        uuids.Add(apply.brief.uuid);
                    }
                    HandleApply(1, uuids);
                }

                break;
            }

            case NetMsg.MSG_TEAM_BE_REJECTED:
            {
                S2CTeamBeRejected pack = S2CPackBase.DeserializePack <S2CTeamBeRejected>(data);

                UINotice.Instance.ShowMessage(string.Format(DBConstText.GetText("TEAM_REJECT_TIPS"), System.Text.Encoding.UTF8.GetString(pack.leader_name)));

                break;
            }

            case NetMsg.MSG_TEAM_PROMOTE:
            {
                S2CTeamPromote pack = S2CPackBase.DeserializePack <S2CTeamPromote>(data);

                // 没有队伍的话,LeaderId要赋值为0
                if (HaveTeam == true)
                {
                    LeaderId = pack.uuid;
                }
                else
                {
                    LeaderId = 0;
                }

                ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_INFO_CHANGED, null);

                UpdateMembersTeamIcon(null);

                // 如果不是转让给自己,则清空申请列表
                if (pack.uuid != Game.GetInstance().LocalPlayerID.obj_idx)
                {
                    ApplyList.Clear();
                    ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_APPLY_INFO_CHANGED, null);

                    PkgTeamMember member = GetMember(pack.uuid);
                    if (member != null)
                    {
                        string msg = string.Format(DBConstText.GetText("TEAM_PROMOTE_TIPS"), System.Text.Encoding.UTF8.GetString(member.brief.name));
                        UINotice.Instance.ShowMessage(msg);
                        ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_SYSTEM_MESSAGE_SHOW, new CEventBaseArgs(msg));
                    }
                }
                else
                {
                    string msg = DBConstText.GetText("TEAM_ME_PROMOTE_TIPS");
                    UINotice.Instance.ShowMessage(msg);
                    ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_SYSTEM_MESSAGE_SHOW, new CEventBaseArgs(msg));

                    mIsAutoMatchingPlayer = false;

                    ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_AUTO_MATCHING_STATE_CHANGED, null);
                }

                break;
            }

            case NetMsg.MSG_TEAM_INVITE:
            {
                S2CTeamInvite pack = S2CPackBase.DeserializePack <S2CTeamInvite>(data);

                if (pack.type > 0)
                {
                    UINotice.Instance.ShowMessage(string.Format(DBConstText.GetText("TEAM_HAVE_INVITED"), System.Text.Encoding.UTF8.GetString(pack.name)));
                }

                AddInviteCD(pack.uuid);

                break;
            }

            case NetMsg.MSG_TEAM_BE_INVITE:
            {
                S2CTeamBeInvite pack = S2CPackBase.DeserializePack <S2CTeamBeInvite>(data);

                if (IsAutoRejectInvite == true)
                {
                    HandleInvite(2, pack.team_id, 1);
                    break;
                }

                bool existing = false;
                foreach (S2CTeamBeInvite teamBeInvite in BeInvitedInfos)
                {
                    if (teamBeInvite.team_id == pack.team_id)
                    {
                        existing = true;
                    }
                }
                if (existing == false)
                {
                    BeInvitedInfos.Add(pack);
                }

                ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_BE_INVITED, null);

                break;
            }

            case NetMsg.MSG_TEAM_HANDLE_INVITE:
            {
                S2CTeamHandleInvite pack = S2CPackBase.DeserializePack <S2CTeamHandleInvite>(data);

                if (pack.choice == 2)
                {
                    // 对方已设置本次登录不再接收邀请
                    if (pack.type == 1)
                    {
                        UINotice.Instance.ShowMessage(string.Format(DBConstText.GetText("TEAM_AUTO_REJECT_TIPS"), System.Text.Encoding.UTF8.GetString(pack.name)));
                    }
                    else
                    {
                        UINotice.Instance.ShowMessage(string.Format(DBConstText.GetText("TEAM_REJECT_INVITE"), System.Text.Encoding.UTF8.GetString(pack.name)));
                    }
                }

                break;
            }

            case NetMsg.MSG_TEAM_INTRO:
            {
                S2CTeamIntro pack = S2CPackBase.DeserializePack <S2CTeamIntro>(data);

                break;
            }

            case NetMsg.MSG_TEAM_TARGET:
            {
                S2CTeamTarget pack = S2CPackBase.DeserializePack <S2CTeamTarget>(data);

                TargetId       = pack.target_id;
                TargetMinLevel = pack.min_lv;
                TargetMaxLevel = pack.max_lv;

                ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_TARGET_CHANGED, null);

                break;
            }

            case NetMsg.MSG_TEAM_MEMBER_INFO:
            {
                S2CTeamMemberInfo pack = S2CPackBase.DeserializePack <S2CTeamMemberInfo>(data);

                PkgTeamMember member = GetMember(pack.uuid);
                if (member != null)
                {
                    member.dungeon_id = pack.dungeon_id;
                    member.brief      = pack.info;
                }

                ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_TEAM_INFO_CHANGED, null);

                break;
            }

            case NetMsg.MSG_TEAM_SET_MATCH:
            {
                S2CTeamSetMatch pack = S2CPackBase.DeserializePack <S2CTeamSetMatch>(data);

                if (pack.auto_match == 0)
                {
                    IsAutoMatchingPlayer = false;
                }
                else
                {
                    IsAutoMatchingPlayer = true;
                }

                break;
            }

            case NetMsg.MSG_TEAM_NEARBY_USER:
            {
                S2CTeamNearbyUser pack = S2CPackBase.DeserializePack <S2CTeamNearbyUser>(data);

                break;
            }

            case NetMsg.MSG_TEAM_ERROR:
            {
                S2CTeamError pack = S2CPackBase.DeserializePack <S2CTeamError>(data);

                PkgTeamMember member = GetMember(pack.uuid);
                if (member != null)
                {
                    UINotice.Instance.ShowMessage(DBConstText.GetText("INSTANCE_CAN_NOT_START_INSTANCE") + xc.TextHelper.GetConstText("CODE_TEXT_LOCALIZATION_83") + GameConst.COLOR_DARK_RED + System.Text.Encoding.UTF8.GetString(member.brief.name) + xc.TextHelper.GetConstText("CODE_TEXT_LOCALIZATION_42") + DBErrorCode.GetErrorString(pack.err_code));
                }

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

                break;
            }

            default: break;
            }
        }
Exemple #3
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);
            }
        }