2
0
Him188 6 жил өмнө
parent
commit
01ff846929

+ 11 - 10
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/ContactImpl.kt

@@ -118,16 +118,17 @@ internal class QQImpl(
                 }
                 is LongConn.OffPicUp.Response.RequireUpload -> {
                     Http.postImage("0x6ff0070", bot.uin, null, imageInput = image.input, inputSize = image.inputSize, uKeyHex = response.uKey.toUHexString(""))
-//                    HighwayHelper.uploadImage(
-//                        client = bot.client,
-//                        serverIp = response.serverIp[0].toIpV4AddressString(),
-//                        serverPort = response.serverPort[0],
-//                        imageInput = image.input,
-//                        inputSize = image.inputSize.toInt(),
-//                        md5 = image.md5,
-//                        uKey = response.uKey,
-//                        commandId = 1
-//                    )
+                    //HighwayHelper.uploadImage(
+                    //    client = bot.client,
+                    //    serverIp = response.serverIp[0].toIpV4AddressString(),
+                    //    serverPort = response.serverPort[0],
+                    //    imageInput = image.input,
+                    //    inputSize = image.inputSize.toInt(),
+                    //    fileMd5 = image.md5,
+                    //    uKey = response.uKey,
+                    //    commandId = 1
+                    //)
+                    // 为什么不能 ??
 
                     return NotOnlineImageFromFile(
                         filepath = response.resourceId,

+ 1 - 1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt

@@ -112,7 +112,7 @@ internal open class QQAndroidClient(
     private val highwayDataTransSequenceIdForGroup: AtomicInt = atomic(87017)
     internal fun nextHighwayDataTransSequenceIdForGroup(): Int = highwayDataTransSequenceIdForGroup.getAndAdd(2)
 
-    private val highwayDataTransSequenceIdForFriend: AtomicInt = atomic(40717)
+    private val highwayDataTransSequenceIdForFriend: AtomicInt = atomic(43973)
     internal fun nextHighwayDataTransSequenceIdForFriend(): Int = highwayDataTransSequenceIdForFriend.getAndAdd(2)
 
     val appClientVersion: Int = 0

+ 4 - 2
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/HighwayHelper.kt

@@ -72,15 +72,17 @@ internal suspend fun HttpClient.postImage(
                 when (imageInput) {
                     is Input -> {
                         var size: Int
-                        while (imageInput.readAvailable(buffer).also { size = it } != 0) {
+                        while (imageInput.readAvailable(buffer).also { size = it } > 0) {
                             channel.writeFully(buffer, 0, size)
+                            channel.flush()
                         }
                     }
                     is ByteReadChannel -> imageInput.copyAndClose(channel)
                     is InputStream -> {
                         var size: Int
-                        while (imageInput.read(buffer).also { size = it } != 0) {
+                        while (imageInput.read(buffer).also { size = it } > 0) {
                             channel.writeFully(buffer, 0, size)
+                            channel.flush()
                         }
                     }
                     else -> error("unsupported imageInput: ${imageInput::class.simpleName}")

+ 1 - 1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/highway/highway.kt

@@ -69,7 +69,7 @@ internal fun createImageDataPacketSequence( // RequestDataTrans
                     localeId = localId
                 ),
                 msgSeghead = CSDataHighwayHead.SegHead(
-                    cacheAddr = 812157193,
+                 //   cacheAddr = 812157193,
                     datalength = chunkedInput.bufferSize,
                     dataoffset = offset,
                     filesize = dataSize.toLong(),

+ 20 - 20
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/channels.kt

@@ -30,11 +30,11 @@ import kotlin.jvm.JvmName
  */
 suspend fun ByteReadChannel.copyTo(dst: OutputStream) {
     @UseExperimental(MiraiInternalAPI::class)
-    ByteArrayPool.useInstance {
-        do {
-            val size = this.readAvailable(it)
-            dst.write(it, 0, size)
-        } while (size != 0)
+    ByteArrayPool.useInstance { buffer ->
+        var size: Int
+        while (this.readAvailable(buffer).also { size = it } > 0) {
+            dst.write(buffer, 0, size)
+        }
     }
 }
 
@@ -43,11 +43,11 @@ suspend fun ByteReadChannel.copyTo(dst: OutputStream) {
  */
 suspend fun ByteReadChannel.copyTo(dst: Output) {
     @UseExperimental(MiraiInternalAPI::class)
-    ByteArrayPool.useInstance {
-        do {
-            val size = this.readAvailable(it)
-            dst.writeFully(it, 0, size)
-        } while (size != 0)
+    ByteArrayPool.useInstance { buffer ->
+        var size: Int
+        while (this.readAvailable(buffer).also { size = it } > 0) {
+            dst.writeFully(buffer, 0, size)
+        }
     }
 }
 
@@ -75,11 +75,11 @@ suspend fun ByteReadChannel.copyTo(dst: kotlinx.coroutines.io.ByteWriteChannel)
 suspend fun ByteReadChannel.copyAndClose(dst: OutputStream) {
     try {
         @UseExperimental(MiraiInternalAPI::class)
-        ByteArrayPool.useInstance {
-            do {
-                val size = this.readAvailable(it)
-                dst.write(it, 0, size)
-            } while (size != 0)
+        ByteArrayPool.useInstance { buffer ->
+            var size: Int
+            while (this.readAvailable(buffer).also { size = it } > 0) {
+                dst.write(buffer, 0, size)
+            }
         }
     } finally {
         dst.close()
@@ -92,11 +92,11 @@ suspend fun ByteReadChannel.copyAndClose(dst: OutputStream) {
 suspend fun ByteReadChannel.copyAndClose(dst: Output) {
     try {
         @UseExperimental(MiraiInternalAPI::class)
-        ByteArrayPool.useInstance {
-            do {
-                val size = this.readAvailable(it)
-                dst.writeFully(it, 0, size)
-            } while (size != 0)
+        ByteArrayPool.useInstance { buffer ->
+            var size: Int
+            while (this.readAvailable(buffer).also { size = it } > 0) {
+                dst.writeFully(buffer, 0, size)
+            }
         }
     } finally {
         dst.close()