From 89f8295e0aeeaf95e6c4ec9f18e85e637a044520 Mon Sep 17 00:00:00 2001 From: creeper123123321 <7974274+creeper123123321@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:19:19 -0300 Subject: [PATCH] fix -1 (disable viaversion) cases --- src/main/java/com/viaversion/aas/util/AddressParser.java | 5 +---- .../com/viaversion/aas/handler/state/HandshakeState.kt | 7 +++---- .../com/viaversion/aas/handler/state/LoginState.kt | 2 +- src/main/kotlin/com/viaversion/aas/web/WebLogin.kt | 9 ++------- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/viaversion/aas/util/AddressParser.java b/src/main/java/com/viaversion/aas/util/AddressParser.java index 51b62c2..867a4c5 100644 --- a/src/main/java/com/viaversion/aas/util/AddressParser.java +++ b/src/main/java/com/viaversion/aas/util/AddressParser.java @@ -117,10 +117,7 @@ public class AddressParser { if (protocolId == null) { protocol = ProtocolVersion.getClosest(arg.replace("_", ".")); } else { - final ProtocolVersion ver = ProtocolVersion.getProtocol(protocolId); - if (ver.isKnown()) { - protocol = ver; - } + protocol = ProtocolVersion.getProtocol(protocolId); } } } diff --git a/src/main/kotlin/com/viaversion/aas/handler/state/HandshakeState.kt b/src/main/kotlin/com/viaversion/aas/handler/state/HandshakeState.kt index 14f8d70..11db111 100644 --- a/src/main/kotlin/com/viaversion/aas/handler/state/HandshakeState.kt +++ b/src/main/kotlin/com/viaversion/aas/handler/state/HandshakeState.kt @@ -48,9 +48,8 @@ class HandshakeState : ConnectionState { } private fun handleNextState(handler: MinecraftHandler, packet: Handshake) { - ProtocolVersion.getProtocol(packet.protocolId).apply { - if (this.isKnown) handler.data.frontVer = this - } + handler.data.frontVer = ProtocolVersion.getProtocol(packet.protocolId) + when (packet.nextState.ordinal) { 1 -> handler.data.state = StatusState() 2 -> handler.data.state = LoginState() @@ -87,7 +86,7 @@ class HandshakeState : ConnectionState { val addressFromWeb = VIAaaSConfig.hostName.any { parsed.serverAddress.equals(it, ignoreCase = true) } handler.data.backServerVer = backProto - if (backProto == AUTO) handler.data.autoDetectProtocol = true + handler.data.autoDetectProtocol = backProto == AUTO (handler.data.state as? LoginState)?.also { it.frontOnline = frontOnline it.backName = parsed.username diff --git a/src/main/kotlin/com/viaversion/aas/handler/state/LoginState.kt b/src/main/kotlin/com/viaversion/aas/handler/state/LoginState.kt index 235e7c4..cc7e109 100644 --- a/src/main/kotlin/com/viaversion/aas/handler/state/LoginState.kt +++ b/src/main/kotlin/com/viaversion/aas/handler/state/LoginState.kt @@ -269,7 +269,7 @@ class LoginState : ConnectionState { val info = AspirinServer.viaWebServer.requestAddressInfo(frontName).await() backAddress = info.backHostAndPort handler.data.backServerVer = info.backVersion - if (info.backVersion == AUTO) handler.data.autoDetectProtocol = true + handler.data.autoDetectProtocol = info.backVersion == AUTO frontOnline = info.frontOnline info.backName?.also { backName = info.backName } } diff --git a/src/main/kotlin/com/viaversion/aas/web/WebLogin.kt b/src/main/kotlin/com/viaversion/aas/web/WebLogin.kt index 4bfba2f..4f0c0ac 100644 --- a/src/main/kotlin/com/viaversion/aas/web/WebLogin.kt +++ b/src/main/kotlin/com/viaversion/aas/web/WebLogin.kt @@ -148,13 +148,8 @@ class WebLogin : WebState { webClient.server.addressCallbacks[callback].complete( AddressInfo( backVersion = obj["version"].asString.let { - val number = Ints.tryParse(it) - val protocol = if (number == null) { - ProtocolVersion.getClosest(it) - } else { - ProtocolVersion.getProtocol(number) - } ?: AUTO - if (!protocol.isKnown) AUTO else protocol + Ints.tryParse(it)?.let { ProtocolVersion.getProtocol(it) } + ?: ProtocolVersion.getClosest(it) ?: AUTO }, backHostAndPort = HostAndPort.fromParts(obj["host"].asString, obj["port"].asInt), frontOnline = obj["frontOnline"].asString.toBooleanStrictOrNull(),