From 2d0fa69899191df351d08939ed2b4459186d30c5 Mon Sep 17 00:00:00 2001 From: sandtechnology <20417547+sandtechnology@users.noreply.github.com> Date: Wed, 16 Sep 2020 08:23:56 +0800 Subject: [PATCH] Try to fix #358 according to @Mrs4s comment (#509) * try to fix #358 according to @Mar8s comment * Disable mirror * Cancel group coroutine when bot leave group and fire event separately * Re-add 0x82 and 0x83 * Revert else logic * Fix build Co-authored-by: Him188 --- .../chat/receive/OnlinePush.PbPushTransMsg.kt | 43 ++++++++++++------- .../packet/chat/receive/OnlinePush.ReqPush.kt | 29 +++++++------ 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.PbPushTransMsg.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.PbPushTransMsg.kt index 13fc05d84..b36f33e59 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.PbPushTransMsg.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.PbPushTransMsg.kt @@ -205,28 +205,41 @@ internal object OnlinePushPbPushTransMsg : A8 32 51 A1 83 3E 03 3F A2 06 B4 B4 BD A8 D5 DF 00 30 39 32 46 45 30 36 31 41 33 37 36 43 44 35 37 35 37 39 45 37 32 34 44 37 37 30 36 46 39 39 43 35 35 33 33 31 34 44 32 44 46 35 45 42 43 31 31 36 */ - readUInt().toLong() // group, uin or code ? - - discardExact(1) + readUInt().toLong() // groupUin + readByte().toInt() // follow type val target = readUInt().toLong() val type = readUByte().toInt() val operator = readUInt().toLong() val groupUin = content.fromUin when (type) { - 0x82 -> bot.getGroupByUinOrNull(groupUin)?.let { group -> - val member = group.getOrNull(target) as? MemberImpl ?: return null - return MemberLeaveEvent.Quit(member.also { - member.cancel(CancellationException("Leaved actively")) - group.members.delegate.remove(member) - }) + 2, 0x82 -> bot.getGroupByUinOrNull(groupUin)?.let { group -> + if (target == bot.id) { + return BotLeaveEvent.Active(group).also { + group.cancel(CancellationException("Leaved actively")) + bot.groups.delegate.remove(group) + } + } else { + val member = group.getOrNull(target) as? MemberImpl ?: return null + return MemberLeaveEvent.Quit(member.also { + member.cancel(CancellationException("Leaved actively")) + group.members.delegate.remove(member) + }) + } } - 0x83 -> bot.getGroupByUin(groupUin).let { group -> - val member = group.getOrNull(target) as? MemberImpl ?: return null - return MemberLeaveEvent.Kick(member.also { - member.cancel(CancellationException("Leaved actively")) - group.members.delegate.remove(member) - }, group.members[operator]) + 3, 0x83 -> bot.getGroupByUin(groupUin).let { group -> + if (target == bot.id) { + return BotLeaveEvent.Kick(group.members[operator]).also { + group.cancel(CancellationException("Being kicked")) + bot.groups.delegate.remove(group) + } + } else { + val member = group.getOrNull(target) as? MemberImpl ?: return null + return MemberLeaveEvent.Kick(member.also { + member.cancel(CancellationException("Being kicked")) + group.members.delegate.remove(member) + }, group.members[operator]) + } } } } 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 49d6f98b9..4af76feef 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 @@ -14,8 +14,6 @@ package net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive -import kotlinx.coroutines.CancellationException -import kotlinx.coroutines.cancel import kotlinx.io.core.ByteReadPacket import kotlinx.io.core.discardExact import kotlinx.io.core.readBytes @@ -478,20 +476,23 @@ internal object Transformers528 : Map by mapOf( return@lambda528 emptySequence() }, // bot 在其他客户端被踢或主动退出而同步情况 - 0xD4L to lambda528 { bot -> + 0xD4L to lambda528 { _ -> // this.soutv("0x210") - @Serializable - data class SubD4( - // ok - val uin: Long - ) : ProtoBuf + /* @Serializable + data class SubD4( + // ok + val uin: Long + ) : ProtoBuf - val uin = vProtobuf.loadAs(SubD4.serializer()).uin - val group = bot.getGroupByUinOrNull(uin) ?: bot.getGroupOrNull(uin) - return@lambda528 if (group != null && bot.groups.delegate.remove(group)) { - group.cancel(CancellationException("Being kicked")) - sequenceOf(BotLeaveEvent.Active(group)) - } else emptySequence() + val uin = vProtobuf.loadAs(SubD4.serializer()).uin + val group = bot.getGroupByUinOrNull(uin) ?: bot.getGroupOrNull(uin) + return@lambda528 if (group != null && bot.groups.delegate.remove(group)) { + group.cancel(CancellationException("Being kicked")) + sequenceOf(BotLeaveEvent.Active(group)) + } else emptySequence()*/ + + //ignore + return@lambda528 emptySequence() }, //戳一戳信息等 0x122L to lambda528 { bot, _ ->