public Task Handle(LoginEvent notification, CancellationToken cancellationToken)
        {
            //如果登录信息有更新, 那么更新数据库
            if (notification.IsNeedUpdate)
            {
                _accountRepository.Update(notification.Info);
            }
            try
            {
                if (notification.IsRegister)
                {
                    //通知注册
                    _ = _mqBus.Publish <RegistMqEvent>(_mapper.Map <RegistMqEvent>(notification.AccounResponse));
                }
                else
                {
                    //通知登录
                    _ = _mqBus.Publish <LoginMqEvent>(_mapper.Map <LoginMqEvent>(notification.AccounResponse));
                }
            }
            catch (Exception ex)
            {
                Log.Logger.Error($"Publish LoginMqEvent exception {ex.Message}");
            }

            //设置登录信息
            _redis.SetLoginCheckInfo(notification.Info.PlatformAccount, notification.Info);
            //设置玩家信息缓存
            _redis.SetAccountInfo(notification.Info);
            return(Task.CompletedTask);
        }
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);
        }