-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconnect.js
44 lines (34 loc) · 1.2 KB
/
connect.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
const emulateTerminalAction = (input) => {
const terminalEl = eval('document').querySelector("#terminal-input");
const propsKey = Object.keys(terminalEl)[1];
terminalEl[propsKey].onChange({ target: { value: input } });
terminalEl[propsKey].onKeyDown({ keyCode: 13, preventDefault: () => { } });
}
/** @param {NS} ns **/
const scanNode = (ns, node, target, scanedServers) => {
let servers = ns.scan(node).filter((server) => !scanedServers.includes(server));
scanedServers.push(...servers);
if (servers.includes(target)) return `connect ${target}`;
for (let server of servers) {
const path = scanNode(ns, server, target, scanedServers);
if (path) return `connect ${server}; ${path}`
}
return '';
};
/** @param {NS} ns **/
export async function main(ns) {
const [target] = ns.args;
if (!target) {
ns.toast('Target to connect not provided!', "error", 10000)
return;
}
let scanedServers = [];
const path = scanNode(ns, ns.getHostname(), target, scanedServers)
if (path) {
emulateTerminalAction(path);
//emulateTerminalAction('clear');
}
else {
ns.toast('Path Not Found', "error", 10000)
}
}