Skip to content

Commit

Permalink
Enable Proxy support for Private Servers (#44)
Browse files Browse the repository at this point in the history
* Enable Proxy support for Private Servers

Usage: RSPS_HOSTNAME=runenite.test RSPS_RSA=c3320dfd7a8e3454add79aab7c597bb5e38c82a10a26e2b70a0539aab26b2fdb4128e8ad1f18f5fb8d11d35c15f4ca6a7fbe8f3196aaf41d2a94f95990e16f5111d5c6a8fbf9e31416615e7a8098d8fcbb0df2727076d3c772ea1fc3de020da8735e1332eb8a3a2d9c739d0f95dc8b74c7186b1645b2a39369fcf64ca467 ./gradlew proxy

* Fix remarks

* WIP

* Doctors hate him for discovering this one weird trick

---------

Co-authored-by: Cygnix <[email protected]>
  • Loading branch information
CygnixDev and Cygnix authored Jan 3, 2025
1 parent e273e50 commit 21cd28d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
15 changes: 14 additions & 1 deletion gui/proxy-tool/src/main/kotlin/net/rsprox/gui/ProxyToolGui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,26 @@ import javax.swing.SwingUtilities
import javax.swing.UIManager

public fun main(args: Array<String>) {
val rspsJavConfigUrl = System.getenv("RSPS_JAVCONFIG_URL")
val rspsModulus = System.getenv("RSPS_RSA")

when {
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()) {
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(rspsJavConfigUrl, rspsModulus) { percentage, actionText, subActionText, progressText ->
SplashScreen.stage(percentage, actionText, subActionText, progressText)
}
SplashScreen.stop()
Expand Down
32 changes: 19 additions & 13 deletions proxy/src/main/kotlin/net/rsprox/proxy/ProxyService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
rspsJavConfigUrl: String?,
rspsModulus: String?,
progressCallback: ProgressCallback,
) {
this.rspsModulus = rspsModulus
logger.info { "Starting proxy service" }
progressCallback.update(0.05, "Proxy", "Creating directories")
createConfigurationDirectories(CONFIGURATION_PATH)
Expand Down Expand Up @@ -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(rspsJavConfigUrl)
progressCallback.update(0.40, "Proxy", "Loading world list")
this.worldListProvider = loadWorldListProvider(javConfig.getWorldListUrl())
progressCallback.update(0.50, "Proxy", "Replacing codebase")
Expand Down Expand Up @@ -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})"
Expand Down Expand Up @@ -524,7 +530,7 @@ public class ProxyService(
ClientType.RuneLite,
operatingSystem,
port,
BigInteger(oldModulus, 16),
BigInteger(rspsModulus ?: oldModulus, 16),
),
)
socket.close()
Expand Down Expand Up @@ -688,6 +694,15 @@ public class ProxyService(
}
}

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" }
config
}
}

private fun loadWorldListProvider(url: String): WorldListProvider {
return runCatching("Failed to instantiate world list provider") {
val provider =
Expand Down Expand Up @@ -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 <T> runCatching(
errorMessage: String,
block: () -> T,
Expand Down
4 changes: 2 additions & 2 deletions proxy/src/main/kotlin/net/rsprox/proxy/binary/BinaryBlob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 21cd28d

Please sign in to comment.