LoginError parsing

This commit is contained in:
Him188 2020-01-24 18:02:56 +08:00
parent a1000b141b
commit 1a0f024081
4 changed files with 8 additions and 11 deletions

View File

@ -11,8 +11,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.Captcha
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.LoginPacket.LoginPacketResponse.Success
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.LoginPacket.LoginPacketResponse.*
import net.mamoe.mirai.qqandroid.network.protocol.packet.login.SvcReqRegisterPacket
import net.mamoe.mirai.utils.*
import net.mamoe.mirai.utils.io.*
@ -31,7 +30,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
launch(CoroutineName("Incoming Packet Receiver")) { processReceive() }
bot.logger.info("Trying login")
when (val response = LoginPacket.SubCommand9(bot.client).sendAndExpect<LoginPacket.LoginPacketResponse>()) {
when (val response: LoginPacket.LoginPacketResponse = LoginPacket.SubCommand9(bot.client).sendAndExpect()) {
is Captcha -> when (response) {
is Captcha.Picture -> {
bot.logger.info("需要图片验证码")
@ -41,6 +40,8 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
}
}
is Error -> error(response.toString())
is Success -> {
bot.logger.info("Login successful")
}
@ -207,10 +208,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
suspend fun <E : Packet> OutgoingPacket.sendAndExpect(): E {
val handler = PacketListener(commandName = commandName, sequenceId = sequenceId)
packetListeners.addLast(handler)
//println(delegate.readBytes().toUHexString())
println("Sending length=" + delegate.remaining)
channel.send(delegate)//) { packetListeners.remove(handler); "Cannot send packet" }
println("Packet sent")
channel.send(delegate)
@Suppress("UNCHECKED_CAST")
return handler.await() as E
}

View File

@ -204,7 +204,7 @@ internal object LoginPacket : PacketFactory<LoginPacket.LoginPacketResponse>("wt
val type = readByte()
println("type=$type")
debugDiscardExact(2)
discardExact(2)
val tlvMap: Map<Int, ByteArray> = this.readTLVMap()
return when (type.toInt()) {
0 -> onLoginSuccess(tlvMap, bot)

View File

@ -28,7 +28,7 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
@UseExperimental(MiraiExperimentalAPI::class)
final override val uin: Long
get() = account.id
final override val logger: MiraiLogger = configuration.logger ?: DefaultLogger("Bot($uin)")
final override val logger: MiraiLogger = configuration.logger ?: DefaultLogger("Bot($uin)").also { configuration.logger = it }
init {
@Suppress("LeakingThis")

View File

@ -4,7 +4,6 @@ import kotlinx.io.core.IoBuffer
import net.mamoe.mirai.Bot
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.coroutineContext
import kotlin.jvm.JvmStatic
/**
@ -26,7 +25,7 @@ class BotConfiguration {
/**
* 日志记录器
*/
var logger: PlatformLogger? = null
var logger: MiraiLogger? = null
/**
* [CoroutineContext]