mirror of
https://github.com/yairm210/Unciv.git
synced 2024-12-23 01:14:30 +07:00
Update UncivServer: (#6427)
- Add `clikt` lib. - Add custom multiplayer file's folder.
This commit is contained in:
parent
477ac78856
commit
ee1af44809
@ -21,7 +21,7 @@ buildscript {
|
||||
mavenCentral()
|
||||
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/") }
|
||||
gradlePluginPortal()
|
||||
maven{ url = uri("https://jitpack.io") } // for the anuken packr
|
||||
maven { url = uri("https://jitpack.io") } // for the anuken packr
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${com.unciv.build.BuildConfig.kotlinVersion}")
|
||||
@ -53,7 +53,7 @@ allprojects {
|
||||
mavenCentral()
|
||||
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/") }
|
||||
maven { url = uri("https://oss.sonatype.org/content/repositories/releases/") }
|
||||
maven{ url = uri("https://jitpack.io") } // for java-discord-rpc
|
||||
maven { url = uri("https://jitpack.io") } // for java-discord-rpc
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,6 +76,7 @@ project(":desktop") {
|
||||
"implementation"("io.ktor:ktor-server-core:1.6.8")
|
||||
"implementation"("io.ktor:ktor-server-netty:1.6.8")
|
||||
"implementation"("ch.qos.logback:logback-classic:1.2.5")
|
||||
"implementation"("com.github.ajalt.clikt:clikt:3.4.0")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
package com.unciv.app.desktop
|
||||
|
||||
import com.github.ajalt.clikt.core.CliktCommand
|
||||
import com.github.ajalt.clikt.parameters.options.default
|
||||
import com.github.ajalt.clikt.parameters.options.option
|
||||
import com.github.ajalt.clikt.parameters.types.int
|
||||
import com.github.ajalt.clikt.parameters.types.restrictTo
|
||||
import io.ktor.application.*
|
||||
import io.ktor.response.*
|
||||
import io.ktor.routing.*
|
||||
@ -12,24 +17,29 @@ import java.io.File
|
||||
|
||||
|
||||
internal object UncivServer {
|
||||
private var serverPort = 8080
|
||||
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
args.forEach { arg ->
|
||||
when {
|
||||
arg.startsWith("-port=") -> with(arg.removePrefix("-port=").toIntOrNull() ?: 0) {
|
||||
if (this in 1024..49151) serverPort = this
|
||||
else println("'port' must be between 1024 and 49151")
|
||||
}
|
||||
}
|
||||
fun main(args: Array<String>) = UncivServerRunner().main(args)
|
||||
}
|
||||
|
||||
private class UncivServerRunner : CliktCommand() {
|
||||
private val port by option(
|
||||
"-p", "-port",
|
||||
envvar = "UncivServerPort",
|
||||
help = "Server port"
|
||||
).int().restrictTo(1024..49151).default(8080)
|
||||
|
||||
private val folder by option(
|
||||
"-f", "-folder",
|
||||
envvar = "UncivServerFolder",
|
||||
help = "Multiplayer file's folder"
|
||||
).default("MultiplayerFiles")
|
||||
|
||||
override fun run() {
|
||||
serverRun(port, folder)
|
||||
}
|
||||
|
||||
println("Server will run on $serverPort port, you can use '-port=XXXX' custom port.")
|
||||
|
||||
val fileFolderName = "MultiplayerFiles"
|
||||
File(fileFolderName).mkdir()
|
||||
println(File(fileFolderName).absolutePath)
|
||||
private fun serverRun(serverPort: Int, fileFolderName: String) {
|
||||
echo("Starting UncivServer for ${File(fileFolderName).absolutePath} on port $serverPort")
|
||||
embeddedServer(Netty, port = serverPort) {
|
||||
routing {
|
||||
get("/isalive") {
|
||||
|
Loading…
Reference in New Issue
Block a user