Beispiel #1
0
        public async Task OnLogin(BattleServerInfo serverInfo = null)
        {
            try
            {
                if (serverInfo == null)
                {
                    Log.Error("onlogin failure");
                    return;
                }
                Log.Info("onlogin");
                roomId = serverInfo.roomId;

                // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中
                ETModel.Session          gateSession  = ETModel.Game.Scene.GetComponent <ETModel.NetOuterComponent>().Create(serverInfo.ipAndPort);
                ETModel.SessionComponent modelSession = ETModel.Game.Scene.GetComponent <ETModel.SessionComponent>();
                if (modelSession == null)
                {
                    modelSession = ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>();
                }
                modelSession.Session = gateSession;

                C2G_LoginGate c2G_LoginGate = new C2G_LoginGate()
                {
                    Token = serverInfo.token, RoomId = serverInfo.roomId, PlayerId = playerUID
                };
                G2C_LoginGate g2C_LoginGate = await modelSession.Session.Call(c2G_LoginGate) as G2C_LoginGate;

                if (g2C_LoginGate != null)
                {
                    if (g2C_LoginGate.Error == ErrorCode.ERR_ConnectGateKeyError)
                    {
                        Game.EventSystem.Run(EventIdType.FightGameEnd);
                    }
                }
                //if (funcs.UsingFrameSync && !func.IsPlayback)
                //{
                //    ETModel.WebSocketBenchmarkComponent testPing = ETModel.Game.Scene.GetComponent<ETModel.WebSocketBenchmarkComponent>();
                //    if (testPing == null)
                //        testPing = ETModel.Game.Scene.AddComponent<ETModel.WebSocketBenchmarkComponent>();
                //    testPing.Session = gateSession;
                //}
                //testPing.UpdatePing();  //开始心跳

                Log.Info("登陆gate成功!");
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Beispiel #2
0
        public async void OnLogin()
        {
            SessionWrap sessionWrap = null;

            try
            {
                IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(ServerIP);

                Session session = Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                sessionWrap = new SessionWrap(session);
                R2C_Login r2CLogin = (R2C_Login)await sessionWrap.Call(new C2R_Login()
                {
                    Account = nickname.text, Password = "******"
                });

                sessionWrap.Dispose();

                connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address);
                Session gateSession = Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                Game.Scene.AddComponent <SessionWrapComponent>().Session = new SessionWrap(gateSession);
                Game.Scene.AddComponent <SessionComponent>().Session     = gateSession;
                //G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionWrapComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key });

                G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await Game.Scene.GetComponent <SessionWrapComponent>().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;

                uiLogin.SetActive(false);
                uiLobby.SetActive(true);
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
        }
Beispiel #3
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);
                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);
            }
        } 
Beispiel #4
0
        public static async ETVoid OnLoginAsync(string account)
        {
            try
            {
                //  ===> 登录session
                Session   session  = Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);
                R2C_Login r2CLogin = (R2C_Login)await session.Call(new C2R_Login()
                {
                    Account = account, Password = "******"
                });

                // ===> 网关session
                Session gateSession = Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address);
                Game.Scene.AddComponent <SessionComponent>().Session = gateSession;


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

                Log.Info("登陆gate成功!");

                // 创建Player
                Player          player          = ComponentFactory.CreateWithId <Player>(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);
            }
        }