forked from mirror/MCSM-Daemon
Feat: restart & command i18n
This commit is contained in:
parent
813d9b1f72
commit
ed0b33ac6f
@ -1,3 +1,4 @@
|
||||
import { $t } from "../../../i18n";
|
||||
// Copyright (C) 2022 MCSManager Team <mcsmanager-dev@outlook.com>
|
||||
|
||||
import Instance from "../../instance/instance";
|
||||
@ -12,7 +13,7 @@ export default class GeneralSendCommand extends InstanceCommand {
|
||||
async exec(instance: Instance, buf?: any): Promise<any> {
|
||||
// 关服命令需要发送命令,但关服命令执行前会设置状态为关闭中状态。
|
||||
// 所以这里只能通过进程是否存在来执行命令
|
||||
if (!instance.process) instance.failure(new Error("命令执行失败,因为实例实际进程不存在."));
|
||||
if (!instance.process) instance.failure(new Error($t("command.instanceNotOpen")));
|
||||
// instance.process.write(buf);
|
||||
instance.process.write(encode(buf, instance.config.oe));
|
||||
if (instance.config.crlf === 2) return instance.process.write("\r\n");
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Copyright (C) 2022 MCSManager Team <mcsmanager-dev@outlook.com>
|
||||
|
||||
import { $t } from "../../../i18n";
|
||||
import Instance from "../../instance/instance";
|
||||
import InstanceCommand from "../base/command";
|
||||
|
||||
@ -10,7 +10,7 @@ export default class GeneralRestartCommand extends InstanceCommand {
|
||||
|
||||
async exec(instance: Instance) {
|
||||
try {
|
||||
instance.println("INFO", "重启实例计划开始执行...");
|
||||
instance.println("INFO", $t("restart.start"));
|
||||
await instance.execPreset("stop");
|
||||
instance.setLock(true);
|
||||
const startCount = instance.startCount;
|
||||
@ -18,13 +18,13 @@ export default class GeneralRestartCommand extends InstanceCommand {
|
||||
const task = setInterval(async () => {
|
||||
try {
|
||||
if (startCount !== instance.startCount) {
|
||||
throw new Error("重启实例状态错误,实例已被启动过,上次状态的重启计划取消");
|
||||
throw new Error($t("restart.error1"));
|
||||
}
|
||||
if (instance.status() !== Instance.STATUS_STOPPING && instance.status() !== Instance.STATUS_STOP) {
|
||||
throw new Error("重启实例状态错误,实例状态应该为停止中状态,现在变为正在运行,重启计划取消");
|
||||
throw new Error($t("restart.error2"));
|
||||
}
|
||||
if (instance.status() === Instance.STATUS_STOP) {
|
||||
instance.println("INFO", "检测到服务器已停止,正在重启实例...");
|
||||
instance.println("INFO", $t("restart.restarting"));
|
||||
await instance.execPreset("start");
|
||||
instance.setLock(false);
|
||||
clearInterval(task);
|
||||
|
@ -27,7 +27,14 @@ export default {
|
||||
},
|
||||
command: {
|
||||
quotes: "错误的命令双引号,无法找到成对双引号,如需使用单个双引号请使用 {quotes} 符号",
|
||||
errLen: "错误的命令长度,请确保命令格式正确"
|
||||
errLen: "错误的命令长度,请确保命令格式正确",
|
||||
instanceNotOpen: "命令执行失败,因为实例实际进程不存在"
|
||||
},
|
||||
restart: {
|
||||
start: "重启实例计划开始执行",
|
||||
error1: "重启实例状态错误,实例已被启动过,上次状态的重启计划取消",
|
||||
error2: "重启实例状态错误,实例状态应该为停止中状态,现在变为正在运行,重启计划取消",
|
||||
restarting: "检测到服务器已停止,正在重启实例..."
|
||||
}
|
||||
};
|
||||
// import { $t } from "../../i18n";
|
||||
|
Loading…
Reference in New Issue
Block a user