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

View File

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

View File

@ -11,6 +11,8 @@ import moe.fuqiuluo.shamrock.config.ActiveRPC
import moe.fuqiuluo.shamrock.config.RPCPort import moe.fuqiuluo.shamrock.config.RPCPort
import moe.fuqiuluo.shamrock.config.ShamrockConfig import moe.fuqiuluo.shamrock.config.ShamrockConfig
import moe.fuqiuluo.shamrock.config.get 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.Process
import moe.fuqiuluo.symbols.XposedHook import moe.fuqiuluo.symbols.XposedHook
@ -20,9 +22,19 @@ private lateinit var server: KritorServer
internal class InitRemoteService : IAction { internal class InitRemoteService : IAction {
override fun invoke(ctx: Context) { override fun invoke(ctx: Context) {
GlobalScope.launch { GlobalScope.launch {
if (ActiveRPC.get() && !::server.isInitialized) { runCatching {
server = KritorServer(RPCPort.get()) if (ActiveRPC.get()) {
server.start() 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) { fun onResp(toServiceMsg: ToServiceMsg, fromServiceMsg: FromServiceMsg) {
runCatching { runCatching {
val cmd = toServiceMsg.getAttribute("__respkey") as? Int? val cmd = toServiceMsg.getAttribute("shamrock_uid") as? Int?
?: return@runCatching ?: return@runCatching
val resp = mRespHandler[cmd] val resp = mRespHandler[cmd]
resp?.invoke(toServiceMsg, fromServiceMsg) resp?.invoke(toServiceMsg, fromServiceMsg)