Commit 09495c0c authored by Him188moe's avatar Him188moe

Enhanced output

parent c5393133
...@@ -219,7 +219,7 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable { ...@@ -219,7 +219,7 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
val data = packet.toByteArray() val data = packet.toByteArray()
socket!!.send(DatagramPacket(data, data.size)) socket!!.send(DatagramPacket(data, data.size))
robot purple "Packet sent: $packet" robot cyanL "Packet sent: $packet"
PacketSentEvent(robot, packet).broadcast() PacketSentEvent(robot, packet).broadcast()
} catch (e: Throwable) { } catch (e: Throwable) {
...@@ -279,7 +279,9 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable { ...@@ -279,7 +279,9 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
*/ */
inner class DebugHandler : PacketHandler() { inner class DebugHandler : PacketHandler() {
override fun onPacketReceived(packet: ServerPacket) { override fun onPacketReceived(packet: ServerPacket) {
robot notice "Packet received: $packet" if (!packet.javaClass.name.endsWith("Encrypted")) {
robot notice "Packet received: $packet"
}
if (packet is ServerEventPacket) { if (packet is ServerEventPacket) {
sendPacket(ClientMessageResponsePacket(robot.account.qqNumber, packet.packetId, sessionKey, packet.eventIdentity)) sendPacket(ClientMessageResponsePacket(robot.account.qqNumber, packet.packetId, sessionKey, packet.eventIdentity))
} }
...@@ -354,10 +356,6 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable { ...@@ -354,10 +356,6 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
} }
} }
is ServerVerificationCodeUnknownPacket -> {
sendPacket(ClientVerificationCodeRefreshPacket(88, robot.account.qqNumber, token0825))
}
is ServerVerificationCodeTransmissionPacket -> { is ServerVerificationCodeTransmissionPacket -> {
if (packet is ServerVerificationCodeWrongPacket) { if (packet is ServerVerificationCodeWrongPacket) {
robot error "验证码错误, 请重新输入" robot error "验证码错误, 请重新输入"
...@@ -377,6 +375,7 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable { ...@@ -377,6 +375,7 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
val code = Scanner(System.`in`).nextLine() val code = Scanner(System.`in`).nextLine()
if (code.isEmpty() || code.length != 4) { if (code.isEmpty() || code.length != 4) {
this.captchaCache = byteArrayOf() this.captchaCache = byteArrayOf()
this.captchaSectionId = 1
sendPacket(ClientVerificationCodeRefreshPacket(packet.packetIdLast + 1, robot.account.qqNumber, token0825)) sendPacket(ClientVerificationCodeRefreshPacket(packet.packetIdLast + 1, robot.account.qqNumber, token0825))
} else { } else {
sendPacket(ClientVerificationCodeSubmitPacket(packet.packetIdLast + 1, robot.account.qqNumber, token0825, code, packet.verificationToken)) sendPacket(ClientVerificationCodeSubmitPacket(packet.packetIdLast + 1, robot.account.qqNumber, token0825, code, packet.verificationToken))
......
...@@ -2,6 +2,7 @@ package net.mamoe.mirai.network.packet ...@@ -2,6 +2,7 @@ package net.mamoe.mirai.network.packet
import lombok.Getter import lombok.Getter
import net.mamoe.mirai.network.Protocol import net.mamoe.mirai.network.Protocol
import net.mamoe.mirai.network.packet.PacketNameFormatter.adjustName
import net.mamoe.mirai.utils.* import net.mamoe.mirai.utils.*
import java.io.DataOutputStream import java.io.DataOutputStream
import java.io.IOException import java.io.IOException
...@@ -62,14 +63,15 @@ abstract class ClientPacket : ByteArrayDataOutputStream(), Packet { ...@@ -62,14 +63,15 @@ abstract class ClientPacket : ByteArrayDataOutputStream(), Packet {
open fun getFixedId(): String = when (this.idHex.length) { open fun getFixedId(): String = when (this.idHex.length) {
0 -> "__ __ __ __" 0 -> "__ __ __ __"
2 -> this.idHex + " __ __" 2 -> this.idHex + " __ __ __"
5 -> this.idHex + " __" 5 -> this.idHex + " __ __"
7 -> this.idHex + " __"
else -> this.idHex else -> this.idHex
} }
override fun toString(): String { override fun toString(): String {
return this.javaClass.simpleName + "(${this.getFixedId()})" + this.getAllDeclaredFields().joinToString(", ", "{", "}") { return adjustName(this.javaClass.simpleName + "(${this.getFixedId()})") + this.getAllDeclaredFields().filterNot { it.name == "idHex" || it.name == "encoded" }.joinToString(", ", "{", "}") {
it.trySetAccessible(); it.name + "=" + it.get(this).let { value -> it.trySetAccessible(); it.name + "=" + it.get(this).let { value ->
when (value) { when (value) {
null -> null null -> null
......
package net.mamoe.mirai.network.packet;
/**
* @author Him188moe
*/
public interface Packet {
}
package net.mamoe.mirai.network.packet
/**
* @author Him188moe
*/
interface Packet {
}
object PacketNameFormatter {
@JvmSynthetic
private var longestNameLength: Int = 43
@JvmSynthetic
fun adjustName(name: String): String {
if (name.length > longestNameLength) {
longestNameLength = name.length
return name
}
return StringBuilder().apply {
repeat(longestNameLength - name.length) {
this.append(" ")
}
}.toString() + name
}
}
\ No newline at end of file
...@@ -223,6 +223,10 @@ class ClientMessageResponsePacket( ...@@ -223,6 +223,10 @@ class ClientMessageResponsePacket(
it.write(eventIdentity) it.write(eventIdentity)
} }
} }
override fun getFixedId(): String {
return packetIdFromServer.toUHexString()
}
} }
/* /*
......
package net.mamoe.mirai.network.packet package net.mamoe.mirai.network.packet
import lombok.Getter import lombok.Getter
import net.mamoe.mirai.network.packet.PacketNameFormatter.adjustName
import net.mamoe.mirai.network.packet.action.ServerSendFriendMessageResponsePacket import net.mamoe.mirai.network.packet.action.ServerSendFriendMessageResponsePacket
import net.mamoe.mirai.network.packet.action.ServerSendGroupMessageResponsePacket import net.mamoe.mirai.network.packet.action.ServerSendGroupMessageResponsePacket
import net.mamoe.mirai.network.packet.login.* import net.mamoe.mirai.network.packet.login.*
...@@ -109,7 +110,7 @@ abstract class ServerPacket(val input: DataInputStream) : Packet { ...@@ -109,7 +110,7 @@ abstract class ServerPacket(val input: DataInputStream) : Packet {
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
override fun toString(): String { override fun toString(): String {
return this.javaClass.simpleName + "(${this.getFixedId()})" + this.getAllDeclaredFields().joinToString(", ", "{", "}") { return adjustName(this.javaClass.simpleName + "(${this.getFixedId()})") + this.getAllDeclaredFields().filterNot { it.name == "idHex" || it.name == "encoded" }.joinToString(", ", "{", "}") {
it.trySetAccessible(); it.name + "=" + it.get(this).let { value -> it.trySetAccessible(); it.name + "=" + it.get(this).let { value ->
when (value) { when (value) {
is ByteArray -> value.toUHexString() is ByteArray -> value.toUHexString()
...@@ -124,8 +125,9 @@ abstract class ServerPacket(val input: DataInputStream) : Packet { ...@@ -124,8 +125,9 @@ abstract class ServerPacket(val input: DataInputStream) : Packet {
fun getFixedId(id: String): String = when (id.length) { fun getFixedId(id: String): String = when (id.length) {
0 -> "__ __ __ __" 0 -> "__ __ __ __"
2 -> "$id __ __" 2 -> "$id __ __ __"
5 -> "$id __" 5 -> "$id __ __"
7 -> "$id __"
else -> id else -> id
} }
......
...@@ -210,12 +210,6 @@ class ServerVerificationCodeCorrectPacket(input: DataInputStream) : ServerVerifi ...@@ -210,12 +210,6 @@ class ServerVerificationCodeCorrectPacket(input: DataInputStream) : ServerVerifi
} }
} }
class ServerVerificationCodeUnknownPacket(input: DataInputStream) : ServerVerificationCodePacket(input) {
override fun decode() {
MiraiLogger.debug(this.input.goto(0).readAllBytes())
}
}
abstract class ServerVerificationCodePacket(input: DataInputStream) : ServerPacket(input) { abstract class ServerVerificationCodePacket(input: DataInputStream) : ServerPacket(input) {
@PacketId("00 BA") @PacketId("00 BA")
......
...@@ -44,6 +44,6 @@ class ServerLoginResponseResendPacket(input: DataInputStream, val flag: Flag) : ...@@ -44,6 +44,6 @@ class ServerLoginResponseResendPacket(input: DataInputStream, val flag: Flag) :
class Encrypted(input: DataInputStream, private val flag: Flag) : ServerPacket(input) { class Encrypted(input: DataInputStream, private val flag: Flag) : ServerPacket(input) {
@TestedSuccessfully @TestedSuccessfully
fun decrypt(tgtgtKey: ByteArray): ServerLoginResponseResendPacket = ServerLoginResponseResendPacket(decryptBy(tgtgtKey), flag).setId(this.idHex) fun decrypt(tgtgtKey: ByteArray): ServerLoginResponseResendPacket = ServerLoginResponseResendPacket(this.decryptBy(tgtgtKey), flag).setId(this.idHex)
} }
} }
...@@ -45,6 +45,8 @@ infix fun Robot.notice(o: Any?) = print(this, o.toString(), LoggerTextFormat.LIG ...@@ -45,6 +45,8 @@ infix fun Robot.notice(o: Any?) = print(this, o.toString(), LoggerTextFormat.LIG
infix fun Robot.purple(o: Any?) = print(this, o.toString(), LoggerTextFormat.PURPLE) infix fun Robot.purple(o: Any?) = print(this, o.toString(), LoggerTextFormat.PURPLE)
infix fun Robot.cyanL(o: Any?) = print(this, o.toString(), LoggerTextFormat.LIGHT_CYAN)
infix fun Robot.success(o: Any?) = print(this, o.toString(), LoggerTextFormat.GREEN) infix fun Robot.success(o: Any?) = print(this, o.toString(), LoggerTextFormat.GREEN)
infix fun Robot.debug(o: Any?) = print(this, o.toString(), LoggerTextFormat.YELLOW) infix fun Robot.debug(o: Any?) = print(this, o.toString(), LoggerTextFormat.YELLOW)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment