mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-19 14:13:48 +01:00
remove last colon any for now
This commit is contained in:
parent
0e74b1a5d6
commit
49f6fda1e4
@ -15,52 +15,43 @@ import { dialogBoxCreate } from "../ui/React/DialogBox";
|
|||||||
import { AddRecentScript } from "./RecentScripts";
|
import { AddRecentScript } from "./RecentScripts";
|
||||||
import { Player } from "../Player";
|
import { Player } from "../Player";
|
||||||
|
|
||||||
export function killWorkerScript(runningScriptObj: RunningScript, hostname: string, rerenderUi?: boolean): boolean;
|
export type killScriptParams = WorkerScript | number | { runningScript: RunningScript; hostname: string };
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (script instanceof WorkerScript) {
|
export function killWorkerScript(params: killScriptParams): boolean {
|
||||||
stopAndCleanUpWorkerScript(script);
|
if (params instanceof WorkerScript) {
|
||||||
|
stopAndCleanUpWorkerScript(params);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else if (script instanceof RunningScript && typeof hostname === "string") {
|
} else if (typeof params === "number") {
|
||||||
|
return killWorkerScriptByPid(params);
|
||||||
|
} else {
|
||||||
// Try to kill by PID
|
// Try to kill by PID
|
||||||
const res = killWorkerScriptByPid(script.pid, rerenderUi);
|
const res = killWorkerScriptByPid(params.runningScript.pid);
|
||||||
if (res) {
|
if (res) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If for some reason that doesn't work, we'll try the old way
|
// If for some reason that doesn't work, we'll try the old way
|
||||||
for (const ws of workerScripts.values()) {
|
for (const ws of workerScripts.values()) {
|
||||||
if (ws.name == script.filename && ws.hostname == hostname && compareArrays(ws.args, script.args)) {
|
if (
|
||||||
stopAndCleanUpWorkerScript(ws, rerenderUi);
|
ws.name == params.runningScript.filename &&
|
||||||
|
ws.hostname == params.hostname &&
|
||||||
|
compareArrays(ws.args, params.runningScript.args)
|
||||||
|
) {
|
||||||
|
stopAndCleanUpWorkerScript(ws);
|
||||||
|
|
||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function killWorkerScriptByPid(pid: number, rerenderUi = true): boolean {
|
function killWorkerScriptByPid(pid: number): boolean {
|
||||||
const ws = workerScripts.get(pid);
|
const ws = workerScripts.get(pid);
|
||||||
if (ws instanceof WorkerScript) {
|
if (ws instanceof WorkerScript) {
|
||||||
stopAndCleanUpWorkerScript(ws, rerenderUi);
|
stopAndCleanUpWorkerScript(ws);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -68,7 +59,7 @@ function killWorkerScriptByPid(pid: number, rerenderUi = true): boolean {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopAndCleanUpWorkerScript(workerScript: WorkerScript, rerenderUi = true): void {
|
function stopAndCleanUpWorkerScript(workerScript: WorkerScript): void {
|
||||||
if (typeof workerScript.atExit === "function") {
|
if (typeof workerScript.atExit === "function") {
|
||||||
try {
|
try {
|
||||||
workerScript.atExit();
|
workerScript.atExit();
|
||||||
@ -83,7 +74,7 @@ function stopAndCleanUpWorkerScript(workerScript: WorkerScript, rerenderUi = tru
|
|||||||
}
|
}
|
||||||
workerScript.env.stopFlag = true;
|
workerScript.env.stopFlag = true;
|
||||||
killNetscriptDelay(workerScript);
|
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
|
* @param {WorkerScript} - Identifier for WorkerScript. Either the object itself, or
|
||||||
* its index in the global workerScripts array
|
* its index in the global workerScripts array
|
||||||
*/
|
*/
|
||||||
function removeWorkerScript(workerScript: WorkerScript, rerenderUi = true): void {
|
function removeWorkerScript(workerScript: WorkerScript): void {
|
||||||
const ip = workerScript.hostname;
|
const ip = workerScript.hostname;
|
||||||
const name = workerScript.name;
|
const name = workerScript.name;
|
||||||
|
|
||||||
@ -127,10 +118,8 @@ function removeWorkerScript(workerScript: WorkerScript, rerenderUi = true): void
|
|||||||
// }
|
// }
|
||||||
AddRecentScript(workerScript);
|
AddRecentScript(workerScript);
|
||||||
|
|
||||||
if (rerenderUi) {
|
|
||||||
WorkerScriptStartStopEventEmitter.emit();
|
WorkerScriptStartStopEventEmitter.emit();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function that interrupts a script's delay if it is in the middle of a
|
* Helper function that interrupts a script's delay if it is in the middle of a
|
||||||
|
@ -1315,7 +1315,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = killWorkerScript(runningScriptObj, server.hostname);
|
res = killWorkerScript({ runningScript: runningScriptObj, hostname: server.hostname });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
@ -1348,7 +1348,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
|
|
||||||
for (let i = server.runningScripts.length - 1; i >= 0; --i) {
|
for (let i = server.runningScripts.length - 1; i >= 0; --i) {
|
||||||
if (safetyguard === true && server.runningScripts[i].pid == workerScript.pid) continue;
|
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;
|
++scriptsKilled;
|
||||||
}
|
}
|
||||||
WorkerScriptStartStopEventEmitter.emit();
|
WorkerScriptStartStopEventEmitter.emit();
|
||||||
@ -2241,7 +2241,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
let suc = false;
|
let suc = false;
|
||||||
for (let i = 0; i < server.runningScripts.length; i++) {
|
for (let i = 0; i < server.runningScripts.length; i++) {
|
||||||
if (server.runningScripts[i].filename == scriptname) {
|
if (server.runningScripts[i].filename == scriptname) {
|
||||||
killWorkerScript(server.runningScripts[i], server.hostname);
|
killWorkerScript({ runningScript: server.runningScripts[i], hostname: server.hostname });
|
||||||
suc = true;
|
suc = true;
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ export function kill(
|
|||||||
terminal.error("No such script is running. Nothing to kill");
|
terminal.error("No such script is running. Nothing to kill");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
killWorkerScript(runningScript, server.hostname, false);
|
killWorkerScript({ runningScript: runningScript, hostname: server.hostname });
|
||||||
terminal.print(`Killing ${scriptName}`);
|
terminal.print(`Killing ${scriptName}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
terminal.error(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 {
|
export function killall(terminal: ITerminal, router: IRouter, player: IPlayer, server: BaseServer): void {
|
||||||
for (let i = server.runningScripts.length - 1; i >= 0; --i) {
|
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();
|
WorkerScriptStartStopEventEmitter.emit();
|
||||||
terminal.print("Killing all running scripts");
|
terminal.print("Killing all running scripts");
|
||||||
|
@ -53,7 +53,7 @@ export function WorkerScriptAccordion(props: IProps): React.ReactElement {
|
|||||||
function logClickHandler(): void {
|
function logClickHandler(): void {
|
||||||
LogBoxEvents.emit(scriptRef);
|
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 {
|
function killScriptClickHandler(): void {
|
||||||
killScript();
|
killScript();
|
||||||
|
@ -151,7 +151,7 @@ function LogWindow(props: IProps): React.ReactElement {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
function kill(): void {
|
function kill(): void {
|
||||||
killWorkerScript(script, script.server, true);
|
killWorkerScript({ runningScript: script, hostname: script.server });
|
||||||
}
|
}
|
||||||
|
|
||||||
function run(): void {
|
function run(): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user