Bitburner

Bitburner

Not enough ratings
Need directions to a server?
By WhiskeyFur
Need a quick route to a particular destination? I've created a script that'll give you the directions.

No more feeling like a lost tourist looking for a node again.
   
Award
Favorite
Favorited
Unfavorite
First you make a left at...
This is something of a shortcut to finding some of those more hard to reach nodes.

You might think your version 2 of the scan-analyzer might give you a way to directly connect to every node... think again.

The scanner only goes to a range of 10 nodes and no further, which means finding the more distant nodes (up to *13* hops from home!) requires actually going a bit into the wilds and connecting further in before attempting that scan again.

I created this utility to find a path to those distant places, and to make it easier, even create a string you can cut and paste right into your terminal to take you right there.

Note, I'm not going to give away any plot based server names here.. that's more an exercise for the reader.
The script
import { getAllServers } from "lib-servers.ns"; /** @param {NS} ns **/ export async function main(ns) { var servers = {} var ctr = 1; var ptr = ns.args[0]; var route = [] try { function printRoute(route) { ns.tprint("ROUTE: connect " + route.join("; connect ") + ";"); } var all = await getAllServers(ns); if (ns.args.length == 0) { ns.tprint("Need to pass in a server name. Execution cancelled.") } else if (!all.filter((s) => s == ns.args[0]).length) { ns.tprint("Unable to locate " + ns.args[0] + ". Did you misspell the name?") } else { for (var server of all) { servers[server] = { name: server, links: ns.scan(server), parent: null } } servers["home"].parent = "home"; while (ctr > 0) { ctr = 0; for (var server of Object.values(servers)) { if (server.parent != null) { for (var link of server.links) { if (servers[link].parent == null) { servers[link].parent = server.name ctr++ } } } } await ns.sleep(10); } while (ptr != "home") { route.unshift(servers[ptr].name) ptr = servers[ptr].parent } printRoute(route); } } catch (ex) { ns.write("dump-trace.txt", JSON.stringify({ "error" : ex, "servers" : servers, "ctr" : ctr, "ptr" : ptr, "route" : route }), "w") } } /** * @param {{servers: any[]}} data * @param {any[]} args * @returns {*[]} */ export function autocomplete(data, args) { return [...data.servers]; }
... and the lib-servers.ns library
/** @param {NS} ns **/ export async function getAllServers(ns) { const nodes = new Set function dfs(node) { nodes.add(node); for (const neighbor of ns.scan(node)) { if (!nodes.has(neighbor)) { dfs(neighbor) } } } dfs("home"); return [...nodes]; }
Example usage
From home to omega-net,
[home ~/]> run find.ns omega-net

Will give you this in a window:
Running script with 1 thread(s), pid 5796 and args: ["omega-net"]. find.ns: ROUTE: connect sigma-cosmetics; connect zer0; connect omega-net;
Any questions?
This script was written with a basic error handler, so if something goes wrong and you need help,
cat dump-trace.txt
and see what it says in there. That may help diagnose what happened.

This is my first guide here so comments and questions are appreciated, and I would love to know how this script helped you out in your own adventures.
25 Comments
secret cheeseman 1 Feb, 2024 @ 1:43am 
export async function main(ns) {
ns.tail()
ns.disableLog('ALL')
ns.enableLog('print')
ns.clearLog()
var exit = ns.args[0] || 'CSEC'
var path = []
ns.print('The path is (paste this into terminal):')
if (exit == 'home') {
ns.print('home')
return
}
if (ns.scan(exit)[0] == 'home') {
ns.print(`home; connect ${exit}`)
return
}
var scanServer = exit
while (ns.scan(scanServer)[0] != 'home') {
path.push(ns.scan(scanServer)[0])
scanServer = ns.scan(scanServer)[0]
}
path.reverse()
path.push(exit)
ns.print(`home; ${'connect ' + path.join("; connect ") + ";"}`)
}
may or may not have made my own teleport
it relies on the parent of the server being the first item in the array, then just does the parents for a while until it reaches Home
Raethor 1 Jun, 2022 @ 2:00pm 
while (ctr > 0) {
ctr = 0;
for (var server of Object.values(servers)) {
if (server.parent != null) {
for (var link of server.links) {
if (servers[link].parent == null) {
servers[link].parent = server.name
ctr++
}
}
}
}

Makes it so that doesn't seem to work.

I removed ctr=0, and changed ctr++ to ctr--

while (ctr > 0) {
for (var server of Object.values(servers)) {
if (server.parent != null) {
for (var link of server.links) {
if (servers[link].parent == null) {
servers[link].parent = server.name
ctr--
}
}
}
}

Which seems to have fixed the issue.
Harg "Orange" 10 Jan, 2022 @ 12:28pm 
it's working perfectly now. Thanks a lot :)
WhiskeyFur  [author] 10 Jan, 2022 @ 4:35am 
Made some updates, so please feel free to double check.
I use a modified (and FAR more complex) version on my game than here, so I can't really check all that easily.

Changes made:
It now WRITES instead of APPENDS to the dump file
Corrected function and library names to match in this example.
Harg "Orange" 9 Jan, 2022 @ 5:00am 
is it possible than ns.scan(server) return null ?
Harg "Orange" 9 Jan, 2022 @ 1:52am 
feel free to add me and let's check that together
Harg "Orange" 9 Jan, 2022 @ 1:52am 
Ok, no more error, but no result, and the dump became insanely huge now

dump-trace.txt

{"error":{},"servers":{"home":{"name":"home","links":["n00dles","foodnstuff","sigma-cosmetics","joesguns","hong-fang-tea","harakiri-sushi","iron-gym","darkweb","pserv-0","pserv-2","pserv-4","pserv-6","pserv-8","pserv-10","pserv-12","pserv-14","pserv-16","pserv-18","pserv-20","pserv-22","pserv-24","pserv-26","pserv-28","pserv-30","pserv-32","pserv-34","pserv-36","pserv-38","pserv-40","pserv-42","pserv-44","pserv-46","pserv-48"],"parent":"home"},"n00dles":{"name":"n00dles","links":["home"],"parent":"home"},"foodnstuff":{"name":"foodnstuff","links":["home","nectar-net"],"parent":"home"},"nectar-net":{"name":"nectar-
...
Harg "Orange" 9 Jan, 2022 @ 1:49am 
+ getAllServers doesn't exist (it is allServers)
I feel you use a different version of the lib.
Harg "Orange" 9 Jan, 2022 @ 1:47am 
man, you import lib-servers.ns while the file is named lib-getServers.ns
let me fix that and retry.
WhiskeyFur  [author] 8 Jan, 2022 @ 5:23pm 
Think I located the issue.. I left out the import line at the top of the cmd-trace program. That has been added back in.

Can you try again with the updated script and see if it works?