Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** @param {NS} ns **/
- function getRootedHomeNeighbors(ns) {
- /**
- * Return all rooted hosts from 'home'
- * Don't return private servers
- */
- let hosts = [];
- ns.scan('home').forEach(e => {
- if (e.includes('psrv-')) {
- return;
- }
- if (ns.hasRootAccess(e)) {
- hosts.push(e);
- }
- });
- return Object.values(hosts);
- }
- /** @param {NS} ns **/
- function getRootedHostNeighbors(ns, host, upstream) {
- /**
- * Return all rooted hosts from host
- */
- let hosts = [];
- ns.scan(host).forEach(e => {
- // Ignore home & upstream neighbor
- if ((e === 'home') || (e === upstream)) {
- return;
- }
- if (ns.hasRootAccess(e)) {
- hosts.push(e);
- }
- });
- return Object.values(hosts);
- }
- /** @param {NS} ns **/
- export function getRootedHosts(ns) {
- /**
- * Return all rooted hosts
- * Checking 5 Depth Levels
- */
- var hosts = [];
- // Depth 1
- getRootedHomeNeighbors(ns).forEach(homeNeighbor => {
- hosts.push(homeNeighbor);
- // Depth 2
- let hostNeighbors1 = getRootedHostNeighbors(ns, homeNeighbor);
- hostNeighbors1.forEach(hostNeighbor1 => {
- hosts.push(hostNeighbor1);
- // Depth 3
- let hostNeighbors2 = getRootedHostNeighbors(ns, hostNeighbor1, homeNeighbor);
- hostNeighbors2.forEach(hostNeighbor2 => {
- hosts.push(hostNeighbor2);
- // Depth 4
- let hostNeighbors3 = getRootedHostNeighbors(ns, hostNeighbor2, hostNeighbor1);
- hostNeighbors3.forEach(hostNeighbor3 => {
- hosts.push(hostNeighbor3);
- // Depth 5
- let hostNeighbors4 = getRootedHostNeighbors(ns, hostNeighbor3, hostNeighbor2);
- hostNeighbors4.forEach(hostNeighbor4 => {
- hosts.push(hostNeighbor4);
- // Done for now, may get deeper scanning later
- })
- });
- });
- });
- });
- return Object.values(hosts);
- }
Advertisement
Add Comment
Please, Sign In to add comment