This commit is contained in:
Him188 2020-04-23 19:08:59 +08:00
parent 6f69497247
commit 4a217d83a6
2 changed files with 27 additions and 2 deletions

View File

@ -155,6 +155,20 @@ internal open class QQAndroidClient(
private val messageSequenceId: AtomicInt = atomic(22911) private val messageSequenceId: AtomicInt = atomic(22911)
internal fun atomicNextMessageSequenceId(): Int = messageSequenceId.getAndAdd(2) internal fun atomicNextMessageSequenceId(): Int = messageSequenceId.getAndAdd(2)
private val friendSeq: AtomicInt = atomic(22911)
internal fun getFriendSeq(): Int {
return friendSeq.value
}
internal fun nextFriendSeq(): Int {
return friendSeq.incrementAndGet()
}
internal fun setFriendSeq(compare: Int, id: Int): Boolean {
return friendSeq.compareAndSet(compare, id % 65535)
}
private val requestPacketRequestId: AtomicInt = atomic(1921334513) private val requestPacketRequestId: AtomicInt = atomic(1921334513)
internal fun nextRequestPacketRequestId(): Int = requestPacketRequestId.getAndAdd(2) internal fun nextRequestPacketRequestId(): Int = requestPacketRequestId.getAndAdd(2)

View File

@ -229,10 +229,21 @@ internal class MessageSvc {
} }
} }
166 -> { 166 -> {
if (msg.msgHead.fromUin == bot.id) {
loop@ while (true) {
val instance = bot.client.getFriendSeq()
if (instance < msg.msgHead.msgSeq) {
if (bot.client.setFriendSeq(instance, msg.msgHead.msgSeq)) {
break@loop
}
} else break@loop
}
return@mapNotNull null
}
val friend = bot.getFriendOrNull(msg.msgHead.fromUin) ?: return@mapNotNull null val friend = bot.getFriendOrNull(msg.msgHead.fromUin) ?: return@mapNotNull null
friend.checkIsFriendImpl() friend.checkIsFriendImpl()
if (msg.msgHead.fromUin == bot.id || !bot.firstLoginSucceed) { if (!bot.firstLoginSucceed) {
return@mapNotNull null return@mapNotNull null
} }
@ -376,7 +387,7 @@ internal class MessageSvc {
sender = client.bot, sender = client.bot,
target = qq, target = qq,
time = currentTimeSeconds.toInt(), time = currentTimeSeconds.toInt(),
sequenceId = rand, sequenceId = client.nextFriendSeq(),
originalMessage = message originalMessage = message
) )
sourceCallback(source) sourceCallback(source)