Пример #1
0
        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);
            }
        }
Пример #2
0
        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());
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        //不懂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);
            }
        }
Пример #7
0
        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);
            }
        }
Пример #8
0
        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);
            }
        }
Пример #9
0
        //不懂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);
            }
        }
Пример #10
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);
            }
        }
Пример #11
0
        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);
        }
Пример #12
0
        public static async ETVoid OnLoginAsync(string account, string password)
        {
            try
            {
                // 显示加载UI
                ETModel.Game.EventSystem.Run(ETModel.EventIdType.ShowLoadingUI);
                // 如果正在登录,就驳回登录请求,为了双重保险,点下登录按钮后,收到服务端响应之前将不能再点击
                if (isLogining)
                {
                    FinalRun();
                    return;
                }

                isLogining = true;

                if (account == "" || password == "")
                {
                    Game.EventSystem.Run(EventIdType.ShowLoginInfo, "账号或密码不能为空");
                    FinalRun();
                    return;
                }

                // 创建一个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);

                Game.EventSystem.Run(EventIdType.ShowLoginInfo, "登陆中。。。");
                // 发送登录请求,账号,密码均为传来的参数
                R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login()
                {
                    Account = account, Password = password
                });

                if (r2CLogin.Error == ErrorCode.ERR_LoginError)
                {
                    Game.EventSystem.Run(EventIdType.ShowLoginInfo, "登录失败,账号或密码错误");
                    FinalRun();
                    return;
                }

                //释放realmSession
                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 = ComponentFactory.Create <Session, ETModel.Session>(gateSession);

                // 增加客户端断线处理组件
                Game.Scene.GetComponent <SessionComponent>().Session.AddComponent <SessionOfflineComponent>();

                // 增加心跳组件
                ETModel.Game.Scene.GetComponent <ETModel.SessionComponent>().Session.AddComponent <HeartBeatComponent>();

                await SessionComponent.Instance.Session.Call(new C2G_LoginGate()
                {
                    Key = r2CLogin.Key
                });

                Game.EventSystem.Run(EventIdType.ShowLoginInfo, "登录成功");

                // 创建Player(抽象化的玩家),这里的id是数据库里的账号id
                Player          player          = ETModel.ComponentFactory.CreateWithId <Player>(r2CLogin.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());
                // Debug.Log("测试玩家信息为" + g2CPlayerInfo.Message);
                FinalRun();
            }
            catch (Exception e)
            {
                Log.Error(e);
                FinalRun();
            }
        }
Пример #13
0
        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);
            }
        }
Пример #14
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;
            }
        }
Пример #15
0
        public override async ETTask C2R_LoginHandler(Session session, C2R_Login request, R2C_Login response, Action reply)
        {
            Console.WriteLine("C2R_LoginHandler");
            // 随机分配一个Gate
            StartConfig config = RealmGateAddressHelper.GetGate();
            //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");

            // 向gate请求一个key,客户端可以拿着这个key连接gate
            G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await ActorMessageSenderComponent.Instance.Call(
                config.SceneInstanceId, new R2G_GetLoginKey()
            {
                Account = request.Account
            });

            string outerAddress = config.GetParent <StartConfig>().GetComponent <OuterConfig>().Address2;

            response.Address = outerAddress;
            response.Key     = g2RGetLoginKey.Key;
            response.GateId  = g2RGetLoginKey.GateId;
            reply();
        }
Пример #16
0
        /// <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);
            }
        }
Пример #17
0
 public virtual async ETTask C2R_LoginHandler(ETModel.Session session, C2R_Login request, R2C_Login response, Action reply)
 {
 }