private async Task <AccountDetail> GetAccountDetail(long id)

        {
            var tAccount = _redis.GetAccountInfo(id);
            var tMoney   = _moneyClient.GetResponseExt <GetMoneyMqCommand, BodyResponse <MoneyMqResponse> >
                               (new GetMoneyMqCommand(id));

            var tLevel = _bus.SendCommand(new GetLevelInfoCommand(id));
            var tGame  = _bus.SendCommand(new GetGameInfoCommand(id));
            await Task.WhenAll(tAccount, tMoney, tLevel, tGame);

            var accountInfo  = tAccount.Result;
            var moneyInfores = tMoney.Result;
            var moneyInfo    = new MoneyInfo(moneyInfores.Message.Body.CurCoins + moneyInfores.Message.Body.Carry, moneyInfores.Message.Body.CurDiamonds,
                                             moneyInfores.Message.Body.MaxCoins, moneyInfores.Message.Body.MaxDiamonds);
            var levelInfo = tLevel.Result.Body;
            var gameInfo  = tGame.Result.Body;

            if (accountInfo == null || moneyInfo == null || levelInfo == null || gameInfo == null)
            {
                return(null);
            }
            return(new AccountDetail(accountInfo.Id, accountInfo.PlatformAccount,
                                     accountInfo.UserName, accountInfo.Sex, accountInfo.HeadUrl,
                                     accountInfo.Type, levelInfo, gameInfo, moneyInfo));
        }
Esempio n. 2
0
        public static async Task <AccountInfo> GetAccountInfo(long id, IAccountInfoRepository _accountRepository, IAccountRedisRepository _redis)
        {
            var accountInfo = await _redis.GetAccountInfo(id);

            if (accountInfo == null)
            {
                accountInfo = await _accountRepository.GetByIdAsync(id);

                if (accountInfo != null)
                {
                    await _redis.SetAccountInfo(accountInfo);
                }
            }
            return(accountInfo);
        }
        public async Task Handle(FinishRegisterRewardEvent notification, CancellationToken cancellationToken)
        {
            using (var loker = _redis.Locker(KeyGenHelper.GenUserKey(notification.Id, AccountInfo.className)))
            {
                loker.Lock();
                AccountInfo info = await _redis.GetAccountInfo(notification.Id);

                if (info == null)
                {
                    info = await _accountRepository.GetByIdAsync(notification.Id);
                }
                info.Flags |= GetAccountBaseInfoMqResponse.SomeFlags.RegisterReward;
                await Task.WhenAll(_accountRepository.UpdateAsync(info), _redis.SetAccountInfo(info));
            }
        }
Esempio n. 4
0
        public async Task <BodyResponse <AccountResponse> > Handle(LoginCommand request, CancellationToken cancellationToken)
        {
            var newAccountInfo = request.Info;
            //根据PlatformAccount字段读取redis,判断该账号是否已经注册
            var loginCheckInfo = await _redis.GetLoginCheckInfo(request.Info.PlatformAccount);

            AccountInfo accountInfo = null;
            bool        isRegister  = false;

            if (loginCheckInfo != null)
            {
                //直接通过ID去查找这个玩家信息
                accountInfo = await _redis.GetAccountInfo(loginCheckInfo.Id);

                if (accountInfo == null)
                {
                    accountInfo = await _accountRepository.GetByIdAsync(loginCheckInfo.Id);
                }
            }

            else
            {
                //查找数据库中是否有这个账号
                accountInfo = await _accountRepository.GetByPlatform(newAccountInfo.PlatformAccount);

                if (accountInfo == null)
                {
                    //注册新账号
                    isRegister = true;
                    long newUid = await _genRepository.GenNewId();

                    accountInfo = new AccountInfo(newUid, newAccountInfo.PlatformAccount,
                                                  newAccountInfo.UserName, newAccountInfo.Sex, newAccountInfo.HeadUrl,
                                                  newAccountInfo.Type, DateTime.Now, GetAccountBaseInfoMqResponse.SomeFlags.None);
                    await _accountRepository.AddAsync(accountInfo);
                }
            }

            if (accountInfo != null)
            {
                newAccountInfo.Id = accountInfo.Id;
                string          token          = TokenHelper.GenToken(accountInfo.Id);
                AccountResponse accounResponse = null;

                bool isNeedUpdate = false;
                //如果登录信息有更新, 那么更新数据库
                if (!isRegister && accountInfo != newAccountInfo)
                {
                    isNeedUpdate = true;
                }
                if (isRegister)
                {
                    var mqResponse = await _moneyAddClient.GetResponseExt <AddMoneyMqCommand, BodyResponse <MoneyMqResponse> >
                                         (new AddMoneyMqCommand(accountInfo.Id, _initRewardInfo.RewardCoins, 0, AddReason.InitReward));

                    var moneyInfo = mqResponse.Message.Body;

                    accounResponse = new AccountResponse(newAccountInfo.Id,
                                                         newAccountInfo.PlatformAccount,
                                                         newAccountInfo.UserName,
                                                         newAccountInfo.Sex,
                                                         newAccountInfo.HeadUrl,
                                                         token, new MoneyInfo(moneyInfo.CurCoins + moneyInfo.Carry,
                                                                              moneyInfo.CurDiamonds,
                                                                              moneyInfo.MaxCoins,
                                                                              moneyInfo.MaxDiamonds),
                                                         _hostManager.GetOneHost(), true, newAccountInfo.Type);
                }
                else
                {
                    //查询玩家金币
                    MoneyMqResponse moneyResponse = null;

                    var mqResponse = await _moneyClient.GetResponseExt <GetMoneyMqCommand, BodyResponse <MoneyMqResponse> >
                                         (new GetMoneyMqCommand(accountInfo.Id));

                    moneyResponse  = mqResponse.Message.Body;
                    accounResponse = new AccountResponse(newAccountInfo.Id,
                                                         newAccountInfo.PlatformAccount,
                                                         newAccountInfo.UserName,
                                                         newAccountInfo.Sex,
                                                         newAccountInfo.HeadUrl,
                                                         token, new MoneyInfo(moneyResponse.CurCoins + moneyResponse.Carry,
                                                                              moneyResponse.CurDiamonds,
                                                                              moneyResponse.MaxCoins,
                                                                              moneyResponse.MaxDiamonds),
                                                         _hostManager.GetOneHost(), false, newAccountInfo.Type);
                }

                _ = _bus.RaiseEvent <LoginEvent>(new LoginEvent(Guid.NewGuid(),
                                                                accounResponse, isRegister, isNeedUpdate, newAccountInfo));
                BodyResponse <AccountResponse> retRresponse =
                    new BodyResponse <AccountResponse>(StatusCodeDefines.Success, null, accounResponse);
                return(retRresponse);
            }

            BodyResponse <AccountResponse> response = new BodyResponse <AccountResponse>(StatusCodeDefines.LoginError,
                                                                                         null, null);

            return(response);
        }