2021-09-16 01:50:44 +02:00
|
|
|
import { ITerminal } from "../ITerminal";
|
2021-09-17 08:58:02 +02:00
|
|
|
import { IRouter } from "../../ui/Router";
|
2021-09-16 01:50:44 +02:00
|
|
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
|
|
|
import { BaseServer } from "../../Server/BaseServer";
|
|
|
|
import { Programs } from "../../Programs/Programs";
|
|
|
|
|
|
|
|
export function runProgram(
|
|
|
|
terminal: ITerminal,
|
2021-09-17 08:58:02 +02:00
|
|
|
router: IRouter,
|
2021-09-16 01:50:44 +02:00
|
|
|
player: IPlayer,
|
|
|
|
server: BaseServer,
|
2021-12-03 20:44:32 +01:00
|
|
|
args: (string | number | boolean)[],
|
2021-09-16 01:50:44 +02:00
|
|
|
): void {
|
|
|
|
if (args.length < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if you have the program on your computer. If you do, execute it, otherwise
|
|
|
|
// display an error message
|
|
|
|
const programName = args[0] + "";
|
|
|
|
|
|
|
|
if (!player.hasProgram(programName)) {
|
2021-12-16 18:20:04 +01:00
|
|
|
terminal.error(
|
|
|
|
`No such (exe, script, js, ns, or cct) file! (Only programs that exist on your home computer or scripts on ${
|
|
|
|
player.getCurrentServer().hostname
|
|
|
|
} can be run)`,
|
|
|
|
);
|
2021-09-16 01:50:44 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const program of Object.values(Programs)) {
|
|
|
|
if (program.name === programName) {
|
|
|
|
program.run(
|
2021-09-18 01:43:08 +02:00
|
|
|
router,
|
2021-09-16 01:50:44 +02:00
|
|
|
terminal,
|
|
|
|
player,
|
|
|
|
server,
|
|
|
|
args.slice(1).map((arg) => arg + ""),
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-27 02:26:05 +02:00
|
|
|
terminal.error("Invalid executable. Cannot be run");
|
2021-09-16 01:50:44 +02:00
|
|
|
}
|