diff --git a/build.gradle.kts b/build.gradle.kts index c3ff7e8..9c8c47d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -30,7 +30,6 @@ dependencies { implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktor_version") implementation("io.ktor:ktor-server-cors-jvm:$ktor_version") implementation("io.ktor:ktor-serialization-kotlinx-json-jvm:$ktor_version") - implementation("io.ktor:ktor-server-websockets-jvm:$ktor_version") implementation("io.ktor:ktor-server-netty-jvm:$ktor_version") implementation("ch.qos.logback:logback-classic:$logback_version") implementation("io.ktor:ktor-server-host-common-jvm:2.2.1") diff --git a/src/main/kotlin/de/steamwar/plugins/Plugins.kt b/src/main/kotlin/de/steamwar/plugins/Plugins.kt index 7285880..3c43033 100644 --- a/src/main/kotlin/de/steamwar/plugins/Plugins.kt +++ b/src/main/kotlin/de/steamwar/plugins/Plugins.kt @@ -19,13 +19,6 @@ import java.time.Duration data class Session(val name: String) fun Application.configurePlugins() { - install(WebSockets) { - pingPeriod = Duration.ofSeconds(15) - timeout = Duration.ofSeconds(15) - maxFrameSize = Long.MAX_VALUE - masking = false - contentConverter = KotlinxWebsocketSerializationConverter(Json) - } install(AutoHeadResponse) install(CachingHeaders) { diff --git a/src/main/kotlin/de/steamwar/routes/Server.kt b/src/main/kotlin/de/steamwar/routes/Server.kt deleted file mode 100644 index 23dd8a5..0000000 --- a/src/main/kotlin/de/steamwar/routes/Server.kt +++ /dev/null @@ -1,69 +0,0 @@ -package de.steamwar.routes - -import io.ktor.server.application.* -import io.ktor.server.response.* -import io.ktor.server.routing.* -import io.ktor.server.websocket.* -import io.ktor.utils.io.streams.* -import io.ktor.websocket.* -import kotlinx.coroutines.* -import kotlinx.coroutines.channels.SendChannel -import kotlinx.serialization.Serializable -import kotlinx.serialization.Transient -import kotlinx.serialization.json.JsonArray -import kotlinx.serialization.json.JsonPrimitive -import java.io.File -import java.io.OutputStream -import kotlin.concurrent.thread - -@Serializable -data class StartServerPayload(val name: String, val port: Int? = null, val world: String? = null, val plugins: String? = null) { - val arguments - get() = run { - val args = mutableListOf() - if (port != null) { - args.add("-p") - args.add(port.toString()) - } - if (world != null) { - args.add("-w") - args.add(world) - } - if (plugins != null) { - args.add("-pl") - args.add(plugins) - } - args - } -} - -class OutputSender(val outgoing: SendChannel): OutputStream() { - val buffer = StringBuilder() - - override fun write(b: Int) = runBlocking { - buffer.append(b.toChar()) - if (b.toChar() == '\n') { - outgoing.send(Frame.Text(buffer.toString())) - buffer.clear() - } - } -} - -fun Routing.configureDevServerRoutes() { - route("/servers") { - get { - call.respondText(JsonArray(File("/servers/").list()?.map { JsonPrimitive(it) } ?: listOf()).toString()) - } - webSocket("/start") { - val startPayload = receiveDeserialized() - val proc = ProcessBuilder("python3", "/binarys/dev.py", startPayload.name, *startPayload.arguments.toTypedArray()).start() - thread { - proc.inputStream.copyTo(OutputSender(outgoing)) - } - var received: Frame? = null - while (incoming.tryReceive().also { received = it.getOrNull() }.isSuccess) { - proc.outputStream.write(received!!.data + "\n".toByteArray()) - } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/de/steamwar/sql/SQLWrapperImpl.kt b/src/main/kotlin/de/steamwar/sql/SQLWrapperImpl.kt index f1f5bca..882d939 100644 --- a/src/main/kotlin/de/steamwar/sql/SQLWrapperImpl.kt +++ b/src/main/kotlin/de/steamwar/sql/SQLWrapperImpl.kt @@ -9,13 +9,13 @@ class SQLWrapperImpl: SQLWrapper { override fun loadSchemTypes(tmpTypes: MutableList?, tmpFromDB: MutableMap?) { val folder = File("/configs/GameModes") if (folder.exists()) { - for (configFile in Arrays.stream(folder.listFiles { file, name -> name.endsWith(".yml") && !name.endsWith(".kits.yml") }) + for (configFile in Arrays.stream(folder.listFiles { _, name -> name.endsWith(".yml") && !name.endsWith(".kits.yml") }) .sorted().collect(Collectors.toList())) { val config: YamlConfiguration = YamlConfiguration.loadConfiguration(configFile) if (!config.isConfigurationSection("Schematic")) continue val type: String = config.getString("Schematic.Type")!! val shortcut: String = config.getString("Schematic.Shortcut")!! - if (tmpFromDB!!.containsKey(type!!.lowercase(Locale.getDefault()))) continue + if (tmpFromDB!!.containsKey(type.lowercase(Locale.getDefault()))) continue var checktype: SchematicType? = null val material: String = config.getString("Schematic.Material", "STONE_BUTTON")!! if (!config.getStringList("CheckQuestions").isEmpty()) {