예제 #1
0
        private async Task HandleLoginOkStateAsync(
            RS_LOGON_CHALLENGE request,
            ChannelWriter <byte> writer,
            Client clientModel,
            AccountInfoEntity accountInfo)
        {
            if (accountInfo.sha_pass_hash.Length != 40) // Invalid password type, should always be 40 characters
            {
                await AUTH_LOGON_PROOF_Writer.WriteAsync(writer, new AUTH_LOGON_PROOF(AccountState.LOGIN_BAD_PASS));

                return;
            }

            var hash = GetPasswordHashFromString(accountInfo.sha_pass_hash);

            clientModel.AuthEngine.CalculateX(request.Account, hash);

            var resposne = new AUTH_LOGON_CHALLENGE(
                clientModel.AuthEngine.PublicB,
                clientModel.AuthEngine.g,
                clientModel.AuthEngine.N,
                clientModel.AuthEngine.Salt,
                AuthEngine.CrcSalt);

            await AUTH_LOGON_CHALLENGE_Writer.WriteAsync(writer, resposne);
        }
 private async Task <AccountState> GetAccountStateAsync(AccountInfoEntity accountInfo)
 {
     return(accountInfo != null
         ? await accountStorage.IsBannedAccountAsync(accountInfo.id)
             ? AccountState.LOGIN_BANNED
             : AccountState.LOGIN_OK
         : AccountState.LOGIN_UNKNOWN_ACCOUNT);
 }
예제 #3
0
        public string GetRegionTarget(string regionTarget)
        {
            string            accountName = CookieWebHelper.AccountName;
            bool              b           = false;
            var               db          = CoreDBContext.GetContext();
            AccountInfoEntity account     = db.Set <AccountInfoEntity>().Where(x => x.AccountName == accountName).FirstOrDefault();

            if (account != null)
            {
                b = Equals(account.RegionTarget, regionTarget);
            }
            return(string.IsNullOrEmpty(regionTarget) ? "没有设置地域" : b ? "账户推广地域" : "计划推广地域");
        }
예제 #4
0
        /// <summary>
        /// Saves the account information.
        /// </summary>
        /// <param name="activatedEvent">The activated event.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        public async Task SaveAccountInfo(ActivatedEvent activatedEvent, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(activatedEvent.PublicKey))
            {
                throw new AddonValidationException($"Invalid {nameof(activatedEvent.PublicKey)} provided.", new Details {
                    Code = ErrorCodes.InvalidInput, Name = nameof(activatedEvent.PublicKey), Value = null
                });
            }

            if (string.IsNullOrEmpty(activatedEvent.TenantId))
            {
                throw new AddonValidationException($"Invalid {nameof(activatedEvent.TenantId)} provided.", new Details {
                    Code = ErrorCodes.InvalidInput, Name = nameof(activatedEvent.TenantId), Value = null
                });
            }

            if (string.IsNullOrEmpty(activatedEvent.ClientCredentials?.ClientId))
            {
                throw new AddonValidationException($"Invalid {nameof(activatedEvent.ClientCredentials.ClientId)} provided.", new Details {
                    Code = ErrorCodes.InvalidInput, Name = nameof(activatedEvent.ClientCredentials.ClientId), Value = null
                });
            }

            if (string.IsNullOrEmpty(activatedEvent.ClientCredentials?.ClientSecret))
            {
                throw new AddonValidationException($"Invalid {nameof(activatedEvent.ClientCredentials.ClientSecret)} provided.", new Details {
                    Code = ErrorCodes.InvalidInput, Name = nameof(activatedEvent.ClientCredentials.ClientSecret), Value = null
                });
            }

            var accountInfoEntity = new AccountInfoEntity()
            {
                PublicKey         = activatedEvent.PublicKey,
                TenantId          = activatedEvent.TenantId,
                ClientCredentials = activatedEvent.ClientCredentials
            };

            var accountInfo = await _repository.GetAccountInfoByTenantId(activatedEvent.TenantId).ConfigureAwait(false);

            if (accountInfo != null)
            {
                throw new AccountValidationException($"Account {activatedEvent.TenantId} is already activated.", new Details {
                    Code = ErrorCodes.AccountAlreadyActivated, Name = nameof(activatedEvent.TenantId), Value = activatedEvent.TenantId
                });
            }

            await _repository.SaveAccount(accountInfoEntity).ConfigureAwait(false);
        }
예제 #5
0
        /// <summary>
        /// Saves or updates the configuration settings
        /// </summary>
        /// <param name="tenantId">The tenant id.</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The updated configuration settings result.</returns>
        public async Task <ConfigurationSettingsResult> SaveOrUpdateConfigurationSettings(string tenantId, List <ConfigurationValueModel> configurationValues, CancellationToken cancellationToken)
        {
            AccountInfoEntity accountInfo = await _repository.GetAccountInfoByTenantId(tenantId).ConfigureAwait(false);

            if (accountInfo == null)
            {
                throw new AccountValidationException($"Account {tenantId} is not activated!", new Details {
                    Code = ErrorCodes.AccountNotActivated, Name = nameof(tenantId), Value = tenantId
                });
            }

            accountInfo = UpdateConfigurationsForAccount(accountInfo, configurationValues);
            var updatedAccountInfoEntity = await _repository.SaveOrUpdateConfigurationSettings(accountInfo).ConfigureAwait(false);

            return(MaskSecretConfigurations(updatedAccountInfoEntity.ConfigurationValues));
        }
예제 #6
0
        /// <summary>
        /// Saves or updates the configurations settings.
        /// </summary>
        /// <param name="accountInfoEntity">The account info entity.</param>
        /// <returns>The updated account info entity.</returns>
        public async Task <AccountInfoEntity> SaveOrUpdateConfigurationSettings(AccountInfoEntity accountInfoEntity)
        {
            var filter = Builders <AccountInfoEntity> .Filter
                         .Where(accountInfo => accountInfo.TenantId == accountInfoEntity.TenantId);

            var options = new FindOneAndUpdateOptions <AccountInfoEntity>
            {
                ReturnDocument = ReturnDocument.After
            };

            var update = Builders <AccountInfoEntity> .Update
                         .Set(account => account.TenantId, accountInfoEntity.TenantId)
                         .Set(account => account.PublicKey, accountInfoEntity.PublicKey)
                         .Set(account => account.ConfigurationValues, accountInfoEntity.ConfigurationValues);

            return(await _accounts.FindOneAndUpdateAsync(filter, update, options));
        }
예제 #7
0
        protected override void DealRowData(string[] fields, SynCheckedDataInfoEntity entity)
        {
            AccountInfoEntity model = ParamHelper.wcfAccount.FindByExpression(x => x.AccountName == entity.AccountName).FirstOrDefault();

            if (model != null)
            {
                model.AccountId    = long.Parse(fields[0]);
                model.Balance      = fields[1] == "-" ? 0 : decimal.Parse(fields[1]);
                model.Cost         = fields[2] == "-" ? 0 : decimal.Parse(fields[2]);
                model.Payment      = fields[3] == "-" ? 0 : decimal.Parse(fields[3]);
                model.Budget       = fields[4] == "-" ? 0 : decimal.Parse(fields[4]);
                model.RegionTarget = fields[5];
                model.ExcludeIp    = fields[6];
                model.OpenDomains  = fields[7];
                ParamHelper.wcfAccount.Update(model);
            }
        }
예제 #8
0
        /// <summary>
        /// Updates the configurations for an account.
        /// </summary>
        /// <param name="accountInfo">The account information.</param>
        /// <param name="configurationValues">The configuration values.</param>
        /// <returns>The updated account info entity.</returns>
        private AccountInfoEntity UpdateConfigurationsForAccount(AccountInfoEntity accountInfo, List <ConfigurationValueModel> configurationValues)
        {
            if (accountInfo.ConfigurationValues == null)
            {
                accountInfo.ConfigurationValues = configurationValues;
            }
            else
            {
                foreach (var config in configurationValues)
                {
                    var matchedItem = accountInfo.ConfigurationValues.FirstOrDefault(f => f.Id == config.Id);
                    if (matchedItem == null)
                    {
                        accountInfo.ConfigurationValues.Add(config);
                    }
                    else
                    {
                        matchedItem.Value = config.Value;
                    }
                }
            }

            return(accountInfo);
        }
예제 #9
0
 /// <summary>
 /// Saves the account info entity.
 /// </summary>
 /// <param name="entity">The account info entity.</param>
 /// <returns></returns>
 public async Task SaveAccount(AccountInfoEntity entity)
 {
     await _accounts.InsertOneAsync(entity).ConfigureAwait(false);
 }
        public async Task HandleAsync(ChannelReader <byte> reader, ChannelWriter <byte> writer, Client clientModel)
        {
            RS_LOGON_CHALLENGE request = await RS_LOGON_CHALLENGE_Reader.ReadAsync(reader);

            clientModel.AccountName = request.AccountName;

            // DONE: Check if our build can join the server
            if (request.Build == mangosGlobalConstants.Required_Build_1_12_1 ||
                request.Build == mangosGlobalConstants.Required_Build_1_12_2 ||
                request.Build == mangosGlobalConstants.Required_Build_1_12_3)
            {
                // TODO: in the far future should check if the account is expired too
                AccountInfoEntity accountInfo = await accountStorage.GetAccountInfoAsync(clientModel.AccountName);

                AccountState accountState = await GetAccountStateAsync(accountInfo).ConfigureAwait(false);

                // DONE: Send results to client
                switch (accountState)
                {
                case AccountState.LOGIN_OK:
                    await HandleLoginOkStateAsync(request, writer, clientModel, accountInfo).ConfigureAwait(false);

                    return;

                case AccountState.LOGIN_UNKNOWN_ACCOUNT:
                    await AUTH_LOGON_PROOF_Writer.WriteAsync(writer, new AUTH_LOGON_PROOF(AccountState.LOGIN_UNKNOWN_ACCOUNT));

                    return;

                case AccountState.LOGIN_BANNED:
                    await AUTH_LOGON_PROOF_Writer.WriteAsync(writer, new AUTH_LOGON_PROOF(AccountState.LOGIN_BANNED));

                    return;

                case AccountState.LOGIN_NOTIME:
                    await AUTH_LOGON_PROOF_Writer.WriteAsync(writer, new AUTH_LOGON_PROOF(AccountState.LOGIN_NOTIME));

                    return;

                case AccountState.LOGIN_ALREADYONLINE:
                    await AUTH_LOGON_PROOF_Writer.WriteAsync(writer, new AUTH_LOGON_PROOF(AccountState.LOGIN_ALREADYONLINE));

                    return;

                case AccountState.LOGIN_FAILED:
                case AccountState.LOGIN_BAD_PASS:
                case AccountState.LOGIN_DBBUSY:
                case AccountState.LOGIN_BADVERSION:
                case AccountState.LOGIN_DOWNLOADFILE:
                case AccountState.LOGIN_SUSPENDED:
                case AccountState.LOGIN_PARENTALCONTROL:
                    break;

                default:
                    await AUTH_LOGON_PROOF_Writer.WriteAsync(writer, new AUTH_LOGON_PROOF(AccountState.LOGIN_FAILED));

                    return;
                }
            }
            else
            {
                // Send BAD_VERSION
                logger.Warning($"WRONG_VERSION {request.Build}");
                await AUTH_LOGON_PROOF_Writer.WriteAsync(writer, new AUTH_LOGON_PROOF(AccountState.LOGIN_BADVERSION));
            }
        }