Filter out customElem without MIRAI_CUSTOM_ELEM_TYPE

This commit is contained in:
Him188 2022-05-21 16:25:03 +01:00
parent 617b32aa14
commit 4b79c197e7

View File

@ -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<CustomMessage> {
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)
}