From f09da918101f7205496c77cbc48ac73bcb89f951 Mon Sep 17 00:00:00 2001 From: creeper123123321 <7974274+creeper123123321@users.noreply.github.com> Date: Sun, 9 Jul 2023 08:59:10 -0300 Subject: [PATCH] fixed 1.8 comparison, invalidate detection fails fixes #231 --- build.gradle.kts | 2 +- .../com/viaversion/aas/handler/BackEndInit.kt | 2 +- .../aas/handler/autoprotocol/ProtocolDetector.kt | 14 +++++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 1f0b270..1dd6cda 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -96,7 +96,7 @@ dependencies { implementation("org.jline:jline-terminal-jansi:3.23.0") implementation("org.slf4j:slf4j-api:$slf4jVer") - val ktorVersion = "2.3.0" + val ktorVersion = "2.3.2" implementation("io.ktor:ktor-network-tls-certificates-jvm:$ktorVersion") implementation("io.ktor:ktor-server-websockets:$ktorVersion") implementation("io.ktor:ktor-server-netty-jvm:$ktorVersion") diff --git a/src/main/kotlin/com/viaversion/aas/handler/BackEndInit.kt b/src/main/kotlin/com/viaversion/aas/handler/BackEndInit.kt index 3767157..d58da31 100644 --- a/src/main/kotlin/com/viaversion/aas/handler/BackEndInit.kt +++ b/src/main/kotlin/com/viaversion/aas/handler/BackEndInit.kt @@ -21,7 +21,7 @@ class BackEndInit(val connectionData: ConnectionData, val proxyUri: URI?, val pr val user = UserConnectionImpl(ch, true) val pipeline = ProtocolPipelineImpl(user) val version = connectionData.backServerVer!! - val isLegacy = LegacyProtocolVersion.protocolCompare(version, ProtocolVersion.v_1_6_4.version) <= 0 + val isLegacy = LegacyProtocolVersion.protocolCompare(version, LegacyProtocolVersion.r1_6_4.version) <= 0 if (isLegacy) { pipeline.add(PreNettyBaseProtocol.INSTANCE) diff --git a/src/main/kotlin/com/viaversion/aas/handler/autoprotocol/ProtocolDetector.kt b/src/main/kotlin/com/viaversion/aas/handler/autoprotocol/ProtocolDetector.kt index ec12ce5..c57b3be 100644 --- a/src/main/kotlin/com/viaversion/aas/handler/autoprotocol/ProtocolDetector.kt +++ b/src/main/kotlin/com/viaversion/aas/handler/autoprotocol/ProtocolDetector.kt @@ -32,7 +32,7 @@ import java.util.concurrent.TimeUnit object ProtocolDetector { val coroutineScope = CoroutineScope(SupervisorJob()) - private val loader = CacheLoader.from> { address -> + val loader = CacheLoader.from> { address -> val future = CompletableFuture() coroutineScope.launch { try { @@ -78,9 +78,17 @@ object ProtocolDetector { future } - private val SERVER_VER = CacheBuilder.newBuilder() + private val versionCache = CacheBuilder.newBuilder() .expireAfterWrite(VIAaaSConfig.protocolDetectorCache.toLong(), TimeUnit.SECONDS) .build(loader) - fun detectVersion(address: InetSocketAddress): CompletableFuture = SERVER_VER[address] + fun detectVersion(address: InetSocketAddress): CompletableFuture { + val future = versionCache[address] + future.whenComplete { _, throwable -> + if (throwable != null) { + versionCache.invalidate(address) + } + } + return future + } }