Commit b479a213 authored by Him188's avatar Him188

Add heartbeat

parent 7d5543eb
...@@ -156,6 +156,7 @@ internal inline fun BytePacketBuilder.writeUniPacket( ...@@ -156,6 +156,7 @@ internal inline fun BytePacketBuilder.writeUniPacket(
writeIntLVPacket(lengthOffset = { it + 4 }, builder = body) writeIntLVPacket(lengthOffset = { it + 4 }, builder = body)
} }
internal val NO_ENCRYPT: ByteArray = ByteArray(0)
/** /**
* com.tencent.qphone.base.util.CodecWarpper#encodeRequest(int, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, byte[], int, int, java.lang.String, byte, byte, byte, byte[], byte[], boolean) * com.tencent.qphone.base.util.CodecWarpper#encodeRequest(int, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, byte[], int, int, java.lang.String, byte, byte, byte, byte[], byte[], boolean)
...@@ -187,8 +188,10 @@ internal inline fun OutgoingPacketFactory<*>.buildLoginOutgoingPacket( ...@@ -187,8 +188,10 @@ internal inline fun OutgoingPacketFactory<*>.buildLoginOutgoingPacket(
writeStringUtf8(it) writeStringUtf8(it)
} }
encryptAndWrite(key) { if (key === NO_ENCRYPT) {
body(sequenceId) body(sequenceId)
} else {
encryptAndWrite(key) { body(sequenceId) }
} }
} }
}) })
...@@ -206,6 +209,23 @@ internal inline fun BytePacketBuilder.writeSsoPacket( ...@@ -206,6 +209,23 @@ internal inline fun BytePacketBuilder.writeSsoPacket(
sequenceId: Int, sequenceId: Int,
body: BytePacketBuilder.() -> Unit body: BytePacketBuilder.() -> Unit
) { ) {
/* send
* 00 00 00 78
* 00 00 94 90
* 20 02 ED BD
* 20 02 ED BD
* 01 00 00 00 00 00 00 00 00 00 01 00
* 00 00 00 04
* 00 00 00 13 48 65 61 72 74 62 65 61 74 2E 41 6C 69 76 65
* 00 00 00 08 59 E7 DF 4F
* 00 00 00 13 38 36 35 31 36 36 30 32 36 34 34 36 39 32 35
* 00 00 00 04
* 00 22 7C 34 36 30 30 30 31 39 31 39 38 37 36 30 32 36 7C 41 38 2E 32 2E 30 2E 32 37 66 36 65 61 39 36
* 00 00 00 04
*
* 00 00 00 04
*/
writeIntLVPacket(lengthOffset = { it + 4 }) { writeIntLVPacket(lengthOffset = { it + 4 }) {
writeInt(sequenceId) writeInt(sequenceId)
writeInt(subAppId.toInt()) writeInt(subAppId.toInt())
......
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package net.mamoe.mirai.qqandroid.network.protocol.packet.login
import kotlinx.io.core.ByteReadPacket
import net.mamoe.mirai.data.Packet
import net.mamoe.mirai.qqandroid.QQAndroidBot
import net.mamoe.mirai.qqandroid.network.QQAndroidClient
import net.mamoe.mirai.qqandroid.network.protocol.packet.*
internal class Heartbeat {
object Alive : OutgoingPacketFactory<Alive.Response>("Heartbeat.Alive") {
object Response : Packet
operator fun invoke(
client: QQAndroidClient
): OutgoingPacket = buildLoginOutgoingPacket(client, 0, key = NO_ENCRYPT) {
writeSsoPacket(client, 537062845, commandName, sequenceId = it) {
}
}
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): Response {
return Response
}
}
}
\ No newline at end of file
...@@ -62,7 +62,7 @@ class BotConfiguration { ...@@ -62,7 +62,7 @@ class BotConfiguration {
/** /**
* 心跳周期. 过长会导致被服务器断开连接. * 心跳周期. 过长会导致被服务器断开连接.
*/ */
var heartbeatPeriodMillis: Long = 300.secondsToMillis var heartbeatPeriodMillis: Long = 30.secondsToMillis
/** /**
* 每次心跳时等待结果的时间. * 每次心跳时等待结果的时间.
* 一旦心跳超时, 整个网络服务将会重启 (将消耗约 5s). 除正在进行的任务 (如图片上传) 会被中断外, 事件和插件均不受影响. * 一旦心跳超时, 整个网络服务将会重启 (将消耗约 5s). 除正在进行的任务 (如图片上传) 会被中断外, 事件和插件均不受影响.
......
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