mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-24 14:30:09 +08:00
Enhanced output
This commit is contained in:
parent
c539313351
commit
09495c0ca9
@ -219,7 +219,7 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
|
||||
|
||||
val data = packet.toByteArray()
|
||||
socket!!.send(DatagramPacket(data, data.size))
|
||||
robot purple "Packet sent: $packet"
|
||||
robot cyanL "Packet sent: $packet"
|
||||
|
||||
PacketSentEvent(robot, packet).broadcast()
|
||||
} catch (e: Throwable) {
|
||||
@ -279,7 +279,9 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
|
||||
*/
|
||||
inner class DebugHandler : PacketHandler() {
|
||||
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) {
|
||||
sendPacket(ClientMessageResponsePacket(robot.account.qqNumber, packet.packetId, sessionKey, packet.eventIdentity))
|
||||
}
|
||||
@ -354,10 +356,6 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
is ServerVerificationCodeUnknownPacket -> {
|
||||
sendPacket(ClientVerificationCodeRefreshPacket(88, robot.account.qqNumber, token0825))
|
||||
}
|
||||
|
||||
is ServerVerificationCodeTransmissionPacket -> {
|
||||
if (packet is ServerVerificationCodeWrongPacket) {
|
||||
robot error "验证码错误, 请重新输入"
|
||||
@ -377,6 +375,7 @@ class RobotNetworkHandler(private val robot: Robot) : Closeable {
|
||||
val code = Scanner(System.`in`).nextLine()
|
||||
if (code.isEmpty() || code.length != 4) {
|
||||
this.captchaCache = byteArrayOf()
|
||||
this.captchaSectionId = 1
|
||||
sendPacket(ClientVerificationCodeRefreshPacket(packet.packetIdLast + 1, robot.account.qqNumber, token0825))
|
||||
} else {
|
||||
sendPacket(ClientVerificationCodeSubmitPacket(packet.packetIdLast + 1, robot.account.qqNumber, token0825, code, packet.verificationToken))
|
||||
|
@ -2,6 +2,7 @@ package net.mamoe.mirai.network.packet
|
||||
|
||||
import lombok.Getter
|
||||
import net.mamoe.mirai.network.Protocol
|
||||
import net.mamoe.mirai.network.packet.PacketNameFormatter.adjustName
|
||||
import net.mamoe.mirai.utils.*
|
||||
import java.io.DataOutputStream
|
||||
import java.io.IOException
|
||||
@ -62,14 +63,15 @@ abstract class ClientPacket : ByteArrayDataOutputStream(), Packet {
|
||||
|
||||
open fun getFixedId(): String = when (this.idHex.length) {
|
||||
0 -> "__ __ __ __"
|
||||
2 -> this.idHex + " __ __"
|
||||
5 -> this.idHex + " __"
|
||||
2 -> this.idHex + " __ __ __"
|
||||
5 -> this.idHex + " __ __"
|
||||
7 -> this.idHex + " __"
|
||||
else -> this.idHex
|
||||
}
|
||||
|
||||
|
||||
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 ->
|
||||
when (value) {
|
||||
null -> null
|
||||
|
@ -1,8 +0,0 @@
|
||||
package net.mamoe.mirai.network.packet;
|
||||
|
||||
/**
|
||||
* @author Him188moe
|
||||
*/
|
||||
public interface Packet {
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
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
|
||||
}
|
||||
}
|
@ -223,6 +223,10 @@ class ClientMessageResponsePacket(
|
||||
it.write(eventIdentity)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getFixedId(): String {
|
||||
return packetIdFromServer.toUHexString()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.mamoe.mirai.network.packet
|
||||
|
||||
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.ServerSendGroupMessageResponsePacket
|
||||
import net.mamoe.mirai.network.packet.login.*
|
||||
@ -109,7 +110,7 @@ abstract class ServerPacket(val input: DataInputStream) : Packet {
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
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 ->
|
||||
when (value) {
|
||||
is ByteArray -> value.toUHexString()
|
||||
@ -124,8 +125,9 @@ abstract class ServerPacket(val input: DataInputStream) : Packet {
|
||||
|
||||
fun getFixedId(id: String): String = when (id.length) {
|
||||
0 -> "__ __ __ __"
|
||||
2 -> "$id __ __"
|
||||
5 -> "$id __"
|
||||
2 -> "$id __ __ __"
|
||||
5 -> "$id __ __"
|
||||
7 -> "$id __"
|
||||
else -> id
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
||||
@PacketId("00 BA")
|
||||
|
@ -44,6 +44,6 @@ class ServerLoginResponseResendPacket(input: DataInputStream, val flag: Flag) :
|
||||
|
||||
class Encrypted(input: DataInputStream, private val flag: Flag) : ServerPacket(input) {
|
||||
@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
|
||||
|
||||
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.debug(o: Any?) = print(this, o.toString(), LoggerTextFormat.YELLOW)
|
||||
|
Loading…
Reference in New Issue
Block a user