/// <summary> /// token 登录-手机号 /// </summary> /// <param name="account"></param> /// <param name="token"></param> /// <returns></returns> public static async Task <int> OnLoginAsyncToken(string account, string token) { int errcode = -1; try { ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address); Session realmSession = ComponentFactory.Create <Session, ETModel.Session>(session); G2C_TokenLogin_Res r2CLogin = (G2C_TokenLogin_Res)await realmSession.Call(new C2G_TokenLogin_Req() { Account = account, Token = token }); errcode = r2CLogin.Error; realmSession.Dispose(); if (r2CLogin.Error != 0) { Game.PopupComponent.ShowMessageBox(r2CLogin.Message); return(r2CLogin.Error); } GamePrefs.SetUserId(r2CLogin.UserId); ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address); ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession; Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession); Game.Scene.GetComponent <SessionComponent>().Session.AddComponent <SessionOfflineComponent>(); G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key, UserId = r2CLogin.UserId }); errcode = g2CLoginGate.Error; if (g2CLoginGate.Error != 0) { Game.PopupComponent.ShowMessageBox(g2CLoginGate.Message); Game.Scene.GetComponent <SessionComponent>().Session.Dispose(); return(g2CLoginGate.Error); } if (Game.Scene.GetComponent <PingComponent>() == null) { Game.Scene.AddComponent <PingComponent, long, Session, Action>(3000, Game.Scene.GetComponent <SessionComponent>().Session, null); } return(g2CLoginGate.Error); } catch (Exception e) { Game.PopupComponent.ShowMessageBox(DataCenterComponent.Instance.tipInfo.NotConnectGateTip); Log.Error("无法连接到网关服务器: " + e.Message); return(errcode); } }
public async void OnLogin() { try { IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address); string text = this.account.GetComponent <InputField>().text; // 创建一个ETModel层的Session ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息 Session realmSession = ComponentFactory.Create <Session, ETModel.Session>(session); R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login() { Account = text, Password = "******" }); realmSession.Dispose(); connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address); // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中 ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession; // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中 Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession); G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key }); UserInfo userInfor = (UserInfo)await SessionComponent.Instance.Session.Call(new UserInfor() { }); //加载心跳组件 Game.Scene.GetComponent <SessionComponent>().Session.AddComponent <HeartBeatComponent>(); Log.Info("登陆gate成功!"); Log.Info("请求信息gate成功!" + " COIN:" + userInfor.Coin + " EXP:" + userInfor.Exp); // 创建Player Player player = ETModel.ComponentFactory.CreateWithId <Player>(g2CLoginGate.PlayerId); PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>(); playerComponent.MyPlayer = player; playerComponent.Add(player); //Log.Info("Login Player.Unitid"+ player.UnitId.ToString()); //Log.Info("Login Player.id" + player.Id.ToString()); Game.Scene.GetComponent <UIComponent>().Create(UIType.EvoUILobby); Game.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin); } catch (Exception e) { Log.Error(e); } }
public static async ETVoid OnLoginAsync(string account, string password) { try { // 创建一个ETModel层的Session ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address); // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息 Session realmSession = ComponentFactory.Create <Session, ETModel.Session>(session); R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login() { Account = account, Password = password }); realmSession.Dispose(); Debug.Log(" LoginHelper-21-key/Address: " + r2CLogin.Key + " / " + r2CLogin.Address); // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中 ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address); ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession; // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中 Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession); ///20190716 ETModel增加心跳包 gateSession.AddComponent <ETModel.PingComponent, long, Action>(5000, () => { Debug.Log("掉线了"); }); G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key }); Log.Info("登陆gate成功!"); // 创建Player Player player = ETModel.ComponentFactory.CreateWithId <Player>(g2CLoginGate.PlayerId); //PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent<PlayerComponent>(); //playerComponent.MyPlayer = player; ETModel.Game.Scene.GetComponent <PlayerComponent>().MyPlayer = player; Game.EventSystem.Run(EventIdType.LoginFinish); // 测试消息有成员是class类型 //G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo) await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo()); } catch (Exception e) { Log.Error(e); } }
public async void OnLogin() { try { this.accountText = this.account.GetComponent <InputField>().text; this.passwordText = this.password.GetComponent <InputField>().text; if (String.IsNullOrWhiteSpace(accountText) || string.IsNullOrWhiteSpace(passwordText)) { Log.Error("----账号或者密码为空"); return; } //登录成功 R2C_Login r2CLogin = (R2C_Login)await sessionWrap.Call(new C2R_Login() { Account = accountText, Password = passwordText }); if (r2CLogin.Error != 0) { Log.Error($"登录失败:{r2CLogin.Error}"); return; } // sessionWrap.Dispose(); //连接gate IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address); Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); Game.Scene.AddComponent <SessionWrapComponent>().Session = new SessionWrap(gateSession); ETModel.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成功!"); // 创建Player // Player player = ETModel.ComponentFactory.CreateWithId<Player>(g2CLoginGate.PlayerId); // PlayerComponent playerComponent = ETModel.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.ToStr()); } }
public async void OnLogin() { try { IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address); string text = this.account.GetComponent <InputField>().text; // 创建一个ETModel层的Session ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息 Session realmSession = ComponentFactory.Create <Session, ETModel.Session>(session); R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login() { Account = text, Password = "******" }); realmSession.Dispose(); connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address); // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中 ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession; // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中 Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession); G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key }); Log.Info("登陆gate成功!"); // 创建Player Player player = ETModel.ComponentFactory.CreateWithId <Player>(g2CLoginGate.PlayerId); PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>(); playerComponent.MyPlayer = player; this.tokenSource.Cancel(); Game.Scene.GetComponent <UIComponent>().Create(UIType.UILobby); Game.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin); // 测试消息有成员是class类型 G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo)await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo()); } catch (Exception e) { Log.Error(e); } }
public async void OnLogin() { try { if (string.IsNullOrEmpty(this.Filed_Account.text) || string.IsNullOrEmpty(this.Filed_PassWord.text)) { txt_LoginState.text = "请输入正确的账号和密码"; return; } IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address); // 创建一个ETModel层的Session ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息 Session realmSession = ComponentFactory.Create <Session, ETModel.Session>(session); R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login() { Account = Filed_Account.text, Password = Filed_PassWord.text }); realmSession.Dispose(); connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address); // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中 ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession; // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中 Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession); G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key }); Log.Info("登陆gate成功!"); Gamer gamer = GamerFactory.Create(g2CLoginGate.UserID, false); Game.Scene.AddComponent <GameDataComponent, Gamer>(gamer); Game.Scene.GetComponent <UIComponent>().CreateOrShow(UIType.UILobby); Close(); } catch (Exception e) { Log.Error(e); } }
public static async ETVoid OnLoginAsync(Entity domain, string account) { try { // 创建一个ETModel层的Session ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address); // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息 Session realmSession = EntityFactory.Create <Session, ETModel.Session>(domain, session); if (account == "") { account = IdGenerater.GenerateId().ToString(); } R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login() { Account = account, Password = "******" }); realmSession.Dispose(); // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中 ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address); ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession; // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中 Game.Scene.AddComponent <SessionComponent>().Session = EntityFactory.Create <Session, ETModel.Session>(Game.Scene, gateSession); G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call( new C2G_LoginGate() { Key = r2CLogin.Key, GateId = r2CLogin.GateId }); Log.Info("登陆gate成功!"); // 创建Player Player player = ETModel.EntityFactory.CreateWithId <Player>(ETModel.Game.Scene, g2CLoginGate.PlayerId); PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>(); playerComponent.MyPlayer = player; Game.EventSystem.Run(EventIdType.LoginFinish); // 测试消息有成员是class类型 G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo)await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo()); } catch (Exception e) { Log.Error(e); } }
//不懂TODO public static async ETVoid OnLoginAsync(string username, string password) { try { // 创建一个ETModel层的Session ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address); // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息 Session realmSession = ComponentFactory.Create <Session, ETModel.Session>(session); //给realm服务器发送账号密码进行登录 返回过来一个gate服务器地址和一个key R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login() { Account = username, Password = password }); realmSession.Dispose(); Log.Debug("r2CLogin.Address:" + r2CLogin.Address); #region 热更层和Model层分别都连接gate服务器地址 SessionComponent.Instance.Session.Call可以分别给的两个层的发消息 // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中 ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address); ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession; // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中 Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession); #endregion G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key }); Log.Info("登陆gate成功!"); // 创建Player Player player = ETModel.ComponentFactory.CreateWithId <Player>(g2CLoginGate.PlayerId); PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>(); playerComponent.MyPlayer = player; //消息机制调用 Game.EventSystem.Run(EventIdType.UILoginPanelFinish); // 测试消息有成员是class类型 G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo)await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo()); } catch (Exception e) { Log.Error(e); } }
public static async ETVoid OnLoginAsync(string account) { try { //创建一个会话实体session ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address); //热更层也创建一个Seesion,将Model层的session传递过去 //热更层的Seesion创建后,会调用Awake方法,在内部关联了Model层的session //以后调用热更层的Seesion 就是调用间接的调用了主工程的 Seesion Session realmSession = ComponentFactory.Create <Session, ETModel.Session>(session); //await等待服务器响应 r2CLogin这个是响应后 解包->反序列化得到的对象 里面已经包含服务器发送过来的数据 R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login() { Account = account, Password = "******" }); realmSession.Dispose(); //服务器返回了网关地址 //那么就根据网关地址创建一个新的Session 连接到网关去 ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address); //在Scene实体中添加SessionComponent组件 并且缓存Session对象 以后就可以直接获取来发送消息 ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession; //这里跟上面逻辑一样,创建热更层的Session,关联到主工程 Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession); G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key }); Log.Info("登陆gate成功!"); // 创建Player Player player = ETModel.ComponentFactory.CreateWithId <Player>(g2CLoginGate.PlayerId); PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>(); playerComponent.MyPlayer = player; Game.EventSystem.Run(EventIdType.LoginFinish); // 测试消息有成员是class类型 G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo)await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo()); } catch (Exception e) { Log.Error(e); } }
//不懂TODO public static async ETVoid OnLoginAsync(string account) { try { // 创建一个ETModel层的Session 建立服务器连接 ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address); // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息 Session realmSession = ComponentFactory.Create <Session, ETModel.Session>(session); R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login() { Account = account, Password = "******" }); realmSession.Dispose(); // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中 Log.Debug("r2CLogin.Address:" + r2CLogin.Address); ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address); ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession; // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中 Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession); G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key }); Log.Info("登陆gate成功!"); // 创建Player Player player = ETModel.ComponentFactory.CreateWithId <Player>(g2CLoginGate.PlayerId); PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>(); playerComponent.MyPlayer = player; //消息机制调用 Game.EventSystem.Run(EventIdType.LoginFinish); // 测试消息有成员是class类型 G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo)await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo()); } catch (Exception e) { Log.Error(e); } }
private static async ETTask <SignInResult> OnSignInSuccessAsync(Func <Session> realmSessionFunc, Func <string, Session> gateSessionFunc, R2C_Authentication r2CLogin) { Log.Info("連接Gate"); Session gateSession = gateSessionFunc?.Invoke(r2CLogin.Address); G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await gateSession.Call(new C2G_LoginGate() { Key = r2CLogin.Key }); return(new SignInResult { Message = g2CLoginGate.Message, Error = g2CLoginGate.Error, playerBaseInfo = r2CLogin.Data, Token = r2CLogin.Token }); }
public async void OnLogin() { SessionWrap sessionWrap = null; try { IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address); string text = this.account.GetComponent <InputField>().text; Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); sessionWrap = new SessionWrap(session); R2C_Login r2CLogin = (R2C_Login)await sessionWrap.Call(new C2R_Login() { Account = text, Password = "******" }); sessionWrap.Dispose(); connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address); Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); Game.Scene.AddComponent <SessionWrapComponent>().Session = new SessionWrap(gateSession); ETModel.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成功!"); // 创建Player Player player = ETModel.ComponentFactory.CreateWithId <Player>(g2CLoginGate.PlayerId); PlayerComponent playerComponent = ETModel.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); } }
public static async ETVoid Login(string account) { // 创建一个ETModel层的Session ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address); // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息 Session realmSession = EntityFactory.Create <Session, ETModel.Session>(Game.Scene, session); R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login() { Account = account, Password = "******" }); realmSession.Dispose(); // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中 ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address); ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession; // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中 Game.Scene.AddComponent <SessionComponent>().Session = EntityFactory.Create <Session, ETModel.Session>(Game.Scene, gateSession); G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key }); Log.Info("登陆gate成功!"); // 创建Player Player player = ETModel.EntityFactory.CreateWithId <Player>(ETModel.Game.Scene, g2CLoginGate.PlayerId); PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>(); playerComponent.MyPlayer = player; // 测试消息有成员是class类型 G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo)await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo()); // 逻辑层不应该去调用UI,逻辑层只关心逻辑并且抛出事件,由UI层自己去订阅事件,而且注意事件名字 // 很多人容易把这个事件取名成LoginFinishiCreateLobbyUI,这是不对的,事件抛出去不可能知道谁订阅了这个事件, // 也不会知道别人订阅这个事件是干什么的,这里只知道我Login Finish Game.EventSystem.Run(EventIdType.LoginFinish); }
public async void OnLogin() { try { // IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address); // 创建一个ETModel层的Session ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); Session realmSession = ComponentFactory.Create <Session, ETModel.Session>(session); /* * 请求登录 */ R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login() { Account = this.account.GetComponent <InputField>().text, Password = this.password.GetComponent <InputField>().text } ); realmSession.Dispose(); /* * 处理登录结果 */ if (r2CLogin.Error == ErrorCode.ERR_Success) { connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address); // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中"111.230.133.20:10002" ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession; // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中 Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession); G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key }); Log.Info("登陆gate成功!"); // 创建Player Player player = ETModel.ComponentFactory.CreateWithId <Player>(g2CLoginGate.PlayerId); PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>(); playerComponent.MyPlayer = player; Game.Scene.GetComponent <UIComponent>().Create(UIType.UILobby); Game.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin); } else if (r2CLogin.Error == ErrorCode.ERR_AccountInvaild) { Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("账号中有不法字符~", onAlertCbLoginFail, "好的~"); } else if (r2CLogin.Error == ErrorCode.ERR_PasswordInvaild) { Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("密码中有不法字符~", onAlertCbLoginFail, "好的~"); } else if (r2CLogin.Error == ErrorCode.ERR_PasswordIncorrect) { Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("密码不正确~", onAlertCbLoginFail, "好的~"); } else if (r2CLogin.Error == ErrorCode.ERR_AccountNotExist) { UIAlertsGrayComponent l = Game.Scene.GetComponent <UIAlertsGrayComponent>(); Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("账号不存在~", onAlertCbLoginFail, "好的~"); } else if (r2CLogin.Error == ErrorCode.ERR_DataBaseRead) { Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("网络异常~", onAlertCbLoginFail, "好的~"); } } catch (Exception e) { Log.Error(e); } }
public async Task OnThirdLogin(string third_id, string name, string head) { //加锁 if (isLogining) { return; } isLogining = true; Session sessionWrap = null; try { UINetLoadingComponent.showNetLoading(); // IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address); IPEndPoint connetEndPoint = NetConfig.getInstance().ToIPEndPointWithYuMing(); #if Localhost connetEndPoint = NetworkHelper.ToIPEndPoint("10.224.5.74:10002"); #endif ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); sessionWrap = ComponentFactory.Create <Session, ETModel.Session>(session); name = name.Replace("'", "*"); R2C_ThirdLogin r2CLogin = (R2C_ThirdLogin)await sessionWrap.Call(new C2R_ThirdLogin() { Third_Id = third_id, MachineId = PlatformHelper.GetMacId(), ChannelName = PlatformHelper.GetChannelName(), ClientVersion = PlatformHelper.GetVersionName(), Name = name, Head = head }); sessionWrap.Dispose(); UINetLoadingComponent.closeNetLoading(); if (r2CLogin.Error != ErrorCode.ERR_Success) { ToastScript.createToast(r2CLogin.Message); return; } UINetLoadingComponent.showNetLoading(); // connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address); // connetEndPoint = NetConfig.getInstance().ToIPEndPointWithYuMing(); string[] temp = r2CLogin.Address.Split(':'); connetEndPoint = ToIPEndPointWithYuMing(Convert.ToInt32(temp[1])); // connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address); #if Localhost connetEndPoint = NetworkHelper.ToIPEndPoint("10.224.5.74:10002"); #endif ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); Game.Scene.GetComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(session); ETModel.Game.Scene.GetComponent <ETModel.SessionComponent>().Session = gateSession; // Log.Info("gateSession:"+ connetEndPoint.ToString()); G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key }); ToastScript.createToast("登录成功"); //挂心跳包 Game.Scene.GetComponent <SessionComponent>().Session.AddComponent <HeartBeatComponent>(); UINetLoadingComponent.closeNetLoading(); await getAllData(); isLoginSuccess = true; Game.Scene.GetComponent <PlayerInfoComponent>().uid = g2CLoginGate.Uid; PlayerInfoComponent.Instance.SetShopInfoList(g2CLoginGate.ShopInfoList); PlayerInfoComponent.Instance.SetBagInfoList(g2CLoginGate.BagList); PlayerInfoComponent.Instance.ownIcon = g2CLoginGate.ownIcon; Game.Scene.GetComponent <UIComponent>().Create(UIType.UIMain); Game.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin); isLogining = false; } catch (Exception e) { sessionWrap?.Dispose(); Log.Error("OnThirdLogin:" + e); isLogining = false; } }
public async Task OnLoginPhone(string phone, string code, string token) { Session sessionWrap = null; try { UINetLoadingComponent.showNetLoading(); //IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address); IPEndPoint connetEndPoint = ToIPEndPointWithYuMing(NetConfig.getInstance().getServerPort()); ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); sessionWrap = ComponentFactory.Create <Session, ETModel.Session>(session); R2C_PhoneLogin r2CLogin = (R2C_PhoneLogin)await sessionWrap.Call(new C2R_PhoneLogin() { Phone = phone, Code = code, Token = token, MachineId = PlatformHelper.GetMacId(), ChannelName = PlatformHelper.GetChannelName(), ClientVersion = PlatformHelper.GetVersionName() }); //R2C_PhoneLogin r2CLogin = (R2C_PhoneLogin)await sessionWrap.Call(new C2R_PhoneLogin() { Phone = phone, Code = code, Token = token, MachineId = "1234", ChannelName = "jav", ClientVersion = "1.1.0" }); sessionWrap.Dispose(); UINetLoadingComponent.closeNetLoading(); if (r2CLogin.Error != ErrorCode.ERR_Success) { ToastScript.createToast(r2CLogin.Message); if (r2CLogin.Error == ErrorCode.ERR_TokenError) { PlayerPrefs.SetString("Phone", ""); PlayerPrefs.SetString("Token", ""); panel_phoneLogin.transform.localScale = new Vector3(1, 1, 1); } if (r2CLogin.Message.CompareTo("用户不存在") == 0) { panel_phoneLogin.transform.localScale = new Vector3(1, 1, 1); } return; } UINetLoadingComponent.showNetLoading(); //connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address); //connetEndPoint = NetConfig.getInstance().ToIPEndPointWithYuMing(); string[] temp = r2CLogin.Address.Split(':'); connetEndPoint = ToIPEndPointWithYuMing(Convert.ToInt32(temp[1])); ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); Game.Scene.GetComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(session); ETModel.Game.Scene.GetComponent <ETModel.SessionComponent>().Session = gateSession; G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key }); UINetLoadingComponent.closeNetLoading(); ToastScript.createToast("登录成功"); //挂心跳包 Game.Scene.GetComponent <SessionComponent>().Session.AddComponent <HeartBeatComponent>(); UINetLoadingComponent.closeNetLoading(); await getAllData(); isLoginSuccess = true; { // 保存Phone PlayerPrefs.SetString("Phone", phone); // 保存Token PlayerPrefs.SetString("Token", r2CLogin.Token); } Game.Scene.GetComponent <PlayerInfoComponent>().uid = g2CLoginGate.Uid; PlayerInfoComponent.Instance.SetShopInfoList(g2CLoginGate.ShopInfoList); PlayerInfoComponent.Instance.SetBagInfoList(g2CLoginGate.BagList); PlayerInfoComponent.Instance.ownIcon = g2CLoginGate.ownIcon; ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>(); await resourcesComponent.LoadBundleAsync($"UIMain.unity3d"); await resourcesComponent.LoadBundleAsync($"Image_Main.unity3d"); Game.Scene.GetComponent <UIComponent>().Create(UIType.UIMain); Game.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin); } catch (Exception e) { sessionWrap?.Dispose(); Log.Error(e); } }
public override async ETTask C2G_LoginGateHandler(Session session, C2G_LoginGate request, G2C_LoginGate response, Action reply) { Console.WriteLine("C2G_LoginGateHandler"); Scene scene = Game.Scene.Get(request.GateId); if (scene == null) { return; } string account = scene.GetComponent <GateSessionKeyComponent>().Get(request.Key); if (account == null) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(); return; } var results = await DBComponent.Instance.Query <Player>(x => x.Account == account); Player player = null; if (results.Count > 0) { player = results[0]; } else { player = EntityFactory.Create <Player, string>(Game.Scene, account); DBComponent.Instance.Save(player).Coroutine(); } scene.GetComponent <PlayerComponent>().Add(player); session.AddComponent <SessionPlayerComponent>().Player = player; session.AddComponent <MailBoxComponent, MailboxType>(MailboxType.GateSession); response.PlayerId = player.Id; reply(); //session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" }); await ETTask.CompletedTask; }
public virtual async ETTask C2G_LoginGateHandler(ETModel.Session session, C2G_LoginGate request, G2C_LoginGate response, Action reply) { }
public async void OnVisitorLogin() { if (isLogining || this.IsDisposed) { return; } NetOuterComponent netOuterComponent = ETModel.Game.Scene.GetComponent <NetOuterComponent>(); //设置登录中状态 isLogining = true; SessionWrap sessionWrap = null; try { string macAddress = SystemInfo.deviceUniqueIdentifier; if (!Define.IsEditorMode) { macAddress += System.DateTime.Now.ToString(); } string password = "******"; IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address); Session session = netOuterComponent.Create(connetEndPoint); sessionWrap = new SessionWrap(session); sessionWrap.session.GetComponent <SessionCallbackComponent>().DisposeCallback += s => { if (Game.Scene.GetComponent <UIComponent>()?.Get(UIType.UILogin) != null) { isLogining = false; } }; R2C_Login r2CLogin = (R2C_Login)await sessionWrap.Call(new C2R_Login() { Account = macAddress, Password = password }); sessionWrap.Dispose(); if (this.IsDisposed) { return; } if (r2CLogin.Error == ErrorCode.ERR_AccountOrPasswordError) { return; } connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address); Session gateSession = netOuterComponent.Create(connetEndPoint); Game.Scene.AddComponent <SessionWrapComponent>().Session = new SessionWrap(gateSession); //SessionWeap添加连接断开组件,用于处理客户端连接断开 Game.Scene.GetComponent <SessionWrapComponent>().Session.AddComponent <SessionOfflineComponent>(); ETModel.Game.Scene.AddComponent <SessionComponent>().Session = gateSession; G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionWrapComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key }); if (g2CLoginGate.Error == ErrorCode.ERR_ConnectGateKeyError) { Game.Scene.GetComponent <SessionWrapComponent>().Session.Dispose(); return; } Log.Info("登陆gate成功!"); //保存本地玩家 User user = ETModel.ComponentFactory.CreateWithId <User, long>(g2CLoginGate.PlayerId, g2CLoginGate.UserId); ClientComponent.Instance.LocalPlayer = user; Game.Scene.GetComponent <UIComponent>().Create(UIType.UILobby); Game.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin); } catch (Exception e) { sessionWrap?.Dispose(); Log.Error(e); } finally { //断开验证服务器的连接 netOuterComponent.Remove(sessionWrap.session.Id); //设置登录处理完成状态 isLogining = false; } }
/// <summary> /// 普通账号游客登录 /// </summary> /// <param name="account"></param> /// <param name="pwd"></param> /// <param name="isGuest"></param> /// <returns></returns> public static async Task <int> OnLoginAsync(string account, string pwd, bool isGuest = false) { int errcode = -1; try { // 创建一个ETModel层的Session ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address); // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息 Session realmSession = ComponentFactory.Create <Session, ETModel.Session>(session); //向服务器申请了一个Key R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login() { Account = account, Password = pwd }); errcode = r2CLogin.Error; realmSession.Dispose(); if (r2CLogin.Error != 0) { if (isGuest && r2CLogin.Error == ErrorCode.ERR_AccountDoesnExist) { return(r2CLogin.Error); } Game.PopupComponent.ShowMessageBox(r2CLogin.Message); return(r2CLogin.Error); } GamePrefs.SetUserId(r2CLogin.UserId); // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中 ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address); ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession; // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中 Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession); //增加客户端断线处理组件 Game.Scene.GetComponent <SessionComponent>().Session.AddComponent <SessionOfflineComponent>(); G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key, UserId = r2CLogin.UserId }); errcode = g2CLoginGate.Error; if (g2CLoginGate.Error != 0) { Game.PopupComponent.ShowMessageBox(g2CLoginGate.Message); Game.Scene.GetComponent <SessionComponent>().Session.Dispose(); return(g2CLoginGate.Error); } if (Game.Scene.GetComponent <PingComponent>() == null) { Game.Scene.AddComponent <PingComponent, long, Session, Action>(3000, Game.Scene.GetComponent <SessionComponent>().Session, null); } return(g2CLoginGate.Error); } catch (Exception e) { // if (e.Message.Equals("ERR_AccountDoesnExist")) throw; Game.PopupComponent.ShowMessageBox(DataCenterComponent.Instance.tipInfo.NotConnectGateTip); Log.Error("无法连接到网关服务器: " + e.Message); return(errcode); } }