mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-13 20:10:09 +08:00
[core] Handle all sso packet
This commit is contained in:
parent
5fd091eaad
commit
92948a484c
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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<TRpcRawPacket.RawData>(commandName) {
|
||||
internal class RawData(val data: ByteArray) : Packet
|
||||
internal object TRpcRawPacket : OutgoingPacketFactory<TRpcRawPacket.RawData>("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")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user