Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.0 KiB
58 lines
2.0 KiB
package org.openrs2.archive.game
|
|
|
|
import jakarta.inject.Inject
|
|
import jakarta.inject.Singleton
|
|
import org.openrs2.db.Database
|
|
|
|
@Singleton
|
|
public class GameDatabase @Inject constructor(
|
|
private val database: Database
|
|
) {
|
|
public suspend fun getGame(name: String, environment: String, language: String): Game? {
|
|
return database.execute { connection ->
|
|
connection.prepareStatement(
|
|
"""
|
|
SELECT v.id, v.url, v.build_major, v.build_minor, v.last_master_index_id, v.language_id, g.scope_id
|
|
FROM game_variants v
|
|
JOIN games g ON g.id = v.game_id
|
|
JOIN environments e ON e.id = v.environment_id
|
|
JOIN languages l ON l.id = v.language_id
|
|
WHERE g.name = ? AND e.name = ? AND l.iso_code = ?
|
|
""".trimIndent()
|
|
).use { stmt ->
|
|
stmt.setString(1, name)
|
|
stmt.setString(2, environment)
|
|
stmt.setString(3, language)
|
|
|
|
stmt.executeQuery().use { rows ->
|
|
if (!rows.next()) {
|
|
return@execute null
|
|
}
|
|
|
|
val id = rows.getInt(1)
|
|
val url: String? = rows.getString(2)
|
|
|
|
var buildMajor: Int? = rows.getInt(3)
|
|
if (rows.wasNull()) {
|
|
buildMajor = null
|
|
}
|
|
|
|
var buildMinor: Int? = rows.getInt(4)
|
|
if (rows.wasNull()) {
|
|
buildMinor = null
|
|
}
|
|
|
|
var lastMasterIndexId: Int? = rows.getInt(5)
|
|
if (rows.wasNull()) {
|
|
lastMasterIndexId = null
|
|
}
|
|
|
|
val languageId = rows.getInt(6)
|
|
val scopeId = rows.getInt(7)
|
|
|
|
return@execute Game(id, url, buildMajor, buildMinor, lastMasterIndexId, languageId, scopeId)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|