Yeet WebSockets

Dieser Commit ist enthalten in:
Chaoscaot 2022-12-24 14:28:20 +01:00
Ursprung 757cbf71bd
Commit 8869c74c99
4 geänderte Dateien mit 2 neuen und 79 gelöschten Zeilen

Datei anzeigen

@ -30,7 +30,6 @@ dependencies {
implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktor_version") implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktor_version")
implementation("io.ktor:ktor-server-cors-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-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("io.ktor:ktor-server-netty-jvm:$ktor_version")
implementation("ch.qos.logback:logback-classic:$logback_version") implementation("ch.qos.logback:logback-classic:$logback_version")
implementation("io.ktor:ktor-server-host-common-jvm:2.2.1") implementation("io.ktor:ktor-server-host-common-jvm:2.2.1")

Datei anzeigen

@ -19,13 +19,6 @@ import java.time.Duration
data class Session(val name: String) data class Session(val name: String)
fun Application.configurePlugins() { 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(AutoHeadResponse)
install(CachingHeaders) { install(CachingHeaders) {

Datei anzeigen

@ -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<String>()
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<Frame>): 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<StartServerPayload>()
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())
}
}
}
}

Datei anzeigen

@ -9,13 +9,13 @@ class SQLWrapperImpl: SQLWrapper {
override fun loadSchemTypes(tmpTypes: MutableList<SchematicType>?, tmpFromDB: MutableMap<String, SchematicType>?) { override fun loadSchemTypes(tmpTypes: MutableList<SchematicType>?, tmpFromDB: MutableMap<String, SchematicType>?) {
val folder = File("/configs/GameModes") val folder = File("/configs/GameModes")
if (folder.exists()) { 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())) { .sorted().collect(Collectors.toList())) {
val config: YamlConfiguration = YamlConfiguration.loadConfiguration(configFile) val config: YamlConfiguration = YamlConfiguration.loadConfiguration(configFile)
if (!config.isConfigurationSection("Schematic")) continue if (!config.isConfigurationSection("Schematic")) continue
val type: String = config.getString("Schematic.Type")!! val type: String = config.getString("Schematic.Type")!!
val shortcut: String = config.getString("Schematic.Shortcut")!! 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 var checktype: SchematicType? = null
val material: String = config.getString("Schematic.Material", "STONE_BUTTON")!! val material: String = config.getString("Schematic.Material", "STONE_BUTTON")!!
if (!config.getStringList("CheckQuestions").isEmpty()) { if (!config.getStringList("CheckQuestions").isEmpty()) {