-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathportWorker.js
31 lines (27 loc) · 1.16 KB
/
portWorker.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
/** @param {NS} ns */
export async function main(ns) {
const [
target, // target server to hack
delay, // delay before the hack begins once this script is started
port, // port from which to fetch the current security/hacking level from
expectedSecurity, // expected security for this job/batch
expectedHackingLevel] = ns.args; // expected hacking level for this job/batch
if (target == undefined || delay == undefined || port == undefined || expectedSecurity == undefined || expectedHackingLevel == undefined) {
ns.tprint('FAIL: Missing some arguments?!');
return;
}
// We wait the requested delay before starting our hack
await ns.sleep(delay);
// We make sure security and hacking level are where we want them to be
const portData = JSON.parse(ns.peek(port));
if (portData.security != expectedSecurity) {
ns.tprint('FAIL: Security is ' + portData.security + ' expected ' + expectedSecurity + ' aborting!');
return;
}
if (portData.hackLevel != expectedHackingLevel) {
ns.tprint('FAIL: Hack level is ' + portData.hackLevel + ' expected ' + expectedHackingLevel + ' aborting!');
return;
}
// Do the hack if we passed the checks!
await ns.hack(target);
}