Commit e4353e47 authored by Him188's avatar Him188

Cleanup

parent 368abbe1
......@@ -22,11 +22,10 @@ import net.mamoe.mirai.utils.io.PlatformDatagramChannel
*
* [BotNetworkHandler] 由 2 个模块构成:
* - [BotSocketAdapter]: 处理数据包底层的发送([ByteArray])
* - [PacketHandler]: 制作 [OutgoingPacket] 并传递给 [BotSocketAdapter] 发送; 分析 [ServerPacket] 并处理
* - [PacketHandler]: 制作 [OutgoingPacket] 并传递给 [BotSocketAdapter] 发送; 分析 [Packet] 并处理
*
* 其中, [PacketHandler] 由 3 个子模块构成:
* - [LoginHandler] 处理 sendTouch/login/verification code 相关
* - [EventPacketHandler] 处理消息相关(群消息/好友消息)([ServerEventPacket])
* - [ActionPacketHandler] 处理动作相关(踢人/加入群/好友列表等)
*
*
......
......@@ -56,7 +56,6 @@ class BotSession(
/**
* Web api 使用
*/
@ExperimentalStdlibApi
var sKey: String = ""
internal set(value) {
field = value
......
......@@ -27,7 +27,6 @@ class ActionPacketHandler(session: BotSession) : PacketHandler(session) {
private var sKeyRefresherJob: Job? = null
@ExperimentalStdlibApi
override suspend fun onPacketReceived(packet: Packet): Unit = with(session) {
when (packet) {
is SKey -> {
......
package net.mamoe.mirai.network.protocol.tim.packet
import kotlinx.io.core.ByteReadPacket
import kotlinx.io.core.readBytes
import net.mamoe.mirai.utils.io.toUHexString
/**
* 一个包的数据 (body)
......@@ -12,7 +14,9 @@ object IgnoredPacket : Packet
/**
* 未知的包.
*/
class UnknownPacket(val id: PacketId, val body: ByteReadPacket) : Packet
class UnknownPacket(val id: PacketId, val body: ByteReadPacket) : Packet {
override fun toString(): String = "UnknownPacket(${id.value.toUHexString()})\nbody=${body.readBytes().toUHexString()}"
}
/**
* 仅用于替换类型应为 [Unit] 的情况
......
......@@ -46,7 +46,9 @@ object SendGroupMessagePacket : SessionPacketFactory<SendGroupMessagePacket.Resp
}
@NoLog
object Response : Packet
object Response : Packet {
override fun toString(): String = "SendGroupMessagePacket.Response"
}
override suspend fun ByteReadPacket.decode(id: PacketId, sequenceId: UShort, handler: BotNetworkHandler<*>): Response = Response
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ import net.mamoe.mirai.network.protocol.tim.packet.KnownPacketId
import net.mamoe.mirai.network.protocol.tim.packet.PacketId
import net.mamoe.mirai.network.protocol.tim.packet.SessionPacketFactory
import net.mamoe.mirai.utils.OnlineStatus
import net.mamoe.mirai.utils.io.toUHexString
data class FriendStatusChanged(
val qq: QQ,
......@@ -30,7 +31,7 @@ object FriendOnlineStatusChangedPacket : SessionPacketFactory<FriendStatusChange
val qq = readUInt()
discardExact(8)
val statusId = readUByte()
val status = OnlineStatus.ofId(statusId) ?: error("Unknown online status id $statusId")
val status = OnlineStatus.ofId(statusId) ?: error("Unknown online status id 0x${statusId.toByte().toUHexString()}u")
return FriendStatusChanged(handler.bot.getQQ(qq), status)
}
......
......@@ -7,7 +7,6 @@ import kotlinx.io.core.readBytes
import kotlinx.io.pool.useInstance
import net.mamoe.mirai.Bot
import net.mamoe.mirai.network.BotNetworkHandler
import net.mamoe.mirai.utils.MiraiLogger
import net.mamoe.mirai.utils.io.ByteArrayPool
import net.mamoe.mirai.utils.io.toUHexString
......@@ -16,14 +15,14 @@ data class UnknownEventPacket(
val identity: EventPacketIdentity,
val body: ByteReadPacket
) : EventPacket {
override fun toString(): String = "UnknownEventPacket(id=${id.toUHexString()}, identity=$identity)"
override fun toString(): String = "UnknownEventPacket(id=${id.toUHexString()}, identity=$identity)\n = ${body.readBytes().toUHexString()}"
}
//TODO This class should be declared with `inline`, but a CompilationException will be thrown
class UnknownEventParserAndHandler(override val id: UShort) : EventParserAndHandler<UnknownEventPacket> {
override suspend fun ByteReadPacket.parse(bot: Bot, identity: EventPacketIdentity): UnknownEventPacket {
MiraiLogger.debug("UnknownEventPacket(${id.toUHexString()}) = ${readBytes().toUHexString()}")
// MiraiLogger.debug("UnknownEventPacket(${id.toUHexString()}) = ${readBytes().toUHexString()}")
return UnknownEventPacket(id, identity, this) //TODO the cause is that `this` reference.
}
......
......@@ -32,7 +32,6 @@ object RequestSKeyPacket : SessionPacketFactory<SKey>() {
override suspend fun ByteReadPacket.decode(id: PacketId, sequenceId: UShort, handler: BotNetworkHandler<*>): SKey {
discardExact(4)
// TODO: 2019/11/2 这里
return SKey(readString(10)).also {
DebugLogger.warning("SKey 包后面${readRemainingBytes().toUHexString()}")
}
......
......@@ -7,10 +7,9 @@ import net.mamoe.mirai.utils.io.getRandomByteArray
private const val GTK_BASE_VALUE: Int = 5381
@ExperimentalStdlibApi
internal fun getGTK(sKey: String): Int {
var value = GTK_BASE_VALUE
for (c in sKey.toCharArray()) {
for (c in sKey.toByteArray()) {
value += (value shl 5) + c.toInt()
}
......
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