-
Notifications
You must be signed in to change notification settings - Fork 48
/
find_server.js
43 lines (39 loc) · 1.19 KB
/
find_server.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
function recursiveScan(ns, parent, server, target, route) {
const children = ns.scan(server);
for (let child of children) {
if (parent == child) {
continue;
}
if (child == target) {
route.unshift(child);
route.unshift(server);
return true;
}
if (recursiveScan(ns, server, child, target, route)) {
route.unshift(server);
return true;
}
}
return false;
}
export async function main(ns) {
const args = ns.flags([["help", false]]);
let route = [];
let server = args._[0];
if (!server || args.help) {
ns.tprint("This script helps you find a server on the network and shows you the path to get to it.");
ns.tprint(`Usage: run ${ns.getScriptName()} SERVER`);
ns.tprint("Example:");
ns.tprint(`> run ${ns.getScriptName()} n00dles`);
return;
}
recursiveScan(ns, '', 'home', server, route);
for (const i in route) {
await ns.sleep(500);
const extra = i > 0 ? "└ " : "";
ns.tprint(`${" ".repeat(i)}${extra}${route[i]}`);
}
}
export function autocomplete(data, args) {
return data.servers;
}