MCSManager/core/procexit.js
2020-10-12 12:28:21 +08:00

34 lines
876 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// MCserver Manger 程序退出
const serverModel = require("../model/ServerModel");
const userModel = require("../model/UserModel");
const counter = require("./counter");
let _endFlag = false;
process.on("SIGINT", function () {
if (_endFlag) return;
_endFlag = true;
MCSERVER.infoLog("PROCESS", "控制面板正在结束与回收资源,请稍等...");
// 保存
counter.save();
serverModel.ServerManager().saveAllMinecraftServer();
userModel.userCenter().saveAllUser();
// 关闭所有服务器
let servers = serverModel.ServerManager().getServerObjects();
for (let k in servers) {
let server = servers[k];
try {
server.stopServer();
} catch (serverErr) {
continue;
}
}
// 异步等待3秒控制面板自动结束
setTimeout(() => {
MCSERVER.infoLog("PROCESS", "EXIT...");
process.exit(0);
}, 3000);
});