closeTail(fn, host, ...args) can now close dead script tails

closeTail(pid) still cannot
This commit is contained in:
Undeemiss 2022-05-17 14:46:30 -05:00
parent 2b9d408b55
commit e17fe6f618
2 changed files with 28 additions and 14 deletions

@ -989,21 +989,35 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
},
closeTail: function (fn: any, hostname: any = workerScript.hostname, ...scriptArgs: any[]): void {
updateDynamicRam("closeTail", getRamCost(Player, "closeTail"));
//Get the script object
let runningScriptObj;
//Get the script details
let server;
let filename;
let args;
if (arguments.length === 0) {
runningScriptObj = workerScript.scriptRef;
//Get the details from the script calling the function
const runningScriptObj = workerScript.scriptRef;
server = runningScriptObj.server;
filename = runningScriptObj.filename;
args = runningScriptObj.args;
} else if (typeof fn === "number") {
runningScriptObj = getRunningScriptByPid(fn, "tail");
//Get the details via the pid of a running script
const runningScriptObj = getRunningScriptByPid(fn, "tail");
if (runningScriptObj == null) {
workerScript.log("closeTail", () => getCannotFindRunningScriptErrorMessage(`${fn}`, hostname, scriptArgs));
return;
}
server = runningScriptObj.server;
filename = runningScriptObj.filename;
args = runningScriptObj.args;
} else {
runningScriptObj = getRunningScript(fn, hostname, "tail", scriptArgs);
//Get the details from the input directly
server = hostname;
filename = fn;
args = scriptArgs;
}
if (runningScriptObj == null) {
workerScript.log("closeTail", () => getCannotFindRunningScriptErrorMessage(fn, hostname, scriptArgs));
return;
}
//Emit an event to tell the game to close the tail window
LogBoxCloserEvents.emit(runningScriptObj);
//Emit an event to tell the game to close the tail window if it exists
LogBoxCloserEvents.emit(server, filename, args.map((x: any): string => `${x}`));
},
nuke: function (_hostname: unknown): boolean {
updateDynamicRam("nuke", getRamCost(Player, "nuke"));

@ -23,7 +23,7 @@ import { Settings } from "../../Settings/Settings";
let layerCounter = 0;
export const LogBoxEvents = new EventEmitter<[RunningScript]>();
export const LogBoxCloserEvents = new EventEmitter<[RunningScript]>();
export const LogBoxCloserEvents = new EventEmitter<[any, any, any[]]>();
export const LogBoxClearEvents = new EventEmitter<[]>();
interface Log {
@ -55,8 +55,8 @@ export function LogBoxManager(): React.ReactElement {
//Event used by ns.closeTail to close tail windows
useEffect(
() =>
LogBoxCloserEvents.subscribe((script: RunningScript) => {
const id = script.server + "-" + script.filename + script.args.map((x: any): string => `${x}`).join("-");
LogBoxCloserEvents.subscribe((hostname: any, filename: any, stringArgs: any[]) => {
const id = hostname + "-" + filename + stringArgs.map((x: any): string => `${x}`).join("-");
close(id);
}),
[],