mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-17 23:08:36 +02:00
Add safeguard toggle to ns.killall()
This commit is contained in:
@@ -1233,16 +1233,21 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
killall: function (_hostname: unknown = workerScript.hostname): boolean {
|
killall: function (_hostname: unknown = workerScript.hostname, _safetyguard: unknown = true): boolean {
|
||||||
updateDynamicRam("killall", getRamCost(Player, "killall"));
|
updateDynamicRam("killall", getRamCost(Player, "killall"));
|
||||||
const hostname = helper.string("killall", "hostname", _hostname);
|
const hostname = helper.string("killall", "hostname", _hostname);
|
||||||
|
const safetyguard = helper.boolean(_safetyguard);
|
||||||
if (hostname === undefined) {
|
if (hostname === undefined) {
|
||||||
throw makeRuntimeErrorMsg("killall", "Takes 1 argument");
|
throw makeRuntimeErrorMsg("killall", "Usage: killall(hostname, [safetyguard boolean])");
|
||||||
}
|
}
|
||||||
const server = safeGetServer(hostname, "killall");
|
const server = safeGetServer(hostname, "killall");
|
||||||
const scriptsRunning = server.runningScripts.length > 0;
|
|
||||||
|
let scriptsKilled = 0;
|
||||||
|
|
||||||
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;
|
||||||
killWorkerScript(server.runningScripts[i], server.hostname, false);
|
killWorkerScript(server.runningScripts[i], server.hostname, false);
|
||||||
|
++scriptsKilled;
|
||||||
}
|
}
|
||||||
WorkerScriptStartStopEventEmitter.emit();
|
WorkerScriptStartStopEventEmitter.emit();
|
||||||
workerScript.log(
|
workerScript.log(
|
||||||
@@ -1250,7 +1255,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
() => `Killing all scripts on '${server.hostname}'. May take a few minutes for the scripts to die.`,
|
() => `Killing all scripts on '${server.hostname}'. May take a few minutes for the scripts to die.`,
|
||||||
);
|
);
|
||||||
|
|
||||||
return scriptsRunning;
|
return scriptsKilled > 0;
|
||||||
},
|
},
|
||||||
exit: function (): void {
|
exit: function (): void {
|
||||||
updateDynamicRam("exit", getRamCost(Player, "exit"));
|
updateDynamicRam("exit", getRamCost(Player, "exit"));
|
||||||
|
|||||||
3
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
3
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@@ -5311,9 +5311,10 @@ export interface NS {
|
|||||||
* If no host is defined, it will kill all scripts, where the script is running.
|
* If no host is defined, it will kill all scripts, where the script is running.
|
||||||
*
|
*
|
||||||
* @param host - IP or hostname of the server on which to kill all scripts.
|
* @param host - IP or hostname of the server on which to kill all scripts.
|
||||||
|
* @param safetyguard - Skips the script that calls this function
|
||||||
* @returns True if any scripts were killed, and false otherwise.
|
* @returns True if any scripts were killed, and false otherwise.
|
||||||
*/
|
*/
|
||||||
killall(host?: string): boolean;
|
killall(host?: string, safetyguard?: boolean): boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Terminates the current script immediately.
|
* Terminates the current script immediately.
|
||||||
|
|||||||
Reference in New Issue
Block a user