Merge pull request #436 from keywet06/master

增加 自动启动功能
This commit is contained in:
Suwings 2021-06-23 09:47:58 +08:00 committed by GitHub
commit add64b8d44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 3 deletions

16
app.js
View File

@ -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", "控制面板启动异常");
}

View File

@ -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; //服务端配置表

View File

@ -78,6 +78,25 @@
</transition>
</div>
</div>
<div class="Panel" :class="serverData.autoStart?'PanelGreen':'PanelGray'">
<div class="PanelTitle">启动设置</div>
<div class="PanelBody">
<transition name="slide-fade">
<div class="PanelItem" v-on:click="toAutoStart(false)" v-show="serverData.autoStart">
<span class="glyphicon glyphicon-retweet" aria-hidden="true"> </span>
服务器自启:
<span style="color: #29b90c">打开</span>
</div>
</transition>
<transition name="slide-fade">
<div class="PanelItem" v-on:click="toAutoStart(true)" v-show="!serverData.autoStart">
<span class="glyphicon glyphicon-retweet" aria-hidden="true"> </span>
服务器自启:
<span style="color: #818181">关闭</span>
</div>
</transition>
</div>
</div>
<div class="Panel PanelGray" v-if="isFtpOpen">
<div class="PanelTitle">FTP 链接信息</div>
<div class="PanelBody">
@ -117,7 +136,8 @@
<div class="PanelTitle">服务端控制组</div>
<div class="PanelBody">
<div class="row">
<div class="col-md-3 col-sm-6" v-on:click="RES.redirectPage('./template/component/terminal.html', null, '')">
<div class="col-md-3 col-sm-6"
v-on:click="RES.redirectPage('./template/component/terminal.html', null, '')">
<div class="PanelItemBlock">
<div class="LogV">
<span class="glyphicon glyphicon-console" aria-hidden="true"> </span>
@ -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;
});
</script>
</script>

View File

@ -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, "权限不足!您并不拥有此服务器.");
});