Skip to content

Commit

Permalink
Fix stats.js not properly filtering out hacknet servers once renamed …
Browse files Browse the repository at this point in the history
…from hacknet-node
  • Loading branch information
alainbryden committed Oct 18, 2024
1 parent 3af8a4f commit 37dc341
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ async function getHudData(ns, bitNode, dictSourceFiles, options) {
const servers = await getAllServersInfo(ns);
const rooted = servers.filter(s => s.hasAdminRights).length;
const purchased = servers.filter(s => s.hostname != "home" && s.purchasedByPlayer).length; // "home" counts as purchased by the game
const likelyHacknet = servers.filter(s => s.hostname.startsWith("hacknet-node-"));
const likelyHacknet = servers.filter(s => s.hostname.startsWith("hacknet-server-") || s.hostname.startsWith("hacknet-node-"));
// Add Server count.
val1.push(true, `${servers.length}/${rooted}/${purchased}`, `The number of servers on the network (${servers.length}) / ` +
`number rooted (${rooted}) / number purchased ` + (likelyHacknet.length > 0 ?
Expand All @@ -258,7 +258,7 @@ async function getHudData(ns, bitNode, dictSourceFiles, options) {
`${formatRam(home.ramUsed, true)} of ${formatRam(home.maxRam, true)} (${formatRam(home.maxRam - home.ramUsed, true)} free)`);
// If the user has any scripts running on hacknet servers, assume they want them included in available RAM stats
const includeHacknet = likelyHacknet.some(s => s.ramUsed > 0);
const [totalMax, totalUsed] = servers.filter(s => s.hasAdminRights && (includeHacknet || !s.hostname.startsWith("hacknet-node-")))
const [totalMax, totalUsed] = servers.filter(s => s.hasAdminRights && (includeHacknet || !(s.hostname.startsWith("hacknet-server-") || s.hostname.startsWith("hacknet-node-"))))
.reduce(([totalMax, totalUsed], s) => [totalMax + s.maxRam, totalUsed + s.ramUsed], [0, 0]);
// Add Total Network RAM and Utilization
val3.push(true, `${formatRam(totalMax)} ${(100 * totalUsed / totalMax).toFixed(1)}%`,
Expand Down

0 comments on commit 37dc341

Please sign in to comment.