/// <summary> /// 进入游戏服务器 /// </summary> /// <param name="ip"></param> /// <param name="port"></param> /// <param name="gameType"></param> public void ConnectGameServer(string ip, int port, bool reconnect = false) { Global.Inst.GetController <NetLoadingController>().ShowLoading(true, false); int old = NetProcess.mCurConnectSessionId; NetProcess.Connect(ip, port, (b, i) => { Global.Inst.GetController <NetLoadingController>().ShowLoading(false); if (b) { LoginModel.Inst.mSessionId = i; NetProcess.ReleaseConnectExpectID(i); MainViewModel.Inst.mNowIp = ip; MainViewModel.Inst.mNowPort = port; GameManager.Instance.StartHeartBreath(Reconnect); Engine.ConnectionManager.Instance.MessageEventQueue.ClearAll(); LoginToGameServer(); } else { if (reconnect) { GameManager.Instance.ReConnet(); } else { Global.Inst.GetController <CommonTipsController>().ShowTips("服务器维护中,请稍后再试", "确定", true, () => { }, null, null, "网络异常"); } } }); }
/// <summary> /// 返回大厅服务器 /// </summary> public void BackToMain(string ip = null, int port = 0) { int old = NetProcess.mCurConnectSessionId; NetProcess.Connect(GameManager.Instance.Ip, GameManager.Instance.port, (b, i) => { if (b) { NetProcess.ReleaseConnectExpectID(i); GameManager.Instance.StartHeartBreath(BackToMain); Engine.ConnectionManager.Instance.MessageEventQueue.ClearAll(); LoginToMainServer(GameManager.Instance.Ip, GameManager.Instance.port); } else { GameManager.Instance.ShowNetTips(); } }); }
/// <summary> /// 连接服务器 /// </summary> /// <param name="call"></param> private void ConnectServer(CallBack call) { NetProcess.ReleaseAllConnect(); string ip = GameManager.Instance.Ip; int port = GameManager.Instance.port; SQDebug.Log("开始连接服务器 ip:" + ip + " port:" + port); NetProcess.Connect(ip, port, (b, id) => { if (b) { NetProcess.ReleaseConnectExpectID(id); MainViewModel.Inst.mNowIp = ip; MainViewModel.Inst.mNowPort = port; GameManager.Instance.StartHeartBreath((tip, tport) => { LoginToServer(LoginModel.Inst.LoginData, null); }); LoginModel.Inst.mSessionId = id; SQDebug.Log("网络连接成功 ip:" + ip + " port:" + port); if (call != null) { call(); } } else { GameManager.Instance.CancelHeartBreath(); Global.Inst.GetController <CommonTipsController>().ShowTips("网络连接失败,请检测网络后重新连接", "确定", () => { ConnectServer(call); }); } }); }