Shamrock: 修复服务器TLS异常

Signed-off-by: 白池 <whitechi73@outlook.com>
This commit is contained in:
白池 2024-03-10 07:57:23 +08:00
parent 638bf72392
commit 1afc0ac6a6
4 changed files with 20 additions and 6 deletions

View File

@ -1,6 +1,8 @@
@file:OptIn(ExperimentalCoroutinesApi::class)
package kritor.server
import io.grpc.Grpc
import io.grpc.InsecureServerCredentials
import io.grpc.ServerBuilder
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -13,8 +15,7 @@ import kotlin.coroutines.CoroutineContext
class KritorServer(
private val port: Int
): CoroutineScope {
private val server = ServerBuilder
.forPort(port)
private val server = Grpc.newServerBuilderForPort(port, InsecureServerCredentials.create())
.addService(Authentication)
.build()!!

View File

@ -14,6 +14,7 @@ private val configFile = configDir.resolve("config.prop")
private val configKeys = setOf(
ActiveRPC,
AntiJvmTrace,
ForceTablet,
PassiveRPC,
ResourceGroup,

View File

@ -11,6 +11,8 @@ import moe.fuqiuluo.shamrock.config.ActiveRPC
import moe.fuqiuluo.shamrock.config.RPCPort
import moe.fuqiuluo.shamrock.config.ShamrockConfig
import moe.fuqiuluo.shamrock.config.get
import moe.fuqiuluo.shamrock.helper.Level
import moe.fuqiuluo.shamrock.helper.LogCenter
import moe.fuqiuluo.symbols.Process
import moe.fuqiuluo.symbols.XposedHook
@ -20,9 +22,19 @@ private lateinit var server: KritorServer
internal class InitRemoteService : IAction {
override fun invoke(ctx: Context) {
GlobalScope.launch {
if (ActiveRPC.get() && !::server.isInitialized) {
server = KritorServer(RPCPort.get())
server.start()
runCatching {
if (ActiveRPC.get()) {
if (!::server.isInitialized) {
server = KritorServer(RPCPort.get())
server.start()
}
} else {
LogCenter.log("ActiveRPC is disabled, KritorServer will not be started.")
}
}.onFailure {
LogCenter.log("Start RPC failed: ${it.message}", Level.ERROR)
}
}
}

View File

@ -48,7 +48,7 @@ internal object MSFHandler {
fun onResp(toServiceMsg: ToServiceMsg, fromServiceMsg: FromServiceMsg) {
runCatching {
val cmd = toServiceMsg.getAttribute("__respkey") as? Int?
val cmd = toServiceMsg.getAttribute("shamrock_uid") as? Int?
?: return@runCatching
val resp = mRespHandler[cmd]
resp?.invoke(toServiceMsg, fromServiceMsg)