From 6e6c1d813d0753fb9619187451f1d3df3e2e64f0 Mon Sep 17 00:00:00 2001 From: "jiahua.liu" Date: Sat, 8 Feb 2020 20:57:31 +0800 Subject: [PATCH] OnlinePushPack JCEs --- .../network/protocol/data/proto/OnlinePush.kt | 26 ++++++++++++++++ .../network/protocol/packet/PacketFactory.kt | 1 + .../packet/chat/receive/OnlinePush.kt | 30 ++++++++++++++++--- .../kotlin/test/ProtoBufDataClassGenerator.kt | 2 +- .../net.mamoe.mirai/utils/BotConfiguration.kt | 2 +- 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/data/proto/OnlinePush.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/data/proto/OnlinePush.kt index 819b6cd77..db5960b1b 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/data/proto/OnlinePush.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/data/proto/OnlinePush.kt @@ -15,4 +15,30 @@ internal class MsgOnlinePush { @SerialId(4) val pingFlag: Int = 0, @SerialId(9) val generalFlag: Int = 0 ) : ProtoBuf +} + +@Serializable +class OnlinePushTrans : ProtoBuf { + @Serializable + class ExtGroupKeyInfo( + @SerialId(1) val curMaxSeq: Int = 0, + @SerialId(2) val curTime: Long = 0L + ) : ProtoBuf + + @Serializable + class PbMsgInfo( + @SerialId(1) val fromUin: Long = 0L, + @SerialId(2) val toUin: Long = 0L, + @SerialId(3) val msgType: Int = 0, + @SerialId(4) val msgSubtype: Int = 0, + @SerialId(5) val msgSeq: Int = 0, + @SerialId(6) val msgUid: Long = 0L, + @SerialId(7) val msgTime: Int = 0, + @SerialId(8) val realMsgTime: Int = 0, + @SerialId(9) val nickName: String = "", + @SerialId(10) val msgData: ByteArray = EMPTY_BYTE_ARRAY, + @SerialId(11) val svrIp: Int = 0, + @SerialId(12) val extGroupKeyInfo: OnlinePushTrans.ExtGroupKeyInfo? = null, + @SerialId(17) val generalFlag: Int = 0 + ) : ProtoBuf } \ No newline at end of file diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt index a9cfe3046..7bf98681a 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/PacketFactory.kt @@ -133,6 +133,7 @@ internal object KnownPacketFactories { object IncomingFactories : List> by mutableListOf( OnlinePush.PbPushGroupMsg, OnlinePush.ReqPush, + OnlinePush.PbPushTransMsg, MessageSvc.PushNotify, ConfigPushSvc.PushReq diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt index 294cb8b95..7cd77bac5 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.kt @@ -12,13 +12,16 @@ import net.mamoe.mirai.event.broadcast import net.mamoe.mirai.message.GroupMessage import net.mamoe.mirai.qqandroid.QQAndroidBot import net.mamoe.mirai.qqandroid.io.serialization.decodeUniPacket +import net.mamoe.mirai.qqandroid.io.serialization.loadAs import net.mamoe.mirai.qqandroid.io.serialization.readProtoBuf import net.mamoe.mirai.qqandroid.network.protocol.data.jce.MsgInfo import net.mamoe.mirai.qqandroid.network.protocol.data.jce.OnlinePushPack import net.mamoe.mirai.qqandroid.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.qqandroid.network.protocol.data.proto.MsgOnlinePush +import net.mamoe.mirai.qqandroid.network.protocol.data.proto.OnlinePushTrans import net.mamoe.mirai.qqandroid.network.protocol.packet.IncomingPacketFactory import net.mamoe.mirai.qqandroid.network.protocol.packet.OutgoingPacket +import net.mamoe.mirai.qqandroid.network.protocol.packet.buildResponseUniPacket import net.mamoe.mirai.qqandroid.utils.toMessageChain import net.mamoe.mirai.utils.cryptor.contentToString import net.mamoe.mirai.utils.io.discardExact @@ -82,13 +85,29 @@ internal class OnlinePush { } } + internal object PbPushTransMsg : IncomingPacketFactory("OnlinePush.PbPushTransMsg") { + + override suspend fun ByteReadPacket.decode(bot: QQAndroidBot, sequenceId: Int): Packet { + val content = this.readProtoBuf(OnlinePushTrans.PbMsgInfo.serializer()) + println(content.contentToString()) + return NoPakcet + } + + override suspend fun QQAndroidBot.handle(packet: Packet, sequenceId: Int): OutgoingPacket? { + return buildResponseUniPacket(client, commandName = "OnlinePush.RespPush", sequenceId = sequenceId) { + + } + } + + + } + //0C 01 B1 89 BE 09 5E 3D 72 A6 00 01 73 68 FC 06 00 00 00 3C internal object ReqPush : IncomingPacketFactory("OnlinePush.ReqPush") { @ExperimentalUnsignedTypes @UseExperimental(ExperimentalStdlibApi::class) override suspend fun ByteReadPacket.decode(bot: QQAndroidBot, sequenceId: Int): Packet { val reqPushMsg = decodeUniPacket(OnlinePushPack.SvcReqPushMsg.serializer(), "req") - println(reqPushMsg.contentToString()) reqPushMsg.vMsgInfos.forEach { msgInfo: MsgInfo -> var debug = "" msgInfo.vMsg!!.read { @@ -152,9 +171,10 @@ internal class OnlinePush { } } } else if (msgInfo.shMsgType.toInt() == 528) { - + val content = msgInfo.vMsg.loadAs(OnlinePushPack.MsgType0x210.serializer()) + println(content.contentToString()) } else if (msgInfo.shMsgType.toInt() == 4352) { - + println("4352") } else { println("unknown shtype ${msgInfo.shMsgType.toInt()}") } @@ -167,7 +187,9 @@ internal class OnlinePush { override suspend fun QQAndroidBot.handle(packet: Packet, sequenceId: Int): OutgoingPacket? { - return null + return buildResponseUniPacket(client, commandName = "OnlinePush.RespPush", sequenceId = sequenceId) { + + } } } } \ No newline at end of file diff --git a/mirai-core-qqandroid/src/jvmTest/kotlin/test/ProtoBufDataClassGenerator.kt b/mirai-core-qqandroid/src/jvmTest/kotlin/test/ProtoBufDataClassGenerator.kt index 0cb54c6a2..03aeff6a5 100644 --- a/mirai-core-qqandroid/src/jvmTest/kotlin/test/ProtoBufDataClassGenerator.kt +++ b/mirai-core-qqandroid/src/jvmTest/kotlin/test/ProtoBufDataClassGenerator.kt @@ -16,7 +16,7 @@ fun main() { println( File( """ - E:\Projects\QQAndroidFF\app\src\main\java\tencent\im\statsvc\getonline + /Users/jiahua.liu/Desktop/QQAndroid-F/app/src/main/java/com/tencent/pb/onlinepush/ """.trimIndent() ) .generateUnarrangedClasses().toMutableList().arrangeClasses().joinToString("\n\n") diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt index 8f213b87e..ce2967121 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt @@ -49,7 +49,7 @@ class BotConfiguration { /** * 心跳周期. 过长会导致被服务器断开连接. */ - var heartbeatPeriodMillis: Long = 30.secondsToMillis + var heartbeatPeriodMillis: Long = 300.secondsToMillis /** * 每次心跳时等待结果的时间. * 一旦心跳超时, 整个网络服务将会重启 (将消耗约 5s). 除正在进行的任务 (如图片上传) 会被中断外, 事件和插件均不受影响.