From a0b2d0c5c50f6087ad4e12bfc99d372f5bc861bd Mon Sep 17 00:00:00 2001 From: zml Date: Sat, 2 Nov 2024 20:59:58 -0700 Subject: [PATCH] fix: resolve ktor3 api breaks --- .../net/kyori/adventure/webui/jvm/Application.kt | 7 ++++--- .../adventure/webui/jvm/minimessage/MiniMessage.kt | 1 - .../minimessage/preview/ServerStatusPreviewManager.kt | 10 ++++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/jvmMain/kotlin/net/kyori/adventure/webui/jvm/Application.kt b/src/jvmMain/kotlin/net/kyori/adventure/webui/jvm/Application.kt index 9464ddc..b3d1d97 100644 --- a/src/jvmMain/kotlin/net/kyori/adventure/webui/jvm/Application.kt +++ b/src/jvmMain/kotlin/net/kyori/adventure/webui/jvm/Application.kt @@ -15,7 +15,8 @@ import io.ktor.server.websocket.WebSockets import io.ktor.server.websocket.pingPeriod import io.ktor.server.websocket.timeout import io.ktor.websocket.WebSocketDeflateExtension -import java.time.Duration +import kotlin.time.Duration +import kotlin.time.Duration.Companion.seconds public fun Application.main() { install(Compression) { @@ -36,8 +37,8 @@ public fun Application.main() { } install(WebSockets) { - pingPeriod = Duration.ofSeconds(15) - timeout = Duration.ofSeconds(5) + pingPeriod = 15.seconds + timeout = 5.seconds extensions { install(WebSocketDeflateExtension) } } diff --git a/src/jvmMain/kotlin/net/kyori/adventure/webui/jvm/minimessage/MiniMessage.kt b/src/jvmMain/kotlin/net/kyori/adventure/webui/jvm/minimessage/MiniMessage.kt index 42c8a77..9a6ea68 100644 --- a/src/jvmMain/kotlin/net/kyori/adventure/webui/jvm/minimessage/MiniMessage.kt +++ b/src/jvmMain/kotlin/net/kyori/adventure/webui/jvm/minimessage/MiniMessage.kt @@ -2,7 +2,6 @@ package net.kyori.adventure.webui.jvm.minimessage import io.ktor.http.HttpStatusCode import io.ktor.server.application.Application -import io.ktor.server.application.call import io.ktor.server.http.content.defaultResource import io.ktor.server.http.content.resource import io.ktor.server.http.content.resources diff --git a/src/jvmMain/kotlin/net/kyori/adventure/webui/jvm/minimessage/preview/ServerStatusPreviewManager.kt b/src/jvmMain/kotlin/net/kyori/adventure/webui/jvm/minimessage/preview/ServerStatusPreviewManager.kt index 251354e..0a45a10 100644 --- a/src/jvmMain/kotlin/net/kyori/adventure/webui/jvm/minimessage/preview/ServerStatusPreviewManager.kt +++ b/src/jvmMain/kotlin/net/kyori/adventure/webui/jvm/minimessage/preview/ServerStatusPreviewManager.kt @@ -8,7 +8,9 @@ import io.ktor.network.sockets.openWriteChannel import io.ktor.server.application.Application import io.ktor.utils.io.ByteReadChannel import io.ktor.utils.io.ByteWriteChannel -import io.ktor.utils.io.close +import io.ktor.utils.io.readByte +import io.ktor.utils.io.readFully +import io.ktor.utils.io.readShort import io.ktor.utils.io.writeByte import io.ktor.utils.io.writeFully import kotlinx.coroutines.CoroutineScope @@ -97,7 +99,7 @@ public class ServerStatusPreviewManager( } } - sendChannel.close() + sendChannel.flushAndClose() } catch (e: Exception) { logger.error("An unknown error occurred whilst responding to a ping from ${socket.remoteAddress}", e) } @@ -157,11 +159,11 @@ public class ServerStatusPreviewManager( var value = int while (true) { if ((value and 0x7F.inv()) == 0) { - writeByte(value) + writeByte(value.toByte()) return } - writeByte((value and 0x7F) or 0x80) + writeByte(((value and 0x7F) or 0x80).toByte()) value = value ushr 7 }