mirror of
https://github.com/yairm210/Unciv.git
synced 2024-12-22 20:34:23 +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}")
|
||||
@ -33,10 +33,10 @@ buildscript {
|
||||
classpath("com.github.anuken:packr:-SNAPSHOT")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
allprojects {
|
||||
apply(plugin = "eclipse")
|
||||
apply(plugin = "idea")
|
||||
apply(plugin = "eclipse")
|
||||
apply(plugin = "idea")
|
||||
|
||||
|
||||
version = "1.0.1"
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,12 +70,13 @@ project(":desktop") {
|
||||
}
|
||||
|
||||
"implementation"("com.github.MinnDevelopment:java-discord-rpc:v2.0.1")
|
||||
|
||||
|
||||
// For server-side
|
||||
|
||||
"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)
|
||||
}
|
||||
|
||||
println("Server will run on $serverPort port, you can use '-port=XXXX' custom port.")
|
||||
private class UncivServerRunner : CliktCommand() {
|
||||
private val port by option(
|
||||
"-p", "-port",
|
||||
envvar = "UncivServerPort",
|
||||
help = "Server port"
|
||||
).int().restrictTo(1024..49151).default(8080)
|
||||
|
||||
val fileFolderName = "MultiplayerFiles"
|
||||
File(fileFolderName).mkdir()
|
||||
println(File(fileFolderName).absolutePath)
|
||||
private val folder by option(
|
||||
"-f", "-folder",
|
||||
envvar = "UncivServerFolder",
|
||||
help = "Multiplayer file's folder"
|
||||
).default("MultiplayerFiles")
|
||||
|
||||
override fun run() {
|
||||
serverRun(port, folder)
|
||||
}
|
||||
|
||||
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