From 843ab4401a4a88be26866a31e9558baf22fcb1ad Mon Sep 17 00:00:00 2001 From: Isaac Shoebottom Date: Thu, 2 Nov 2023 10:42:44 -0300 Subject: [PATCH] Add dogshit code with no ports --- no-ports/auto-upgrade.js | 13 +++++++++++++ no-ports/hack-all.js | 4 ++++ no-ports/hack-args.js | 15 +++++++++++++++ no-ports/hack.js | 15 +++++++++++++++ no-ports/recursive-copy.js | 33 ++++++++++++++++++++++++++++++++ no-ports/recursive-kill.js | 26 +++++++++++++++++++++++++ no-ports/recursive-run.js | 30 +++++++++++++++++++++++++++++ no-ports/root.js | 9 +++++++++ no-ports/run.js | 39 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 184 insertions(+) create mode 100644 no-ports/auto-upgrade.js create mode 100644 no-ports/hack-all.js create mode 100644 no-ports/hack-args.js create mode 100644 no-ports/hack.js create mode 100644 no-ports/recursive-copy.js create mode 100644 no-ports/recursive-kill.js create mode 100644 no-ports/recursive-run.js create mode 100644 no-ports/root.js create mode 100644 no-ports/run.js diff --git a/no-ports/auto-upgrade.js b/no-ports/auto-upgrade.js new file mode 100644 index 0000000..8e4bf98 --- /dev/null +++ b/no-ports/auto-upgrade.js @@ -0,0 +1,13 @@ +/** @param {NS} ns */ +export async function main(ns) { + let level = ns.getHackingLevel() + + while (level < 999) { + let newLevel = ns.getHackingLevel() + if (newLevel !== level) { + ns.run("run.js") + } + level = newLevel + await ns.sleep(10 * 1000) // 10 seconds + } +} \ No newline at end of file diff --git a/no-ports/hack-all.js b/no-ports/hack-all.js new file mode 100644 index 0000000..818072c --- /dev/null +++ b/no-ports/hack-all.js @@ -0,0 +1,4 @@ +/** @param {NS} ns */ +export async function main(ns) { + ns.run("recursive-run.js", 1, "home", "hack-args.js") +} \ No newline at end of file diff --git a/no-ports/hack-args.js b/no-ports/hack-args.js new file mode 100644 index 0000000..fdca928 --- /dev/null +++ b/no-ports/hack-args.js @@ -0,0 +1,15 @@ +/** @param {NS} ns */ +export async function main(ns) { + let hostname = ns.args[0] + let cost = ns.args[1] + let moneyThresh = ns.getServerMaxMoney(hostname) * 0.75; + let securityThresh = ns.getServerMinSecurityLevel(hostname) + 5; + + let numThreads = ns.getServerMaxRam(hostname) / cost + numThreads = Math.floor(numThreads) + + if (numThreads < 1 || numThreads == Infinity) { + numThreads = 1 + } + ns.spawn("hack.js", numThreads, hostname, moneyThresh, securityThresh) +} \ No newline at end of file diff --git a/no-ports/hack.js b/no-ports/hack.js new file mode 100644 index 0000000..63298ec --- /dev/null +++ b/no-ports/hack.js @@ -0,0 +1,15 @@ +/** @param {NS} ns */ +export async function main(ns) { + var target = ns.args[0] + var moneyThresh = ns.args[1] + var securityThresh = ns.args[2] + while (true) { + if (ns.getServerSecurityLevel(target) > securityThresh) { + await ns.weaken(target); + } else if (ns.getServerMoneyAvailable(target) < moneyThresh) { + await ns.grow(target); + } else { + await ns.hack(target); + } + } +} \ No newline at end of file diff --git a/no-ports/recursive-copy.js b/no-ports/recursive-copy.js new file mode 100644 index 0000000..ebe73f6 --- /dev/null +++ b/no-ports/recursive-copy.js @@ -0,0 +1,33 @@ +/** @param {NS} ns */ +export async function main(ns) { + let parent + if (ns.args[0] == undefined) { + parent = "home" + } else { + parent = ns.args[0] + } + + let files = [ + "hack-args.js", + "hack.js", + "root.js", + "recursive-copy.js", + "recursive-kill.js", + "recursive-run.js" + ] + let script = "recursive-copy.js" + let servers = ns.scan() + + for (const server of servers) { + if (server == parent) { + continue + } + if (server == "home") { + continue + } + //ns.tprint("Copied to: :", server) + ns.scp(files, server, "home") + + ns.exec(script, server, 1, ns.getHostname()) // script, dest, thread count, arg1 + } +} \ No newline at end of file diff --git a/no-ports/recursive-kill.js b/no-ports/recursive-kill.js new file mode 100644 index 0000000..97c68e3 --- /dev/null +++ b/no-ports/recursive-kill.js @@ -0,0 +1,26 @@ +/** @param {NS} ns */ +export async function main(ns) { + let parent + if (ns.args[0] == undefined) { + parent = "home" + } else { + parent = ns.args[0] + } + let script = "recursive-kill.js" + + let servers = ns.scan() + + for (const server of servers) { + if (server == parent) { + continue + } + if (!ns.hasRootAccess(server)) { + ns.exec("root.js", ns.getHostname(), 1, server) + } + + //ns.tprint("Killed all scripts on: ", server) + ns.killall(server, true) + + ns.exec(script, server, 1, ns.getHostname()) + } +} \ No newline at end of file diff --git a/no-ports/recursive-run.js b/no-ports/recursive-run.js new file mode 100644 index 0000000..dff2e35 --- /dev/null +++ b/no-ports/recursive-run.js @@ -0,0 +1,30 @@ +/** @param {NS} ns */ +export async function main(ns) { + let parent = ns.args[0] + let script = ns.args[1] + let selfScript = "recursive-run.js" + let servers = ns.scan() + //ns.tprint("INFO Scan of ", ns.getHostname(), ": ", servers) + + for (const server of servers) { + if (server === parent) { + continue; + } + ns.exec(selfScript, server, 1, ns.getHostname(), script) + await ns.sleep(50) + + let procs = ns.ps(server) + if (procs.length > 0) { + //ns.tprint("INFO Ram in use on ", server, ": ", ns.getServerUsedRam(server)) + let ram = ns.getServerMaxRam(server) - ns.getServerUsedRam(server) + //ns.tprint("INFO Available ram on ", server, ": ", ram) + //ns.tprint("INFO Filename of running script: ", procs[0].filename) + } + + if (ns.getServerRequiredHackingLevel(server) < ns.getHackingLevel()) { + // after thread args, first arg is the server it us running on, and then the cost of the hack script + ns.tprint("RUN Started hacking server: ", server) + ns.exec(script, server, 1, server, ns.getScriptRam("hack.js", server)) + } + } +} \ No newline at end of file diff --git a/no-ports/root.js b/no-ports/root.js new file mode 100644 index 0000000..b51714f --- /dev/null +++ b/no-ports/root.js @@ -0,0 +1,9 @@ +/** @param {NS} ns */ +export async function main(ns) { + let server = ns.args[0] + if (ns.getServerNumPortsRequired(server) <= 2) { + ns.brutessh(server) + ns.ftpcrack(server) + ns.nuke(server) + } +} \ No newline at end of file diff --git a/no-ports/run.js b/no-ports/run.js new file mode 100644 index 0000000..fc9daba --- /dev/null +++ b/no-ports/run.js @@ -0,0 +1,39 @@ +/** @param {NS} ns */ +export async function main(ns) { + ns.run("recursive-kill.js") + await ns.sleep(1000) + ns.run("recursive-copy.js") + await ns.sleep(1000) + //home is first arg for root, hack-args is the script to run + ns.run("recursive-run.js", 1, "root-server", "hack-args.js") + + //problem is that the scanning takes place on the same sever instead of the server that is the parent + //need last child of each node to spawn the process on parent, as spawning on on children always needs extra ram + // + //root scans nodes, saves to list + //the last execution of the exec on the last child passes in a flag to spawn on parent + //wait for the parent to finish using sleep (maybe find better way to syncronize) + //start hack-args function on parent + // + //each child becomes the "root" and repeats + + // SCRATCH ALLAT + // its pretty much unsolveable, either way you go up or down the node tree, you end up with the problem + // not knowing if a server will have enough ram to run the hack args script, because the end node + // becomes circular. the only way to solve the problem would be to be able to have enough ram to call + // spawn after the for loop after recursive-run is called for all children in the for loop. + + // so for now just will have to run a manual command for each sever with less than 8gb of ram + // a more elegant but more set in stone solution might be to just collect every unique hostname + // (print to console, but don't include parent, and exclude duplicates) + // and then just run an exec on each one in a for loop + + //hack to get n00dles working, since it has low ram + await ns.sleep(1000) + ns.exec("hack-args.js", "n00dles", 1, "n00dles", 2.20) + + // start auto upgrade if not running + if (!ns.isRunning("auto-upgrade.js")) { + ns.run("auto-upgrade.js") + } +} \ No newline at end of file