Skip to content

Commit

Permalink
Test colored member card
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Jul 3, 2021
1 parent 4e95154 commit e84d2c2
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 10 deletions.
20 changes: 14 additions & 6 deletions mirai-core/src/commonMain/kotlin/contact/NormalMemberImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ internal class GroupMessageProcessor : SimpleNoticeProcessor<MsgOnlinePush.PbPus
if (this[0] == 0x0A.toByte()) {
val nameBuf = loadAs(Oidb0x8fc.CommCardNameBuf.serializer())
if (nameBuf.richCardName.isNotEmpty()) {
return@runCatching nameBuf.richCardName.joinToString("") { it.text.encodeToString() }
return@runCatching nameBuf.richCardName.joinToString("") { it.text }
}
}
return@runCatching null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ internal class Oidb0x8fc : ProtoBuf {
@Serializable
internal class CommCardNameBuf(
@ProtoNumber(1) @JvmField val richCardName: List<RichCardNameElem> = emptyList(),
@ProtoNumber(2) @JvmField val coolId: Int,
) : ProtoBuf

@Serializable
Expand All @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ internal object KnownPacketFactories {
TroopManagement.GetAdmin,
// TroopManagement.GetGroupInfo,
TroopManagement.EditGroupNametag,
TroopManagement.SetMemberNameNew,
TroopManagement.Kick,
TroopEssenceMsgManager.SetEssence,
NudgePacket,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -323,6 +325,53 @@ internal class TroopManagement {
}
}

class RichName(
val name: String,
val control: ByteArray? = null
) {
fun toRichCardNames(): List<Oidb0x8fc.RichCardNameElem> {
return if (control == null) listOf(Oidb0x8fc.RichCardNameElem(text = name))
else listOf(Oidb0x8fc.RichCardNameElem(text = name))
}
}

internal object SetMemberNameNew : OutgoingPacketFactory<CommonOidbResponse<Oidb0x8fc.RspBody>>("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<Oidb0x8fc.RspBody> {
return readOidbRespCommon(Oidb0x8fc.RspBody.serializer()) { it }
}
}

internal object EditGroupNametag :
OutgoingPacketFactory<EditGroupNametag.Response>("friendlist.ModifyGroupCardReq") {
object Response : Packet {
Expand Down Expand Up @@ -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 = ""
Expand Down

0 comments on commit e84d2c2

Please sign in to comment.