From 0f91587ae7fd5ffb73f58d40871124620fa89b69 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 11 Apr 2020 22:29:54 +0800 Subject: [PATCH] Fix nameCard deserializing --- .../protocol/packet/chat/receive/OnlinePush.kt | 12 ++++++------ .../net/mamoe/mirai/qqandroid/utils/ByteArrayPool.kt | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt index 77d7f7462..0b22a9401 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt @@ -84,12 +84,12 @@ internal class OnlinePush { val group = bot.getGroupOrNull(pbPushMsg.msg.msgHead.groupInfo!!.groupCode) ?: return null // 机器人还正在进群 val sender = group[pbPushMsg.msg.msgHead.fromUin] as MemberImpl val name = extraInfo?.groupCard?.run { - try { - loadAs(Oidb0x8fc.CommCardNameBuf.serializer()).richCardName!!.first { it.text.isNotEmpty() } - .text.encodeToString() - } catch (e: Exception) { - encodeToString() - } + kotlin.runCatching { + if (this[0] == 0x0A.toByte() && this[1] == 0x0A.toByte() && this[2] == 0x0A.toByte() && this[3] == 0x08.toByte()) + loadAs(Oidb0x8fc.CommCardNameBuf.serializer()).richCardName?.firstOrNull { it.text.isNotEmpty() } + ?.text?.encodeToString() + else return@runCatching null + }.getOrNull() ?: encodeToString() } ?: pbPushMsg.msg.msgHead.groupInfo.groupCard // 没有 extraInfo 就从 head 里取 val flags = extraInfo?.flags ?: 0 diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/ByteArrayPool.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/ByteArrayPool.kt index e957dec82..586633752 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/ByteArrayPool.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/ByteArrayPool.kt @@ -10,7 +10,7 @@ internal object ByteArrayPool : DefaultPool(256) { /** * 每一个 [ByteArray] 的大小 */ - const val BUFFER_SIZE: Int = 81920 / 2 + const val BUFFER_SIZE: Int = 8192 * 8 override fun produceInstance(): ByteArray = ByteArray(BUFFER_SIZE)