Beispiel #1
0
        private static async ETTask <IActorResponse> Run(this ActorLocationSender self, IActorRequest iActorRequest)
        {
            long instanceId = self.InstanceId;

            using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.ActorLocationSender, self.Id))
            {
                if (self.InstanceId != instanceId)
                {
                    throw new RpcException(ErrorCode.ERR_ActorRemove, $"{MongoHelper.ToJson(iActorRequest)}");
                }

                return(await self.RunInner(iActorRequest));
            }
        }
Beispiel #2
0
        public ETTask <IResponse> CallWithoutException(IRequest request)
        {
            int rpcId = ++RpcId;
            var tcs   = new ETTaskCompletionSource <IResponse>();

            this.requestCallback[rpcId] = (response) =>
            {
                if (response is ErrorResponse)
                {
                    tcs.SetException(new Exception($"Rpc error: {MongoHelper.ToJson(response)}"));
                    return;
                }

                tcs.SetResult(response);
            };

            request.RpcId = rpcId;
            this.Send(request);
            return(tcs.Task);
        }
Beispiel #3
0
        protected override async ETTask Run(Session session, C2R_Login request, R2C_Login response, Action reply)
        {
            // 随机分配一个Gate
            StartSceneConfig config = RealmGateAddressHelper.GetGate(session.DomainZone());

            Log.Debug($"gate address: {MongoHelper.ToJson(config)}");

            string accountName = request.Account;
            string password    = request.Password;
            //验证账号密码
            List <Account> list = await DBComponent.Instance.Query <Account>(
                a => a.AccountName.Equals(accountName) && a.Password.Equals(password)
                );

            Account account;

            if (list == null || list.Count == 0)
            {
                account = EntityFactory.Create <Account, string, string>(Game.Scene, accountName, password);
                await DBComponent.Instance.Save(account);
            }
            else
            {
                account = list[0];
            }

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

            response.Address = config.OuterAddress;
            response.Key     = g2RGetLoginKey.Key;

            Log.Info($"Gate:{response.Address}, Key:{response.Key}");
            response.GateId = g2RGetLoginKey.GateId;
            reply();
        }
Beispiel #4
0
 public static string MessageToStr(object message)
 {
     return(MongoHelper.ToJson(message));
 }
Beispiel #5
0
 public static string ToJson(object obj)
 {
     return(MongoHelper.ToJson(obj));
 }