Skip to content

Instantly share code, notes, and snippets.

@heathkit
Created May 16, 2022 08:16
Show Gist options
  • Save heathkit/c69e0e04dc2136cc0c19215750c1f6ec to your computer and use it in GitHub Desktop.
Save heathkit/c69e0e04dc2136cc0c19215750c1f6ec to your computer and use it in GitHub Desktop.
Bitburner stuff
// deploy.js
/** @param {NS} ns */
export async function main(ns) {
let previousHost = ns.args[0]
ns.printf("Previous host: %s", previousHost)
let currentHost = ns.getHostname()
let hosts = ns.scan()
for (let host of hosts) {
if (host === previousHost) continue;
if (ns.getServerRequiredHackingLevel(host) < ns.getHackingLevel()) {
if (ns.getServerNumPortsRequired(host) > 0) {
await ns.brutessh(host)
}
await ns.nuke(host)
}
if (ns.hasRootAccess(host)) {
await ns.scp(['deploy.js','exploit.js'], host)
ns.exec('deploy.js', host, 1, currentHost)
}
}
let max = ns.getServerMaxRam(currentHost)
let cost = ns.getScriptRam('exploit.js')
let threads = Math.floor(max/cost)
ns.spawn('exploit.js',threads)
}
// exploit.js
/** @param {NS} ns */
export async function main(ns) {
//let host = ns.getHostname()
let host = 'harakiri-sushi'
let growThresh = ns.getServerMaxMoney(host) * 0.75
let weakenThresh = ns.getServerMinSecurityLevel(host) + 3
while (true) {
if (ns.getServerSecurityLevel(host) > weakenThresh) {
await ns.weaken(host)
} else if (ns.getServerMoneyAvailable(host) < growThresh) {
await ns.grow(host)
} else {
await ns.hack(host)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment