-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-status.js
110 lines (88 loc) · 4.01 KB
/
check-status.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/** An log only script that reports the current status of our botnet's activities.
* Driven 100% by port data
* Written By: Zharay
* URL: https://github.com/Zharay/BitburnerBotnet
**/
/** @param {NS} ns */
export async function main(ns) {
ns.disableLog("ALL");
// Options
const showTargetCount = false;
const showHostCount = false;
var serverProcesses = ns.ps();
var coordinatorID = 0;
serverProcesses.forEach ( function(x) {
if (x.filename == "coordinator.js")
coordinatorID = x.pid;
});
var gTargets = ns.getPortHandle(1);
var gHosts = ns.getPortHandle(2);
var gStatus = ns.getPortHandle(3);
var gRam = ns.getPortHandle(4);
var gExp = ns.getPortHandle(5);
while(gTargets.peek() == "NULL PORT DATA" && gStatus.peek() == "NULL PORT DATA") {
ns.print("Waiting for data...");
await ns.sleep(500);
}
await ns.sleep(1000);
var runTime = 0;
while (ns.isRunning(coordinatorID)) {
ns.clearLog();
var rawTargets = gTargets.peek();
var rawHosts = gHosts.peek();
var rawStatus = gStatus.peek();
var rawRam = gRam.peek();
var rawExp = gExp.peek();
if (rawTargets != "NULL PORT DATA" && rawStatus != "NULL PORT DATA") {
var jTargets = JSON.parse(rawTargets);
var jStatus = JSON.parse(rawStatus);
if (jTargets.length == jStatus.length) {
for(var i = 0; i < jTargets.length; i++) {
if (isNaN(jTargets[i].security) || isNaN(jTargets[i].curMoney) || isNaN(jTargets[i].maxMoney) || !jStatus[i].isTarget)
continue;
var TIX = jStatus[i].TIX != "" ? `[${jStatus[i].TIX}]` : "";
var stockLabel = jStatus[i].isLong ? " [L] " : (jStatus[i].isShort ? " [S]" : "");
ns.print(`Target: ${jTargets[i].target} ${TIX} ${stockLabel} (HL ${jTargets[i].hackerLevel})`);
ns.print(`Security: ${ns.nFormat(jTargets[i].security, "0.00")} / ${(jTargets[i].minSecurity+5)} [${ns.nFormat(jStatus[i].security, "0.00")}]`);
ns.print(`Money: ${ns.nFormat(jTargets[i].curMoney, "$0.000a")} / ${ns.nFormat(jTargets[i].maxMoney, "$0.000a")} [${ns.nFormat(jTargets[i].maxMoney * jTargets[i].thresholdModifier, "$0.000a")}]`);
ns.print(`Growth: ${jTargets[i].growth} | Hack Chance: ${ns.nFormat(ns.hackAnalyzeChance(jTargets[i].target), "0.00%")}`);
if (jStatus[i].isLong || jStatus[i].isShort) ns.print(`Longs?: ${jStatus[i].isLong} | Shorts?: ${jStatus[i].isShort} | pChng: ${ns.nFormat(jStatus[i].profitChange, "0.00%")}`);
if (isNaN(jStatus[i].hackRam) || isNaN(jStatus[i].growRam) || isNaN(jStatus[i].weakenRam))
continue;
ns.print(`Hack: ${jStatus[i].hackThreads} threads | ${ns.nFormat(jStatus[i].hackRam * Math.pow(1000,3), "0.00b")} RAM`);
ns.print(`Grow: ${jStatus[i].growThreads} threads | ${ns.nFormat(jStatus[i].growRam * Math.pow(1000,3), "0.00b")} RAM`);
ns.print(`Weak: ${jStatus[i].weakenThreads} threads | ${ns.nFormat(jStatus[i].weakenRam * Math.pow(1000,3), "0.00b")} RAM`);
ns.print(" ");
}
}
}
if (rawExp != "NULL PORT DATA") {
var jExp = JSON.parse(rawExp);
var eHack = 0, eGrow = 0, eWeak = 0;
jExp.forEach( function(x) {
if (isNaN(x.hackThreads) || isNaN(x.growThreads) || isNaN(x.weakenThreads))
return;
eHack += Math.floor(x.hackThreads);
eGrow += Math.floor(x.growThreads);
eWeak += Math.floor(x.weakenThreads);
} );
ns.print(`EXP Threads: ${eHack} H | ${eGrow} G | ${eWeak} W`);
ns.print(" ");
}
if (rawRam != "NULL PORT DATA") {
var jRam = JSON.parse(rawRam);
if (isNaN(jRam.usedRam) || isNaN(jRam.totalRam))
continue;
ns.print(`${ns.nFormat(jRam.usedRam * Math.pow(1000,3), "0.00b")} / ${ns.nFormat(jRam.totalRam * Math.pow(1000,3), "0.00b")} (${ns.nFormat( (jRam.totalRam == 0 ? 0 : jRam.usedRam / jRam.totalRam), '0.000%')})`);
}
if (showTargetCount && rawTargets != "NULL PORT DATA") {
ns.print(`Number of Targets: ${JSON.parse(rawTargets).length}`);
}
if (showHostCount && rawHosts != "NULL PORT DATA") {
ns.print(`Number of Hosts: ${JSON.parse(rawHosts).length}`);
}
ns.print(`Runtime: ${ns.tFormat(runTime*1000)}`);
runTime++;
await ns.sleep(1000);
}
}