From 4d67c2e475d2d022fd5d4baf7589d65cd6b028c3 Mon Sep 17 00:00:00 2001 From: "jiahua.liu" Date: Thu, 23 Jan 2020 20:01:35 +0800 Subject: [PATCH] Android Protocol - Chatting packet --- .../network/protocol/packet/chat/ChatType.kt | 25 +++++++++++++++ .../packet/{image => chat}/ImagePacket.kt | 31 +++++++++++-------- .../protocol/packet/chat/MessagePacket.kt | 2 ++ .../net/mamoe/mirai/qqandroid/QQAndroidBot.kt | 3 +- 4 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/ChatType.kt rename mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/{image => chat}/ImagePacket.kt (86%) create mode 100644 mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/MessagePacket.kt diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/ChatType.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/ChatType.kt new file mode 100644 index 000000000..14a3de7d5 --- /dev/null +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/ChatType.kt @@ -0,0 +1,25 @@ +package net.mamoe.mirai.qqandroid.network.protocol.packet.chat + +/** + * TROOP仍然不知道是什么 + */ +enum class ChatType(val internalID: Int) { + + FRIEND(2),//可以为任何数字 + + CONTACT(1006), + + //未知,推测为"组" + TROOP(1), + TROOP_HCTOPIC(1026), + + //坦白说 + CONFESS_A(1033), + CONFESS_B(1034), + + CM_GAME_TEMP(1036), + + DISCUSSION(3000), + + DEVICE_MSG(9501), +} \ No newline at end of file diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/image/ImagePacket.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/ImagePacket.kt similarity index 86% rename from mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/image/ImagePacket.kt rename to mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/ImagePacket.kt index 1ac73a47c..c8c448329 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/image/ImagePacket.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/ImagePacket.kt @@ -1,4 +1,4 @@ -package net.mamoe.mirai.qqandroid.network.protocol.packet.image +package net.mamoe.mirai.qqandroid.network.protocol.packet.chat import kotlinx.io.core.ByteReadPacket import kotlinx.serialization.SerialId @@ -23,12 +23,25 @@ internal object ImagePacket : PacketFactory() fun createCmd0x325Packet(req: ImgReq, networkType: Int = 5): Cmd0x352Packet { if (req is UploadImgReq) - return Cmd0x352Packet(1, req, null, null, networkType) + return Cmd0x352Packet( + 1, + req, + null, + null, + networkType + ) if (req is GetImgUrlReq) - return Cmd0x352Packet(2, null, req, null, networkType) + return Cmd0x352Packet( + 2, + null, + req, + null, + networkType + ) error("Unknown ImgReq") } + @Serializable internal class Cmd0x352Packet( @SerialId(1) val subCommand: Int, //2是GetImgUrlReq 1是UploadImgReq @@ -72,7 +85,7 @@ internal object ImagePacket : PacketFactory() @SerialId(2) val dstUni: Int, @SerialId(3) val fileResID: String,//UUID /** - * UUID例子: + * UUID例子: 没有找到 */ @SerialId(4) val urlFlag: Int = 1, //5 unknown, 好像没用 @@ -81,15 +94,7 @@ internal object ImagePacket : PacketFactory() @SerialId(8) val requestPlatformType: Int = 9,//确定 @SerialId(9) val srcFileType: Int = 1,//2=ftn,1=picplatform,255 @SerialId(10) val innerIP: Int = 0,//确定 - @SerialId(11) val addressBook: Int = 0,//chatType == 1006为1 我觉得发0没问题 - /** - * chattype - * 1008时为Troop - * 1 时为? - * 9999时为? - * 1036时为? - * 1006时为? - */ + @SerialId(11) val addressBook: Int = 0,//[ChatType.internalID]== 1006为1[为CONTACT时] 我觉得发0没问题 @SerialId(12) val buType: Int = 1,//确定 @SerialId(13) val buildVer: String = "8.2.0.1296",//版本号 @SerialId(14) val timestamp: Int = currentTimeSeconds.toInt(),//(pic_up_timestamp) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/MessagePacket.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/MessagePacket.kt new file mode 100644 index 000000000..d2a95a391 --- /dev/null +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/MessagePacket.kt @@ -0,0 +1,2 @@ +package net.mamoe.mirai.qqandroid.network.protocol.packet.chat + diff --git a/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt b/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt index e53e85447..d8b33251d 100644 --- a/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt +++ b/mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt @@ -12,4 +12,5 @@ internal actual class QQAndroidBot actual constructor( context: Context, account: BotAccount, configuration: BotConfiguration -) : QQAndroidBotBase(context, account, configuration) \ No newline at end of file +) : QQAndroidBotBase(context, account, configuration) +