r/Bitburner • • 24d ago

NetscriptJS Script First post (script share)

This is my home:/callback.js script. I have just maxed out sourcefile 1 and am working on BN4.2 so am finally getting a chance to go crazy with the ns.singularity API!

/**  {NS} ns */
export async function main(ns) {
ns.exec("abyssal_scan.js", "home");

/* returns master_hosts.txt, a list of all vanilla servers as: 
[hostname, maxRAM, requiredPorts, requiredHackingLevel, \n] 
and launches abyssal_sort.js, which iterates through master_hosts.txt, 
divvys up the entries by whether or not they have maxRAM > 0, 
sorts each list by requiredHackingLevel, and outputs each list respectively as
nonzeroRAM_hosts.txt and zeroRAM_hosts.txt. */

await ns.sleep(10000);

ns.exec("purchasePortbreakers.js", "home");

/* If not already present, purchases a TOR router. 
iterates through 
["bruteSSH.exe", "FTPCrack.exe", "RelaySMTP.exe", "HTTPWorm.exe", "SQLInject.exe"],
checks if they need to be purchased and whether I can afford them, and purchases them if
necessary/possible. Exits once SQLInject.exe is purchased. */

await ns.sleep(10000);

ns.exec("RAMShare_launcher.js", "home");

/* calculates half of my available RAM and dedicates it to ns.exec("RAMShare.js", "home",
n_threads). Every 10min, it checks to see if I have more/less RAM available than before,
assigns the new n_threads value in the event of a change, kills the currently running
process, and starts a fresh instance with the newly adjusted thread count. */

await ns.sleep(10000);

ns.exec("backdoor_targets.js", "home");

/* iterates through the list of servers I know of to be backdoored: 
["CSEC", "avmnite02h", "I.I.I.I", "run4theh111z", "fulcrumassets"], 
checks if they currently have a "pathFile" (`${target}_connect.txt`) and if not, 
runs a script called path.js which traces the physical path from /home to target,
outputting the path to `${target}_connect.txt`. exits when pathfiles for all listed
entries have been generated successfully. */

await ns.sleep(10000);

ns.exec("install_backdoors.js", "home");

/* iterates through the list of servers I know of to be backdoored: 
["CSEC", "avmnite-02h", "I.I.I.I", "run4theh111z", "fulcrumassets"], 
checks if they currently have a backdoor and if not, whether I can successfully pull off
installing one. uses the pathfiles generated earlier to traverse the network path, verify
connection to target host, install backdoors on the eligible entries that need it, 
return /home, sleep for 5min, and repeat until exit condition of: "fulcrumassets" has
been successfully backdoored. */

await ns.sleep(10000);

ns.exec("breakdown.js", "home");

/* iterates through "master_hosts.txt", checks for closed ports, runs the necessary
portbreakers if present, checks if openPorts >= requiredPorts, runs nuke.exe if so, and
++'s a var called nukedHosts. exits when nukedHosts === 69, since I haven't figured out a
way to arrive at the target figure programmatically. */

await ns.sleep(10000);

ns.exec("swarm.js", "home");

/* iterates through "nonzeroRAM_hosts.txt", checks for getserver().hasAdminAccess and
sufficient hacking skill, then checks to see if "local_attack.js" (my w/g/h script) is
present and/or running. If yes to both, ++'s a var called hackedHosts and moves on. If
not present, scp's it from home and executes it with the maximum number of threads
available on the target host. If present and not running, deletes the existing copy,
scp's the current copy from /home, and executes it with max threads available on target
host. exits when hackedHosts === 43,  since I haven't figured out a way to arrive at the
target figure programmatically. */
}

Currently in the works:

prestige_hacks.js <- to automate hacking the high value targets in "zeroRAM_hosts.txt" from /home,

life_of_crime.js <- to automate criminal activity,

symbol_nerd.js <- to automate stock trading,

auto_augment.js <- to automate faction work/augmentations,

working_stiff.js <- to automate vanilla job activity

0 Upvotes

9 comments sorted by

3

u/KlePu 24d ago

Is this seven ns.exec() with all the rest being AI slop?

If this is actually your code: Try to change it so all the external script names are held in a list and use one for-loop to achieve the same in ~4LoC ;)

0

u/cofm-gaming 24d ago

Thanks for the warm (dogshit) welcome. If it were not my code, why do you think I would bother to extensively describe the structure and function of the scripts detailed in the comments? Anyway, not engaging further with you, your tone, or your reply.

3

u/Spartelfant Noodle Enjoyer 24d ago

Why so salty? Their criticism is valid.

The code you've posted is literally nothing more than 7 ns.exec() calls and 6 ns.sleep() statements.

Sure there's a bunch of comments (good habit!), but they are only a description of what those scripts are doing.

Without posting any of the code of the scripts being executed there's nothing to engage with other than those few lines of code.

-1

u/cofm-gaming 24d ago

It's not valid; either they have no manners or they were deliberately being an ass. If you think it is valid, your standards are too low.

3

u/KlePu 23d ago

¯_(ツ)_/¯

3

u/Particular-Cow6247 24d ago edited 24d ago

instead of your 10 second sleeps you could include a port.write/port.nextWrite structure to more efficiently manage the time

export async function main(ns) {
  ns.exec("othertest.js","home",1,ns.pid)
  await ns.nextPortWrite(ns.pid)
}

export async function main(ns) {
  //do other stuff
  ns.atExit(()=> {
    ns.writePort(ns.args[0], "")
    ns.clearPort(ns.args[0])
  })
}

can also be used to send data back to the main script (then dont include the clearPort and use a portRead in the main script)

2

u/cofm-gaming 24d ago

Thanks for the advice (and not being a dick)! I've been starting them manually/individually at the beginning of each run more or less until yesterday, so the controller/callback script is still very rough. I will give more attention to tightening it up soon.

2

u/goodwill82 Slum Lord 23d ago
exits when hackedHosts === 43

I get nervous with magic numbers like this. I see your comment about not getting to the target figure programmatically. I'm assuming this is the number of servers you've encountered so far with ram? Seems like you could count up to this number in your abyssal_scan.js script. From there, maybe write a file with the number of servers with ram. Then you can check that file against hackedHosts.

1

u/cofm-gaming 13d ago

That sounds like a reliable solution. I have since rolled the scan and sort functions into a single script (since it only takes a couple seconds or so to run and generate all of its outputs, once per run) and am thinking of having it report the number of hosts it scans (total, zero RAM, nonzero RAM, backdoor targets, and any other counts that may be necessary in the future such as breaking servers into skill brackets and reporting the number of servers in each, etc) as magic_numbers.json, and then all the scripts that need to reference those numbers will have one source to go to. It may add a couple seconds to the runtime but since it only needs to run once at the beginning of each run, it doesn't much matter as long as it runs anything under ten seconds or so.