//-----------------------私有方法---------------------------------- private async void register(string count, string pw) { IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address); ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); Session realmSession = ComponentFactory.Create <Session, ETModel.Session>(session); R2C_Register r2cRegister = (R2C_Register)await realmSession.Call(new C2R_Register() { Account = count, Password = pw }); if (r2cRegister.Error == ErrorCode.ERR_Success) { Debug.Log("注册成功"); Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("注册成功!", onAlertCbRegisterSuccess, "马上登录~"); } else if (r2cRegister.Error == ErrorCode.ERR_AccountInvaild) { Debug.Log("账号不和法"); Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("注册失败!账号中有不法字符", onAlertCbRegisterFail, "好的~"); } else if (r2cRegister.Error == ErrorCode.ERR_PasswordInvaild) { Debug.Log("密码不和法"); Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("注册失败!密码中有不法字符", onAlertCbRegisterFail, "好的~"); } else if (r2cRegister.Error == ErrorCode.ERR_DataBaseWriteDown) { Debug.Log("网络异常"); Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("注册失败!网络异常", onAlertCbRegisterFail, "好的~"); } realmSession.Dispose(); }
public static async ETVoid OnRegisterAsync(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_Register r2CRegister = (R2C_Register)await realmSession.Call(new C2R_Register() { Account = account, Password = password }); realmSession.Dispose(); Log.Info(r2CRegister.Message + r2CRegister.Error); if (r2CRegister.Error == 0) { Game.EventSystem.Run(EventIdType.RegisterFinish); } else if (r2CRegister.Error == ErrorCode.ERR_AccountHasRegistered) { Log.Info(r2CRegister.Message); } } catch (Exception e) { Log.Error(e); } }
/// <summary> /// 注册按钮事件 /// </summary> public async void OnRegister() { if (isRegistering || this.IsDisposed) { return; } //设置登录中状态 isRegistering = true; Session sessionWrap = null; txt_LoginState.text = ""; try { //创建登录服务器连接 IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address); ETModel.Session session = Game.Scene.ModelScene.GetComponent <NetOuterComponent>().Create(connetEndPoint); sessionWrap = ComponentFactory.Create <Session, ETModel.Session>(session); //发送注册请求 txt_LoginState.text = "正在注册中...."; R2C_Register r2C_Register_Ack = await sessionWrap.Call(new C2R_Register() { Account = Filed_Account.text, Password = Filed_PassWord.text }) as R2C_Register; //等待服务器返回注册消息. txt_LoginState.text = ""; if (this.IsDisposed) { return; } if (r2C_Register_Ack.Error == ErrorCode.ERR_AccountAlreadyRegister) { txt_LoginState.text = "注册失败,账号已被注册"; Filed_Account.text = ""; Filed_PassWord.text = ""; return; } //注册成功自动登录 OnLogin(); } catch (Exception e) { txt_LoginState.text = "注册异常"; Log.Error(e.ToStr()); } finally { //断开验证服务器的连接 sessionWrap?.Dispose(); //设置注册处理完成状态 isRegistering = false; } }
public static async ETVoid OnRegisterAsync(string account, string password) { try { Log.Info("注册请求"); // 如果正在注册,就驳回登录请求,为了双重保险,点下登录按钮后,收到服务端响应之前将不能再点击 if (isRegistering) { return; } if (account == "" || password == "") { Game.EventSystem.Run(EventIdType.ShowLoginInfo, "账号或密码不能为空"); Log.Info("信息显示完毕"); FinalRun(); return; } isRegistering = true; // 创建一个ETModel层的Session ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>() .Create(GlobalConfigComponent.Instance.GlobalProto.Address); // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息 realmSession = ComponentFactory.Create <Session, ETModel.Session>(session); Game.EventSystem.Run(EventIdType.ShowLoginInfo, "正在注册"); // 发送登录请求,账号,密码均为传来的参数 R2C_Register r2CRegister = (R2C_Register)await realmSession.Call(new C2R_Register() { Account = account, Password = password }); if (r2CRegister.Error == ErrorCode.ERR_AccountAlreadyRegister) { Game.EventSystem.Run(EventIdType.ShowLoginInfo, "注册失败,账号已被注册"); FinalRun(); return; } LoginHelper.OnLoginAsync(account, password).Coroutine(); FinalRun(); } catch (Exception e) { Game.EventSystem.Run(EventIdType.ShowLoginInfo, "注册异常"); FinalRun(); } }
private async void OnRegister() { 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; } IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address); Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); sessionWrap = new SessionWrap(session); R2C_Register register = (R2C_Register)await sessionWrap.Call(new C2R_Register() { Account = accountText, Password = passwordText }); switch (register.Error) { case ErrorCode.ERR_Success: Log.Info("成功注册"); break; case ErrorCode.ERR_AccountExist: Log.Error("用户名已被注册"); break; } } catch (Exception e) { sessionWrap?.Dispose(); Log.Error(e.ToStr()); } }