示例#1
0
        // 等10分钟再获取一次
        public static async ETTask WaitTenMinGetAllRouter(this RouterAddressComponent self)
        {
            await TimerComponent.Instance.WaitAsync(5 * 60 * 1000);

            if (self.IsDisposed)
            {
                return;
            }
            await self.GetAllRouter();
        }
示例#2
0
文件: LoginHelper.cs 项目: x00568/ET
        public static async ETTask Login(Scene clientScene, string account, string password)
        {
            try
            {
                // 创建一个ETModel层的Session
                R2C_Login r2CLogin;
                Session   session = null;
                try
                {
                    clientScene.RemoveComponent <RouterAddressComponent>();
                    // 获取路由跟realmDispatcher地址
                    RouterAddressComponent routerAddressComponent = clientScene.GetComponent <RouterAddressComponent>();
                    if (routerAddressComponent == null)
                    {
                        routerAddressComponent = clientScene.AddComponent <RouterAddressComponent, string, int>(ConstValue.RouterHttpHost, ConstValue.RouterHttpPort);
                        await routerAddressComponent.Init();

                        clientScene.AddComponent <NetKcpComponent, AddressFamily, int>(routerAddressComponent.RouterManagerIPAddress.AddressFamily, CallbackType.SessionStreamDispatcherClientOuter);
                    }
                    IPEndPoint realmAddress = routerAddressComponent.GetRealmAddress(account);

                    session = await RouterHelper.CreateRouterSession(clientScene, realmAddress);

                    {
                        r2CLogin = (R2C_Login)await session.Call(new C2R_Login()
                        {
                            Account = account, Password = password
                        });
                    }
                }
                finally
                {
                    session?.Dispose();
                }

                // 创建一个gate Session,并且保存到SessionComponent中
                Session gateSession = await RouterHelper.CreateRouterSession(clientScene, NetworkHelper.ToIPEndPoint(r2CLogin.Address));

                clientScene.AddComponent <SessionComponent>().Session = gateSession;

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

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

                await Game.EventSystem.PublishAsync(clientScene, new EventType.LoginFinish());
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
示例#3
0
文件: RouterHelper.cs 项目: x00568/ET
        public static async ETTask <(uint, IPEndPoint)> GetRouterAddress(Scene clientScene, IPEndPoint address, uint localConn, uint remoteConn)
        {
            Log.Info($"start get router address: {clientScene.Id} {address} {localConn} {remoteConn}");
            //return (RandomHelper.RandUInt32(), address);
            RouterAddressComponent routerAddressComponent = clientScene.GetComponent <RouterAddressComponent>();
            IPEndPoint             routerInfo             = routerAddressComponent.GetAddress();

            uint recvLocalConn = await Connect(routerInfo, address, localConn, remoteConn);

            Log.Info($"finish get router address: {clientScene.Id} {address} {localConn} {remoteConn} {recvLocalConn} {routerInfo}");
            return(recvLocalConn, routerInfo);
        }
示例#4
0
        public static IPEndPoint GetRealmAddress(this RouterAddressComponent self, string account)
        {
            int    v       = account.Mode(self.Info.Realms.Count);
            string address = self.Info.Realms[v];

            string[]  ss        = address.Split(':');
            IPAddress ipAddress = IPAddress.Parse(ss[0]);

            //if (self.IPAddress.AddressFamily == AddressFamily.InterNetworkV6)
            //{
            //    ipAddress = ipAddress.MapToIPv6();
            //}
            return(new IPEndPoint(ipAddress, int.Parse(ss[1])));
        }
示例#5
0
        public static IPEndPoint GetAddress(this RouterAddressComponent self)
        {
            if (self.Info.Routers.Count == 0)
            {
                return(null);
            }

            string address = self.Info.Routers[self.RouterIndex++ % self.Info.Routers.Count];

            string[]  ss        = address.Split(':');
            IPAddress ipAddress = IPAddress.Parse(ss[0]);

            if (self.RouterManagerIPAddress.AddressFamily == AddressFamily.InterNetworkV6)
            {
                ipAddress = ipAddress.MapToIPv6();
            }
            return(new IPEndPoint(ipAddress, int.Parse(ss[1])));
        }
示例#6
0
        private static async ETTask GetAllRouter(this RouterAddressComponent self)
        {
            string url = $"http://{self.RouterManagerHost}:{self.RouterManagerPort}/get_router?v={RandomHelper.RandUInt32()}";

            Log.Debug($"start get router info: {url}");
            string routerInfo = await HttpClientHelper.Get(url);

            Log.Debug($"recv router info: {routerInfo}");
            HttpGetRouterResponse httpGetRouterResponse = JsonHelper.FromJson <HttpGetRouterResponse>(routerInfo);

            self.Info = httpGetRouterResponse;
            Log.Debug($"start get router info finish: {JsonHelper.ToJson(httpGetRouterResponse)}");

            // 打乱顺序
            RandomHelper.BreakRank(self.Info.Routers);

            self.WaitTenMinGetAllRouter().Coroutine();
        }
示例#7
0
 public static async ETTask Init(this RouterAddressComponent self)
 {
     self.RouterManagerIPAddress = NetworkHelper.GetHostAddress(self.RouterManagerHost);
     await self.GetAllRouter();
 }