From e73175b7c58030c418648b92b5c29797e39a4947 Mon Sep 17 00:00:00 2001 From: creeper123123321 <7974274+creeper123123321@users.noreply.github.com> Date: Thu, 25 Mar 2021 18:13:44 -0300 Subject: [PATCH] implement #87 multiple hostname suffix --- .../creeper123123321/viaaas/config/VIAaaSConfig.kt | 2 +- .../viaaas/handler/state/HandshakeState.kt | 8 +++++++- src/main/resources/viaaas.yml | 9 +++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/config/VIAaaSConfig.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/config/VIAaaSConfig.kt index 1c00700..d682f61 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/config/VIAaaSConfig.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/config/VIAaaSConfig.kt @@ -16,7 +16,7 @@ object VIAaaSConfig : Config(File("config/viaaas.yml")) { val isNativeTransportMc: Boolean get() = this.getBoolean("native-transport-mc", true) val port: Int get() = this.getInt("port", 25565) val bindAddress: String get() = this.getString("bind-address", "localhost")!! - val hostName: String get() = this.getString("host-name", "viaaas.localhost")!! + val hostName: List get() = this.getString("host-name", "viaaas.localhost")!!.split(",") val mcRsaSize: Int get() = this.getInt("mc-rsa-size", 4096) val useStrongRandom: Boolean get() = this.getBoolean("use-strong-random", true) val blockLocalAddress: Boolean get() = this.getBoolean("block-local-address", true) 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 7f1f78a..3c1822a 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 @@ -23,6 +23,7 @@ class HandshakeState : MinecraftConnectionState { RateLimiter.create(VIAaaSConfig.rateLimitConnectionMc) }) } + override val state: State get() = State.HANDSHAKE @@ -43,7 +44,12 @@ class HandshakeState : MinecraftConnectionState { val extraData = packet.address.substringAfter(0.toChar(), missingDelimiterValue = "") // todo val virtualHostNoExtra = packet.address.substringBefore(0.toChar()) - val parsed = VIAaaSAddress().parse(virtualHostNoExtra, VIAaaSConfig.hostName) + val parsed = VIAaaSConfig.hostName.map { + VIAaaSAddress().parse(virtualHostNoExtra, it) + }.sortedBy { + it.viaSuffix == null + }.first() + val backProto = parsed.protocol val hadHostname = parsed.viaSuffix != null diff --git a/src/main/resources/viaaas.yml b/src/main/resources/viaaas.yml index 3a0c95f..d685c19 100644 --- a/src/main/resources/viaaas.yml +++ b/src/main/resources/viaaas.yml @@ -26,14 +26,15 @@ use-strong-random: false ###### # VIAaaS virtual hosts options ###### -# Host name of this instance, that will be used in the virtual host as a suffix. -host-name: viaaas.localhost -# Requires online mode for front-end connections. May be useful for stopping bots. -force-online-mode: false # Requires virtual host to contain the value from "host-name" as a suffix. # A false value will allow virtual hosts with no suffix, connecting to the virtual host sent by client. # A false value could be used for transparent proxying. require-host-name: true +# Host names of this instance, that will be used in the virtual host as a suffix. +# Use commas for separating multiple hostnames. +host-name: viaaas.localhost,via.localhost +# Requires online mode for front-end connections. May be useful for stopping bots. +force-online-mode: false # Default port to be used when connecting to the backend server. # Use -1 to reuse the port sent by client, useful for transparent proxying. default-backend-port: 25565