示例#1
0
        protected override async ETTask Run(Session session, C2G_LoginGate request, G2C_LoginGate response, Action reply)
        {
            Scene  scene   = session.DomainScene();
            string account = scene.GetComponent <GateSessionKeyComponent>().Get(request.Key);

            if (account == null)
            {
                response.Error   = ErrorCore.ERR_ConnectGateKeyError;
                response.Message = "Gate key验证失败!";
                reply();
                return;
            }

            session.RemoveComponent <SessionAcceptTimeoutComponent>();

            PlayerComponent playerComponent = scene.GetComponent <PlayerComponent>();
            Player          player          = playerComponent.AddChild <Player, string>(account);

            playerComponent.Add(player);
            session.AddComponent <SessionPlayerComponent>().Player = player;
            session.AddComponent <MailBoxComponent, MailboxType>(MailboxType.GateSession);

            response.PlayerId = player.Id;
            reply();
            await ETTask.CompletedTask;
        }
示例#2
0
        public static async ETVoid OnLoginAsync(Entity domain, string address, string account)
        {
            try
            {
                // 创建一个ETModel层的Session
                Session session = Game.Scene.GetComponent <NetOuterComponent>().Create(address);

                // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息
                Session   realmSession = EntityFactory.Create <Session, Session>(domain, session);
                R2C_Login r2CLogin     = (R2C_Login)await realmSession.Call(new C2R_Login()
                {
                    Account = account, Password = "******"
                });

                realmSession.Dispose();

                // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中
                Session gateSession = Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address);
                Game.Scene.AddComponent <SessionComponent>().Session = gateSession;

                // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中
                Game.Scene.AddComponent <SessionComponent>().Session = EntityFactory.Create <Session, 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          = EntityFactory.CreateWithId <Player>(Game.Scene, g2CLoginGate.PlayerId);
                PlayerComponent playerComponent = 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);
            }
        }
示例#3
0
 public void Awake()
 {
     Instance = this;
 }
示例#4
0
        public static async ETVoid OnLoginAsync()
        {
            try
            {
                UILoginComponent login = Game.Scene.GetComponent <UIComponent>().Get(UIType.UILogin).GetComponent <UILoginComponent>();

                // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息
                Session   realmSession = Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);
                R2C_Login r2CLogin     = (R2C_Login)await realmSession.Call(new C2R_Login()
                {
                    Account = "abc", Password = "******"
                });

                realmSession.Dispose();
                Log.Info("正在登录中...");

                //判断Realm服务器返回结果
                if (r2CLogin.Error == ErrorCode.ERR_AccountOrPasswordError)
                {
                    Log.Info("登录失败,账号或密码错误");
                    login.account.text  = "";
                    login.password.text = "";
                    return;
                }


                // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中
                Session gateSession = Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address);
                Game.Scene.AddComponent <SessionComponent>().Session = gateSession;
                SessionComponent.Instance.Session = gateSession;

                G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await gateSession.Call(
                    new C2G_LoginGate()
                {
                    Key = r2CLogin.Key, GateId = r2CLogin.GateId
                });

                //判断登陆Gate服务器返回结果
                if (g2CLoginGate.Error == ErrorCode.ERR_ConnectGateKeyError)
                {
                    Log.Info("连接网关服务器超时");
                    login.account.text  = "";
                    login.password.text = "";
                    gateSession.Dispose();
                    return;
                }
                //判断通过则登陆Gate成功
                Log.Info("登陆gate成功!");

                // 创建Player
                Player          player          = EntityFactory.CreateWithId <Player>(Game.Scene, g2CLoginGate.PlayerId);
                PlayerComponent playerComponent = 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);
            }
        }
示例#5
0
 public static Player[] GetAll(this PlayerComponent self)
 {
     return(self.idPlayers.Values.ToArray());
 }
示例#6
0
 public static void Remove(this PlayerComponent self, long id)
 {
     self.idPlayers.Remove(id);
 }
示例#7
0
 public static Player Get(this PlayerComponent self, long id)
 {
     self.idPlayers.TryGetValue(id, out Player gamer);
     return(gamer);
 }
示例#8
0
 public static void Add(this PlayerComponent self, Player player)
 {
     self.idPlayers.Add(player.Id, player);
 }