-
Notifications
You must be signed in to change notification settings - Fork 0
/
rconnect.js
35 lines (31 loc) · 1.19 KB
/
rconnect.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
export async function main(ns) {
let target = ns.args[0];
let paths = { "home": "" };
let queue = Object.keys(paths);
let name;
let output;
let pathToTarget;
while ((name = queue.shift())) {
let path = paths[name];
let scanRes = ns.scan(name);
for (let newSv of scanRes) {
if (paths[newSv] === undefined) {
queue.push(newSv);
paths[newSv] = `${path},${newSv}`;
if (newSv == target)
pathToTarget = paths[newSv].substr(1).split(",");
}
}
}
output = "home; ";
pathToTarget.forEach(server => output += " connect " + server + ";");
const doc = eval("document")
const terminalInput = doc.getElementById("terminal-input");
terminalInput.value = output;
const handler = Object.keys(terminalInput)[1];
terminalInput[handler].onChange({ target: terminalInput });
terminalInput[handler].onKeyDown({ keyCode: 13, preventDefault: () => null });
}
export function autocomplete(data, args) {
return ["CSEC", "avmnite-02h", "I.I.I.I", "run4theh111z", "The-Cave", "powerhouse-fitness"]; // This script autocompletes the list of servers.
}