Bitburner-Scripts/servers/home/watcher.ts

42 lines
1.4 KiB
TypeScript
Raw Normal View History

import { checkForNewPrograms, ProgramState, recursiveHackingRequired } from "./utils"
2023-11-03 21:53:07 -03:00
2023-11-03 18:42:37 -03:00
export async function main(ns: NS) {
2023-11-03 21:53:07 -03:00
let levels = recursiveHackingRequired(ns)
2023-11-04 16:48:17 -03:00
let hackingLevel = ns.getHackingLevel()
let state: ProgramState[] = [
{ program: "BruteSSH.exe", exists: false },
{ program: "FTPCrack.exe", exists: false },
{ program: "relaySMTP.exe", exists: false },
{ program: "HTTPWorm.exe", exists: false },
{ program: "SQLInject.exe", exists: false },
]
2023-11-13 14:13:14 -04:00
checkForNewPrograms(ns, state)
2023-11-04 16:48:17 -03:00
// Remove levels that are already hacked
levels = levels.filter(level => level > hackingLevel)
2023-11-03 21:53:07 -03:00
do {
2023-11-13 14:11:46 -04:00
let restart = false
if (Math.min(...levels) <= hackingLevel) {
2023-11-13 13:36:25 -04:00
ns.tprint(`Hacking level increased past ${Math.min(...levels)}}, is now ${hackingLevel}`)
2023-11-04 16:48:17 -03:00
ns.tprint(`Remaining levels to hack: ${levels}`)
2023-11-13 13:38:39 -04:00
// remove the level from the list, so we don't try to hack it again
levels = levels.filter(level => level > hackingLevel)
2023-11-13 14:11:46 -04:00
restart = true
}
if (checkForNewPrograms(ns, state)) {
ns.tprint(`New programs found: ${state.filter(program => program.exists).map(program => program.program)}`)
restart = true
}
if (restart) {
2023-11-03 21:56:55 -03:00
ns.run("killall.js")
2023-11-03 18:42:37 -03:00
await ns.sleep(1000) // 1 second
2023-11-03 21:56:55 -03:00
ns.run("hackallservers.js")
2023-11-03 18:42:37 -03:00
}
2023-11-04 16:48:17 -03:00
hackingLevel = ns.getHackingLevel()
2023-11-03 18:42:37 -03:00
// Wait 1 second before checking again
await ns.sleep(1000)
2023-11-03 22:55:07 -03:00
} while (hackingLevel <= Math.max(...levels))
2023-11-03 18:42:37 -03:00
}