Example #1
0
        public static async ETTask Login(Scene zoneScene, string address, string account, string password, Action onError = null)
        {
            try
            {
                // 创建一个ETModel层的Session
                R2C_Login r2CLogin;
                Session   session = null;
                try
                {
                    session = zoneScene.GetComponent <NetKcpComponent>().Create(NetworkHelper.ToIPEndPoint(address));
                    {
                        r2CLogin = (R2C_Login)await session.Call(new C2R_Login()
                        {
                            Account = account, Password = password
                        });
                    }
                }
                finally
                {
                    session?.Dispose();
                }

                long   channelId       = RandomHelper.RandInt64();
                var    routercomponent = zoneScene.AddComponent <GetRouterComponent, long, long>(r2CLogin.GateId, channelId);
                string routerAddress   = await routercomponent.Tcs;
                if (routerAddress == "")
                {
                    zoneScene.RemoveComponent <GetRouterComponent>();
                    throw new Exception("routerAddress 失败");
                }
                Log.Debug("routerAddress 获取成功:" + routerAddress);
                zoneScene.RemoveComponent <GetRouterComponent>();
                // 创建一个gate Session,并且保存到SessionComponent中
                Session gateSession = zoneScene.GetComponent <NetKcpComponent>().Create(channelId, NetworkHelper.ToIPEndPoint(routerAddress));
                gateSession.AddComponent <RouterDataComponent>().Gateid = r2CLogin.GateId;

                gateSession.AddComponent <PingComponent>();
                zoneScene.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(new EventType.LoginFinish()
                {
                    ZoneScene = zoneScene
                });
            }
            catch (Exception e)
            {
                onError?.Invoke();
                Log.Error(e);
            }
        }
Example #2
0
        public static async ETTask <long> Remove <T>(this DBComponent self, Expression <Func <T, bool> > filter, string collection = null) where T : Entity
        {
            using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, RandomHelper.RandInt64() % DBComponent.TaskCount))
            {
                DeleteResult result = await self.GetCollection <T>(collection).DeleteManyAsync(filter);

                return(result.DeletedCount);
            }
        }
Example #3
0
        public static async ETTask <List <T> > QueryJson <T>(this DBComponent self, long taskId, string json, string collection = null) where T : Entity
        {
            using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, RandomHelper.RandInt64() % DBComponent.TaskCount))
            {
                FilterDefinition <T> filterDefinition = new JsonFilterDefinition <T>(json);
                IAsyncCursor <T>     cursor           = await self.GetCollection <T>(collection).FindAsync(filterDefinition);

                return(await cursor.ToListAsync());
            }
        }
Example #4
0
        public static async ETTask <List <T> > Query <T>(this DBComponent self, Expression <Func <T, bool> > filter, string collection = null)
            where T : Entity
        {
            using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, RandomHelper.RandInt64() % DBComponent.TaskCount))
            {
                IAsyncCursor <T> cursor = await self.GetCollection <T>(collection).FindAsync(filter);

                return(await cursor.ToListAsync());
            }
        }
        protected override async ETTask Run(Scene scene, R2G_GetLoginKey request, G2R_GetLoginKey response, Action reply)
        {
            long key = RandomHelper.RandInt64();

            scene.GetComponent <GateSessionKeyComponent>().Add(key, request.Account);
            response.Key    = key;
            response.GateId = scene.Id;
            reply();
            await ETTask.CompletedTask;
        }
Example #6
0
        public static Session Create(this NetKcpComponent self, IPEndPoint realIPEndPoint)
        {
            long    channelId = RandomHelper.RandInt64();
            Session session   = EntityFactory.CreateWithParentAndId <Session, AService>(self, channelId, self.Service);

            session.RemoteAddress = realIPEndPoint;
            session.AddComponent <SessionIdleCheckerComponent, int>(NetThreadComponent.checkInteral);

            self.Service.GetOrCreate(session.Id, realIPEndPoint);

            return(session);
        }
Example #7
0
        public static async ETTask InsertBatch <T>(this DBComponent self, IEnumerable <T> list, string collection = null) where T : Entity
        {
            if (collection == null)
            {
                collection = typeof(T).Name;
            }

            using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.DB, RandomHelper.RandInt64() % DBComponent.TaskCount))
            {
                await self.GetCollection(collection).InsertManyAsync(list);
            }
        }