From 4b79c197e75f334fe3871e7236c75cbfe6d93740 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 21 May 2022 16:25:03 +0100 Subject: [PATCH] Filter out customElem without MIRAI_CUSTOM_ELEM_TYPE --- .../kotlin/message/protocol/impl/CustomMessageProtocol.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/CustomMessageProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/CustomMessageProtocol.kt index 230c51e44..264be5a6f 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/CustomMessageProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/CustomMessageProtocol.kt @@ -21,6 +21,10 @@ internal class CustomMessageProtocol : MessageProtocol() { add(Decoder()) } + private companion object { + private const val MIRAI_CUSTOM_ELEM_TYPE = 103904510 // "mirai.hashCode()" + } + private class Encoder : MessageEncoder { override suspend fun MessageEncoderContext.process(data: CustomMessage) { markAsConsumed() @@ -39,9 +43,6 @@ internal class CustomMessageProtocol : MessageProtocol() { ) } - private companion object { - private const val MIRAI_CUSTOM_ELEM_TYPE = 103904510 // "mirai.hashCode()" - } } private class Decoder : MessageDecoder { @@ -49,6 +50,7 @@ internal class CustomMessageProtocol : MessageProtocol() { if (data.customElem == null) return markAsConsumed() kotlin.runCatching { + if (data.customElem.enumType != MIRAI_CUSTOM_ELEM_TYPE) return data.customElem.data.read { CustomMessage.load(this) }