mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-04 06:28:28 +08:00
Changed configuration format to HOCON.
This commit is contained in:
parent
f43e154bc7
commit
bc3c3c19b2
@ -2,8 +2,10 @@
|
||||
|
||||
## Configuration
|
||||
|
||||
Put a config.json file in the directory where psoserv will run or pass
|
||||
the `--config=/path/to/config.json` parameter to specify a configuration file.
|
||||
Put a psoserv.conf file in the directory where psoserv will run or pass
|
||||
the `--config=/path/to/file.conf` parameter to specify a configuration file.
|
||||
The [HOCON](https://github.com/lightbend/config#using-hocon-the-json-superset) format is used to
|
||||
describe configurations.
|
||||
|
||||
## Proxy
|
||||
|
||||
@ -11,55 +13,60 @@ Phantasmal PSO server can proxy any other PSO server. Below is a sample configur
|
||||
locally running Tethealla server using the standard Tethealla client. Be sure to modify
|
||||
tethealla.ini and set server port to 22000.
|
||||
|
||||
```json
|
||||
{
|
||||
"proxy": {
|
||||
"bindAddress": "localhost",
|
||||
"remoteAddress": "localhost",
|
||||
"servers": [
|
||||
{
|
||||
"name": "patch_proxy",
|
||||
"version": "PC",
|
||||
"bindPort": 11000,
|
||||
"remotePort": 21000
|
||||
},
|
||||
{
|
||||
"name": "patch_data_proxy",
|
||||
"version": "PC",
|
||||
"bindPort": 11001,
|
||||
"remotePort": 21001
|
||||
},
|
||||
{
|
||||
"name": "login_proxy",
|
||||
"version": "BB",
|
||||
"bindPort": 12000,
|
||||
"remotePort": 22000
|
||||
},
|
||||
{
|
||||
"name": "character_proxy",
|
||||
"version": "BB",
|
||||
"bindPort": 12001,
|
||||
"remotePort": 22001
|
||||
},
|
||||
{
|
||||
"name": "ship_proxy",
|
||||
"version": "BB",
|
||||
"bindPort": 13000,
|
||||
"remotePort": 5278
|
||||
},
|
||||
{
|
||||
"name": "block_1_proxy",
|
||||
"version": "BB",
|
||||
"bindPort": 13001,
|
||||
"remotePort": 5279
|
||||
},
|
||||
{
|
||||
"name": "block_2_proxy",
|
||||
"version": "BB",
|
||||
"bindPort": 13002,
|
||||
"remotePort": 5280
|
||||
}
|
||||
]
|
||||
```hocon
|
||||
proxy: {
|
||||
# Default local address used by all proxies, can be overwritten per proxy.
|
||||
bindAddress: localhost
|
||||
# Default address of the remote server used by all proxies, can be overwritten per proxy.
|
||||
remoteAddress: localhost
|
||||
# One server configuration per address/port pair that needs to be proxied.
|
||||
servers: [
|
||||
{
|
||||
# Name used for e.g. the logs.
|
||||
name: patch_proxy
|
||||
# PC or BB, determines the message format encryption cipher used.
|
||||
version: PC
|
||||
# Local port the proxy will listen on.
|
||||
bindPort: 11000
|
||||
# Remote port the proxy will connect to.
|
||||
remotePort: 21000
|
||||
}
|
||||
{
|
||||
name: patch_data_proxy
|
||||
version: PC
|
||||
bindPort: 11001
|
||||
remotePort: 21001
|
||||
}
|
||||
{
|
||||
name: login_proxy
|
||||
version: BB
|
||||
bindPort: 12000
|
||||
remotePort: 22000
|
||||
}
|
||||
{
|
||||
name: character_proxy
|
||||
version: BB
|
||||
bindPort: 12001
|
||||
remotePort: 22001
|
||||
}
|
||||
{
|
||||
name: ship_proxy
|
||||
version: BB
|
||||
bindPort: 13000
|
||||
remotePort: 5278
|
||||
}
|
||||
{
|
||||
name: block_1_proxy
|
||||
version: BB
|
||||
bindPort: 13001
|
||||
remotePort: 5279
|
||||
}
|
||||
{
|
||||
name: block_2_proxy
|
||||
version: BB
|
||||
bindPort: 13002
|
||||
remotePort: 5280
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
@ -13,5 +13,5 @@ val serializationVersion: String by project.extra
|
||||
dependencies {
|
||||
implementation(project(":core"))
|
||||
implementation(project(":psolib"))
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-hocon:$serializationVersion")
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package world.phantasmal.psoserv
|
||||
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.json.Json
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.hocon.Hocon
|
||||
import kotlinx.serialization.hocon.decodeFromConfig
|
||||
import mu.KotlinLogging
|
||||
import world.phantasmal.psoserv.encryption.BbCipher
|
||||
import world.phantasmal.psoserv.encryption.Cipher
|
||||
@ -47,22 +49,25 @@ fun main(args: Array<String>) {
|
||||
|
||||
// Try default config file location if no file specified with --config argument.
|
||||
if (configFile == null) {
|
||||
configFile = File("config.json").takeIf { it.isFile }
|
||||
configFile = File("psoserv.conf").takeIf { it.isFile }
|
||||
}
|
||||
|
||||
val config: Config
|
||||
|
||||
// Parse the config file if we found one, otherwise use default config.
|
||||
if (configFile != null) {
|
||||
val config: Config = if (configFile != null) {
|
||||
LOGGER.info { "Using configuration file $configFile." }
|
||||
|
||||
val json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
if (!configFile.exists()) {
|
||||
error(""""$configFile" does not exist.""")
|
||||
} else if (!configFile.isFile) {
|
||||
error(""""$configFile" is not a file.""")
|
||||
} else if (!configFile.canRead()) {
|
||||
error("""Don't have permission to read "$configFile".""")
|
||||
}
|
||||
|
||||
config = json.decodeFromString(configFile.readText())
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
Hocon.decodeFromConfig(ConfigFactory.parseFile(configFile))
|
||||
} else {
|
||||
config = DEFAULT_CONFIG
|
||||
DEFAULT_CONFIG
|
||||
}
|
||||
|
||||
// Initialize and start the server.
|
||||
@ -70,7 +75,9 @@ fun main(args: Array<String>) {
|
||||
|
||||
LOGGER.info { "Starting up." }
|
||||
|
||||
server.start()
|
||||
if (!server.start()) {
|
||||
LOGGER.info { "Nothing to do, stopping." }
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
LOGGER.error(e) { "Failed to start up." }
|
||||
}
|
||||
@ -80,9 +87,10 @@ private class PhantasmalServer(
|
||||
private val servers: List<Server>,
|
||||
private val proxyServers: List<ProxyServer>,
|
||||
) {
|
||||
fun start() {
|
||||
fun start(): Boolean {
|
||||
servers.forEach(Server::start)
|
||||
proxyServers.forEach(ProxyServer::start)
|
||||
return servers.isNotEmpty() || proxyServers.isNotEmpty()
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
|
Loading…
Reference in New Issue
Block a user