From 5edc4a18217aa9f330eef50372d48ab1eec5becf Mon Sep 17 00:00:00 2001 From: Sho Sakuma Date: Fri, 6 Feb 2026 18:43:19 +0900 Subject: feat: Add global chat protocol --- .../lunaticChat/engine/protocol/PluginMessage.kt | 20 ++++++++++++++++++++ .../engine/protocol/PluginMessageCodec.kt | 7 +++++++ 2 files changed, 27 insertions(+) (limited to 'engine') diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/protocol/PluginMessage.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/protocol/PluginMessage.kt index 4f3a572..cee7837 100644 --- a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/protocol/PluginMessage.kt +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/protocol/PluginMessage.kt @@ -55,4 +55,24 @@ sealed interface PluginMessage { val protocolVersion: String, val online: Boolean, ) : PluginMessage + + /** + * Global chat message (Paper ↔ Velocity ↔ Paper) + * + * @property messageId UUID for deduplication + * @property serverName Source server identifier + * @property playerId UUID as string + * @property playerName Player name + * @property message Chat message content + * @property timestamp Message timestamp (milliseconds since epoch) + */ + @Serializable + data class GlobalChatMessage( + val messageId: String, + val serverName: String, + val playerId: String, + val playerName: String, + val message: String, + val timestamp: Long = System.currentTimeMillis(), + ) : PluginMessage } diff --git a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/protocol/PluginMessageCodec.kt b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/protocol/PluginMessageCodec.kt index 042a7dc..85b51f0 100644 --- a/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/protocol/PluginMessageCodec.kt +++ b/engine/src/main/kotlin/dev/m1sk9/lunaticChat/engine/protocol/PluginMessageCodec.kt @@ -23,6 +23,7 @@ object PluginMessageCodec { const val HANDSHAKE_RESPONSE = "handshake_response" const val STATUS_REQUEST = "status_request" const val STATUS_RESPONSE = "status_response" + const val GLOBAL_CHAT = "global_chat" } /** @@ -49,6 +50,9 @@ object PluginMessageCodec { is PluginMessage.StatusResponse -> { SubChannel.STATUS_RESPONSE to json.encodeToString(message) } + is PluginMessage.GlobalChatMessage -> { + SubChannel.GLOBAL_CHAT to json.encodeToString(message) + } } dataOut.writeUTF(subChannel) @@ -84,6 +88,9 @@ object PluginMessageCodec { SubChannel.STATUS_RESPONSE -> { json.decodeFromString(messageJson) } + SubChannel.GLOBAL_CHAT -> { + json.decodeFromString(messageJson) + } else -> throw IllegalArgumentException("Unknown sub-channel: $subChannel") } } -- cgit v1.2.1