-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoconnect.js
More file actions
38 lines (31 loc) · 938 Bytes
/
autoconnect.js
File metadata and controls
38 lines (31 loc) · 938 Bytes
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
import {getHostPath} from 'serverdata.js'
import {runTerminalCommand} from 'terminalcmd.js'
/**
1. find the path of a server.
2. follows / auto-connects the path to the target host
*/
export async function autoConnect(ns, targetHostname, verbose) {
const startMs = Date.now();
let fullPath = getHostPath(ns, targetHostname, verbose);
if(fullPath.length == 0) {
return;
}
for(let i = 0; i < fullPath.length; i++) {
let pathPart = fullPath[i];
await runTerminalCommand("connect" + " " + pathPart);
}
if(verbose) {
const endMs = Date.now();
ns.tprintf("%s -> autoConnect(targetHostname=%s, verbose=%s) -> executed in %i ms",
ns.getScriptName(), targetHostname, verbose, endMs - startMs
);
}
}
/** @param {NS} ns */
export async function main(ns) {
let targetHostname = "";
if(ns.args.length >= 1) {
targetHostname = ns.args[0];
}
await autoConnect(ns, targetHostname, true);
}