Commit dd050152 authored by Him188's avatar Him188

Restore ip resolver

parent 048fe647
......@@ -2,6 +2,8 @@
package net.mamoe.mirai.network.protocol.tim
import net.mamoe.mirai.utils.solveIpAddress
object TIMProtocol {
val SERVER_IP: List<String> = {
//add("183.60.56.29")
......@@ -14,7 +16,7 @@ object TIMProtocol {
"sz8.tencent.com",
"sz9.tencent.com",
"sz2.tencent.com"
).forEach { list.add(it) }
).forEach { list.add(solveIpAddress(it)) } // 需 IPv4 地址
list.toList()
}()//不使用lazy, 在初始化时就加载.
......
......@@ -4,32 +4,30 @@ import com.soywiz.klock.TimeSpan
import com.soywiz.klock.seconds
import net.mamoe.mirai.network.protocol.tim.packet.login.TouchResponsePacket
import kotlin.jvm.JvmField
import kotlin.jvm.JvmOverloads
/**
* 网络和连接配置
*/
class BotNetworkConfiguration @JvmOverloads constructor(
class BotNetworkConfiguration {
/**
* 等待 [TouchResponsePacket] 的时间
*/
var touchTimeout: TimeSpan = 2.seconds,
var touchTimeout: TimeSpan = 2.seconds
/**
* 是否使用随机的设备名.
* 使用随机可以降低被封禁的风险, 但可能导致每次登录都需要输入验证码
* 当一台设备只登录少量账号时, 将此项设置为 `true` 可能更好.
*/
var randomDeviceName: Boolean = false,
var randomDeviceName: Boolean = false
/**
* 心跳周期. 过长会导致被服务器断开连接.
*/
var heartbeatPeriod: TimeSpan = 60.seconds,
var heartbeatPeriod: TimeSpan = 60.seconds
/**
* 每次心跳时等待结果的时间.
* 一旦心跳超时, 整个网络服务将会重启 (将消耗约 1s). 除正在进行的任务 (如图片上传) 会被中断外, 事件和插件均不受影响.
*/
var heartbeatTimeout: TimeSpan = 2.seconds
) {
companion object {
/**
......
......@@ -30,6 +30,11 @@ expect fun crc32(key: ByteArray): Int
*/
expect fun md5(byteArray: ByteArray): ByteArray
/**
* hostname 解析 ipv4
*/
expect fun solveIpAddress(hostname: String): String
/**
* Localhost 解析
*/
......
......@@ -51,7 +51,7 @@ fun DataInput.md5(): ByteArray {
return digest.digest()
}
//actual fun solveIpAddress(hostname: String): String = InetAddress.getByName(hostname).hostAddress
actual fun solveIpAddress(hostname: String): String = InetAddress.getByName(hostname).hostAddress
actual fun localIpAddress(): String = InetAddress.getLocalHost().hostAddress
......
......@@ -17,6 +17,8 @@ actual class PlatformDatagramChannel actual constructor(serverHost: String, serv
actual suspend fun read(buffer: IoBuffer) = withContext(Dispatchers.IO) {
try {
(channel as ReadableByteChannel).read(buffer)
} catch (e: ClosedChannelException) {
throw e
} catch (e: Throwable) {
throw ReadPacketInternalException(e)
}
......
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