From 34d4b1ae1e75d42afc9bff6d8ba7015a7a30c6a0 Mon Sep 17 00:00:00 2001 From: Cygnix Date: Sun, 29 Dec 2024 14:22:43 +0100 Subject: [PATCH 1/4] Enable Proxy support for Private Servers Usage: RSPS_HOSTNAME=runenite.test RSPS_RSA=c3320dfd7a8e3454add79aab7c597bb5e38c82a10a26e2b70a0539aab26b2fdb4128e8ad1f18f5fb8d11d35c15f4ca6a7fbe8f3196aaf41d2a94f95990e16f5111d5c6a8fbf9e31416615e7a8098d8fcbb0df2727076d3c772ea1fc3de020da8735e1332eb8a3a2d9c739d0f95dc8b74c7186b1645b2a39369fcf64ca467 ./gradlew proxy --- .../kotlin/net/rsprox/gui/ProxyToolGui.kt | 10 +++++- .../kotlin/net/rsprox/proxy/ProxyService.kt | 32 +++++++++++-------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/ProxyToolGui.kt b/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/ProxyToolGui.kt index 0e23cefd..92f4e2b9 100644 --- a/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/ProxyToolGui.kt +++ b/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/ProxyToolGui.kt @@ -6,13 +6,21 @@ import javax.swing.SwingUtilities import javax.swing.UIManager public fun main(args: Array) { + val rspsHost = System.getenv("RSPS_HOSTNAME") + val rspsRsa = System.getenv("RSPS_RSA") + + when { + rspsRsa == null && rspsHost != null -> throw IllegalArgumentException("Missing ENV variable: RSPS_RSA") + rspsRsa != null && rspsHost == null -> throw IllegalArgumentException("Missing ENV variable: RSPS_HOSTNAME") + } + if (args.isNotEmpty()) { System.setProperty("net.rsprox.gui.args", args.joinToString("|")) } Locale.setDefault(Locale.US) SplashScreen.init() SplashScreen.stage(0.0, "Preparing", "Setting up environment") - App.service.start { percentage, actionText, subActionText, progressText -> + App.service.start(rspsHost, rspsRsa) { percentage, actionText, subActionText, progressText -> SplashScreen.stage(percentage, actionText, subActionText, progressText) } SplashScreen.stop() diff --git a/proxy/src/main/kotlin/net/rsprox/proxy/ProxyService.kt b/proxy/src/main/kotlin/net/rsprox/proxy/ProxyService.kt index d6e6afcd..6648667f 100644 --- a/proxy/src/main/kotlin/net/rsprox/proxy/ProxyService.kt +++ b/proxy/src/main/kotlin/net/rsprox/proxy/ProxyService.kt @@ -92,8 +92,14 @@ public class ProxyService( private val connections: ProxyConnectionContainer = ProxyConnectionContainer() private lateinit var credentials: BinaryCredentialsStore private val gamePackProvider: GamePackProvider = GamePackProvider() + private var rspsModulus: String? = null - public fun start(progressCallback: ProgressCallback) { + public fun start( + rspsHost: String?, + rspsModulus: String?, + progressCallback: ProgressCallback, + ) { + this.rspsModulus = rspsModulus logger.info { "Starting proxy service" } progressCallback.update(0.05, "Proxy", "Creating directories") createConfigurationDirectories(CONFIGURATION_PATH) @@ -121,7 +127,7 @@ public class ProxyService( this.availablePort = properties.getProperty(PROXY_PORT_MIN) this.bootstrapFactory = BootstrapFactory(allocator, properties) progressCallback.update(0.35, "Proxy", "Loading jav config") - val javConfig = loadJavConfig() + val javConfig = loadJavConfig(rspsHost) progressCallback.update(0.40, "Proxy", "Loading world list") this.worldListProvider = loadWorldListProvider(javConfig.getWorldListUrl()) progressCallback.update(0.50, "Proxy", "Replacing codebase") @@ -466,7 +472,7 @@ public class ProxyService( ClientType.Native, os, port, - BigInteger(result.oldModulus, 16), + BigInteger(rspsModulus ?: result.oldModulus, 16), ), ) ClientTypeDictionary[port] = "Native (${os.shortName})" @@ -524,7 +530,7 @@ public class ProxyService( ClientType.RuneLite, operatingSystem, port, - BigInteger(oldModulus, 16), + BigInteger(rspsModulus ?: oldModulus, 16), ), ) socket.close() @@ -688,6 +694,15 @@ public class ProxyService( } } + private fun loadJavConfig(rspsHost: String?): JavConfig { + val url = "http://${rspsHost ?: "oldschool.runescape.com"}/jav_config.ws" + return runCatching("Failed to load jav_config.ws from $url") { + val config = JavConfig(URL(url)) + logger.debug { "Jav config loaded from $url" } + config + } + } + private fun loadWorldListProvider(url: String): WorldListProvider { return runCatching("Failed to instantiate world list provider") { val provider = @@ -790,15 +805,6 @@ public class ProxyService( private val logger = InlineLogger() private val PROPERTIES_FILE = CONFIGURATION_PATH.resolve("proxy.properties") - private fun loadJavConfig(): JavConfig { - val url = "http://oldschool.runescape.com/jav_config.ws" - return runCatching("Failed to load jav_config.ws from $url") { - val config = JavConfig(URL(url)) - logger.debug { "Jav config loaded from $url" } - config - } - } - private inline fun runCatching( errorMessage: String, block: () -> T, From c147d11bf317e80c78b285f134ab702e49c2f153 Mon Sep 17 00:00:00 2001 From: Cygnix Date: Sun, 29 Dec 2024 14:38:24 +0100 Subject: [PATCH 2/4] Fix remarks --- .../src/main/kotlin/net/rsprox/gui/ProxyToolGui.kt | 10 +++++----- proxy/src/main/kotlin/net/rsprox/proxy/ProxyService.kt | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/ProxyToolGui.kt b/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/ProxyToolGui.kt index 92f4e2b9..cef76277 100644 --- a/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/ProxyToolGui.kt +++ b/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/ProxyToolGui.kt @@ -6,12 +6,12 @@ import javax.swing.SwingUtilities import javax.swing.UIManager public fun main(args: Array) { - val rspsHost = System.getenv("RSPS_HOSTNAME") - val rspsRsa = System.getenv("RSPS_RSA") + val javConfig = System.getenv("RSPS_JAVCONFIG_URL") + val rsa = System.getenv("RSPS_RSA") when { - rspsRsa == null && rspsHost != null -> throw IllegalArgumentException("Missing ENV variable: RSPS_RSA") - rspsRsa != null && rspsHost == null -> throw IllegalArgumentException("Missing ENV variable: RSPS_HOSTNAME") + rsa == null && javConfig != null -> throw IllegalArgumentException("Missing ENV variable: RSPS_RSA") + rsa != null && javConfig == null -> throw IllegalArgumentException("Missing ENV variable: RSPS_JAVCONFIG_URL") } if (args.isNotEmpty()) { @@ -20,7 +20,7 @@ public fun main(args: Array) { Locale.setDefault(Locale.US) SplashScreen.init() SplashScreen.stage(0.0, "Preparing", "Setting up environment") - App.service.start(rspsHost, rspsRsa) { percentage, actionText, subActionText, progressText -> + App.service.start(javConfig, rsa) { percentage, actionText, subActionText, progressText -> SplashScreen.stage(percentage, actionText, subActionText, progressText) } SplashScreen.stop() diff --git a/proxy/src/main/kotlin/net/rsprox/proxy/ProxyService.kt b/proxy/src/main/kotlin/net/rsprox/proxy/ProxyService.kt index 6648667f..4123b4c8 100644 --- a/proxy/src/main/kotlin/net/rsprox/proxy/ProxyService.kt +++ b/proxy/src/main/kotlin/net/rsprox/proxy/ProxyService.kt @@ -95,7 +95,7 @@ public class ProxyService( private var rspsModulus: String? = null public fun start( - rspsHost: String?, + rspsJavConfigUrl: String?, rspsModulus: String?, progressCallback: ProgressCallback, ) { @@ -127,7 +127,7 @@ public class ProxyService( this.availablePort = properties.getProperty(PROXY_PORT_MIN) this.bootstrapFactory = BootstrapFactory(allocator, properties) progressCallback.update(0.35, "Proxy", "Loading jav config") - val javConfig = loadJavConfig(rspsHost) + val javConfig = loadJavConfig(rspsJavConfigUrl) progressCallback.update(0.40, "Proxy", "Loading world list") this.worldListProvider = loadWorldListProvider(javConfig.getWorldListUrl()) progressCallback.update(0.50, "Proxy", "Replacing codebase") @@ -694,8 +694,8 @@ public class ProxyService( } } - private fun loadJavConfig(rspsHost: String?): JavConfig { - val url = "http://${rspsHost ?: "oldschool.runescape.com"}/jav_config.ws" + private fun loadJavConfig(customUrl: String?): JavConfig { + val url = customUrl ?: "http://oldschool.runescape.com/jav_config.ws" return runCatching("Failed to load jav_config.ws from $url") { val config = JavConfig(URL(url)) logger.debug { "Jav config loaded from $url" } From 5884fe72d9a7ef40dd794bf66122077ca682609a Mon Sep 17 00:00:00 2001 From: Cygnix Date: Sun, 29 Dec 2024 14:39:50 +0100 Subject: [PATCH 3/4] WIP --- .../main/kotlin/net/rsprox/gui/ProxyToolGui.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/ProxyToolGui.kt b/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/ProxyToolGui.kt index cef76277..b20243ba 100644 --- a/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/ProxyToolGui.kt +++ b/gui/proxy-tool/src/main/kotlin/net/rsprox/gui/ProxyToolGui.kt @@ -6,12 +6,17 @@ import javax.swing.SwingUtilities import javax.swing.UIManager public fun main(args: Array) { - val javConfig = System.getenv("RSPS_JAVCONFIG_URL") - val rsa = System.getenv("RSPS_RSA") + val rspsJavConfigUrl = System.getenv("RSPS_JAVCONFIG_URL") + val rspsModulus = System.getenv("RSPS_RSA") when { - rsa == null && javConfig != null -> throw IllegalArgumentException("Missing ENV variable: RSPS_RSA") - rsa != null && javConfig == null -> throw IllegalArgumentException("Missing ENV variable: RSPS_JAVCONFIG_URL") + rspsModulus == null && rspsJavConfigUrl != null -> throw IllegalArgumentException( + "Missing ENV variable: RSPS_RSA", + ) + + rspsModulus != null && rspsJavConfigUrl == null -> throw IllegalArgumentException( + "Missing ENV variable: RSPS_JAVCONFIG_URL", + ) } if (args.isNotEmpty()) { @@ -20,7 +25,7 @@ public fun main(args: Array) { Locale.setDefault(Locale.US) SplashScreen.init() SplashScreen.stage(0.0, "Preparing", "Setting up environment") - App.service.start(javConfig, rsa) { percentage, actionText, subActionText, progressText -> + App.service.start(rspsJavConfigUrl, rspsModulus) { percentage, actionText, subActionText, progressText -> SplashScreen.stage(percentage, actionText, subActionText, progressText) } SplashScreen.stop() From a8a9a1143ebfca6c36e938449bdf06cdfbcca753 Mon Sep 17 00:00:00 2001 From: Cygnix Date: Sun, 29 Dec 2024 15:07:59 +0100 Subject: [PATCH 4/4] Doctors hate him for discovering this one weird trick --- proxy/src/main/kotlin/net/rsprox/proxy/binary/BinaryBlob.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/kotlin/net/rsprox/proxy/binary/BinaryBlob.kt b/proxy/src/main/kotlin/net/rsprox/proxy/binary/BinaryBlob.kt index 6bd4b1f2..a5c05022 100644 --- a/proxy/src/main/kotlin/net/rsprox/proxy/binary/BinaryBlob.kt +++ b/proxy/src/main/kotlin/net/rsprox/proxy/binary/BinaryBlob.kt @@ -188,10 +188,10 @@ public data class BinaryBlob( header.revision, header.js5MasterIndex, ) - val world = header.worldId + val info = LiveConnectionInfo( - "oldschool${world - 300}.runescape.com", + header.worldHost, PORT, header.revision, key,