-
Notifications
You must be signed in to change notification settings - Fork 48
/
find_coding_contract.js
39 lines (34 loc) · 1.06 KB
/
find_coding_contract.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
function scan(ns, parent, server, list) {
const children = ns.scan(server);
for (let child of children) {
if (parent == child) {
continue;
}
list.push(child);
scan(ns, server, child, list);
}
}
export function list_servers(ns) {
const list = [];
scan(ns, '', 'home', list);
return list;
}
export async function main(ns) {
const args = ns.flags([["help", false]]);
if (args.help) {
ns.tprint("This script helps you find an unsolved coding contract.");
ns.tprint(`Usage: run ${ns.getScriptName()}`);
ns.tprint("Example:");
ns.tprint(`> run ${ns.getScriptName()}`);
return;
}
let servers = list_servers(ns);
const boughtServers = ns.getPurchasedServers(ns);
servers = servers.filter(s => !boughtServers.includes(s));
const hostname = servers.find(s => ns.ls(s).find(f => f.endsWith(".cct")))
if(!hostname) {
ns.tprint("No coding contract found.");
return;
}
ns.tprint(`Found coding contract on '${hostname}'.`)
}