Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Proxy support for Private Servers #44

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 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,21 @@ import javax.swing.SwingUtilities
import javax.swing.UIManager

public fun main(args: Array<String>) {
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()
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(
rspsHost: 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(rspsHost)
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(rspsHost: String?): JavConfig {
val url = "http://${rspsHost ?: "oldschool.runescape.com"}/jav_config.ws"
CygnixDev marked this conversation as resolved.
Show resolved Hide resolved
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