From 92948a484cfa6647fe4895f45fb8626c61757d5a Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sat, 17 Jun 2023 14:01:32 +0800 Subject: [PATCH] [core] Handle all sso packet --- .../kotlin/network/components/PacketCodec.kt | 7 ++++- .../network/protocol/packet/OutgoingPacket.kt | 11 ++++---- .../network/protocol/packet/PacketFactory.kt | 4 --- .../protocol/packet/sso/TRpcRawPacket.kt | 26 +++++++++---------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt b/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt index 18f5834fc..211504bb7 100644 --- a/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt +++ b/mirai-core/src/commonMain/kotlin/network/components/PacketCodec.kt @@ -392,11 +392,16 @@ internal class PacketCodecImpl : PacketCodec { * This function wraps exceptions into [IncomingPacket] */ override suspend fun processBody(bot: QQAndroidBot, input: RawIncomingPacket): IncomingPacket? { - val factory = KnownPacketFactories.findPacketFactory(input.commandName) ?: return null + val factory = KnownPacketFactories.findPacketFactory(input.commandName) + ?: TRpcRawPacket.takeIf { input.commandName.startsWith(TRpcRawPacket.COMMAND_PREFIX) } + ?: return null return kotlin.runCatching { input.body.toReadPacket().use { body -> when (factory) { + // specially + is TRpcRawPacket -> TRpcRawPacket.decode(input, body) + is OutgoingPacketFactory -> factory.decode(bot, body) is IncomingPacketFactory -> factory.decode(bot, body, input.sequenceId) } diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/OutgoingPacket.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/OutgoingPacket.kt index 539a43842..3ef19401c 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/OutgoingPacket.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/OutgoingPacket.kt @@ -16,7 +16,7 @@ import net.mamoe.mirai.internal.network.* import net.mamoe.mirai.internal.network.components.EcdhInitialPublicKeyUpdater import net.mamoe.mirai.internal.network.protocol.data.proto.SSOReserveField import net.mamoe.mirai.internal.network.protocol.packet.chat.receive.MessageSvcPbSendMsg -import net.mamoe.mirai.internal.network.protocol.packet.sso.SsoEstablishShareKey +import net.mamoe.mirai.internal.network.protocol.packet.sso.TRpcRawPacket import net.mamoe.mirai.internal.spi.EncryptService import net.mamoe.mirai.internal.spi.EncryptServiceContext import net.mamoe.mirai.internal.utils.io.encryptAndWrite @@ -260,13 +260,14 @@ internal fun createChannelProxy(client: QQAndroidClient): EncryptService.Channel uin: Long, data: ByteArray ): EncryptService.ChannelResult? { - if (commandName == SsoEstablishShareKey.commandName) { + if (commandName.startsWith(TRpcRawPacket.COMMAND_PREFIX)) { val packet = client.bot.network.sendAndExpect( - SsoEstablishShareKey.buildLoginOutgoingPacket( + TRpcRawPacket.buildLoginOutgoingPacket( client = client, encryptMethod = PacketEncryptType.Empty, uin = uin.toString(), - remark = remark + remark = remark, + commandName = commandName, ) { writeSsoPacket( client, @@ -277,7 +278,7 @@ internal fun createChannelProxy(client: QQAndroidClient): EncryptService.Channel ) } ) - return EncryptService.ChannelResult(SsoEstablishShareKey.commandName, packet.data) + return EncryptService.ChannelResult(commandName, packet.data) } return null } diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/PacketFactory.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/PacketFactory.kt index d2e6ad780..e0219ced6 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/PacketFactory.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/PacketFactory.kt @@ -26,8 +26,6 @@ import net.mamoe.mirai.internal.network.protocol.packet.login.ConfigPushSvc import net.mamoe.mirai.internal.network.protocol.packet.login.Heartbeat import net.mamoe.mirai.internal.network.protocol.packet.login.StatSvc import net.mamoe.mirai.internal.network.protocol.packet.login.WtLogin -import net.mamoe.mirai.internal.network.protocol.packet.sso.SsoEstablishShareKey -import net.mamoe.mirai.internal.network.protocol.packet.sso.SsoSecureA2Access import net.mamoe.mirai.internal.network.protocol.packet.summarycard.ChangeFriendRemark import net.mamoe.mirai.internal.network.protocol.packet.summarycard.SummaryCard import net.mamoe.mirai.utils.DeprecatedSinceMirai @@ -133,8 +131,6 @@ internal object KnownPacketFactories { WtLogin.Login, WtLogin.ExchangeEmp, WtLogin.TransEmp, - SsoEstablishShareKey, - SsoSecureA2Access, StatSvc.Register, StatSvc.GetOnlineStatus, StatSvc.SimpleGet, diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/sso/TRpcRawPacket.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/sso/TRpcRawPacket.kt index 72680aec2..04ebb5a09 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/sso/TRpcRawPacket.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/sso/TRpcRawPacket.kt @@ -12,24 +12,22 @@ package net.mamoe.mirai.internal.network.protocol.packet.sso import io.ktor.utils.io.core.* import net.mamoe.mirai.internal.QQAndroidBot import net.mamoe.mirai.internal.network.Packet +import net.mamoe.mirai.internal.network.components.RawIncomingPacket import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketFactory -internal abstract class TRpcRawPacket(commandName: String) : - OutgoingPacketFactory(commandName) { - internal class RawData(val data: ByteArray) : Packet +internal object TRpcRawPacket : OutgoingPacketFactory("trpc.o3.*") { + const val COMMAND_PREFIX = "trpc.o3." + + + internal class RawData( + val command: String, + val data: ByteArray, + ) : Packet override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): RawData { - return RawData(readBytes()) + error("") } - companion object { - const val COMMAND_PREFIX = "trpc.o3" - } + fun decode(raw: RawIncomingPacket, body: ByteReadPacket): RawData = + RawData(raw.commandName, body.readBytes()) } - -internal object SsoEstablishShareKey : - TRpcRawPacket("$COMMAND_PREFIX.ecdh_access.EcdhAccess.SsoEstablishShareKey") - -internal object SsoSecureA2Access : - TRpcRawPacket("$COMMAND_PREFIX.ecdh_access.EcdhAccess.SsoSecureA2Access") -