forked from openrs2/openrs2
parent
d32ea82032
commit
d119cc07b5
@ -0,0 +1,26 @@ |
||||
plugins { |
||||
`maven-publish` |
||||
kotlin("jvm") |
||||
} |
||||
|
||||
dependencies { |
||||
api("com.google.inject:guice:${Versions.guice}") |
||||
|
||||
implementation(project(":yaml")) |
||||
} |
||||
|
||||
publishing { |
||||
publications.create<MavenPublication>("maven") { |
||||
from(components["java"]) |
||||
|
||||
pom { |
||||
packaging = "jar" |
||||
name.set("OpenRS2 Configuration") |
||||
description.set( |
||||
""" |
||||
Provides a parser for OpenRS2's main configuration file. |
||||
""".trimIndent() |
||||
) |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,23 @@ |
||||
package dev.openrs2.conf |
||||
|
||||
data class Config( |
||||
val game: String, |
||||
val operator: String, |
||||
val domain: String |
||||
) { |
||||
val internalGame: String |
||||
val internalOperator: String |
||||
|
||||
init { |
||||
internalGame = game.toInternalName() |
||||
internalOperator = operator.toInternalName() |
||||
} |
||||
|
||||
companion object { |
||||
private val INTERNAL_NAME_REGEX = Regex("(?i)[^a-z0-9]+") |
||||
|
||||
private fun String.toInternalName(): String { |
||||
return replace(INTERNAL_NAME_REGEX, "_").trim('_').toLowerCase() |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,15 @@ |
||||
package dev.openrs2.conf |
||||
|
||||
import com.google.inject.AbstractModule |
||||
import com.google.inject.Scopes |
||||
import dev.openrs2.yaml.YamlModule |
||||
|
||||
class ConfigModule : AbstractModule() { |
||||
override fun configure() { |
||||
install(YamlModule()) |
||||
|
||||
bind(Config::class.java) |
||||
.toProvider(ConfigProvider::class.java) |
||||
.`in`(Scopes.SINGLETON) |
||||
} |
||||
} |
@ -0,0 +1,24 @@ |
||||
package dev.openrs2.conf |
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper |
||||
import java.nio.file.Files |
||||
import java.nio.file.Paths |
||||
import javax.inject.Inject |
||||
import javax.inject.Provider |
||||
|
||||
class ConfigProvider @Inject constructor(private val mapper: ObjectMapper) : Provider<Config> { |
||||
override fun get(): Config { |
||||
if (Files.notExists(CONFIG_PATH)) { |
||||
Files.copy(EXAMPLE_CONFIG_PATH, CONFIG_PATH) |
||||
} |
||||
|
||||
return Files.newBufferedReader(CONFIG_PATH).use { reader -> |
||||
mapper.readValue(reader, Config::class.java) |
||||
} |
||||
} |
||||
|
||||
companion object { |
||||
private val CONFIG_PATH = Paths.get("etc/config.yaml") |
||||
private val EXAMPLE_CONFIG_PATH = Paths.get("etc/config.example.yaml") |
||||
} |
||||
} |
@ -1,3 +1,4 @@ |
||||
/config.yaml |
||||
/loader.p12 |
||||
/private.key |
||||
/public.key |
||||
|
@ -0,0 +1,10 @@ |
||||
--- |
||||
# The name of the game. All references to "RuneScape" are replaced with this |
||||
# string. |
||||
game: OpenRS2 |
||||
# The name of the organisation running the game. All references to "Jagex" are |
||||
# replaced with this string. |
||||
operator: OpenRS2 |
||||
# The game's domain name. All references to "runescape.com" are replaced with |
||||
# this string. It should, at a minimum, have `www` and `www-wtqa` hostnames. |
||||
domain: openrs2.dev |
Loading…
Reference in new issue