diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaSAddress.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaSAddress.kt index 506db0d..645c5da 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaSAddress.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/VIAaaSAddress.kt @@ -1,6 +1,7 @@ package com.github.creeper123123321.viaaas import us.myles.ViaVersion.api.protocol.ProtocolVersion +import java.util.* class VIAaaSAddress { var serverAddress: String? = null @@ -38,30 +39,23 @@ class VIAaaSAddress { } fun parseOption(part: String): Boolean { - if (part.startsWith("_")) { + val option = when { + part.length < 2 -> null + part.startsWith("_") -> part[1] + part[1] == '_' -> part[0] + else -> null + }?.toString() + if (option != null) { val arg = part.substring(2) - when { - part.startsWith("_p", ignoreCase = true) -> port = arg.toInt() - part.startsWith("_o", ignoreCase = true) -> { - online = when { + when (option.toLowerCase(Locale.ROOT)) { + "p" -> port = arg.toInt() + "o" -> online = when { arg.startsWith("t", ignoreCase = true) -> true arg.startsWith("f", ignoreCase = true) -> false else -> null } - } - part.startsWith("_v", ignoreCase = true) -> { - try { - protocol = arg.toInt() - } catch (e: NumberFormatException) { - ProtocolVersion.getClosest(arg.replace("_", "."))?.also { - protocol = it.version - } - } - if (protocol == -2) { - protocol = null - } - } - part.startsWith("_u", ignoreCase = true) -> { + "v" -> parseProtocol(arg) + "u" -> { if (arg.length > 16) throw IllegalArgumentException("Invalid username") username = arg } @@ -70,4 +64,17 @@ class VIAaaSAddress { } return false } + + private fun parseProtocol(arg: String) { + try { + protocol = arg.toInt() + } catch (e: NumberFormatException) { + ProtocolVersion.getClosest(arg.replace("_", "."))?.also { + protocol = it.version + } + } + if (protocol == -2) { + protocol = null + } + } } \ No newline at end of file diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/handler/state/HandshakeState.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/handler/state/HandshakeState.kt index 8b75332..85fcdea 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/handler/state/HandshakeState.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/handler/state/HandshakeState.kt @@ -70,7 +70,7 @@ class HandshakeState : MinecraftConnectionState { ) if (!hadHostname && VIAaaSConfig.requireHostName) { - throw UnsupportedOperationException("This VIAaaS instance requires you to use the hostname") + throw UnsupportedOperationException("Missing domain suffix in hostname") } if (packet.nextState == State.STATUS) { @@ -85,4 +85,4 @@ class HandshakeState : MinecraftConnectionState { override fun onInactivated(handler: MinecraftHandler) { // Not worth logging } -} \ No newline at end of file +} diff --git a/src/main/resources/viaaas.yml b/src/main/resources/viaaas.yml index db62336..3c52e4a 100644 --- a/src/main/resources/viaaas.yml +++ b/src/main/resources/viaaas.yml @@ -16,7 +16,7 @@ mc-rsa-size: 4096 use-strong-random: true # Blocks connection to local addresses block-local-address: true -# Requires virtual host to contain the value from "host-name" +# Requires virtual host to contain the value from "host-name" as a suffix # A false value could be used for transparent proxying. require-host-name: true # Default port to be used to connect to backend server @@ -37,4 +37,4 @@ rate-limit-ws: 1.5 # Rate limits new front-end connections per second per ip. Will disconnect when hit rate-limit-connection-mc: 10.0 # Limits how many usernames a websocket connection can listen to. -listening-ws-limit: 10 \ No newline at end of file +listening-ws-limit: 10