[core] try to refresh keys on receiving login result 180

This commit is contained in:
StageGuard 2023-09-06 15:54:34 +08:00
parent 60f1e79e49
commit cfbb880b73
No known key found for this signature in database
GPG Key ID: F6FF8760A883492B

View File

@ -18,6 +18,7 @@ import net.mamoe.mirai.internal.AbstractBot
import net.mamoe.mirai.internal.QQAndroidBot
import net.mamoe.mirai.internal.network.*
import net.mamoe.mirai.internal.network.DebuggingProperties.SHOW_TLV_MAP_ON_LOGIN_SUCCESS
import net.mamoe.mirai.internal.network.components.KeyRefreshProcessor
import net.mamoe.mirai.internal.network.handler.logger
import net.mamoe.mirai.internal.network.protocol.packet.*
import net.mamoe.mirai.internal.network.protocol.packet.login.wtlogin.WtLogin8
@ -241,8 +242,8 @@ internal class WtLogin {
// 40: blocked
// 161: 今日操作次数过多,请等待一天后再试。 (SMS)
// 162: 可能也是 SMS 太频繁
// 180可能是需要换服务器 IP
180 -> onChangeServerIpv6(tlvMap, bot)
// 180可能是需要换服务器或者 refresh key
180 -> onRequestRefreshKeys(tlvMap, bot)
204 /*-52*/ -> onDevLockLogin(tlvMap, bot)
// 1, 15 -> onErrorMessage(tlvMap) ?: error("Cannot find error message")
else -> {
@ -258,16 +259,42 @@ internal class WtLogin {
return tlvMap.entries.joinToString { "${it.key}=${it.value.toUHexString()}" }
}
// temporary function name
private fun onChangeServerIpv6(
// request refresh keys or change server ip?
private suspend fun onRequestRefreshKeys(
tlvMap: TlvMap,
bot: QQAndroidBot
): LoginPacketResponse.Error {
tlvMap[0x161]?.let { bot.client.analysisTlv161(it) }
): LoginPacketResponse {
val errorMessage = onErrorMessage(0x146, tlvMap, bot)
if (errorMessage != null) {
return errorMessage
}
return onErrorMessage(0x146, tlvMap, bot)
?: LoginPacketResponse.Error(bot, 0x146, "login failed",
"login result type 180 without error message", "")
// analysis tlv t161
val t161 = (tlvMap[0x161]
?: return LoginPacketResponse.Error(bot, 0x146, "login failed",
"login result type 180 without and t161 error message", ""))
.toReadPacket()
.apply { discardExact(2) }
.withUse { _readTLVMap() }
.also { tm ->
tm[0x173]?.let { bot.client.analysisTlv173(it) }
tm[0x17f]?.let { bot.client.analysisTlv17f(it) }
}
val t172 = t161[0x172]
if (t172 != null) {
bot.client.rollbackSig = t172
runCatching {
bot.components[KeyRefreshProcessor].refreshKeysNow(bot.network)
}.fold(
onSuccess = { return LoginPacketResponse.Success(bot) },
onFailure = { return LoginPacketResponse.Error(bot, 0x146, "login failed",
"failed to refresh keys on receiving login result type 180", "") }
)
} else {
return LoginPacketResponse.Error(bot, 0x146, "login failed",
"login result type 180 without t172", "")
}
}
private fun onDevLockLogin(