QQA Debugging update

This commit is contained in:
Him188 2020-01-24 17:44:25 +08:00
parent ddab66f165
commit 9ff1ff604c

View File

@ -172,6 +172,12 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
sealed class LoginPacketResponse : Packet { sealed class LoginPacketResponse : Packet {
object Success : LoginPacketResponse() object Success : LoginPacketResponse()
data class Error(
val title: String,
val message: String,
val errorInfo: String
) : LoginPacketResponse()
sealed class Captcha : LoginPacketResponse() { sealed class Captcha : LoginPacketResponse() {
class Slider( class Slider(
val data: IoBuffer val data: IoBuffer
@ -197,32 +203,38 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
println("subCommand=$subCommand") println("subCommand=$subCommand")
val type = readByte() val type = readByte()
println("type=$type") println("type=$type")
when (type.toInt()) { return when (type.toInt()) {
0 -> { 0 -> onLoginSuccess(bot)
onLoginSuccess(bot) 1, 15 -> onErrorMessage()
} 2 -> onSolveLoginCaptcha(bot)
1 -> { else -> error("unknown login result type: $type")
throw Exception("Wrong Password")
}
2 -> {
onSolveLoginCaptcha(bot)
}
} }
if (type.toInt() != 0) { }
DebugLogger.debug("unknown login result type: $type")
} private fun ByteReadPacket.onErrorMessage(): LoginPacketResponse.Error {
return LoginPacketResponse.Success discardExact(2)
val tlvMap = readTLVMap()
tlvMap[0x146]?.toReadPacket()?.run {
readShort() // ver
readShort() // code
val title = readUShortLVString()
val message = readUShortLVString()
val errorInfo = readUShortLVString()
return LoginPacketResponse.Error(title, message, errorInfo)
} ?: error("Cannot find error message")
} }
@UseExperimental(MiraiDebugAPI::class) @UseExperimental(MiraiDebugAPI::class)
suspend fun ByteReadPacket.onSolveLoginCaptcha(bot: QQAndroidBot) = this.debugPrint("login验证码解析").run { suspend fun ByteReadPacket.onSolveLoginCaptcha(bot: QQAndroidBot): LoginPacketResponse.Captcha = this.debugPrint("login验证码解析").run {
val client = bot.client val client = bot.client
debugDiscardExact(2) debugDiscardExact(2)
val tlvMap: Map<Int, ByteArray> = this.readTLVMap() val tlvMap: Map<Int, ByteArray> = this.readTLVMap()
// val ret = tlvMap[0x104]?.let { println(it.toUHexString()) } // val ret = tlvMap[0x104]?.let { println(it.toUHexString()) }
println() println()
val question = tlvMap[0x165] ?: error("CAPTCHA QUESTION UNKNOWN") val question = tlvMap[0x165] ?: error("CAPTCHA QUESTION UNKNOWN")
when(question[18].toUHexString()){ when (question[18].toUHexString()) {
"36" -> { "36" -> {
//图片验证 //图片验证
debugPrint("是一个图片验证码") debugPrint("是一个图片验证码")
@ -236,10 +248,11 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
error("UNKNOWN CAPTCHA QUESTION: $question") error("UNKNOWN CAPTCHA QUESTION: $question")
} }
} }
return TODO()
} }
@UseExperimental(MiraiDebugAPI::class) @UseExperimental(MiraiDebugAPI::class)
fun ByteReadPacket.onLoginSuccess(bot: QQAndroidBot) = this.debugPrint("login成功解析").run { private fun ByteReadPacket.onLoginSuccess(bot: QQAndroidBot): LoginPacketResponse.Success {
val client = bot.client val client = bot.client
debugDiscardExact(2) debugDiscardExact(2)
val tlvMap: Map<Int, ByteArray> = this.readTLVMap() val tlvMap: Map<Int, ByteArray> = this.readTLVMap()
@ -446,6 +459,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
} }
} }
return LoginPacketResponse.Success
} }