From e84d2c21a6280fa5027b6b0bda610099cab57a54 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 3 Jul 2021 22:00:59 +0800 Subject: [PATCH] Test colored member card --- .../kotlin/contact/NormalMemberImpl.kt | 20 ++++--- .../network/notice/GroupMessageProcessor.kt | 2 +- .../network/protocol/data/proto/OIDB.kt | 5 +- .../network/protocol/packet/PacketFactory.kt | 1 + .../protocol/packet/chat/TroopManagement.kt | 52 ++++++++++++++++++- 5 files changed, 70 insertions(+), 10 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/contact/NormalMemberImpl.kt b/mirai-core/src/commonMain/kotlin/contact/NormalMemberImpl.kt index be5647a64c..419398e707 100644 --- a/mirai-core/src/commonMain/kotlin/contact/NormalMemberImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/NormalMemberImpl.kt @@ -19,13 +19,13 @@ import net.mamoe.mirai.contact.* import net.mamoe.mirai.data.MemberInfo import net.mamoe.mirai.event.broadcast import net.mamoe.mirai.event.events.* -import net.mamoe.mirai.internal.message.OnlineMessageSourceToGroupImpl -import net.mamoe.mirai.internal.message.OnlineMessageSourceToStrangerImpl import net.mamoe.mirai.internal.message.OnlineMessageSourceToTempImpl import net.mamoe.mirai.internal.message.createMessageReceipt import net.mamoe.mirai.internal.network.protocol.packet.chat.TroopManagement +import net.mamoe.mirai.internal.network.protocol.packet.chat.toResult import net.mamoe.mirai.message.MessageReceipt import net.mamoe.mirai.message.data.Message +import net.mamoe.mirai.utils.autoHexToBytes import net.mamoe.mirai.utils.cast import net.mamoe.mirai.utils.currentTimeSeconds import kotlin.contracts.ExperimentalContracts @@ -96,11 +96,19 @@ internal class NormalMemberImpl constructor( _nameCard = newValue launch { bot.network.run { - TroopManagement.EditGroupNametag( + TroopManagement.SetMemberNameNew( bot.client, - this@NormalMemberImpl, - newValue, - ).sendWithoutExpect() + group.groupCode, + this@NormalMemberImpl.id, + TroopManagement.RichName(newValue, "25 C4 80 C4 80 07 C3 95".autoHexToBytes()) + ).sendAndExpect().also { + it.toResult("Set member nick").getOrThrow() + } +// TroopManagement.EditGroupNametag( +// bot.client, +// this@NormalMemberImpl, +// newValue, +// ).sendWithoutExpect() } MemberCardChangeEvent(oldValue, newValue, this@NormalMemberImpl).broadcast() } diff --git a/mirai-core/src/commonMain/kotlin/network/notice/GroupMessageProcessor.kt b/mirai-core/src/commonMain/kotlin/network/notice/GroupMessageProcessor.kt index 074079ea23..a17f53585a 100644 --- a/mirai-core/src/commonMain/kotlin/network/notice/GroupMessageProcessor.kt +++ b/mirai-core/src/commonMain/kotlin/network/notice/GroupMessageProcessor.kt @@ -188,7 +188,7 @@ internal class GroupMessageProcessor : SimpleNoticeProcessor = emptyList(), + @ProtoNumber(2) @JvmField val coolId: Int, ) : ProtoBuf @Serializable @@ -264,7 +265,7 @@ internal class Oidb0x8fc : ProtoBuf { @ProtoNumber(5) @JvmField val specialTitle: ByteArray = EMPTY_BYTE_ARRAY, @ProtoNumber(6) @JvmField val specialTitleExpireTime: Int = 0, @ProtoNumber(7) @JvmField val uinName: ByteArray = EMPTY_BYTE_ARRAY, - @ProtoNumber(8) @JvmField val memberCardName: ByteArray = EMPTY_BYTE_ARRAY, + @ProtoNumber(8) @JvmField val memberCardName: String = "", @ProtoNumber(9) @JvmField val phone: ByteArray = EMPTY_BYTE_ARRAY, @ProtoNumber(10) @JvmField val email: ByteArray = EMPTY_BYTE_ARRAY, @ProtoNumber(11) @JvmField val remark: ByteArray = EMPTY_BYTE_ARRAY, @@ -279,7 +280,7 @@ internal class Oidb0x8fc : ProtoBuf { @Serializable internal class RichCardNameElem( @ProtoNumber(1) @JvmField val ctrl: ByteArray = EMPTY_BYTE_ARRAY, - @ProtoNumber(2) @JvmField val text: ByteArray = EMPTY_BYTE_ARRAY, + @ProtoNumber(2) @JvmField val text: String = "", ) : ProtoBuf @Serializable diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/PacketFactory.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/PacketFactory.kt index 66d28fe9dd..7bf49f6b6d 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/PacketFactory.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/PacketFactory.kt @@ -152,6 +152,7 @@ internal object KnownPacketFactories { TroopManagement.GetAdmin, // TroopManagement.GetGroupInfo, TroopManagement.EditGroupNametag, + TroopManagement.SetMemberNameNew, TroopManagement.Kick, TroopEssenceMsgManager.SetEssence, NudgePacket, diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/TroopManagement.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/TroopManagement.kt index c43b671e9d..7552bb7f02 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/TroopManagement.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/TroopManagement.kt @@ -27,7 +27,9 @@ import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketFactory import net.mamoe.mirai.internal.network.protocol.packet.buildOutgoingUniPacket import net.mamoe.mirai.internal.network.subAppId import net.mamoe.mirai.internal.utils.io.serialization.* +import net.mamoe.mirai.utils.autoHexToBytes import net.mamoe.mirai.utils.daysToSeconds +import net.mamoe.mirai.utils.encodeToString internal class TroopManagement { @@ -323,6 +325,53 @@ internal class TroopManagement { } } + class RichName( + val name: String, + val control: ByteArray? = null + ) { + fun toRichCardNames(): List { + return if (control == null) listOf(Oidb0x8fc.RichCardNameElem(text = name)) + else listOf(Oidb0x8fc.RichCardNameElem(text = name)) + } + } + + internal object SetMemberNameNew : OutgoingPacketFactory>("OidbSvc.0x8fc_3") { + operator fun invoke( + client: QQAndroidClient, + groupCode: Long, + memberId: Long, + richName: RichName + ) = buildOutgoingUniPacket(client) { + writeOidb( + 2300, 3, Oidb0x8fc.ReqBody.serializer(), Oidb0x8fc.ReqBody( + groupCode = groupCode, + memLevelInfo = listOf( + Oidb0x8fc.MemberInfo( + uin = memberId, + memberCardName = richName.name, + commRichCardName = Oidb0x8fc.CommCardNameBuf( + richCardName = listOfNotNull( + if (richName.control != null) Oidb0x8fc.RichCardNameElem(ctrl = richName.control) else null, + Oidb0x8fc.RichCardNameElem(text = richName.name) + ), + coolId = 0, + ).toByteArray(Oidb0x8fc.CommCardNameBuf.serializer()), + + ) + ), + msgClientInfo = Oidb0x8fc.ClientInfo( + implat = 109, + ingClientver = client.buildVer + ) + ) + ) + } + + override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): CommonOidbResponse { + return readOidbRespCommon(Oidb0x8fc.RspBody.serializer()) { it } + } + } + internal object EditGroupNametag : OutgoingPacketFactory("friendlist.ModifyGroupCardReq") { object Response : Packet { @@ -362,7 +411,8 @@ internal class TroopManagement { gender = 0, dwuin = member.id, dwFlag = 31, - sName = newName, + sName = "<" + "25 C4 80 C4 80 07 C3 95".autoHexToBytes() + .encodeToString() + ">" + newName, sPhone = "", sEmail = "", sRemark = ""