forked from bitburner-official/bitburner-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opened_servers.js
36 lines (32 loc) · 1.03 KB
/
opened_servers.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
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;
}
/** @param {NS} ns **/
export async function main(ns) {
const args = ns.flags([["help", false]]);
if (args.help) {
ns.tprint("This script lists all servers on which you can run scripts.");
ns.tprint(`Usage: run ${ns.getScriptName()}`);
ns.tprint("Example:");
ns.tprint(`> run ${ns.getScriptName()}`);
return;
}
const servers = list_servers(ns).filter(s => ns.hasRootAccess(s)).concat(['home']);
for(const server of servers) {
const used = ns.getServerUsedRam(server);
const max = ns.getServerMaxRam(server);
ns.tprint(`${server} is opened. ${used} GB / ${max} GB (${(100*used/max).toFixed(2)}%)`)
}
}