From bc57001e368ed92c3e86233d42b155112784c0e6 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Oct 2019 21:37:34 +0800 Subject: [PATCH] Image uploading --- .../network/protocol/tim/TIMBotNetworkHandler.kt | 10 +++++----- .../network/protocol/tim/packet/UploadFriendImage.kt | 2 +- .../network/protocol/tim/packet/UploadGroupImage.kt | 6 +++--- .../kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt index 0df5f70c7..9abf79f97 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/TIMBotNetworkHandler.kt @@ -182,6 +182,11 @@ internal class TIMBotNetworkHandler internal constructor(private val bot: Bot) : } packet.use { + val name = packet::class.simpleName + if (name != null && !name.endsWith("Encrypted") && !name.endsWith("Raw")) { + bot.logCyan("Packet received: $packet") + } + //coz removeIf is not inline handlersLock.withLock { temporaryPacketHandlers.removeIfInlined { @@ -189,11 +194,6 @@ internal class TIMBotNetworkHandler internal constructor(private val bot: Bot) : } } - val name = packet::class.simpleName - if (name != null && !name.endsWith("Encrypted") && !name.endsWith("Raw")) { - bot.logCyan("Packet received: $packet") - } - if (packet is ServerEventPacket) { //no need to sync acknowledgement packets NetworkScope.launch { diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadFriendImage.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadFriendImage.kt index 53d7bea0c..7444bf9a5 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadFriendImage.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadFriendImage.kt @@ -16,7 +16,7 @@ import net.mamoe.mirai.utils.* */ suspend fun QQ.uploadImage(image: PlatformImage): ImageId = with(bot.network.session) { //SubmitImageFilenamePacket(account, account, "sdiovaoidsa.png", sessionKey).sendAndExpect().join() - + DebugLogger.logPurple("正在上传好友图片, md5=${image.md5.toUHexString()}") return FriendImageIdRequestPacket(account, sessionKey, account, image).sendAndExpect { if (it.uKey != null) { require(httpPostFriendImage( diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadGroupImage.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadGroupImage.kt index 55f10a0af..6ca87ae97 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadGroupImage.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/network/protocol/tim/packet/UploadGroupImage.kt @@ -195,11 +195,11 @@ class GroupImageIdRequestPacket( //if (readUByte() != UByte.MIN_VALUE) { //服务器还没有 - discardExact(remaining - 128) - uKey = readBytes(128) + discardExact(remaining - 128 - 14) + uKey = readBytes(128) //} else { // println("服务器已经有了这个图片") - // println("后文 = ${readRemainingBytes().toUHexString()}") + //println("后文 = ${readRemainingBytes().toUHexString()}") //} diff --git a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt index 4fe0fa1c5..1221817c3 100644 --- a/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt +++ b/mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/PlatformUtilsJvm.kt @@ -73,7 +73,7 @@ actual suspend fun httpPostFriendImage( "&range=" + "0" + "&uin=" + botNumber.toLong()).openConnection() as HttpURLConnection conn.setRequestProperty("User-Agent", "QQClient") - conn.setRequestProperty("Content-Length", "" + fileSize) + conn.setRequestProperty("Content-Length", imageData.toString()) conn.setRequestProperty("Connection", "Keep-Alive") conn.requestMethod = "POST" conn.doOutput = true @@ -98,7 +98,7 @@ actual suspend fun httpPostGroupImage(uKeyHex: String, fileSize: Long, imageData "&term=pc" + "&ver=5603" + "&ukey=" + uKeyHex.replace(" ", "")).openConnection() as HttpURLConnection - conn.setRequestProperty("Content-Length", fileSize.toString()) + conn.setRequestProperty("Content-Length", imageData.remaining.toString()) conn.setRequestProperty("Connection", "Keep-Alive") conn.requestMethod = "POST" conn.doOutput = true