-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathprogram-manager.js
49 lines (45 loc) · 1.53 KB
/
program-manager.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
// the purpose of the program-manager is to buy all the programs
// from the darkweb we can afford so we don't have to do it manually
// or write them ourselves. Like tor-manager, this script dies a natural death
// once all programs are bought.
export async function main(ns) {
const programNames = ["BruteSSH.exe", "FTPCrack.exe", "relaySMTP.exe", "HTTPWorm.exe", "SQLInject.exe", "DeepscanV1.exe", "DeepscanV2.exe", "Autolink.exe"];
const programCosts = [500000, 1500000, 5000000, 30000000, 250000000, 500000, 25000000, 1000000];
var hasAllPrograms = false;
while (true) {
if (hasAllPrograms) {
break;
}
if (!hasTor(ns)) {
await ns.sleep(2000);
continue;
}
var foundMissingProgram = false;
for (var i = 0; i < programNames.length; ++i) {
var prog = programNames[i];
if (hasProgram(ns, prog)) {
continue;
} else {
foundMissingProgram = true;
}
var cost = programCosts[i];
if (cost <= getPlayerMoney(ns)) {
ns.purchaseProgram(prog);
}
}
if (!foundMissingProgram) {
hasAllPrograms = true;
}
await ns.sleep(2000);
}
}
function getPlayerMoney(ns) {
return ns.getServerMoneyAvailable("home");
}
function hasProgram(ns, program) {
return ns.fileExists(program, "home");
}
function hasTor(ns) {
var homeNodes = ns.scan("home");
return homeNodes.includes("darkweb");
}