From 636f4cbead904fd6f47f05f6ee5bfce6be84197c Mon Sep 17 00:00:00 2001 From: Him188 Date: Wed, 16 Sep 2020 10:24:17 +0800 Subject: [PATCH] Fix potential packet missing in NewContact --- .../network/protocol/data/proto/StructMsg.kt | 4 +- .../protocol/packet/chat/NewContact.kt | 43 ++++++++++--------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/data/proto/StructMsg.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/data/proto/StructMsg.kt index 43de46657..4804fc9b7 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/data/proto/StructMsg.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/data/proto/StructMsg.kt @@ -186,8 +186,8 @@ internal class Structmsg : ProtoBuf { @ProtoNumber(5) @JvmField val latestGroupSeq: Long = 0L, @ProtoNumber(6) @JvmField val followingFriendSeq: Long = 0L, @ProtoNumber(7) @JvmField val followingGroupSeq: Long = 0L, - @ProtoNumber(9) @JvmField val friendmsgs: List? = null, - @ProtoNumber(10) @JvmField val groupmsgs: List? = null, + @ProtoNumber(9) @JvmField val friendmsgs: List = emptyList(), + @ProtoNumber(10) @JvmField val groupmsgs: List = emptyList(), @ProtoNumber(11) @JvmField val msgRibbonFriend: StructMsg? = null, @ProtoNumber(12) @JvmField val msgRibbonGroup: StructMsg? = null, @ProtoNumber(13) @JvmField val msgDisplay: String = "", diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/NewContact.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/NewContact.kt index e415c4c1e..e634f79d4 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/NewContact.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/NewContact.kt @@ -20,6 +20,8 @@ import net.mamoe.mirai.event.events.NewFriendRequestEvent import net.mamoe.mirai.getGroupOrNull import net.mamoe.mirai.qqandroid.QQAndroidBot import net.mamoe.mirai.qqandroid.message.contextualBugReportException +import net.mamoe.mirai.qqandroid.network.MultiPacket +import net.mamoe.mirai.qqandroid.network.MultiPacketByIterable import net.mamoe.mirai.qqandroid.network.Packet import net.mamoe.mirai.qqandroid.network.QQAndroidClient import net.mamoe.mirai.qqandroid.network.protocol.data.proto.Structmsg @@ -32,7 +34,7 @@ import net.mamoe.mirai.qqandroid.utils.io.serialization.writeProtoBuf internal class NewContact { internal object SystemMsgNewFriend : - OutgoingPacketFactory("ProfileService.Pb.ReqSystemMsgNew.Friend") { + OutgoingPacketFactory?>("ProfileService.Pb.ReqSystemMsgNew.Friend") { operator fun invoke(client: QQAndroidClient) = buildOutgoingUniPacket(client) { writeProtoBuf( @@ -56,20 +58,21 @@ internal class NewContact { } - override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): NewFriendRequestEvent? { - readBytes().loadAs(Structmsg.RspSystemMsgNew.serializer()).run { - val struct = friendmsgs?.firstOrNull() - return struct?.msg?.run { - NewFriendRequestEvent( - bot, - struct.msgSeq, - msgAdditional, - struct.reqUin, - groupCode, - reqUinNick - ) + override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): MultiPacket? { + return readBytes().loadAs(Structmsg.RspSystemMsgNew.serializer()).run { + friendmsgs.mapNotNull { struct -> + struct.msg?.run { + NewFriendRequestEvent( + bot, + struct.msgSeq, + msgAdditional, + struct.reqUin, + groupCode, + reqUinNick + ) + } } - } + }.let { MultiPacketByIterable(it) } } internal object Action : OutgoingPacketFactory("ProfileService.Pb.ReqSystemMsgAction.Friend") { @@ -107,7 +110,7 @@ internal class NewContact { internal object SystemMsgNewGroup : - OutgoingPacketFactory("ProfileService.Pb.ReqSystemMsgNew.Group") { + OutgoingPacketFactory?>("ProfileService.Pb.ReqSystemMsgNew.Group") { operator fun invoke(client: QQAndroidClient) = buildOutgoingUniPacket(client) { writeProtoBuf( @@ -143,11 +146,9 @@ internal class NewContact { } - override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Packet? { - readBytes().loadAs(Structmsg.RspSystemMsgNew.serializer()).run { - val struct = groupmsgs?.firstOrNull() - - return struct?.msg?.run { + override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): MultiPacket? { + return readBytes().loadAs(Structmsg.RspSystemMsgNew.serializer()).groupmsgs.mapNotNull { struct -> + struct.msg?.run { //this.soutv("SystemMsg") when (subType) { 1 -> { // 处理被邀请入群 或 处理成员入群申请 @@ -212,7 +213,7 @@ internal class NewContact { ) } } - } + }.let { MultiPacketByIterable(it) } } internal object Action : OutgoingPacketFactory("ProfileService.Pb.ReqSystemMsgAction.Group") {