/// <summary>
        /// 注册按钮事件
        /// </summary>
        public async void OnRegister()
        {
            if (isRegistering || this.IsDisposed)
            {
                return;
            }

            //设置登录中状态
            isRegistering = true;
            SessionWrap sessionWrap = null;

            prompt.text = "";
            try
            {
                //创建登录服务器连接
                IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);
                Session    session        = Game.Scene.ModelScene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                sessionWrap = new SessionWrap(session);

                //发送注册请求
                prompt.text = "正在注册中....";
                R2C_Register_Ack r2C_Register_Ack = await sessionWrap.Call(new C2R_Register_Req()
                {
                    Account = account.text, Password = password.text
                }) as R2C_Register_Ack;

                prompt.text = "";

                if (this.IsDisposed)
                {
                    return;
                }

                if (r2C_Register_Ack.Error == ErrorCode.ERR_AccountAlreadyRegister)
                {
                    prompt.text   = "注册失败,账号已被注册";
                    account.text  = "";
                    password.text = "";
                    return;
                }

                //注册成功自动登录
                OnLogin();
            }
            catch (Exception e)
            {
                prompt.text = "注册异常";
                Log.Error(e.ToStr());
            }
            finally
            {
                //断开验证服务器的连接
                sessionWrap?.Dispose();
                //设置注册处理完成状态
                isRegistering = false;
            }
        }
        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());
            }
        }
Beispiel #3
0
        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);
            }
        }
        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());
            }
        }
        /// <summary>
        /// 登录按钮事件
        /// </summary>
        public async void OnLogin()
        {
            if (isLogining || this.IsDisposed)
            {
                return;
            }
            NetOuterComponent netOuterComponent = Game.Scene.ModelScene.GetComponent <NetOuterComponent>();

            //设置登录中状态
            isLogining = true;
            SessionWrap sessionWrap = null;

            try
            {
                //创建登录服务器连接
                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.LandlordsLogin) != null)
                    {
                        prompt.text = "连接失败";
                        isLogining  = false;
                    }
                };

                //发送登录请求
                prompt.text = "正在登录中....";
                R2C_Login_Ack r2C_Login_Ack = await sessionWrap.Call(new C2R_Login_Req()
                {
                    Account = account.text, Password = password.text
                }) as R2C_Login_Ack;

                prompt.text = "";

                if (this.IsDisposed)
                {
                    return;
                }

                if (r2C_Login_Ack.Error == ErrorCode.ERR_LoginError)
                {
                    prompt.text   = "登录失败,账号或密码错误";
                    password.text = "";
                    return;
                }

                //创建Gate服务器连接
                connetEndPoint = NetworkHelper.ToIPEndPoint(r2C_Login_Ack.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;

                //登录Gate服务器
                G2C_LoginGate_Ack g2C_LoginGate_Ack = await SessionWrapComponent.Instance.Session.Call(new C2G_LoginGate_Req()
                {
                    Key = r2C_Login_Ack.Key
                }) as G2C_LoginGate_Ack;

                if (g2C_LoginGate_Ack.Error == ErrorCode.ERR_ConnectGateKeyError)
                {
                    prompt.text   = "连接网关服务器超时";
                    password.text = "";
                    Game.Scene.GetComponent <SessionWrapComponent>().Session.Dispose();
                    return;
                }

                Log.Info("登录成功");

                //保存本地玩家
                User user = ETModel.ComponentFactory.CreateWithId <User, long>(g2C_LoginGate_Ack.PlayerID, g2C_LoginGate_Ack.UserID);
                ClientComponent.Instance.LocalPlayer = user;

                //跳转到大厅界面
                Game.Scene.GetComponent <UIComponent>().Create(UIType.LandlordsLobby);
                Game.Scene.GetComponent <UIComponent>().Remove(UIType.LandlordsLogin);
            }
            catch (Exception e)
            {
                prompt.text = "登录异常";
                Log.Error(e.ToStr());
            }
            finally
            {
                //断开验证服务器的连接
                netOuterComponent.Remove(sessionWrap.session.Id);
                //设置登录处理完成状态
                isLogining = false;
            }
        }
Beispiel #6
0
        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;
            }
        }