Depth first recursive script dies after going through a couple of branches?
Hi, I just started playing, and I was trying to put together a script that would go through all the servers depth first, nuke them, then run as many threads of the basic EHT script on as it can (just the one from the tutorial minus the nuking that was included), but for whatever reason after going through 2 branches from home fully (which is the n00dles server, plus one proper branch) it just goes "Script finished running" followed by "printf: Failed to run due to script being killed." and I don't understand why it's finishing, and more specifically why it's finishing at the end of the second branch and not the first. Not sure if I just missed something about how the scripts work or if I'm just being dumb here somewhere
/** @param {NS} ns */
export async function main(ns: NS) {
let target: string = ns.args[0]?.toString();
target ??= "max-hardware";
deploy(ns, "home", [], target);
ns.tprintf("%s hacked", target);
}
async function deploy(ns: NS, server: string, checked: string[], target: string) {
ns.printf("INFO: Deploying to %s", server)
const neighs = ns.scan(server).filter((neigh) => !checked.includes(neigh));
ns.printf("INFO: Neighbors: %s", neighs)
if (server != "home") {
ns.scp("eht.js", server);
nukeServer(ns, server);
ns.killall(server, true);
const execThreads = calcThreads(ns, server);
ns.printf("INFO: Threads to deploy %d", execThreads)
ns.exec("eht.js", server, execThreads, target);
}
const checkedServers = checked.concat(server);
ns.printf("INFO: Checked servers: %s", checkedServers)
for (const neigh of neighs) {
await deploy(ns, neigh, checkedServers, target);
}
}
function nukeServer(ns: NS, server: string) {
if (ns.fileExists("BruteSSH.exe", "home")) {
ns.brutessh(server);
}
if (ns.fileExists("FTPCrack.exe", "home")) {
ns.ftpcrack(server);
}
if (ns.fileExists("relaySMTP.exe", "home")) {
ns.relaysmtp(server);
}
if (ns.fileExists("HTTPWorm.exe", "home")) {
ns.httpworm(server);
}
if (ns.fileExists("SQLInject.exe", "home")) {
ns.sqlinject(server);
}
ns.nuke(server);
}
function calcThreads(ns: NS, server: string) {
return Math.floor(ns.getServerMaxRam(server) / ns.getScriptRam("eht.js"));
}