-
Notifications
You must be signed in to change notification settings - Fork 0
/
releasethekraken.js
54 lines (46 loc) · 1.66 KB
/
releasethekraken.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { getNodes, canHack, getPersonalServers, penetrate, getCracks, getNumCracks, readAndSortChaching} from "./utils.js";
/** @param {NS} ns */
export async function main(ns) {
let nodes = [];
const SCRIPT = "moneymoneymoney.js";
let SCRIPT_RAM = ns.getScriptRam(SCRIPT);
const homeServer = ns.getHostname();
const cracks = getCracks(ns);
let numCracks = getNumCracks(ns, cracks);
ns.tprint(`Number of available cracks: ${numCracks}`);
const targetList = await readAndSortChaching(ns)
// const target = targetList[0]["server"]
const target = ns.args[0]
ns.tprint(`Targeting ${target}`)
function getHackableNodes() {
return getNodes(ns).filter(node => canHack(ns, node, numCracks, SCRIPT_RAM))
.concat(getPersonalServers(ns)).concat(["home"]);
}
function deployHack(node) {
ns.print(`Deploying to ${node}`);
ns.scp(SCRIPT, node);
if (!ns.hasRootAccess(node) && numCracks >= ns.getServerNumPortsRequired(node)) {
penetrate(ns, node, cracks, homeServer);
ns.nuke(node);
}
ns.scriptKill(SCRIPT, node);
let maxThreads = Math.floor((ns.getServerMaxRam(node) - ns.getServerUsedRam(node)) / SCRIPT_RAM);
ns.exec(SCRIPT, node, maxThreads, target);
}
var i = 0;
// Main loop
while (true) {
let newNodes = getHackableNodes();
if (SCRIPT_RAM != ns.getScriptRam(SCRIPT)) {
newNodes.forEach(node => deployHack(node));
} else {
newNodes.filter(node => !nodes.includes(node)).forEach(node => deployHack(node));
}
nodes = newNodes;
ns.print(`Hacking nodes: ${nodes.join(', ')}`);
ns.print(`${i}`);
i++;
SCRIPT_RAM = ns.getScriptRam(SCRIPT);
await ns.sleep(1000);
}
}