From 24a63f785b86d62167f6fd1be8c8c74be1d20efd Mon Sep 17 00:00:00 2001 From: Vomitblood Date: Wed, 29 Apr 2026 17:38:35 +0800 Subject: [PATCH] adsf --- src/super.ts | 5 ++++ src/test.ts | 6 +++-- src/utils/nuke.ts | 48 ++++++++++++++++++++++++++++++++++ src/utils/scan.ts | 27 +++++++++++-------- src/utils/script-propagator.ts | 28 ++++++++++++++++++++ 5 files changed, 101 insertions(+), 13 deletions(-) create mode 100644 src/utils/nuke.ts create mode 100644 src/utils/script-propagator.ts diff --git a/src/super.ts b/src/super.ts index 0edc058..22183a7 100644 --- a/src/super.ts +++ b/src/super.ts @@ -1,6 +1,11 @@ import { NS } from '@ns'; export const main = async (ns: NS) => { + if (ns.args.length !== 1) { + ns.tprint('Usage: run super.js [target]'); + return; + } + const target = ns.args[0].toString(); ns.tprint('Target selected: ' + target); diff --git a/src/test.ts b/src/test.ts index df6da43..e61d5d6 100644 --- a/src/test.ts +++ b/src/test.ts @@ -1,7 +1,9 @@ import { NS } from '@ns'; +import { nuke } from './utils/nuke'; import { scan } from './utils/scan'; +import { scriptPropagator } from './utils/script-propagator'; export const main = (ns: NS) => { - const hosts = scan(ns, undefined, 50); - ns.tprint(hosts); + ns.tprint(scan(ns, { rootAccess: true })); + scriptPropagator(ns); }; diff --git a/src/utils/nuke.ts b/src/utils/nuke.ts new file mode 100644 index 0000000..e20b452 --- /dev/null +++ b/src/utils/nuke.ts @@ -0,0 +1,48 @@ +import { NS } from '@ns'; +import { scan } from './scan'; + +// get root access to all the servers that we can +// then return a list of all the servers we have root access to +export const nuke = (ns: NS) => { + // get a list of all hosts + const allHosts: string[] = scan(ns); + const newlyNukedHosts: string[] = []; + + let alreadyNukedCount = 0; + let newlyNukedCount = 0; + let skippedCount = 0; + + // attempt to nuke them all + allHosts.forEach((host) => { + // check if we already have root access to this host + if (ns.hasRootAccess(host)) { + alreadyNukedCount++; + return; + } + + try { + ns.nuke(host); + + // Verification: Did it actually work? + if (ns.hasRootAccess(host)) { + ns.tprint(`Successfully nuked ${host}`); + newlyNukedCount++; + newlyNukedHosts.push(host); + } else { + ns.tprint(`Failed to nuke ${host} (Insufficient ports)`); + skippedCount++; + } + } catch (error) { + ns.tprint(`Error nuking ${host}: ${error}`); + skippedCount++; + } + }); + + // print a summary of the results + ns.tprint(`Already rooted: ${alreadyNukedCount}`); + ns.tprint(`Newly rooted: ${newlyNukedCount}`); + ns.tprint(`Skipped: ${skippedCount}`); + + // scan again to get the list of all hosts we have root access to + return newlyNukedHosts; +}; diff --git a/src/utils/scan.ts b/src/utils/scan.ts index 0a23c20..e5115ab 100644 --- a/src/utils/scan.ts +++ b/src/utils/scan.ts @@ -1,12 +1,16 @@ import { NS } from '@ns'; -export const scan = ( - ns: NS, - rootAccess?: boolean, - requiredHackingSkill?: number, - portsForNuke?: number, - ram?: number, -): string[] => { +interface ScanOptions { + rootAccess?: boolean; + requiredHackingSkill?: number; + portsForNuke?: number; + ram?: number; +} + +export const scan = (ns: NS, options: ScanOptions = {}): string[] => { + // destructure options + const { rootAccess, requiredHackingSkill, portsForNuke, ram } = options; + // initialize a new set to store a list of all hosts const allHosts = new Set(['home']); @@ -20,10 +24,11 @@ export const scan = ( // now we start the filtering into another new list const filteredHosts = Array.from(allHosts).filter((host: string) => { - if (rootAccess && ns.hasRootAccess(host) !== rootAccess) return false; - if (requiredHackingSkill && ns.getServerRequiredHackingLevel(host) > requiredHackingSkill) return false; - if (portsForNuke && ns.getServerNumPortsRequired(host) > portsForNuke) return false; - if (ram && ns.getServerMaxRam(host) < ram) return false; + if (rootAccess !== undefined && ns.hasRootAccess(host) !== rootAccess) return false; + if (requiredHackingSkill !== undefined && ns.getServerRequiredHackingLevel(host) > requiredHackingSkill) + return false; + if (portsForNuke !== undefined && ns.getServerNumPortsRequired(host) > portsForNuke) return false; + if (ram !== undefined && ns.getServerMaxRam(host) < ram) return false; return true; }); diff --git a/src/utils/script-propagator.ts b/src/utils/script-propagator.ts new file mode 100644 index 0000000..85511d2 --- /dev/null +++ b/src/utils/script-propagator.ts @@ -0,0 +1,28 @@ +import { NS } from '@ns'; +import { scan } from './scan'; + +export const scriptPropagator = (ns: NS) => { + // get all hosts with root access + const rootedHosts: string[] = scan(ns, { rootAccess: true }); + + // get all the script files, only the js files + const allScripts: string[] = ns.ls('home', '.js'); + + let totalSynced = 0; + + // iterate through all the rooted hosts and copy the scripts to them + rootedHosts.forEach((host) => { + try { + ns.scp(allScripts, host); + ns.tprint(`Synced scripts to ${host}`); + totalSynced++; + } catch (error) { + ns.tprint(`Failed to sync scripts to ${host}: ${error}`); + } + }); + + ns.tprint(`Total hosts synced: ${totalSynced}`); + + // return the list of rooted hosts for potential further use + return rootedHosts; +};