-
Notifications
You must be signed in to change notification settings - Fork 2
/
worm.ns
54 lines (41 loc) · 929 Bytes
/
worm.ns
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
async function worm(ns, node) {
await ns.sleep(100);
if (ns.hasRootAccess(node) && taken_over.includes(node))
{
past_nodes.push(node);
var children = ns.scan(node);
for (var i = 0; i < children.length; i++)
{
if(past_nodes.includes(children[i])) continue;
if(node != children[i])
{
await worm(ns, children[i]);
await ns.sleep(100);
}
}
}
else
{
// takeover node
if (ns.getHackingLevel() > ns.getServerRequiredHackingLevel(node))
{
ns.print("taking over node: " + node);
ns.run("takeover.script", 1, node);
await ns.sleep(100);
taken_over.push(node);
}
}
}
var past_nodes = ["home"];
var taken_over = ["home"];
/** @param {NS} ns **/
export async function main(ns) {
var root_host = ns.getHostname();
ns.print("rooting worm at: " + root_host);
while (true)
{
await ns.sleep(10000);
await worm(ns, root_host);
past_nodes = ["home"];
}
}