diff --git a/scan.js b/scan.js index 02a53e18..4219d4ac 100644 --- a/scan.js +++ b/scan.js @@ -1,8 +1,21 @@ +import { getConfiguration, formatRam, formatMoney, formatNumber } from './helpers.js' + +const argsSchema = [ + ['hide-stats', false], // Set to false to hide detailed server statistics (RAM, max money, etc...) +]; + +export function autocomplete(data, _) { + data.flags(argsSchema); + return []; +} + /** * @param {NS} ns * @returns interactive server map */ export function main(ns) { + const options = getConfiguration(ns, argsSchema); + const showStats = !options['hide-stats']; const factionServers = ["CSEC", "avmnite-02h", "I.I.I.I", "run4theh111z", "w0r1d_d43m0n", "fulcrumassets"], css = ` `, doc = eval("document"), terminalInsert = html => doc.getElementById("terminal").insertAdjacentHTML('beforeend', `
  • ${html}
  • `), @@ -37,6 +51,7 @@ export function main(ns) { hasAdminRights: ns.hasRootAccess(serverName), purchasedByPlayer: serverName.includes('daemon') || serverName.includes('hacknet'), backdoorInstalled: true // No way of knowing without ns.getServer + // TODO: Other things needed if showStats is true } */ }, createServerEntry = serverName => { @@ -44,19 +59,29 @@ export function main(ns) { requiredHackLevel = server.requiredHackingSkill, rooted = server.hasAdminRights, canHack = requiredHackLevel <= myHackLevel, - shouldBackdoor = !server?.backdoorInstalled && canHack && serverName != 'home' && rooted && !server.purchasedByPlayer, + shouldBackdoor = !server.backdoorInstalled && canHack && serverName != 'home' && rooted && !server.purchasedByPlayer, contracts = ns.ls(serverName, ".cct") return `` + `${serverName}` + (server.purchasedByPlayer ? '' : ` (${requiredHackLevel})`) - + `${(shouldBackdoor ? ' [backdoor]' : '')}` + + `${(shouldBackdoor ? ` [backdoor]` : '')}` + ` ${contracts.map(c => `@`)}` + + (showStats ? ` ... ` + + `Money: ` + ((server.moneyMax > 0 ? `${formatMoney(server.moneyAvailable, 4, 1).padStart(7)} / ` : '') + `${formatMoney(server.moneyMax, 4, 1).padStart(7)} `).padEnd(18) + + `Sec: ${formatNumber(server.hackDifficulty, 0, 0).padStart(2)}/${formatNumber(server.minDifficulty, 0, 0)} `.padEnd(11) + + `RAM: ${formatRam(server.maxRam).replace(' ', '').padStart(5)}` + (server.maxRam > 0 ? ` (${formatNumber(server.ramUsed * 100.0 / server.maxRam, 0, 1)}% used)` : '') + + `` : '') + "" }, buildOutput = (parent = servers[0], prefix = ["\n"]) => { let output = prefix.join("") + createServerEntry(parent) + if (showStats) { // Roughly right-align server stats if enabled + const expectedLength = parent.length + (2 * prefix.length) + (output.includes('backdoor') ? 10 : 0) + + (output.match(/@/g) || []).length + (((output.match(/\(\d+\)/g) || [{ length: 0 }])[0].length) + 1); + output = output.replace('...', '.'.repeat(Math.max(1, 60 - expectedLength))); + } for (let i = 0; i < servers.length; i++) { if (parentByIndex[i] != parent) continue let newPrefix = prefix.slice()