Skip to content

Commit

Permalink
feat: REQUEST_TOKEN_INTERVAL
Browse files Browse the repository at this point in the history
  • Loading branch information
cssxsh committed Jul 13, 2023
1 parent ea98c78 commit 90328a1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@

## JVM 参数

| property | default | desc |
|:-----------------------------------------------|:----------------|:---------------------------:|
| `xyz.cssxsh.mirai.tool.KFCFactory.config` | KFCFactory.json | KFCFactory config file path |
| `xyz.cssxsh.mirai.tool.ViVo50.Session.timeout` | 60000 | Session except timeout (ms) |
| property | default | desc |
|:--------------------------------------------------------|:----------------|:--------------------------------:|
| `xyz.cssxsh.mirai.tool.KFCFactory.config` | KFCFactory.json | KFCFactory config file path |
| `xyz.cssxsh.mirai.tool.ViVo50.Session.timeout` | 60000 | Session except timeout (ms) |
| `xyz.cssxsh.mirai.tool.UnidbgFetchQsign.token.interval` | 2400000 | RequestToken interval, 0 is stop |

以上参数在 `1.9.5` 中加入

Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/xyz/cssxsh/mirai/tool/KFCFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public class KFCFactory(private val config: File) : EncryptService.Factory {
when (val type = server.type.ifEmpty { throw IllegalArgumentException("need server type") }) {
"fuqiuluo/unidbg-fetch-qsign", "fuqiuluo", "unidbg-fetch-qsign" -> {
try {
URL(server.base).openConnection().connect()
val about = URL(server.base).readText()
if ("version" !in about) {
// 低于等于 1.1.3 的的版本 requestToken 不工作
System.setProperty(UnidbgFetchQsign.REQUEST_TOKEN_INTERVAL, "0")
}
} catch (cause: ConnectException) {
throw RuntimeException("请检查 unidbg-fetch-qsign by ${server.base} 的可用性", cause)
}
Expand Down
16 changes: 15 additions & 1 deletion src/main/kotlin/xyz/cssxsh/mirai/tool/UnidbgFetchQsign.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,18 @@ public class UnidbgFetchQsign(private val server: String, private val key: Strin
if (commandName == "StatSvc.register") {
if (!token.get() && token.compareAndSet(false, true)) {
launch(CoroutineName("RequestToken")) {
// requestToken(uin = context.id)
while (isActive) {
val interval = System.getProperty(REQUEST_TOKEN_INTERVAL, "2400000").toLong()
if (interval == 0L) break
delay(interval)
val request = try {
requestToken(uin = context.id)
} catch (cause: Throwable) {
logger.error(cause)
continue
}
callback(uin = context.id, request = request)
}
}
}
}
Expand Down Expand Up @@ -189,6 +200,9 @@ public class UnidbgFetchQsign(private val server: String, private val key: Strin

@JvmStatic
internal val logger: MiraiLogger = MiraiLogger.Factory.create(UnidbgFetchQsign::class)

@JvmStatic
public val REQUEST_TOKEN_INTERVAL: String = "xyz.cssxsh.mirai.tool.UnidbgFetchQsign.token.interval"
}
}

Expand Down

0 comments on commit 90328a1

Please sign in to comment.