|
|
@ -1,14 +1,18 @@ |
|
|
|
package org.openrs2.archive.cache |
|
|
|
package org.openrs2.archive.cache |
|
|
|
|
|
|
|
|
|
|
|
import org.openrs2.archive.game.GameDatabase |
|
|
|
import org.openrs2.archive.game.GameDatabase |
|
|
|
|
|
|
|
import org.openrs2.archive.jav.JavConfig |
|
|
|
import org.openrs2.net.BootstrapFactory |
|
|
|
import org.openrs2.net.BootstrapFactory |
|
|
|
import org.openrs2.net.awaitSuspend |
|
|
|
import org.openrs2.net.awaitSuspend |
|
|
|
|
|
|
|
import java.net.URI |
|
|
|
|
|
|
|
import java.net.http.HttpClient |
|
|
|
import javax.inject.Inject |
|
|
|
import javax.inject.Inject |
|
|
|
import javax.inject.Singleton |
|
|
|
import javax.inject.Singleton |
|
|
|
import kotlin.coroutines.suspendCoroutine |
|
|
|
import kotlin.coroutines.suspendCoroutine |
|
|
|
|
|
|
|
|
|
|
|
@Singleton |
|
|
|
@Singleton |
|
|
|
public class CacheDownloader @Inject constructor( |
|
|
|
public class CacheDownloader @Inject constructor( |
|
|
|
|
|
|
|
private val client: HttpClient, |
|
|
|
private val bootstrapFactory: BootstrapFactory, |
|
|
|
private val bootstrapFactory: BootstrapFactory, |
|
|
|
private val gameDatabase: GameDatabase, |
|
|
|
private val gameDatabase: GameDatabase, |
|
|
|
private val importer: CacheImporter |
|
|
|
private val importer: CacheImporter |
|
|
@ -16,10 +20,13 @@ public class CacheDownloader @Inject constructor( |
|
|
|
public suspend fun download(gameName: String) { |
|
|
|
public suspend fun download(gameName: String) { |
|
|
|
val game = gameDatabase.getGame(gameName) ?: throw Exception("Game not found") |
|
|
|
val game = gameDatabase.getGame(gameName) ?: throw Exception("Game not found") |
|
|
|
|
|
|
|
|
|
|
|
val hostname = game.hostname ?: throw Exception("Hostname not set") |
|
|
|
val url = game.url ?: throw Exception("URL not set") |
|
|
|
val port = game.port ?: throw Exception("Port not set") |
|
|
|
|
|
|
|
val build = game.build ?: throw Exception("Current build not set") |
|
|
|
val build = game.build ?: throw Exception("Current build not set") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val config = JavConfig.download(client, url) |
|
|
|
|
|
|
|
val codebase = config.config[CODEBASE] ?: throw Exception("Codebase missing") |
|
|
|
|
|
|
|
val hostname = URI(codebase).host ?: throw Exception("Hostname missing") |
|
|
|
|
|
|
|
|
|
|
|
val group = bootstrapFactory.createEventLoopGroup() |
|
|
|
val group = bootstrapFactory.createEventLoopGroup() |
|
|
|
try { |
|
|
|
try { |
|
|
|
suspendCoroutine<Unit> { continuation -> |
|
|
|
suspendCoroutine<Unit> { continuation -> |
|
|
@ -28,7 +35,7 @@ public class CacheDownloader @Inject constructor( |
|
|
|
bootstrap, |
|
|
|
bootstrap, |
|
|
|
game.id, |
|
|
|
game.id, |
|
|
|
hostname, |
|
|
|
hostname, |
|
|
|
port, |
|
|
|
PORT, |
|
|
|
build, |
|
|
|
build, |
|
|
|
game.lastMasterIndexId, |
|
|
|
game.lastMasterIndexId, |
|
|
|
continuation, |
|
|
|
continuation, |
|
|
@ -36,10 +43,15 @@ public class CacheDownloader @Inject constructor( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
bootstrap.handler(Js5ChannelInitializer(handler)) |
|
|
|
bootstrap.handler(Js5ChannelInitializer(handler)) |
|
|
|
.connect(hostname, port) |
|
|
|
.connect(hostname, PORT) |
|
|
|
} |
|
|
|
} |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
group.shutdownGracefully().awaitSuspend() |
|
|
|
group.shutdownGracefully().awaitSuspend() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private companion object { |
|
|
|
|
|
|
|
private const val CODEBASE = "codebase" |
|
|
|
|
|
|
|
private const val PORT = 443 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|