Files
2026-02-14 11:07:47 -06:00

48 lines
1.6 KiB
JavaScript

/** @param {NS} ns */
export async function main(ns) {
// Defines the "target server", which is the server
// that we're going to hack. In this case, it's "n00dles"
// const targets = ["n00dles", "joesguns"];
let target = ns.peek(1) ? ns.peek(1) : "joesguns";
//const target = "joesguns";
// Loops through all the values in "targets"
// for (let t in targets) {
// let target = targets[t];
// Defines how much money a server should have before we hack it
// In this case, it is set to the maximum amount of money.
const moneyThresh = ns.getServerMaxMoney(target);
// Defines the minimum security level the target server can
// have. If the target's security level is higher than this,
// we'll weaken it before doing anything else
const securityThresh = ns.getServerMinSecurityLevel(target);
// If we have the BruteSSH.exe program, use it to open the SSH Port
// on the target server
if (ns.fileExists("BruteSSH.exe", "home")) {
ns.brutessh(target);
}
// Get root access to target server
ns.nuke(target);
// Infinite loop that continously hacks/grows/weakens the target server
while (true) {
target = ns.peek(1) ? ns.peek(1) : target;
ns.print("targeting: " + target);
if (ns.getServerSecurityLevel(target) > securityThresh) {
// If the server's security level is above our threshold, weaken it
await ns.weaken(target);
} else if (ns.getServerMoneyAvailable(target) < moneyThresh) {
// If the server's money is less than our threshold, grow it
await ns.grow(target);
} else {
// Otherwise, hack it
await ns.hack(target);
}
}
// }
}