forked from openrs2/openrs2
parent
fdd0f118f2
commit
689c315bf3
@ -1,15 +1,18 @@ |
|||||||
package org.openrs2.archive.cache |
package org.openrs2.archive.cache |
||||||
|
|
||||||
import com.github.ajalt.clikt.core.CliktCommand |
import com.github.ajalt.clikt.core.CliktCommand |
||||||
|
import com.github.ajalt.clikt.parameters.arguments.argument |
||||||
|
import com.github.ajalt.clikt.parameters.arguments.default |
||||||
import com.google.inject.Guice |
import com.google.inject.Guice |
||||||
import kotlinx.coroutines.runBlocking |
import kotlinx.coroutines.runBlocking |
||||||
import org.openrs2.archive.ArchiveModule |
import org.openrs2.archive.ArchiveModule |
||||||
|
|
||||||
public class DownloadCommand : CliktCommand(name = "download") { |
public class DownloadCommand : CliktCommand(name = "download") { |
||||||
|
private val game by argument().default("oldschool") |
||||||
|
|
||||||
override fun run(): Unit = runBlocking { |
override fun run(): Unit = runBlocking { |
||||||
val injector = Guice.createInjector(ArchiveModule) |
val injector = Guice.createInjector(ArchiveModule) |
||||||
val downloader = injector.getInstance(CacheDownloader::class.java) |
val downloader = injector.getInstance(CacheDownloader::class.java) |
||||||
// TODO(gpe): make these configurable and/or fetch from the database |
downloader.download(game) |
||||||
downloader.download("oldschool1.runescape.com", 43594, 193) |
|
||||||
} |
} |
||||||
} |
} |
||||||
|
@ -0,0 +1,8 @@ |
|||||||
|
package org.openrs2.archive.game |
||||||
|
|
||||||
|
public data class Game( |
||||||
|
public val id: Int, |
||||||
|
public val hostname: String?, |
||||||
|
public val port: Int?, |
||||||
|
public val build: Int? |
||||||
|
) |
@ -0,0 +1,45 @@ |
|||||||
|
package org.openrs2.archive.game |
||||||
|
|
||||||
|
import org.openrs2.db.Database |
||||||
|
import javax.inject.Inject |
||||||
|
import javax.inject.Singleton |
||||||
|
|
||||||
|
@Singleton |
||||||
|
public class GameDatabase @Inject constructor( |
||||||
|
private val database: Database |
||||||
|
) { |
||||||
|
public suspend fun getGame(name: String): Game? { |
||||||
|
return database.execute { connection -> |
||||||
|
connection.prepareStatement( |
||||||
|
""" |
||||||
|
SELECT id, hostname, port, build |
||||||
|
FROM games |
||||||
|
WHERE name = ? |
||||||
|
""".trimIndent() |
||||||
|
).use { stmt -> |
||||||
|
stmt.setString(1, name) |
||||||
|
|
||||||
|
stmt.executeQuery().use { rows -> |
||||||
|
if (!rows.next()) { |
||||||
|
return@execute null |
||||||
|
} |
||||||
|
|
||||||
|
val id = rows.getInt(1) |
||||||
|
val hostname: String? = rows.getString(2) |
||||||
|
|
||||||
|
var port: Int? = rows.getInt(3) |
||||||
|
if (rows.wasNull()) { |
||||||
|
port = null |
||||||
|
} |
||||||
|
|
||||||
|
var build: Int? = rows.getInt(4) |
||||||
|
if (rows.wasNull()) { |
||||||
|
build = null |
||||||
|
} |
||||||
|
|
||||||
|
return@execute Game(id, hostname, port, build) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue