YuMao 2024-10-29 11:40:49 +08:00
parent 92438f876a
commit abb20ad0f1
3 changed files with 17 additions and 11 deletions

View File

@ -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);
}
}

View File

@ -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");

View File

@ -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));
}
}