Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Shamrock: fix #124
Browse files Browse the repository at this point in the history
  • Loading branch information
Simplxss committed Dec 4, 2023
1 parent 4e3870a commit ec39aa7
Showing 1 changed file with 64 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,32 @@ internal object PrimitiveListener {
subType = pb[1, 2, 2].asInt
}
val msgTime = pb[1, 2, 6].asLong
when (msgType) {
33 -> onGroupMemIncreased(msgTime, pb)
34 -> onGroupMemberDecreased(msgTime, pb)
44 -> onGroupAdminChange(msgTime, pb)
84 -> onGroupApply(msgTime, pb)
87 -> onInviteGroup(msgTime, pb)
528 -> when (subType) {
35 -> onFriendApply(msgTime, pb)
39 -> onCardChange(msgTime, pb)
// invite
68 -> onGroupApply(msgTime, pb)
138 -> onC2CRecall(msgTime, pb)
290 -> onC2cPoke(msgTime, pb)
}
try {
when (msgType) {
33 -> onGroupMemIncreased(msgTime, pb)
34 -> onGroupMemberDecreased(msgTime, pb)
44 -> onGroupAdminChange(msgTime, pb)
84 -> onGroupApply(msgTime, pb)
87 -> onInviteGroup(msgTime, pb)
528 -> when (subType) {
35 -> onFriendApply(msgTime, pb)
39 -> onCardChange(msgTime, pb)
// invite
68 -> onGroupApply(msgTime, pb)
138 -> onC2CRecall(msgTime, pb)
290 -> onC2cPoke(msgTime, pb)
}

732 -> when (subType) {
12 -> onGroupBan(msgTime, pb)
16 -> onGroupTitleChange(msgTime, pb)
17 -> onGroupRecall(msgTime, pb)
20 -> onGroupPokeAndGroupSign(msgTime, pb)
21 -> onEssenceMessage(msgTime, pb)
732 -> when (subType) {
12 -> onGroupBan(msgTime, pb)
16 -> onGroupTitleChange(msgTime, pb)
17 -> onGroupRecall(msgTime, pb)
20 -> onGroupPokeAndGroupSign(msgTime, pb)
21 -> onEssenceMessage(msgTime, pb)
}
}
} catch (e: Exception) {
LogCenter.log("onMsgPush(msgType: $msgType): "+e.stackTraceToString(), Level.WARN)
}
}

Expand Down Expand Up @@ -153,8 +157,21 @@ internal object PrimitiveListener {


private suspend fun onCardChange(msgTime: Long, pb: ProtoMap) {
val targetId = pb[1, 3, 2, 1, 13, 2].asUtf8String
val newCardList = pb[1, 3, 2, 1, 13, 3].asList
var detail = pb[1, 3, 2]
if (detail !is ProtoMap) {
try {
val readPacket = ByteReadPacket(detail.asByteArray)
readPacket.readBuf32Long()
readPacket.discardExact(1)
detail = ProtoUtils.decodeFromByteArray(readPacket.readBytes(readPacket.readShort().toInt()))
readPacket.release()
} catch (e: Exception) {
LogCenter.log("onCardChange error: ${e.stackTraceToString()}", Level.WARN)
}
}

val targetId = detail[1, 13, 2].asUtf8String
val newCardList = detail[1, 13, 3].asList
var newCard = ""
newCardList
.value
Expand All @@ -163,7 +180,7 @@ internal object PrimitiveListener {
newCard = it[2].asUtf8String
}
}
val groupId = pb[1, 3, 2, 1, 13, 4].asLong
val groupId = pb[1, 13, 4].asLong
var oldCard = ""
val targetQQ = ContactHelper.getUinByUidAsync(targetId).toLong()
LogCenter.log("群组[$groupId]成员$targetQQ 群名片变动 -> $newCard")
Expand All @@ -181,14 +198,18 @@ internal object PrimitiveListener {
}

private suspend fun onGroupTitleChange(msgTime: Long, pb: ProtoMap) {
val groupCode = pb[1, 1, 1].asULong

val readPacket = ByteReadPacket(pb[1, 3, 2].asByteArray)
val detail = if (readPacket.readBuf32Long() == groupCode) {
readPacket.discardExact(1)
ProtoUtils.decodeFromByteArray(readPacket.readBytes(readPacket.readShort().toInt()))
} else pb[1, 3, 2]
readPacket.release()
var detail = pb[1, 3, 2]
if (detail !is ProtoMap) {
try {
val readPacket = ByteReadPacket(detail.asByteArray)
readPacket.readBuf32Long()
readPacket.discardExact(1)
detail = ProtoUtils.decodeFromByteArray(readPacket.readBytes(readPacket.readShort().toInt()))
readPacket.release()
} catch (e: Exception) {
LogCenter.log("onGroupTitleChange error: ${e.stackTraceToString()}", Level.WARN)
}
}

val targetUin = detail[5, 5].asLong

Expand All @@ -213,14 +234,18 @@ internal object PrimitiveListener {
}

private suspend fun onEssenceMessage(msgTime: Long, pb: ProtoMap) {
val groupCode = pb[1, 1, 1].asULong

val readPacket = ByteReadPacket(pb[1, 3, 2].asByteArray)
val detail = if (readPacket.readBuf32Long() == groupCode) {
readPacket.discardExact(1)
ProtoUtils.decodeFromByteArray(readPacket.readBytes(readPacket.readShort().toInt()))
} else pb[1, 3, 2]
readPacket.release()
var detail = pb[1, 3, 2]
if (detail !is ProtoMap) {
try {
val readPacket = ByteReadPacket(detail.asByteArray)
readPacket.readBuf32Long()
readPacket.discardExact(1)
detail = ProtoUtils.decodeFromByteArray(readPacket.readBytes(readPacket.readShort().toInt()))
readPacket.release()
} catch (e: Exception) {
LogCenter.log("onEssenceMessage error: ${e.stackTraceToString()}", Level.WARN)
}
}

val groupId = detail[4].asLong
val mesSeq = detail[37].asInt
Expand Down

0 comments on commit ec39aa7

Please sign in to comment.