mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-23 14:20:24 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
8c81ae268f
@ -14,6 +14,7 @@ import net.mamoe.mirai.qqandroid.event.PacketReceivedEvent
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.KnownPacketFactories
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacket
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.LoginPacket
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.LoginPacket.LoginPacketResponse.*
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.StatSvc
|
||||
import net.mamoe.mirai.utils.*
|
||||
import net.mamoe.mirai.utils.io.*
|
||||
@ -32,37 +33,38 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
||||
launch(CoroutineName("Incoming Packet Receiver")) { processReceive() }
|
||||
|
||||
bot.logger.info("Trying login")
|
||||
when (val response: LoginPacket.LoginPacketResponse = LoginPacket.SubCommand9(bot.client).sendAndExpect()) {
|
||||
is UnsafeLogin -> {
|
||||
bot.logger.info("Login unsuccessful, device auth is needed")
|
||||
bot.logger.info("登陆失败, 原因为非常用设备登陆")
|
||||
bot.logger.info("Open the following URL in QQ browser and complete the verification")
|
||||
bot.logger.info("将下面这个链接在QQ浏览器中打开并完成认证后尝试再次登陆")
|
||||
bot.logger.info(response.url)
|
||||
return
|
||||
}
|
||||
|
||||
var response: LoginPacket.LoginPacketResponse = LoginPacket.SubCommand9(bot.client).sendAndExpect()
|
||||
captcha@ while (true) {
|
||||
when (response) {
|
||||
is LoginPacket.LoginPacketResponse.Captcha -> when (response) {
|
||||
is LoginPacket.LoginPacketResponse.Captcha.Picture -> {
|
||||
bot.logger.info("需要图片验证码")
|
||||
var result = bot.configuration.captchaSolver.invoke(bot, response.data)
|
||||
if (result === null || result.length != 4) {
|
||||
//refresh captcha
|
||||
@Suppress("SpellCheckingInspection")
|
||||
result = "ABCD"
|
||||
}
|
||||
bot.logger.info("提交验证码")
|
||||
|
||||
response = LoginPacket.SubCommand2(bot.client, response.sign, result).sendAndExpect()
|
||||
// goto outer when
|
||||
}
|
||||
|
||||
is LoginPacket.LoginPacketResponse.Captcha.Slider -> {
|
||||
error("需要滑动验证码")
|
||||
is Captcha -> when (response) {
|
||||
is Captcha.Picture -> {
|
||||
bot.logger.info("需要图片验证码")
|
||||
var result = bot.configuration.captchaSolver.invoke(bot, response.data)
|
||||
if (result === null || result.length != 4) {
|
||||
//refresh captcha
|
||||
result = "ABCD"
|
||||
}
|
||||
bot.logger.info("提交验证码")
|
||||
val captchaResponse: LoginPacket.LoginPacketResponse =
|
||||
LoginPacket.SubCommand2(bot.client, response.sign, result).sendAndExpect()
|
||||
}
|
||||
|
||||
is LoginPacket.LoginPacketResponse.Error -> error(response.toString())
|
||||
|
||||
is LoginPacket.LoginPacketResponse.Success -> {
|
||||
bot.logger.info("Login successful")
|
||||
break@captcha
|
||||
is Captcha.Slider -> {
|
||||
bot.logger.info("需要滑动验证码")
|
||||
}
|
||||
}
|
||||
|
||||
is Error -> error(response.toString())
|
||||
|
||||
is Success -> {
|
||||
bot.logger.info("Login successful")
|
||||
}
|
||||
}
|
||||
|
||||
println("d2key=${bot.client.wLoginSigInfo.d2Key.toUHexString()}")
|
||||
|
@ -112,7 +112,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
|
||||
isGuidFromFileNull = false,
|
||||
isGuidAvailable = true,
|
||||
isGuidChanged = false,
|
||||
guidFlag = guidFlag(GuidSource.FROM_STORAGE, MacOrAndroidIdChangeFlag.NoChange),
|
||||
guidFlag = guidFlag(GuidSource.FROM_STORAGE, MacOrAndroidIdChangeFlag(0)),
|
||||
buildModel = client.device.model,
|
||||
guid = client.device.guid,
|
||||
buildBrand = client.device.brand,
|
||||
@ -222,6 +222,10 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UnsafeLogin(val url: String) : LoginPacketResponse()
|
||||
|
||||
class DeviceLockLogin() : LoginPacketResponse()
|
||||
}
|
||||
|
||||
@InternalAPI
|
||||
@ -246,10 +250,24 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
|
||||
0 -> onLoginSuccess(tlvMap, bot)
|
||||
1, 15 -> onErrorMessage(tlvMap)
|
||||
2 -> onSolveLoginCaptcha(tlvMap, bot)
|
||||
-96 -> onUnsafeDeviceLogin(tlvMap, bot)
|
||||
-52 -> onDeviceLockLogin(tlvMap, bot)
|
||||
else -> error("unknown login result type: $type")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun onDeviceLockLogin(tlvMap: Map<Int, ByteArray>, bot: QQAndroidBot): LoginPacketResponse.DeviceLockLogin {
|
||||
println(tlvMap[0x104]!!.toUHexString())
|
||||
println(tlvMap[0x402]!!.toUHexString())
|
||||
println(tlvMap[0x403]!!.toUHexString())
|
||||
return LoginPacketResponse.DeviceLockLogin();
|
||||
}
|
||||
|
||||
private fun onUnsafeDeviceLogin(tlvMap: Map<Int, ByteArray>, bot: QQAndroidBot): LoginPacketResponse.UnsafeLogin {
|
||||
return LoginPacketResponse.UnsafeLogin(tlvMap[0x204]!!.toReadPacket().readRemainingBytes().encodeToString())
|
||||
}
|
||||
|
||||
private fun onErrorMessage(tlvMap: Map<Int, ByteArray>): LoginPacketResponse.Error {
|
||||
return tlvMap[0x146]?.toReadPacket()?.run {
|
||||
readShort() // ver
|
||||
|
Loading…
Reference in New Issue
Block a user