-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdemon.js
52 lines (46 loc) · 1.29 KB
/
demon.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
import { LogMessage, GetServerPath, GetAllServers } from 'utils.js';
/** @param {NS} ns */
export async function main(ns) {
try {
const WD = 'w0r1d_d43m0n';
const server = ns.getServer(WD);
if (ns.scan(WD).length == 0) {
if (!ns.args.includes('silent'))
ns.tprint('WARN: ' + WD + ' isn\'t connected yet');
return;
}
if (server.hackDifficulty > ns.getHackingLevel()) {
if (!ns.args.includes('silent'))
ns.tprint('WARN: Hacking level (' + ns.getHackingLevel() + ') isn\'t high enough to destroy ' + WD);
return;
}
if (!server.hasAdminRights) {
if (!ns.args.includes('silent'))
ns.tprint('WARN: We do not have root access to ' + WD);
return;
}
const path = GetServerPath(ns, WD);
for (const node of path) {
if (!ns.singularity.connect(node)) {
ns.tprint('ERROR: Could not connect to ' + node);
}
else {
if (!ns.args.includes('silent'))
ns.tprint('INFO: Connected to ' + node);
}
}
try {
await ns.singularity.installBackdoor();
if (ns.getServer(WD).backdoorInstalled) {
ns.tprint('INFO: Installed backdoor on ' + WD);
LogMessage(ns, 'INFO: Installed backdoor on ' + WD);
for (let server of GetAllServers(ns)) {
ns.killall(server, true);
}
}
}
catch { }
ns.singularity.connect('home');
}
catch {}
}