mirror of
https://github.com/MCSManager/MCSManager.git
synced 2025-02-17 15:59:41 +08:00
This commit is contained in:
parent
92438f876a
commit
abb20ad0f1
@ -2,11 +2,23 @@ import Instance from "../instance/instance";
|
||||
import InstanceCommand from "./base/command";
|
||||
|
||||
export default class SendCommand extends InstanceCommand {
|
||||
public static CTRL_C = "\x03";
|
||||
|
||||
constructor(public readonly cmd: string) {
|
||||
super("SendCommand");
|
||||
}
|
||||
|
||||
async exec(instance: Instance) {
|
||||
// If it is "Ctrl+C" or "^c" command, bypass RCON and other command execution behaviors,
|
||||
// send signals directly or write commands directly.
|
||||
if (this.cmd.toLowerCase() === "^c") {
|
||||
instance.process?.kill("SIGINT");
|
||||
return;
|
||||
}
|
||||
if (this.cmd == SendCommand.CTRL_C) {
|
||||
instance.process?.write(SendCommand.CTRL_C);
|
||||
return;
|
||||
}
|
||||
return await instance.execPreset("command", this.cmd);
|
||||
}
|
||||
}
|
||||
|
@ -18,13 +18,7 @@ export default class GeneralStopCommand extends InstanceCommand {
|
||||
|
||||
const stopCommandList = stopCommand.split("\n");
|
||||
for (const stopCommand of stopCommandList) {
|
||||
if (stopCommand.toLowerCase() == "^c") {
|
||||
instance.process.kill("SIGINT");
|
||||
} else if (instance.config.enableRcon) {
|
||||
await instance.exec(new RconCommand(stopCommand));
|
||||
} else {
|
||||
await instance.exec(new SendCommand(stopCommand));
|
||||
}
|
||||
await instance.exec(new SendCommand(stopCommand));
|
||||
}
|
||||
|
||||
instance.print("\n");
|
||||
|
@ -18,11 +18,11 @@ export default class PtyStopCommand extends InstanceCommand {
|
||||
instance.println("INFO", $t("TXT_CODE_pty_stop.execCmd", { stopCommand: stopCommand }));
|
||||
|
||||
const stopCommandList = stopCommand.split("\n");
|
||||
for (const stopCommandColumn of stopCommandList) {
|
||||
if (stopCommandColumn.toLocaleLowerCase() == "^c") {
|
||||
await instance.exec(new SendCommand("\x03"));
|
||||
for (const stopCommand of stopCommandList) {
|
||||
if (stopCommand.toLocaleLowerCase() == "^c") {
|
||||
await instance.exec(new SendCommand(SendCommand.CTRL_C));
|
||||
} else {
|
||||
await instance.exec(new SendCommand(stopCommandColumn));
|
||||
await instance.exec(new SendCommand(stopCommand));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user