From a14d2a2e9ad56aeab50b71cd434d12fdca6f75ee Mon Sep 17 00:00:00 2001 From: keywet06 Date: Wed, 23 Jun 2021 09:15:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 16 ++++++++++++++ core/Process/Mcserver.js | 1 + public/template/component/console.html | 29 +++++++++++++++++++++++--- route/websocket/console/server-mask.js | 17 +++++++++++++++ 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index a43438d..0ff7aec 100644 --- a/app.js +++ b/app.js @@ -282,6 +282,22 @@ app.use("/fs", require("./onlinefs/controller/function")); if (MCSERVER.allError <= 0) { MCSERVER.infoLog("INFO", "控制面板已经启动"); + // 异步等待3秒,打开已配置打开 MCSM 时自启的服务器 + setTimeout(() => { + var serverModel = require("./model/ServerModel"); + let servers = serverModel.ServerManager().getServerObjects(); + for (let k in servers) { + try { + let server = servers[k]; + if (server.dataModel.autoStart) { + server.start(); + } + } catch (serverErr) { + MCSERVER.error("自动开启某服务器失败:", serverErr); + continue; + } + } + }, 3000); } else { MCSERVER.infoLog("INFO", "控制面板启动异常"); } diff --git a/core/Process/Mcserver.js b/core/Process/Mcserver.js index 70b46c4..8678014 100644 --- a/core/Process/Mcserver.js +++ b/core/Process/Mcserver.js @@ -24,6 +24,7 @@ class MinecraftServer extends ServerProcess { this.dataModel.oe = SYSTEM_CODE; this.dataModel.autoRestart = false; //是否自动重启 + this.dataModel.autoStart = false; //是否自动启动 this.dataModel.schedule = []; //计划任务配置项目 this.properties = undefined; //服务端配置表 diff --git a/public/template/component/console.html b/public/template/component/console.html index c0eae03..cc61c9b 100644 --- a/public/template/component/console.html +++ b/public/template/component/console.html @@ -78,6 +78,25 @@ +
+
启动设置
+
+ +
+ + 服务器自启: + 打开 +
+
+ +
+ + 服务器自启: + 关闭 +
+
+
+
FTP 链接信息
@@ -117,7 +136,8 @@
服务端控制组
-
+
@@ -199,6 +219,9 @@ toAutoRestart: function () { WS.sendMsg("server/console/autorestart", serverName); }, + toAutoStart: function () { + WS.sendMsg("server/console/autostart", serverName); + }, toOnlineFs: function () { var path = MCSERVER.URL("fs_auth/auth/" + encodeURIComponent(serverName)); window.open(path); @@ -256,7 +279,7 @@ username: MCSERVER.listenServername }, watch: { - run: function (cur, old) {} + run: function (cur, old) { } } }); @@ -324,4 +347,4 @@ MI.onDestroy("resize", PAGE.chartResizeFunc); PAGE.ChartLogIs = false; }); - + \ No newline at end of file diff --git a/route/websocket/console/server-mask.js b/route/websocket/console/server-mask.js index fe42177..f866909 100644 --- a/route/websocket/console/server-mask.js +++ b/route/websocket/console/server-mask.js @@ -20,3 +20,20 @@ WebSocketObserver().listener("server/console/autorestart", (data) => { } response.wsMsgWindow(data.ws, "权限不足!您并不拥有此服务器."); }); +//自动启动设定 +WebSocketObserver().listener("server/console/autostart", (data) => { + let serverName = data.body.trim(); + let userName = data.WsSession.username; + if (permssion.isCanServer(userName, serverName)) { + let server = serverModel.ServerManager().getServer(serverName); + server.dataModel.autoStart = !server.dataModel.autoStart; //同上 + try { + server.save(); + response.wsMsgWindow(data.ws, "更改设置成功!"); + } catch (err) { + response.wsMsgWindow(data.ws, "更改设置失败!不正常,请刷新网页重新设置!"); + } + return; + } + response.wsMsgWindow(data.ws, "权限不足!您并不拥有此服务器."); +});