Commit 9694ba0c authored by Him188's avatar Him188

Fix `fixToUHex`

parent bd74907f
...@@ -102,7 +102,7 @@ internal object GroupImagePacket : SessionPacketFactory<GroupImageResponse>() { ...@@ -102,7 +102,7 @@ internal object GroupImagePacket : SessionPacketFactory<GroupImageResponse>() {
@SerialId(2) val bot: Int, @SerialId(2) val bot: Int,
@SerialId(3) val const1: Byte = 0, @SerialId(3) val const1: Byte = 0,
@SerialId(4) val md5: ByteArray, @SerialId(4) val md5: ByteArray,
@SerialId(5) val const2: Short = 0x0E2D, @SerialId(5) val const2: Short = 0x0F2D,
@SerialId(6) val const3: ByteArray = constValue3, @SerialId(6) val const3: ByteArray = constValue3,
@SerialId(7) val const4: Byte = 1, @SerialId(7) val const4: Byte = 1,
// 8 is missing // 8 is missing
......
...@@ -103,7 +103,7 @@ internal object GroupPacket : SessionPacketFactory<GroupPacket.GroupPacketRespon ...@@ -103,7 +103,7 @@ internal object GroupPacket : SessionPacketFactory<GroupPacket.GroupPacketRespon
internal interface GroupPacketResponse : Packet internal interface GroupPacketResponse : Packet
@NoLog //@NoLog
internal object MessageResponse : Packet, GroupPacketResponse { internal object MessageResponse : Packet, GroupPacketResponse {
override fun toString(): String = "GroupPacket.MessageResponse" override fun toString(): String = "GroupPacket.MessageResponse"
} }
......
...@@ -11,7 +11,11 @@ import io.ktor.http.content.OutgoingContent ...@@ -11,7 +11,11 @@ import io.ktor.http.content.OutgoingContent
import io.ktor.http.userAgent import io.ktor.http.userAgent
import kotlinx.coroutines.io.ByteWriteChannel import kotlinx.coroutines.io.ByteWriteChannel
import kotlinx.io.core.Input import kotlinx.io.core.Input
import kotlinx.io.core.readAvailable
import kotlinx.io.pool.useInstance
import net.mamoe.mirai.contact.GroupId import net.mamoe.mirai.contact.GroupId
import net.mamoe.mirai.utils.io.ByteArrayPool
import net.mamoe.mirai.utils.io.debugPrint
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
...@@ -32,7 +36,7 @@ internal suspend inline fun HttpClient.postImage( ...@@ -32,7 +36,7 @@ internal suspend inline fun HttpClient.postImage(
parameters["htcmd"] = htcmd parameters["htcmd"] = htcmd
parameters["uin"] = uin.toString() parameters["uin"] = uin.toString()
if (groupId != null) parameters["groupcode"] = groupId.value.toLong().toString() if (groupId != null) parameters["groupcode"] = groupId.value.toString()
parameters["term"] = "pc" parameters["term"] = "pc"
parameters["ver"] = "5603" parameters["ver"] = "5603"
...@@ -41,17 +45,20 @@ internal suspend inline fun HttpClient.postImage( ...@@ -41,17 +45,20 @@ internal suspend inline fun HttpClient.postImage(
parameters["ukey"] = uKeyHex parameters["ukey"] = uKeyHex
userAgent("QQClient") userAgent("QQClient")
buildString().debugPrint("URL")
} }
body = object : OutgoingContent.WriteChannelContent() { body = object : OutgoingContent.WriteChannelContent() {
override val contentType: ContentType = ContentType.Image.PNG override val contentType: ContentType = ContentType.Image.Any
override val contentLength: Long = inputSize override val contentLength: Long = inputSize
override suspend fun writeTo(channel: ByteWriteChannel) { override suspend fun writeTo(channel: ByteWriteChannel) {
val buffer = byteArrayOf(1) ByteArrayPool.useInstance { buffer: ByteArray ->
repeat(contentLength.toInt()) { var size: Int
imageInput.readFully(buffer, 0, 1) while (imageInput.readAvailable(buffer).also { size = it } != 0) {
channel.writeFully(buffer, 0, 1) channel.writeFully(buffer, 0, size)
}
} }
} }
} }
......
...@@ -64,6 +64,9 @@ internal object MemberMuteEventPacketParserAndHandler : KnownEventParserAndHandl ...@@ -64,6 +64,9 @@ internal object MemberMuteEventPacketParserAndHandler : KnownEventParserAndHandl
} }
0x11u -> debugPrintIfFail("解析禁言包(0x02DC)时"){ // 猜测这个失败是撤回?? 0x11u -> debugPrintIfFail("解析禁言包(0x02DC)时"){ // 猜测这个失败是撤回??
// 00 0A 00 04 01 00 00 00 00 0C 00 05 00 01 00 01 01 27 0B 60 E7 11 00 33 08 07 20 E7 C1 AD B8 02 5A 29 08 A6 FE C0 A4 0A 1A 19 08 BC 15 10 C1 95 BC F0 05 18 CA CA 8F DE 04 20 00 28 00 30 A6 FE C0 A4 0A 2A 02 08 00 30 00 38 00
// 失败
discardExact(15) discardExact(15)
discardExact(2) discardExact(2)
val group = bot.getGroup(readQQ()) val group = bot.getGroup(readQQ())
......
...@@ -95,7 +95,7 @@ fun Byte.fixToUHex(): String = this.toUByte().fixToUHex() ...@@ -95,7 +95,7 @@ fun Byte.fixToUHex(): String = this.toUByte().fixToUHex()
/** /**
* 转无符号十六进制表示, 并补充首位 `0`. * 转无符号十六进制表示, 并补充首位 `0`.
*/ */
fun UByte.fixToUHex(): String = if (this.toInt() in 0..9) "0${this.toString(16).toUpperCase()}" else this.toString(16).toUpperCase() fun UByte.fixToUHex(): String = if (this.toInt() in 0..15) "0${this.toString(16).toUpperCase()}" else this.toString(16).toUpperCase()
/** /**
* 将无符号 Hex 转为 [ByteArray], 有根据 hex 的 [hashCode] 建立的缓存. * 将无符号 Hex 转为 [ByteArray], 有根据 hex 的 [hashCode] 建立的缓存.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment