Fixed bugs

This commit is contained in:
Him188 2019-09-29 21:13:52 +08:00
parent 97c86eba64
commit 23c060fb44
4 changed files with 15 additions and 15 deletions

View File

@ -2,12 +2,12 @@ package net.mamoe.mirai.event.events.network;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.event.Cancellable;
import net.mamoe.mirai.network.packet.ServerCatchaPacket;
import net.mamoe.mirai.network.packet.ServerPacket;
import net.mamoe.mirai.network.packet.ServerVerificationCodePacket;
/**
* 服务器接到某数据包时触发这个事件.
* 注意, 当接收到数据包的加密包( {@link ServerVerificationCodePacket.Encrypted})也会触发这个事件, 随后才会
* 注意, 当接收到数据包的加密包( {@link ServerCatchaPacket.Encrypted})也会触发这个事件, 随后才会
*
* @author Him188moe
*/

View File

@ -290,7 +290,7 @@ internal class BotNetworkHandlerImpl(private val bot: Bot) : BotNetworkHandler {
return
}
is ServerVerificationCodeCorrectPacket -> {
is ServerCaptchaCorrectPacket -> {
this.randomTgtgtKey = getRandomByteArray(16)
this.token00BA = packet.token00BA
socket.sendPacket(ClientLoginResendPacket3105(bot.account.qqNumber, bot.account.password, this.loginTime, this.loginIP, this.randomTgtgtKey, this.token0825, this.token00BA))
@ -307,8 +307,8 @@ internal class BotNetworkHandlerImpl(private val bot: Bot) : BotNetworkHandler {
}
}
is ServerVerificationCodeTransmissionPacket -> {
if (packet is ServerVerificationCodeWrongPacket) {
is ServerCaptchaTransmissionPacket -> {
if (packet is ServerCaptchaWrongPacket) {
bot.error("验证码错误, 请重新输入")
captchaSectionId = 1
this.captchaCache = byteArrayOf()
@ -390,7 +390,7 @@ internal class BotNetworkHandlerImpl(private val bot: Bot) : BotNetworkHandler {
}
is ServerVerificationCodePacket.Encrypted -> socket.distributePacket(packet.decrypt())
is ServerCatchaPacket.Encrypted -> socket.distributePacket(packet.decrypt())
is ServerLoginResponseVerificationCodeInitPacket.Encrypted -> socket.distributePacket(packet.decrypt())
is ServerLoginResponseKeyExchangePacket.Encrypted -> socket.distributePacket(packet.decrypt(this.randomTgtgtKey))
is ServerLoginResponseSuccessPacket.Encrypted -> socket.distributePacket(packet.decrypt(this.randomTgtgtKey))

View File

@ -111,7 +111,7 @@ abstract class ServerPacket(val input: DataInputStream) : Packet {
"00 58" -> ServerHeartbeatResponsePacket(stream)
"00 BA" -> ServerVerificationCodePacket.Encrypted(stream, idHex)
"00 BA" -> ServerCatchaPacket.Encrypted(stream, idHex)
"00 CE", "00 17" -> ServerEventPacket.Raw.Encrypted(stream, idHex.hexToBytes())

View File

@ -126,7 +126,7 @@ class ClientVerificationCodeRefreshPacket(
* 验证码输入错误, 同时也会给一部分验证码
*/
@PacketId("00 BA 32")
class ServerVerificationCodeWrongPacket(input: DataInputStream, dataSize: Int, packetId: ByteArray) : ServerVerificationCodeTransmissionPacket(input, dataSize, packetId)
class ServerCaptchaWrongPacket(input: DataInputStream, dataSize: Int, packetId: ByteArray) : ServerCaptchaTransmissionPacket(input, dataSize, packetId)
/**
* 服务器发送验证码图片文件一部分过来
@ -134,7 +134,7 @@ class ServerVerificationCodeWrongPacket(input: DataInputStream, dataSize: Int, p
* @author Him188moe
*/
@PacketId("00 BA 31")
open class ServerVerificationCodeTransmissionPacket(input: DataInputStream, private val dataSize: Int, private val packetId: ByteArray) : ServerVerificationCodePacket(input) {
open class ServerCaptchaTransmissionPacket(input: DataInputStream, private val dataSize: Int, private val packetId: ByteArray) : ServerCatchaPacket(input) {
lateinit var captchaSectionN: ByteArray
lateinit var verificationToken: ByteArray//56bytes
@ -177,7 +177,7 @@ fun main() {
* @author Him188moe
*/
@PacketId("00 BA 32")
class ServerVerificationCodeCorrectPacket(input: DataInputStream) : ServerVerificationCodePacket(input) {
class ServerCaptchaCorrectPacket(input: DataInputStream) : ServerCatchaPacket(input) {
lateinit var token00BA: ByteArray//56 bytes
@ -187,24 +187,24 @@ class ServerVerificationCodeCorrectPacket(input: DataInputStream) : ServerVerifi
}
}
abstract class ServerVerificationCodePacket(input: DataInputStream) : ServerPacket(input) {
abstract class ServerCatchaPacket(input: DataInputStream) : ServerPacket(input) {
@PacketId("00 BA")
class Encrypted(input: DataInputStream, private val id: String) : ServerPacket(input) {
fun decrypt(): ServerVerificationCodePacket {
fun decrypt(): ServerCatchaPacket {
this.input goto 14
val data = TEA.decrypt(this.input.readAllBytes().cutTail(1), Protocol.key00BA.hexToBytes())
if (id.startsWith("00 BA 32")) {
return when (data.size) {
66,
95 -> ServerVerificationCodeCorrectPacket(data.dataInputStream())
95 -> ServerCaptchaCorrectPacket(data.dataInputStream())
//66 -> ServerVerificationCodeUnknownPacket(data.dataInputStream())
else -> return ServerVerificationCodeWrongPacket(data.dataInputStream(), data.size, this.input.readNBytesAt(3, 4))
else -> return ServerCaptchaWrongPacket(data.dataInputStream(), data.size, this.input.readNBytesAt(3, 4))
}.setId(this.idHex)
}
return ServerVerificationCodeTransmissionPacket(data.dataInputStream(), data.size, this.input.readNBytesAt(3, 4)).setId(this.idHex)
return ServerCaptchaTransmissionPacket(data.dataInputStream(), data.size, this.input.readNBytesAt(3, 4)).setId(this.idHex)
}
override fun getFixedId(): String = this.getFixedId(id)