From 4d9a376ee429e14002a5ce2cf74d43e38d085ee0 Mon Sep 17 00:00:00 2001 From: SpoilerRules Date: Sat, 23 Mar 2024 16:57:47 +0100 Subject: [PATCH] fixed retrying causes the generation delay to be ignored for the next validation --- config/detekt/detekt-baseline.xml | 26 ++++----- config/detekt/detekt.yml | 16 +----- .../spoiligaming/generator/GeneratorBean.kt | 3 +- .../generator/NitroValidationWrapper.kt | 32 ++++++----- .../generator/NitroValidatorOrdinary.kt | 54 ++++++++++--------- 5 files changed, 66 insertions(+), 65 deletions(-) diff --git a/config/detekt/detekt-baseline.xml b/config/detekt/detekt-baseline.xml index 761c603..dc947a9 100644 --- a/config/detekt/detekt-baseline.xml +++ b/config/detekt/detekt-baseline.xml @@ -2,18 +2,20 @@ - MaxLineLength:CommonElement.kt$CommonElement.Companion$"-fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 12; -fx-background-radius: 12; -fx-background-color: ${ColorPalette.CONTROL_COLOR}; -fx-focus-color: transparent; -fx-padding: 0;" - MaxLineLength:CommonElement.kt$CommonElement.Companion$"-fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 13; -fx-background-radius: 12; -fx-background-color: ${ColorPalette.SECONDARY_COLOR};" - MaxLineLength:ElementColorPicker.kt$ElementColorPicker$"-fx-color-label-visible: false; -fx-background-color: ${ColorPalette.CONTROL_COLOR}; -fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.ACCENT_COLOR};" - MaxLineLength:ElementFilePicker.kt$ElementFilePicker$"-fx-background-color: ${ColorPalette.CONTROL_COLOR}; -fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.ACCENT_COLOR}; -fx-padding: 0;" - MaxLineLength:ElementList.kt$ElementList$"-fx-background-color: ${ColorPalette.TEXT_COLOR}; -fx-scale-x: 0.6; -fx-scale-y: 0.4; -fx-shape: 'M480-362q-8 0-15-2.5t-13-8.5L268-557q-11-11-11-28t11-28q11-11 28-11t28 11l156 156 156-156q11-11 28-11t28 11q11 11 11 28t-11 28L508-373q-6 6-13 8.5t-15 2.5Z';" - MaxLineLength:ElementList.kt$ElementList$"-fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaBold.family}'; -fx-font-size: 13; -fx-background-radius: 12; -fx-background-color: ${ColorPalette.CONTROL_COLOR};" - MaxLineLength:ElementText.kt$ElementText$"-fx-background-color: ${ColorPalette.CONTROL_COLOR}; -fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.ACCENT_COLOR}; -fx-padding: 0 5 0 5;" - MaxLineLength:ElementValue.kt$ElementValue$"-fx-background-color: ${ColorPalette.CONTROL_COLOR}; -fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.ACCENT_COLOR};" - MaxLineLength:ElementValue.kt$ElementValue$"-fx-background-color: ${ColorPalette.CONTROL_COLOR}; -fx-text-fill: ${ColorPalette.TEXT_COLOR}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 15; -fx-background-radius: 12;" - MaxLineLength:GeneratorBean.kt$GeneratorBean$Logger.printWarning("Nitro generation was skipped because ${CEnum.UNDERLINE}the Proxy File path was empty${CEnum.RESET}, even though Custom Proxy mode was set to 'One File' and enabled. Please check your proxy settings.") - MaxLineLength:Main.kt$localVersion != remoteVersion -> Logger.printWarning("${CEnum.RED}An update is available!${CEnum.RESET} Please visit https://github.com/SpoilerRules/nitro-generator/releases/latest to download the latest version (${CEnum.BRIGHT_PURPLE}$remoteVersion${CEnum.RESET}).") - MaxLineLength:NitroValidationWrapper.kt$NitroValidationWrapper$Logger.printWarning("${threadIdentity?.let { "${CEnum.RESET}[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$it${CEnum.RESET}] " } ?: ""}Retrying validation of $nitroCode in ${CEnum.ORANGE}${index + 1}${CEnum.RESET} seconds.") + MaxLineLength:CommonElement.kt$CommonElement.Companion$"-fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 12; -fx-background-radius: 12; -fx-background-color: ${ColorPalette.controlColor}; -fx-focus-color: transparent; -fx-padding: 0;" + MaxLineLength:CommonElement.kt$CommonElement.Companion$"-fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 13; -fx-background-radius: 12; -fx-background-color: ${ColorPalette.secondaryColor};" + MaxLineLength:ElementColorPicker.kt$ElementColorPicker$"-fx-color-label-visible: false; -fx-background-color: ${ColorPalette.controlColor}; -fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.accentColor};" + MaxLineLength:ElementFilePicker.kt$ElementFilePicker$"-fx-background-color: ${ColorPalette.controlColor}; -fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.accentColor}; -fx-padding: 0;" + MaxLineLength:ElementList.kt$ElementList$"-fx-background-color: ${ColorPalette.textColor}; -fx-scale-x: 0.6; -fx-scale-y: 0.4; -fx-shape: 'M480-362q-8 0-15-2.5t-13-8.5L268-557q-11-11-11-28t11-28q11-11 28-11t28 11l156 156 156-156q11-11 28-11t28 11q11 11 11 28t-11 28L508-373q-6 6-13 8.5t-15 2.5Z';" + MaxLineLength:ElementList.kt$ElementList$"-fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaBold.family}'; -fx-font-size: 13; -fx-background-radius: 12; -fx-background-color: ${ColorPalette.controlColor};" + MaxLineLength:ElementText.kt$ElementText$"-fx-background-color: ${ColorPalette.controlColor}; -fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.accentColor}; -fx-padding: 0 5 0 5;" + MaxLineLength:ElementValue.kt$ElementValue$"-fx-background-color: ${ColorPalette.controlColor}; -fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 14; -fx-background-radius: 12; -fx-highlight-fill: ${ColorPalette.accentColor};" + MaxLineLength:ElementValue.kt$ElementValue$"-fx-background-color: ${ColorPalette.controlColor}; -fx-text-fill: ${ColorPalette.textColor}; -fx-font-family: '${ResourceHandler.comfortaaSemiBold.family}'; -fx-font-size: 15; -fx-background-radius: 12;" + MaxLineLength:GeneratorBean.kt$GeneratorBean$"Nitro generation was skipped because ${CEnum.UNDERLINE}the Proxy File path was empty${CEnum.RESET}, even though Custom Proxy mode was set to 'One File' and enabled. Please check your proxy settings." + MaxLineLength:Main.kt$"${CEnum.RED}An update is available!${CEnum.RESET} Please visit https://github.com/SpoilerRules/nitro-generator/releases/latest to download the latest version (${CEnum.BRIGHT_PURPLE}$remoteVersion${CEnum.RESET})." + MaxLineLength:NitroValidationWrapper.kt$NitroValidationWrapper$"${threadIdentity?.let { "${CEnum.RESET}[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$it${CEnum.RESET}] " } ?: ""}Retrying validation of $nitroCode in ${CEnum.ORANGE}${configuration.generalSettings.retryDelay - index}${CEnum.RESET} seconds." + MaxLineLength:NitroValidatorAdvancedMt.kt$NitroValidatorAdvancedMt$Logger.printDebug("[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$threadIdentity${CEnum.RESET}] Using proxy: ${CEnum.CYAN}${proxyInfo.first}:${proxyInfo.second}${CEnum.RESET}") MaxLineLength:NitroValidatorAdvancedMt.kt$NitroValidatorAdvancedMt$throw ConnectException("[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$threadIdentity${CEnum.RESET}] Failed to establish a connection to validate the nitro code because the next proxy is null.") + MaxLineLength:TabProxy.kt$TabProxy$if (BaseConfigurationFactory.getInstance().proxySettings.rawContentSeparator == "\n") "\\n" else BaseConfigurationFactory.getInstance().proxySettings.rawContentSeparator diff --git a/config/detekt/detekt.yml b/config/detekt/detekt.yml index 4aa1cde..f25e6d1 100644 --- a/config/detekt/detekt.yml +++ b/config/detekt/detekt.yml @@ -192,18 +192,7 @@ exceptions: ThrowingNewInstanceOfSameException: active: true TooGenericExceptionCaught: - active: true - excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/androidUnitTest/**', '**/androidInstrumentedTest/**', '**/jsTest/**', '**/iosTest/**'] - exceptionNames: - - 'ArrayIndexOutOfBoundsException' - - 'Error' - - 'Exception' - - 'IllegalMonitorStateException' - - 'IndexOutOfBoundsException' - - 'NullPointerException' - - 'RuntimeException' - - 'Throwable' - allowedExceptionNameRegex: '_|(ignore|expected).*' + active: false TooGenericExceptionThrown: active: true exceptionNames: @@ -502,8 +491,7 @@ style: ignoreActualFunction: true excludedFunctions: [] LoopWithTooManyJumpStatements: - active: true - maxJumpCount: 1 + active: false MagicNumber: active: false MandatoryBracesLoops: diff --git a/src/main/kotlin/com/spoiligaming/generator/GeneratorBean.kt b/src/main/kotlin/com/spoiligaming/generator/GeneratorBean.kt index e187cce..302477c 100644 --- a/src/main/kotlin/com/spoiligaming/generator/GeneratorBean.kt +++ b/src/main/kotlin/com/spoiligaming/generator/GeneratorBean.kt @@ -23,7 +23,7 @@ object GeneratorBean { period = BaseConfigurationFactory.getInstance().generalSettings.generationDelay.takeIf { it != 0L } ?: 1, ) { val config = BaseConfigurationFactory.getInstance() - // reset isAnythingChanged to ensure concurrent operations work + // reset isConfigUpdated to ensure concurrent operations work BaseConfigurationFactory.isConfigUpdated = false if (isGenerationPaused.get()) return@timer @@ -41,7 +41,6 @@ object GeneratorBean { when { config.proxySettings.mode in 1..3 && !config.multithreadingSettings.enabled -> NitroValidatorOrdinary.validateNitro(nitroCode, 0, config) - else -> handleConcurrentValidation(nitroCode, config) } diff --git a/src/main/kotlin/com/spoiligaming/generator/NitroValidationWrapper.kt b/src/main/kotlin/com/spoiligaming/generator/NitroValidationWrapper.kt index b797ce8..6325ce0 100644 --- a/src/main/kotlin/com/spoiligaming/generator/NitroValidationWrapper.kt +++ b/src/main/kotlin/com/spoiligaming/generator/NitroValidationWrapper.kt @@ -164,12 +164,14 @@ object NitroValidationWrapper { override fun checkClientTrusted( chain: Array, authType: String, - ) {} + ) { + } override fun checkServerTrusted( chain: Array, authType: String, - ) {} + ) { + } override fun getAcceptedIssuers(): Array? = null }, @@ -264,20 +266,26 @@ object NitroValidationWrapper { threadIdentity: String?, crossinline validateFunction: (String, BaseConfigurationFactory, Int) -> Unit, ) { - // no need for delay between retries when retry delay is <= 0 or custom proxy is enabled and custom proxy mode is in the range 2 to 3. - if (configuration.generalSettings.retryDelay > 0 && !(configuration.proxySettings.enabled && configuration.proxySettings.mode in 2..3)) { - for (index in (configuration.generalSettings.retryDelay - 1) downTo 0) { + val shouldDelay = configuration.generalSettings.retryDelay > 0 && !(configuration.proxySettings.enabled && configuration.proxySettings.mode in 2..3) + val shouldRetryWithoutDelay = configuration.proxySettings.mode in 2..3 && configuration.proxySettings.enabled || configuration.generalSettings.retryDelay <= 0 + + when { + shouldDelay -> { + repeat(configuration.generalSettings.retryDelay) { index -> + Logger.printWarning( + "${threadIdentity?.let { "${CEnum.RESET}[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$it${CEnum.RESET}] " } ?: ""}Retrying validation of $nitroCode in ${CEnum.ORANGE}${configuration.generalSettings.retryDelay - index}${CEnum.RESET} seconds.", + ) + Thread.sleep(1000) + } + } + shouldRetryWithoutDelay -> { + Logger.printDebug("retrying without delay") Logger.printWarning( - "${threadIdentity?.let { "${CEnum.RESET}[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$it${CEnum.RESET}] " } ?: ""}Retrying validation of $nitroCode in ${CEnum.ORANGE}${index + 1}${CEnum.RESET} seconds.", + "${threadIdentity?.let { "${CEnum.RESET}[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$it${CEnum.RESET}] " } ?: ""}Retrying validation of Nitro code: $nitroCode.", ) - Thread.sleep(1000) } - } else if (configuration.proxySettings.mode in 2..3 && configuration.proxySettings.enabled || configuration.generalSettings.retryDelay <= 0) { - Logger.printWarning( - "${threadIdentity?.let { "${CEnum.RESET}[${CEnum.BLUE}THREAD: ${CEnum.RESET}${CEnum.CYAN}$it${CEnum.RESET}] " } ?: ""}Retrying validation of Nitro code: $nitroCode.", - ) } - validateFunction(nitroCode, configuration, retryCount) + threadIdentity?.let { validateFunction(nitroCode, configuration, retryCount) } } } diff --git a/src/main/kotlin/com/spoiligaming/generator/NitroValidatorOrdinary.kt b/src/main/kotlin/com/spoiligaming/generator/NitroValidatorOrdinary.kt index 962c776..bad1f73 100644 --- a/src/main/kotlin/com/spoiligaming/generator/NitroValidatorOrdinary.kt +++ b/src/main/kotlin/com/spoiligaming/generator/NitroValidatorOrdinary.kt @@ -44,36 +44,40 @@ object NitroValidatorOrdinary { var nitroValidationRetries = retryCount - runCatching { - with(getConnection(nitroCode, config)) { - NitroValidationWrapper.setProperties(this, config) + while (true) { + try { + with(getConnection(nitroCode, config)) { + NitroValidationWrapper.setProperties(this, config) - disconnect() - NitroValidationWrapper.reactToResponseCode( - responseCode, - nitroCode, - nitroValidationRetries, - config, - null, - ) { - nitroValidationRetries++ - // KNOWN ISSUE: instantly starts validating another nitro code after current validation has completed - NitroValidationWrapper.retryValidation(nitroCode, config, retryCount, null) { code, _, _ -> - validateNitro( - code, - nitroValidationRetries, - BaseConfigurationFactory.getInstance(), - ) + disconnect() + NitroValidationWrapper.reactToResponseCode( + responseCode, + nitroCode, + nitroValidationRetries, + config, + null, + ) { + nitroValidationRetries++ + NitroValidationWrapper.retryValidation(nitroCode, config, retryCount, null) { code, _, _ -> + validateNitro( + code, + nitroValidationRetries, + BaseConfigurationFactory.getInstance(), + ) + } } } - } - }.onFailure { - Logger.printError("Occurred while validating a nitro code: ${it.message}") + break + } catch (error: Exception) { + Logger.printError("Occurred while validating a nitro code: ${error.message}") - if (config.generalSettings.retryTillValid) { - NitroValidationWrapper.retryValidation(nitroCode, config, retryCount, null) { code, _, _ -> + if (config.generalSettings.retryTillValid) { nitroValidationRetries++ - validateNitro(code, nitroValidationRetries, BaseConfigurationFactory.getInstance()) + NitroValidationWrapper.retryValidation(nitroCode, config, retryCount, null) { _, _, _ -> + nitroValidationRetries++ + } + } else { + break } } }