From de484ecb9a082c9fbb0f17f6d30526760d98370c Mon Sep 17 00:00:00 2001 From: ryoii Date: Sun, 12 Jul 2020 11:42:21 +0800 Subject: [PATCH 1/4] Remove debug log --- .../packet/chat/receive/OnlinePush.ReqPush.kt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt index 161167c40..d97309dc3 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt @@ -456,23 +456,23 @@ internal object Transformers528 : Map by mapOf( var85.troopface = var3; var85.hasSetNewTroopHead = true; */ - bot.logger.debug( - contextualBugReportException( - "解析 Transformers528 0x27L ModGroupProfile 群头像修改", - forDebug = "this=${this._miraiContentToString()}" - ) - ) +// bot.logger.debug( +// contextualBugReportException( +// "解析 Transformers528 0x27L ModGroupProfile 群头像修改", +// forDebug = "this=${this._miraiContentToString()}" +// ) +// ) null } 3 -> { // troop.credit.data // top_package/akkz.java:3475 // top_package/akkz.java:3498 - bot.logger.debug( - contextualBugReportException( - "解析 Transformers528 0x27L ModGroupProfile 群 troop.credit.data", - forDebug = "this=${this._miraiContentToString()}" - ) - ) +// bot.logger.debug( +// contextualBugReportException( +// "解析 Transformers528 0x27L ModGroupProfile 群 troop.credit.data", +// forDebug = "this=${this._miraiContentToString()}" +// ) +// ) null } From 42716ab62d9861d0828cfe23c4db06be5dc6417e Mon Sep 17 00:00:00 2001 From: ryoii Date: Sun, 12 Jul 2020 11:43:51 +0800 Subject: [PATCH 2/4] Fix #375, broadcast `BotJoinGroupEvent` when create new group from other client --- .../chat/receive/MessageSvc.PbGetMsg.kt | 57 +++++++++++-------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt index 6bf941e3e..3fa76c5c6 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt @@ -44,7 +44,6 @@ import net.mamoe.mirai.qqandroid.network.protocol.packet.buildOutgoingUniPacket import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.GroupInfoImpl import net.mamoe.mirai.qqandroid.network.protocol.packet.chat.NewContact import net.mamoe.mirai.qqandroid.network.protocol.packet.list.FriendList -import net.mamoe.mirai.qqandroid.utils._miraiContentToString import net.mamoe.mirai.qqandroid.utils.io.serialization.readProtoBuf import net.mamoe.mirai.qqandroid.utils.io.serialization.toByteArray import net.mamoe.mirai.qqandroid.utils.io.serialization.writeProtoBuf @@ -147,21 +146,32 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory { msg -> - when (msg.msgHead.msgType) { - 33 -> bot.groupListModifyLock.withLock { // 邀请入群 - val group = bot.getGroupByUinOrNull(msg.msgHead.fromUin) - if (msg.msgHead.authUin == bot.id) { - if (group != null) { - return@mapNotNull null - } - // 新群 + suspend fun createGroupForBot(groupUin: Long): Group? { + val group = bot.getGroupByUinOrNull(groupUin) + if (group != null) { + return null + } - val newGroup = bot.getNewGroup(Group.calculateGroupCodeByGroupUin(msg.msgHead.fromUin)) - ?: return@mapNotNull null - bot.groups.delegate.addLast(newGroup) - return@mapNotNull BotJoinGroupEvent.Active(newGroup) + return bot.getNewGroup(Group.calculateGroupCodeByGroupUin(groupUin))?.apply { + bot.groups.delegate.addLast(this) + } + } + + when (msg.msgHead.msgType) { + 33 -> bot.groupListModifyLock.withLock { + + if (msg.msgHead.authUin == bot.id) { + // 邀请入群 + return@mapNotNull createGroupForBot(msg.msgHead.fromUin)?.let { + // TODO: 这里被邀请入群应该是Invite(),但是没有获取邀请人的信息,邀请人的信息在msg.msgContent里,未解包 + // BotJoinGroupEvent.Invite() + BotJoinGroupEvent.Active(it) + } } else { - group ?: return@mapNotNull null + + // 成员申请入群 + val group = bot.getGroupByUinOrNull(msg.msgHead.fromUin) + ?: return@mapNotNull null // 主动入群, 直接加入: msgContent=27 0B 60 E7 01 76 E4 B8 DD 82 3E 03 3F A2 06 B4 B4 BD A8 D5 DF 00 30 42 39 41 30 33 45 38 34 30 39 34 42 46 30 45 32 45 38 42 31 43 43 41 34 32 42 38 42 44 42 35 34 44 42 31 44 32 32 30 46 30 38 39 46 46 35 41 38 // 主动直接加入 27 0B 60 E7 01 76 E4 B8 DD 82 3E 03 3F A2 06 B4 B4 BD A8 D5 DF 00 30 33 30 45 38 42 31 33 46 41 41 31 33 46 38 31 35 34 41 38 33 32 37 31 43 34 34 38 35 33 35 46 45 31 38 32 43 39 42 43 46 46 32 44 39 39 46 41 37 @@ -192,19 +202,20 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory bot.groupListModifyLock.withLock { // 其他客户端入群 - val group = bot.getGroupByUinOrNull(msg.msgHead.fromUin) - if (msg.msgHead.toUin == bot.id && group == null) { + 38 -> bot.groupListModifyLock.withLock { // 建群 + return@mapNotNull createGroupForBot(msg.msgHead.fromUin) + ?.let { BotJoinGroupEvent.Active(it) } + } - val newGroup = bot.getNewGroup(Group.calculateGroupCodeByGroupUin(msg.msgHead.fromUin)) - ?: return@mapNotNull null - bot.groups.delegate.addLast(newGroup) - return@mapNotNull BotJoinGroupEvent.Active(newGroup) + 85 -> bot.groupListModifyLock.withLock { // 其他客户端入群 + return@mapNotNull if (msg.msgHead.toUin == bot.id) { + createGroupForBot(msg.msgHead.fromUin) + ?.let { BotJoinGroupEvent.Active(it) } } else { - // unknown - return@mapNotNull null + null } } + /* 34 -> { // 主动入群 From 2f0ff513a2807e5f5074173380fb5a88704a5b95 Mon Sep 17 00:00:00 2001 From: ryoii Date: Wed, 15 Jul 2020 15:14:38 +0800 Subject: [PATCH 3/4] Close #435, support FriendRecallEvent --- .../packet/chat/receive/OnlinePush.ReqPush.kt | 42 +++++++++++++++++++ .../net.mamoe.mirai/event/events/message.kt | 4 +- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt index d97309dc3..bcfac4e9b 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt @@ -21,6 +21,7 @@ import kotlinx.io.core.discardExact import kotlinx.io.core.readBytes import kotlinx.io.core.readUInt import kotlinx.serialization.Serializable +import kotlinx.serialization.protobuf.ProtoId import net.mamoe.mirai.JavaFriendlyAPI import net.mamoe.mirai.data.FriendInfo import net.mamoe.mirai.event.events.* @@ -353,6 +354,47 @@ internal inline fun lambda528(crossinline block: MsgType0x210.(QQAndroidBot) -> */ internal object Transformers528 : Map by mapOf( + 0x8AL to lambda528 { bot -> + @Serializable + data class Sub8AInner( + @ProtoId(1) val fromUin: Long, + @ProtoId(2) val botUin: Long, + @ProtoId(3) val srcId: Int, + @ProtoId(4) val srcInternalId: Int, + @ProtoId(5) val time: Int, + @ProtoId(6) val random: Int, // 同srcInternalId + @ProtoId(7) val flag1: Boolean, // true + @ProtoId(8) val flag2: Boolean, // false + @ProtoId(9) val flag3: Boolean, // false + @ProtoId(12) val flag4: Boolean // true + ) : ProtoBuf + + @Serializable + data class Sub8A( + @ProtoId(1) val inner: Sub8AInner, + @ProtoId(2) val v2: Boolean, // true + @ProtoId(3) val v3: Boolean, // true + @ProtoId(4) val v4: Boolean, // false + @ProtoId(5) val v5: ByteArray? = null // struct{ boolean(1), boolean(2) } + ) : ProtoBuf + + val sub8A = vProtobuf.loadAs(Sub8A.serializer()).inner + + if (sub8A.botUin == bot.id) { + return@lambda528 sequenceOf( + MessageRecallEvent.FriendRecall( + bot = bot, + messageId = sub8A.srcId, + messageInternalId = sub8A.srcInternalId, + messageTime = sub8A.time, + operator = sub8A.fromUin + ) + ) + } + + return@lambda528 emptySequence() + }, + // Network(1994701021) 16:03:54 : unknown group 528 type 0x0000000000000026, data: 08 01 12 40 0A 06 08 F4 EF BB 8F 04 10 E7 C1 AD B8 02 18 01 22 2C 10 01 1A 1A 18 B4 DC F8 9B 0C 20 E7 C1 AD B8 02 28 06 30 02 A2 01 04 08 93 D6 03 A8 01 08 20 00 28 00 32 08 18 01 20 FE AF AF F5 05 28 00 // VIP 进群提示 0x26L to ignoredLambda528, diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/message.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/message.kt index 862e33129..f6abeece4 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/message.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/events/message.kt @@ -296,14 +296,14 @@ sealed class MessageRecallEvent : BotEvent, AbstractEvent() { /** * 好友消息撤回事件, 暂不支持. - */ // TODO: 2020/4/22 支持好友消息撤回事件的解析和主动广播 + */ data class FriendRecall internal constructor( override val bot: Bot, override val messageId: Int, override val messageInternalId: Int, override val messageTime: Int, /** - * 撤回操作人, 可能为 [Bot.id] 或好友的 [User.id] + * 撤回操作人, 好友的 [User.id] */ val operator: Long ) : MessageRecallEvent(), Packet { From c95306c12eb54fbc68d97d0996a39a9f280c8cf1 Mon Sep 17 00:00:00 2001 From: ryoii Date: Wed, 15 Jul 2020 17:42:25 +0800 Subject: [PATCH 4/4] Fix BotJoinGroupEvent.Invite --- .../network/protocol/packet/chat/NewContact.kt | 9 +++++---- .../packet/chat/receive/MessageSvc.PbGetMsg.kt | 11 ++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) 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 553461ebf..91ad6ce0c 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 @@ -173,10 +173,11 @@ internal class NewContact { } 2 -> { // 被邀请入群, 自动同意, 不需处理 - val group = bot.getNewGroup(groupCode) ?: return null - val invitor = group[actionUin] - - BotJoinGroupEvent.Invite(invitor) +// val group = bot.getNewGroup(groupCode) ?: return null +// val invitor = group[actionUin] +// +// BotJoinGroupEvent.Invite(invitor) + null } 3 -> { // 已被请他管理员处理 null diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt index 3fa76c5c6..5771b393b 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt @@ -48,6 +48,7 @@ import net.mamoe.mirai.qqandroid.utils.io.serialization.readProtoBuf import net.mamoe.mirai.qqandroid.utils.io.serialization.toByteArray import net.mamoe.mirai.qqandroid.utils.io.serialization.writeProtoBuf import net.mamoe.mirai.qqandroid.utils.read +import net.mamoe.mirai.qqandroid.utils.toInt import net.mamoe.mirai.qqandroid.utils.toUHexString import net.mamoe.mirai.utils.currentTimeSeconds import net.mamoe.mirai.utils.debug @@ -163,9 +164,10 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory bot.groupListModifyLock.withLock { // 其他客户端入群 + + // msg.msgHead.authUin: 处理人 + return@mapNotNull if (msg.msgHead.toUin == bot.id) { createGroupForBot(msg.msgHead.fromUin) ?.let { BotJoinGroupEvent.Active(it) }