remove last colon any for now

This commit is contained in:
Olivier Gagnon 2022-07-20 01:48:54 -04:00
parent 0e74b1a5d6
commit 49f6fda1e4
6 changed files with 27 additions and 38 deletions

@ -15,52 +15,43 @@ import { dialogBoxCreate } from "../ui/React/DialogBox";
import { AddRecentScript } from "./RecentScripts";
import { Player } from "../Player";
export function killWorkerScript(runningScriptObj: RunningScript, hostname: string, rerenderUi?: boolean): boolean;
export function killWorkerScript(workerScript: WorkerScript): boolean;
export function killWorkerScript(pid: number): boolean;
export function killWorkerScript(
script: RunningScript | WorkerScript | number,
hostname?: string,
rerenderUi?: boolean,
): boolean {
if (rerenderUi == null || typeof rerenderUi !== "boolean") {
rerenderUi = true;
}
export type killScriptParams = WorkerScript | number | { runningScript: RunningScript; hostname: string };
if (script instanceof WorkerScript) {
stopAndCleanUpWorkerScript(script);
export function killWorkerScript(params: killScriptParams): boolean {
if (params instanceof WorkerScript) {
stopAndCleanUpWorkerScript(params);
return true;
} else if (script instanceof RunningScript && typeof hostname === "string") {
} else if (typeof params === "number") {
return killWorkerScriptByPid(params);
} else {
// Try to kill by PID
const res = killWorkerScriptByPid(script.pid, rerenderUi);
const res = killWorkerScriptByPid(params.runningScript.pid);
if (res) {
return res;
}
// If for some reason that doesn't work, we'll try the old way
for (const ws of workerScripts.values()) {
if (ws.name == script.filename && ws.hostname == hostname && compareArrays(ws.args, script.args)) {
stopAndCleanUpWorkerScript(ws, rerenderUi);
if (
ws.name == params.runningScript.filename &&
ws.hostname == params.hostname &&
compareArrays(ws.args, params.runningScript.args)
) {
stopAndCleanUpWorkerScript(ws);
return true;
}
}
return false;
} else if (typeof script === "number") {
return killWorkerScriptByPid(script, rerenderUi);
} else {
console.error(`killWorkerScript() called with invalid argument:`);
console.error(script);
return false;
}
}
function killWorkerScriptByPid(pid: number, rerenderUi = true): boolean {
function killWorkerScriptByPid(pid: number): boolean {
const ws = workerScripts.get(pid);
if (ws instanceof WorkerScript) {
stopAndCleanUpWorkerScript(ws, rerenderUi);
stopAndCleanUpWorkerScript(ws);
return true;
}
@ -68,7 +59,7 @@ function killWorkerScriptByPid(pid: number, rerenderUi = true): boolean {
return false;
}
function stopAndCleanUpWorkerScript(workerScript: WorkerScript, rerenderUi = true): void {
function stopAndCleanUpWorkerScript(workerScript: WorkerScript): void {
if (typeof workerScript.atExit === "function") {
try {
workerScript.atExit();
@ -83,7 +74,7 @@ function stopAndCleanUpWorkerScript(workerScript: WorkerScript, rerenderUi = tru
}
workerScript.env.stopFlag = true;
killNetscriptDelay(workerScript);
removeWorkerScript(workerScript, rerenderUi);
removeWorkerScript(workerScript);
}
/**
@ -93,7 +84,7 @@ function stopAndCleanUpWorkerScript(workerScript: WorkerScript, rerenderUi = tru
* @param {WorkerScript} - Identifier for WorkerScript. Either the object itself, or
* its index in the global workerScripts array
*/
function removeWorkerScript(workerScript: WorkerScript, rerenderUi = true): void {
function removeWorkerScript(workerScript: WorkerScript): void {
const ip = workerScript.hostname;
const name = workerScript.name;
@ -127,9 +118,7 @@ function removeWorkerScript(workerScript: WorkerScript, rerenderUi = true): void
// }
AddRecentScript(workerScript);
if (rerenderUi) {
WorkerScriptStartStopEventEmitter.emit();
}
}
/**

@ -1315,7 +1315,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
return false;
}
res = killWorkerScript(runningScriptObj, server.hostname);
res = killWorkerScript({ runningScript: runningScriptObj, hostname: server.hostname });
}
if (res) {
@ -1348,7 +1348,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
for (let i = server.runningScripts.length - 1; i >= 0; --i) {
if (safetyguard === true && server.runningScripts[i].pid == workerScript.pid) continue;
killWorkerScript(server.runningScripts[i], server.hostname, false);
killWorkerScript({ runningScript: server.runningScripts[i], hostname: server.hostname });
++scriptsKilled;
}
WorkerScriptStartStopEventEmitter.emit();
@ -2241,7 +2241,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
let suc = false;
for (let i = 0; i < server.runningScripts.length; i++) {
if (server.runningScripts[i].filename == scriptname) {
killWorkerScript(server.runningScripts[i], server.hostname);
killWorkerScript({ runningScript: server.runningScripts[i], hostname: server.hostname });
suc = true;
i--;
}

@ -39,7 +39,7 @@ export function kill(
terminal.error("No such script is running. Nothing to kill");
return;
}
killWorkerScript(runningScript, server.hostname, false);
killWorkerScript({ runningScript: runningScript, hostname: server.hostname });
terminal.print(`Killing ${scriptName}`);
} catch (e) {
terminal.error(e + "");

@ -7,7 +7,7 @@ import { WorkerScriptStartStopEventEmitter } from "../../Netscript/WorkerScriptS
export function killall(terminal: ITerminal, router: IRouter, player: IPlayer, server: BaseServer): void {
for (let i = server.runningScripts.length - 1; i >= 0; --i) {
killWorkerScript(server.runningScripts[i], server.hostname, false);
killWorkerScript({ runningScript: server.runningScripts[i], hostname: server.hostname });
}
WorkerScriptStartStopEventEmitter.emit();
terminal.print("Killing all running scripts");

@ -53,7 +53,7 @@ export function WorkerScriptAccordion(props: IProps): React.ReactElement {
function logClickHandler(): void {
LogBoxEvents.emit(scriptRef);
}
const killScript = killWorkerScript.bind(null, scriptRef as any, scriptRef.server);
const killScript = killWorkerScript.bind(null, { runningScript: scriptRef, hostname: scriptRef.server });
function killScriptClickHandler(): void {
killScript();

@ -151,7 +151,7 @@ function LogWindow(props: IProps): React.ReactElement {
}, []);
function kill(): void {
killWorkerScript(script, script.server, true);
killWorkerScript({ runningScript: script, hostname: script.server });
}
function run(): void {