mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-23 22:30:47 +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.KnownPacketFactories
|
||||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacket
|
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
|
||||||
|
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.qqandroid.network.protocol.packet.login.StatSvc
|
||||||
import net.mamoe.mirai.utils.*
|
import net.mamoe.mirai.utils.*
|
||||||
import net.mamoe.mirai.utils.io.*
|
import net.mamoe.mirai.utils.io.*
|
||||||
@ -32,37 +33,38 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
|||||||
launch(CoroutineName("Incoming Packet Receiver")) { processReceive() }
|
launch(CoroutineName("Incoming Packet Receiver")) { processReceive() }
|
||||||
|
|
||||||
bot.logger.info("Trying login")
|
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()
|
is Captcha -> when (response) {
|
||||||
captcha@ while (true) {
|
is Captcha.Picture -> {
|
||||||
when (response) {
|
bot.logger.info("需要图片验证码")
|
||||||
is LoginPacket.LoginPacketResponse.Captcha -> when (response) {
|
var result = bot.configuration.captchaSolver.invoke(bot, response.data)
|
||||||
is LoginPacket.LoginPacketResponse.Captcha.Picture -> {
|
if (result === null || result.length != 4) {
|
||||||
bot.logger.info("需要图片验证码")
|
//refresh captcha
|
||||||
var result = bot.configuration.captchaSolver.invoke(bot, response.data)
|
result = "ABCD"
|
||||||
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("需要滑动验证码")
|
|
||||||
}
|
}
|
||||||
|
bot.logger.info("提交验证码")
|
||||||
|
val captchaResponse: LoginPacket.LoginPacketResponse =
|
||||||
|
LoginPacket.SubCommand2(bot.client, response.sign, result).sendAndExpect()
|
||||||
}
|
}
|
||||||
|
is Captcha.Slider -> {
|
||||||
is LoginPacket.LoginPacketResponse.Error -> error(response.toString())
|
bot.logger.info("需要滑动验证码")
|
||||||
|
|
||||||
is LoginPacket.LoginPacketResponse.Success -> {
|
|
||||||
bot.logger.info("Login successful")
|
|
||||||
break@captcha
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is Error -> error(response.toString())
|
||||||
|
|
||||||
|
is Success -> {
|
||||||
|
bot.logger.info("Login successful")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println("d2key=${bot.client.wLoginSigInfo.d2Key.toUHexString()}")
|
println("d2key=${bot.client.wLoginSigInfo.d2Key.toUHexString()}")
|
||||||
|
@ -112,7 +112,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
|
|||||||
isGuidFromFileNull = false,
|
isGuidFromFileNull = false,
|
||||||
isGuidAvailable = true,
|
isGuidAvailable = true,
|
||||||
isGuidChanged = false,
|
isGuidChanged = false,
|
||||||
guidFlag = guidFlag(GuidSource.FROM_STORAGE, MacOrAndroidIdChangeFlag.NoChange),
|
guidFlag = guidFlag(GuidSource.FROM_STORAGE, MacOrAndroidIdChangeFlag(0)),
|
||||||
buildModel = client.device.model,
|
buildModel = client.device.model,
|
||||||
guid = client.device.guid,
|
guid = client.device.guid,
|
||||||
buildBrand = client.device.brand,
|
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
|
@InternalAPI
|
||||||
@ -246,10 +250,24 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
|
|||||||
0 -> onLoginSuccess(tlvMap, bot)
|
0 -> onLoginSuccess(tlvMap, bot)
|
||||||
1, 15 -> onErrorMessage(tlvMap)
|
1, 15 -> onErrorMessage(tlvMap)
|
||||||
2 -> onSolveLoginCaptcha(tlvMap, bot)
|
2 -> onSolveLoginCaptcha(tlvMap, bot)
|
||||||
|
-96 -> onUnsafeDeviceLogin(tlvMap, bot)
|
||||||
|
-52 -> onDeviceLockLogin(tlvMap, bot)
|
||||||
else -> error("unknown login result type: $type")
|
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 {
|
private fun onErrorMessage(tlvMap: Map<Int, ByteArray>): LoginPacketResponse.Error {
|
||||||
return tlvMap[0x146]?.toReadPacket()?.run {
|
return tlvMap[0x146]?.toReadPacket()?.run {
|
||||||
readShort() // ver
|
readShort() // ver
|
||||||
|
Loading…
Reference in New Issue
Block a user