public override void Dispose() { if (this.IsDisposed) { return; } base.Dispose(); this.Session.Dispose(); this.Session = null; Instance = null; }
/// <summary> /// Opens a new <see cref="QuickBloxSession"/>. /// </summary> /// <returns>Returns QuickBlox session object for communicating with the QuickBlox' REST Api.</returns> public QuickBloxSession OpenSession() { lock (locker) { if (currentSession == null || currentSession.Expiration <= DateTime.UtcNow) { var session = String.IsNullOrWhiteSpace(configuration.Username) || String.IsNullOrWhiteSpace(configuration.UserPassword) ? OpenAnonymousSession() : OpenUserSession(); session.SessionFactory = this; Provider = new QuickBloxQueryProvider(configuration.Endpoint, session.Token); currentSession = new SessionWrap(session); } } return currentSession.Session; }
public async void OnLogin() { SessionWrap sessionWrap = null; try { IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address); string text = pname.text; string pass = password.text; Session session = Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); sessionWrap = new SessionWrap(session); R2C_Login r2CLogin = (R2C_Login)await sessionWrap.Call(new C2R_Login() { Account = text, Password = pass }); sessionWrap.Dispose(); connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address); Session gateSession = Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); Game.Scene.AddComponent <SessionWrapComponent>().Session = new SessionWrap(gateSession); Game.Scene.AddComponent <SessionComponent>().Session = gateSession; G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionWrapComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key }); Log.Info("登陆gate成功!"); uiLogin.SetActive(false); uiLobby.SetActive(true); // 创建Player Player player = ComponentFactory.CreateWithId <Player>(g2CLoginGate.PlayerId); PlayerComponent playerComponent = Game.Scene.GetComponent <PlayerComponent>(); playerComponent.MyPlayer = player; //Game.Scene.GetComponent<UIComponent>().Create(UIType.UILobby); //Game.Scene.GetComponent<UIComponent>().Remove(UIType.UILogin); } catch (Exception e) { sessionWrap?.Dispose(); Log.Error(e); } }