-
Notifications
You must be signed in to change notification settings - Fork 0
/
rscan.js
76 lines (67 loc) · 2.78 KB
/
rscan.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
let facServers = {
"CSEC" : "yellow",
"avmnite-02h" : "yellow",
"I.I.I.I" : "yellow",
"run4theh111z" : "yellow",
"The-Cave" : "orange",
"w0r1d_d43m0n" : "red"
};
let svObj = (name = 'home', depth = 0) => ({ name: name, depth: depth });
export function getServers(ns) {
let result = [];
let visited = { 'home': 0 };
let queue = Object.keys(visited);
let name;
while ((name = queue.pop())) {
let depth = visited[name];
result.push(svObj(name, depth));
let scanRes = ns.scan(name);
for (let i = scanRes.length; i >= 0; i--) {
if (visited[scanRes[i]] === undefined) {
queue.push(scanRes[i]);
visited[scanRes[i]] = depth + 1;
}
}
}
return result;
}
export async function main(ns) {
let output = "Network:";
getServers(ns).forEach(server => {
let name = server.name;
let hackColor = ns.hasRootAccess(name) ? "lime" : "red";
let nameColor = facServers[name] ? facServers[name] : "white";
let hoverText = ["Req Level: ", ns.getServerRequiredHackingLevel(name),
" Req Ports: ", ns.getServerNumPortsRequired(name),
" Memory: ", ns.getServerRam(name)[0], "GB",
" Security: ", ns.getServerSecurityLevel(name),
"/", ns.getServerMinSecurityLevel(name),
" Money: ", Math.round(ns.getServerMoneyAvailable(name)).toLocaleString(), " (",
Math.round(100 * ns.getServerMoneyAvailable(name)/ns.getServerMaxMoney(name)), "%)"
].join("");
let ctText = "";
ns.ls(name, ".cct").forEach(ctName => {
ctText += ["<a title='", ctName,
//Comment out the next line to reduce footprint by 5 GB
" ", ns.codingcontract.getContractType(ctName, name),
"'>©</a>"].join("");
});
output += ["<br>", "---".repeat(server.depth),
`<font color=${hackColor}>■ </font>`,
`<a class='scan-analyze-link' title='${hoverText}''
onClick="(function()
{
const terminalInput = document.getElementById('terminal-input');
terminalInput.value='home; run rconnect.js ${name}';
const handler = Object.keys(terminalInput)[1];
terminalInput[handler].onChange({target:terminalInput});
terminalInput[handler].onKeyDown({keyCode:13,preventDefault:()=>null});
})();"
style='color:${nameColor}'>${name}</a> `,
`<font color='fuchisa'>${ctText}</font>`,
].join("");
});
const doc = eval("document")
const list = doc.getElementById("terminal");
list.insertAdjacentHTML('beforeend',output);
}