Handle ConfigPushSvc.PushReq.PushReqResponse.ChangeServer in ConfigPushSvc

This commit is contained in:
Karlatemp 2021-02-09 15:08:50 +08:00
parent 0780756bd4
commit 17c2069c82
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
2 changed files with 30 additions and 13 deletions

View File

@ -371,19 +371,8 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo
logger.info { "ConfigPushSvc.PushReq: Success." }
}
is ConfigPushSvc.PushReq.PushReqResponse.ChangeServer -> {
bot.logger.info { "Server requires reconnect." }
bot.logger.info { "Server list: ${resp.serverList.joinToString()}." }
if (resp.serverList.isNotEmpty()) {
bot.serverList.clear()
resp.serverList.shuffled().forEach {
bot.serverList.add(it.host to it.port)
}
}
bot.bdhSyncer.saveToCache()
bot.bdhSyncer.saveServerListToCache()
bot.launch { BotOfflineEvent.RequireReconnect(bot).broadcast() }
logger.info { "ConfigPushSvc.PushReq: Require reconnect" }
// handled in ConfigPushSvc
return@launch
}
}

View File

@ -9,10 +9,14 @@
package net.mamoe.mirai.internal.network.protocol.packet.login
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.io.core.ByteReadPacket
import kotlinx.serialization.Serializable
import net.mamoe.mirai.event.AbstractEvent
import net.mamoe.mirai.event.Event
import net.mamoe.mirai.event.broadcast
import net.mamoe.mirai.event.events.BotOfflineEvent
import net.mamoe.mirai.internal.QQAndroidBot
import net.mamoe.mirai.internal.message.contextualBugReportException
import net.mamoe.mirai.internal.network.BdhSession
@ -30,6 +34,7 @@ import net.mamoe.mirai.internal.utils.io.serialization.loadAs
import net.mamoe.mirai.internal.utils.io.serialization.readUniPacket
import net.mamoe.mirai.internal.utils.io.serialization.tars.TarsId
import net.mamoe.mirai.internal.utils.io.serialization.writeJceStruct
import net.mamoe.mirai.utils.info
import net.mamoe.mirai.utils.toUHexString
import java.lang.IllegalStateException
import net.mamoe.mirai.internal.network.protocol.data.jce.PushReq as PushReqJceStruct
@ -144,6 +149,25 @@ internal class ConfigPushSvc {
)
}
fun handleRequireReconnect(resp: PushReqResponse.ChangeServer) {
bot.logger.info { "Server requires reconnect." }
bot.logger.info { "Server list: ${resp.serverList.joinToString()}." }
if (resp.serverList.isNotEmpty()) {
bot.serverList.clear()
resp.serverList.shuffled().forEach {
bot.serverList.add(it.host to it.port)
}
}
bot.bdhSyncer.saveToCache()
bot.bdhSyncer.saveServerListToCache()
bot.launch {
delay(1000)
BotOfflineEvent.RequireReconnect(bot).broadcast()
}
}
when (packet) {
is PushReqResponse.Success -> {
handleSuccess(packet)
@ -172,6 +196,10 @@ internal class ConfigPushSvc {
// writePacket(this.build().debugPrintThis())
}
}
is PushReqResponse.ChangeServer -> {
handleRequireReconnect(packet)
return null
}
else -> {
// handled in QQABot
return null