Commit e4353e47 authored by Him188's avatar Him188

Cleanup

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