public void Quit(bool callApplicationQuit) { // 保存用户配置 GlobalSettings.GetInstance().Save(); // 如果开启了跨服,关闭跨服Socket if (Net.NetClient.CrossToggle) { CrossServerIntegration.GetInstance().Stop(); } StopNetClient(); // 关闭Sqlite连接 DBManager.Instance.CloseAllSqliteDB(); //发送客户端关闭通知 ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_QUIT_GAME, null); LuaScriptMgr.Instance.Destroy(); #if !UNITY_EDITOR if (callApplicationQuit) { Application.Quit(); } #endif }
/// <summary> /// 重试连接服务器 /// </summary> /// <param name="remainTime"></param> void RetryConnect() { if (Game.Instance.Connected) // 副连接断开的时候等待副连接连接成功的消息即可 { if (m_IsSendRecon == false) // 没有发送MSG_MWAR_RECONN协议的时候先发送 { m_IsSendRecon = true; m_IsRecvToken = false; GameDebug.Log("<<<MSG_MWAR_RECONN"); var mwar_recon = new C2SMwarReconn(); mwar_recon.token = m_CrossToken; NetClient.GetBaseClient().SendData <C2SMwarReconn>(NetMsg.MSG_MWAR_RECONN, mwar_recon); } else { if (m_IsRecvToken == true) // 等待副连接Token协议 { if (CrossServerIntegration.GetInstance().Connected == false) // 副连接未连接上的时候,尝试重连 { CrossServerIntegration.GetInstance().Stop(); CrossServerIntegration.GetInstance().StartConnect(); } } } } else { Game.Instance.StopNetClient(); Game.Instance.Login(); } }
public void OnNetDisconnect(NetType netType, int e) { if (netType == NetType.NT_UDP) { return; } Debug.Log("Disconnect to server! Error:" + e.ToString()); // 如果开启了跨服,关闭跨服Socket if (Net.NetClient.CrossToggle) { CrossServerIntegration.GetInstance().Stop(); } // 关闭主Socket StopNetClient(); string notice = ""; if (mQueueMax) // 排队中 { notice = xc.TextHelper.GetConstText("CODE_TEXT_LOCALIZATION_33"); ui.UIWidgetHelp.GetInstance().ShowNoticeDlg(xc.ui.ugui.UINoticeWindow.EWindowType.WT_OK_DisableCloseBtn, notice, OnClickRetryBtn, null); } else if (mLoginConflict) { ui.UIWidgetHelp.GetInstance().ShowNoticeDlg(xc.ui.ugui.UINoticeWindow.EWindowType.WT_OK_DisableCloseBtn, mLoginConflictNotice, x => { mLoginConflict = false; IBridge bridge = DBOSManager.getDBOSManager().getBridge(); bridge.logout(); }, null, "UINotice2Window"); } else if (mMaintainServer)// 维护服务器中 { ui.UIWidgetHelp.GetInstance().ShowNoticeDlg(xc.ui.ugui.UINoticeWindow.EWindowType.WT_OK_DisableCloseBtn, mMaintainServerNotice, x => { mMaintainServer = false; IBridge bridge = DBOSManager.getDBOSManager().getBridge(); bridge.logout(); }, null, "UINotice2Window"); } else if (!IsEnterGame)// 还未进入游戏 { ui.UIWidgetHelp.GetInstance().ShowNoticeDlg(xc.ui.ugui.UINoticeWindow.EWindowType.WT_OK_DisableCloseBtn, xc.TextHelper.GetConstText("CODE_TEXT_LOCALIZATION_34"), x => { IBridge bridge = DBOSManager.getDBOSManager().getBridge(); bridge.logout(); }, null, "UINotice2Window"); } ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_NET_MAIN_DISCONNECT, null); }
public static CrossServerIntegration GetInstance() { if (msInstance == null) { msInstance = new CrossServerIntegration(); } return(msInstance); }
void Relogin() { // 如果开启了跨服,关闭跨服Socket if (Net.NetClient.CrossToggle) { CrossServerIntegration.GetInstance().Stop(); } StopNetClient(); m_GameMachine.React((uint)GameEvent.GE_DISCONNECT); }
/// <summary> /// 副连接心跳包超时 /// </summary> void OnCrossHeartTimeout(float remainTime) { if (remainTime > 0) { return; } if (mCrossHeartTimeout != null) { mCrossHeartTimeout.Destroy(); mCrossHeartTimeout = null; } //如果Timeout时间内没有消息返回,则表示网络已断开 //if (NetClient.CrossToggle) //CrossServerIntegration.GetInstance().Stop(); CrossServerIntegration.GetInstance().OnNetDisconnect(NetType.NT_TCP, -2); }
/// <summary> /// 点击重新登录SDK的按钮 /// </summary> /// <param name="param"></param> void OnClickSDKRelogin(System.Object param) { // 关闭主连接 StopNetClient(); // 关闭副连接 if (Net.NetClient.CrossToggle) { CrossServerIntegration.GetInstance().Stop(); } #if UNITY_ANDROID IBridge bridge = DBOSManager.getDBOSManager().getBridge(); if (bridge != null) { bridge.reboot(); } #else Application.Quit(); #endif }
//----------------------------------- // 网络消息 //----------------------------------- void HandleServerData(ushort protocol, byte[] data) { switch (protocol) { case NetMsg.MSG_ACC_SESSION: // 接收主连接Token { GameDebug.Log(">>>MSG_ACC_SESSION"); var session = S2CPackBase.DeserializePack <S2CAccSession>(data); GlobalConfig.Instance.Token = session.token; break; } case NetMsg.MSG_ACC_SESSION_LOGIN: // 接收主连接Token登录的结果 { GameDebug.Log(">>>MSG_ACC_SESSION_LOGIN"); var session_login = S2CPackBase.DeserializePack <S2CAccSessionLogin>(data); if (session_login.result == 0) { GameDebug.Log("主连接重连失败"); m_ForceRebot = true; m_Machine.React((uint)EFSMEvent.DE_ReconnectFail); } else { GameDebug.Log("主连接重连成功"); } break; } case NetMsg.MSG_MWAR_TOKEN: // 收到副连接的Token信息就开始Connect { GameDebug.Log(">>>MSG_MWAR_TOKEN"); if (NetClient.CrossToggle) { CrossServerIntegration.GetInstance().Stop(); } S2CMwarToken rep = S2CPackBase.DeserializePack <S2CMwarToken>(data); m_IsRecvToken = true; m_CrossToken = rep.token; if (Game.Instance.Connected) // 主连接连上了再连接副连接 { ConnectCrossServer(rep.ip, (int)rep.port, rep.token); } else { m_WaitConnect = MainGame.HeartBehavior.StartCoroutine(WaitConnectCrossServer(rep.ip, (int)rep.port, rep.token)); } break; } case NetMsg.MSG_MWAR_LOGIN: // 副连接登录成功 { GameDebug.Log(">>>MSG_MWAR_LOGIN"); var mwar_login = S2CPackBase.DeserializePack <S2CMwarLogin>(data); if (mwar_login.result == 0) { if (m_Machine != null) // 副连接连上了才表示网络连接成功 { UINotice.Instance.ShowMessage(xc.TextHelper.GetConstText("CODE_TEXT_LOCALIZATION_87")); m_Machine.React((uint)EFSMEvent.DE_ReconnectFail); } } else if (mwar_login.result == 1) { ClientEventMgr.Instance.FireEvent((int)ClientEvent.CE_NET_CROSS_CONNECTED, null); } break; } case NetMsg.MSG_ACC_HEART: // 主连接心跳包 { //Debug.Log(">>>MSG_ACC_HEART"); // 服务器有返回消息,则将计时器销毁 if (m_HeartTimeout != null) { m_HeartTimeout.Destroy(); m_HeartTimeout = null; } var dt = UnityEngine.Time.realtimeSinceStartup - mLastPingTime; PingTime.GetInstance().DelayTime = dt; } break; case NetMsg.MSG_ACC_HEART_MWAR: // 副连接心跳包 { //Debug.Log(">>>MSG_ACC_HEART_MWAR"); // 服务器有返回消息,则将计时器销毁 if (mCrossHeartTimeout != null) { mCrossHeartTimeout.Destroy(); mCrossHeartTimeout = null; } } break; } }
void ConnectCrossServer(byte[] ip, int port, byte[] token) { string serverIp = System.Text.Encoding.UTF8.GetString(ip); CrossServerIntegration.GetInstance().StartConnect(serverIp, (int)port, token); }