For those who are looking for something useful out here. I hope you will not blindly copy/paste it in your game but will find out a few new ideas for structuring your code.
Also I can see several rooms for improvements:
- Create supervisor process that will watch for new available nodes and nuke them for you, so you need to execute something like `run nuke-all-supervisor.js` only once per installing augments.
- Another room for improvement is installing backdoor. It needs you to progress in the game a bit though, in order to unlock the required API.
使用法
run nuke-all.js
Nukes all the servers you have to meet hacking level. As simple as it looks. No further attention is required. Branding image contains my very first step after installing augments.
Memory consumption
As you can see below, memory consumption for this script is below 8G, which means you can use it at early game. I only now have recognized that the getPurchasedServers function takes half of RAM and it doesn’t really require it, so you can improve memory consumption for your needs.
[home ~/]> mem nuke-all.js This script requires 4.75GB of RAM to run for 1 thread(s) 2.25GB | getPurchasedServers (fn) 1.60GB | baseCost (その他) 200.00MB | スキャン (fn) 100.00MB | getServerRequiredHackingLevel (fn) 100.00MB | getServerNumPortsRequired (fn) 100.00MB | fileExists (fn) 50.00MB | hasRootAccess (fn) 50.00MB | getHackingLevel (fn) 50.00MB | nuke (fn) 50.00MB | brutessh (fn) 50.00MB | ftpcrack (fn) 50.00MB | relaysmtp (fn) 50.00MB | httpworm (fn) 50.00MB | sqlinject (fn)
スクリプト
nuke-all.js – Executable script uses library functions to clarify and simplify behavior.
import { acquireRootAccess, buildNetwork, networkToServerList } from 'utils' /** @param {NS} ns **/ 非同期関数メインのエクスポート(ns) { const network = buildNetwork(ns) const networkList = networkToServerList(network) const notNuked = networkList.filter((サーバ) => !ns.hasRootAccess(サーバ)) ために (const host of notNuked) { acquireRootAccess(ns, host) } ns.toast(`${ns.getScriptName()} done`) }
utils.js – Set of utility/library functions
/** * Returns list of callables you can use to open ports on specified server. * * @param {NS} ns * @returns {Array.<(サーバ: 弦): void>} */ export function getAvailableMethods(ns) { const methods = [] ために (const [method, ファイル] の [ [ns.ブルーテッシュ, 「BruteSSH.exe」], [ns.ftpcrack, 「FTPCrack.exe」], [ns.relaysmtp, 「リレーSMTP.exe」], [ns.httpworm, 「HTTPワーム.exe」], [ns.sqlinject, 「SQLInject.exe」] ]) { もし (ns.file存在します(ファイル)) { methods.push(method) } } return methods } /** * Try to acquire Root access to the target server. * * @param {NS} ns * @param {弦} target Server name to get Root access to. * @returns {ブール値} Was attempt successful or not. */ export function acquireRootAccess(ns, ターゲット) { もし (!ns.hasRootAccess(ターゲット)) { もし (ns.getHackingLevel() < ns.getServerRequiredHackingLevel(ターゲット)) { ns.print(`ERROR: Not enough hacking level for ${ターゲット}`) return false } const methods = getAvailableMethods(ns); もし (methods.length < ns.getServerNumPorts必須(ターゲット)) { ns.print(`ERROR: Not enough breaking methods for ${ターゲット}`) return false } ために (const method of methods) { method(ターゲット) } ns.核(ターゲット) } return true } /** * Simple directed graph representation of a network, which consists of * it's name and list of child nodes. * * @typedef {{名前: 弦, 子供たち: NetworkNode[]}} NetworkNode */ /** * Returns network representation in form of directed graph using DFS. * The most common case is that you do not care about network nodes you can * not nuke right now. That is why this function only returns nodes for * which you have meet hacking level. * * @param {NS} ns * @param {弦} name Name of the network node/server we are working with. * @param {弦[]} used List of nodes we have already processed. * @returns {NetworkNode} Directed graph */ export function buildNetwork(ns, name = 'home', used = []) { used.push(名前) const node = { 名前: 名前, 子供たち: [] } const serverList = ns.getPurchasedServers() ために (const child of ns.scan(node.name)) { もし (ns.getServerRequiredHackingLevel(child) <= ns.getHackingLevel() && !used.includes(child) && !サーバーリスト.includes(child) ) { node.children.push(buildNetwork(ns, child, 使用済み)) } } return node } /** * It is not strictly required to works with network in form of a graph. * Sometimes we just have to know what nodes are present. This is what * this function is for: to convert data structure format from directed * graph to plain list of network's nodes. * * @param {NetworkNode} ノード * @returns {弦[]} List of all servers in the network. */ export function networkToServerList(ノード) { const list = [node.name] もし (node.children.length) { ために (const child of node.children) { list.push(...networkToServerList(child)) } } return list }
これが今日私たちがこの目的で共有するすべてです ビットバーナー ガイド. このガイドは元々、次の者によって作成および執筆されました。 koutoftimer. このガイドを更新できなかった場合, これに従って最新のアップデートを見つけることができます リンク.