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); }
public async Task <WrappedResponse <AccountResponse> > Handle(LoginCommand request, CancellationToken cancellationToken) { var newAccountInfo = request.Info; //判断该平台ID是否已经注册, 先从redis查找 var loginCheckInfo = await _redisRep.GetLoginCheckInfo(newAccountInfo.PlatformAccount); bool isRegister = false; AccountInfo accountInfo; if (loginCheckInfo != null) { //直接通过ID去查找这个玩家信息 accountInfo = await _redisRep.GetAccountInfo(loginCheckInfo.Id); //为空从数据库读取 if (accountInfo == null) { accountInfo = await _accountRep.GetByIdAsync(loginCheckInfo.Id); } } else { //查找数据库中是否有这个账号 accountInfo = await _accountRep.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); await _accountRep.AddAsync(accountInfo); } } if (accountInfo != null) { newAccountInfo.Id = accountInfo.Id; string token = TokenTool.GenToken(accountInfo.Id); AccountResponse accounResponse; bool isNeedUpdate = false; if (!isRegister && accountInfo.IsNeedUpdate(newAccountInfo)) { isNeedUpdate = true; } if (isRegister) { var mqResponse = await _moneyAddClient.GetResponseExt <AddMoneyMqCmd, WrappedResponse <MoneyMqResponse> > (new AddMoneyMqCmd(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), WSHostManager.GetOneHost(), true, newAccountInfo.Type); } else { var mqResponse = await _moneyClient.GetResponseExt <GetMoneyMqCmd, WrappedResponse <MoneyMqResponse> > (new GetMoneyMqCmd(accountInfo.Id)); 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), WSHostManager.GetOneHost(), false, newAccountInfo.Type); } _ = _bus.RaiseEvent <LoginEvent>(new LoginEvent(Guid.NewGuid(), accounResponse, isRegister, isNeedUpdate, newAccountInfo)); WrappedResponse <AccountResponse> retRresponse = new WrappedResponse <AccountResponse>(ResponseStatus.Success, null, accounResponse); return(retRresponse); } WrappedResponse <AccountResponse> response = new WrappedResponse <AccountResponse>(ResponseStatus.LoginError, null, null); return(response); }