Shamrock: Allow modification of active WebSocket listening address

Signed-off-by: WhiteChi <whitechi73@outlook.com>
This commit is contained in:
WhiteChi 2023-11-02 08:05:16 +08:00
parent c67b49790f
commit b76ef7efb3
4 changed files with 17 additions and 6 deletions

View File

@ -21,7 +21,7 @@ import org.java_websocket.WebSocket
import org.java_websocket.handshake.ClientHandshake
import java.net.URI
internal class WebSocketService(port: Int): WebSocketTransmitServlet(port) {
internal class WebSocketService(host: String, port: Int): WebSocketTransmitServlet(host, port) {
private val eventJobList = mutableSetOf<Job>()
override fun submitFlowJob(job: Job) {

View File

@ -32,8 +32,9 @@ import java.util.Collections
import kotlin.concurrent.timer
internal abstract class WebSocketTransmitServlet(
host:String,
port: Int
) : BaseTransmitServlet, WebSocketServer(InetSocketAddress(port)) {
) : BaseTransmitServlet, WebSocketServer(InetSocketAddress(host, port)) {
protected val eventReceivers: MutableList<WebSocket> = Collections.synchronizedList(mutableListOf<WebSocket>())
override val address: String

View File

@ -118,9 +118,9 @@ internal class XposedEntry: IXposedHookLoadPackage {
log("Process Name = " + MobileQQ.getMobileQQ().qqProcessName.apply {
// if (!contains("msf", ignoreCase = true)) return // 非MSF进程 退出
if (contains("peak")) {
PlatformUtils.killProcess(ctx, this)
}
//if (contains("peak")) {
// PlatformUtils.killProcess(ctx, this)
//}
})
PlatformUtils.isTim()

View File

@ -70,7 +70,17 @@ internal class InitRemoteService : IAction {
private fun startWebSocketServer() {
GlobalScope.launch {
try {
val server = WebSocketService(ShamrockConfig.getActiveWebSocketConfig()?.port ?: 5700)
val config = ShamrockConfig.getActiveWebSocketConfig() ?: return@launch
config.address ?: kotlin.run {
LogCenter.log("WebSocketServer地址不合法", Level.ERROR)
return@launch
}
config.port ?: kotlin.run {
LogCenter.log("WebSocketServer端口不合法", Level.ERROR)
return@launch
}
require(config.port in 0 .. 65536) { "WebSocketServer端口不合法" }
val server = WebSocketService(config.address, config.port!!)
server.start()
} catch (e: Throwable) {
LogCenter.log(e.stackTraceToString(), Level.ERROR)