Compare commits
36 Commits
b40c4d07e8
...
master
Author | SHA1 | Date | |
---|---|---|---|
b99827a84b | |||
62b1d6edfd | |||
78d8153f8e | |||
461775a92f | |||
70ec4d9463 | |||
1d3ce073f6 | |||
9bacf4f97f | |||
9b4042af40 | |||
e6aca2e998 | |||
df2d550eb6 | |||
c320b31ac3 | |||
f0d4017711 | |||
2ca91f574f | |||
7de44a3c2f | |||
afa44d0ea4 | |||
83ba1af0cc | |||
fad1c1a7c4 | |||
ab6635d00e | |||
116daf3781 | |||
1af46c5d6f | |||
f52af72140 | |||
12d9165162 | |||
5febd7ed3b | |||
8dff0b71d6 | |||
f7fa595d71 | |||
6e1b576bcf | |||
6c6f8b0b70 | |||
90fef7e53a | |||
92ad2da7b7 | |||
a3bdb2ccd1 | |||
677f23ea8d | |||
29d88170ab | |||
74aae19a82 | |||
5d6063917b | |||
22ddbbde5d | |||
683daff911 |
10
.editorconfig
Normal file
10
.editorconfig
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# All files
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
# Markup files
|
||||||
|
[*.{json,yml}]
|
||||||
|
indent_style = space
|
215
.gitattributes
vendored
Normal file
215
.gitattributes
vendored
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
## GITATTRIBUTES FOR WEB PROJECTS
|
||||||
|
#
|
||||||
|
# These settings are for any web project.
|
||||||
|
#
|
||||||
|
# Details per file setting:
|
||||||
|
# text These files should be normalized (i.e. convert CRLF to LF).
|
||||||
|
# binary These files are binary and should be left untouched.
|
||||||
|
#
|
||||||
|
# Note that binary is a macro for -text -diff.
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
# Auto detect
|
||||||
|
## Handle line endings automatically for files detected as
|
||||||
|
## text and leave all files detected as binary untouched.
|
||||||
|
## This will handle all files NOT defined below.
|
||||||
|
* text=auto
|
||||||
|
|
||||||
|
# Source code
|
||||||
|
*.bash text eol=lf
|
||||||
|
*.bat text eol=crlf
|
||||||
|
*.cmd text eol=crlf
|
||||||
|
*.coffee text
|
||||||
|
*.css text diff=css
|
||||||
|
*.htm text diff=html
|
||||||
|
*.html text diff=html
|
||||||
|
*.inc text
|
||||||
|
*.ini text
|
||||||
|
*.js text
|
||||||
|
*.json text
|
||||||
|
*.jsx text
|
||||||
|
*.less text
|
||||||
|
*.ls text
|
||||||
|
*.map text -diff
|
||||||
|
*.od text
|
||||||
|
*.onlydata text
|
||||||
|
*.php text diff=php
|
||||||
|
*.pl text
|
||||||
|
*.ps1 text eol=crlf
|
||||||
|
*.py text diff=python
|
||||||
|
*.rb text diff=ruby
|
||||||
|
*.sass text
|
||||||
|
*.scm text
|
||||||
|
*.scss text diff=css
|
||||||
|
*.sh text eol=lf
|
||||||
|
.husky/* text eol=lf
|
||||||
|
*.sql text
|
||||||
|
*.styl text
|
||||||
|
*.tag text
|
||||||
|
*.ts text
|
||||||
|
*.tsx text
|
||||||
|
*.xml text
|
||||||
|
*.xhtml text diff=html
|
||||||
|
|
||||||
|
# Docker
|
||||||
|
Dockerfile text
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
*.ipynb text eol=lf
|
||||||
|
*.markdown text diff=markdown
|
||||||
|
*.md text diff=markdown
|
||||||
|
*.mdwn text diff=markdown
|
||||||
|
*.mdown text diff=markdown
|
||||||
|
*.mkd text diff=markdown
|
||||||
|
*.mkdn text diff=markdown
|
||||||
|
*.mdtxt text
|
||||||
|
*.mdtext text
|
||||||
|
*.txt text
|
||||||
|
AUTHORS text
|
||||||
|
CHANGELOG text
|
||||||
|
CHANGES text
|
||||||
|
CONTRIBUTING text
|
||||||
|
COPYING text
|
||||||
|
copyright text
|
||||||
|
*COPYRIGHT* text
|
||||||
|
INSTALL text
|
||||||
|
license text
|
||||||
|
LICENSE text
|
||||||
|
NEWS text
|
||||||
|
readme text
|
||||||
|
*README* text
|
||||||
|
TODO text
|
||||||
|
|
||||||
|
# Templates
|
||||||
|
*.dot text
|
||||||
|
*.ejs text
|
||||||
|
*.erb text
|
||||||
|
*.haml text
|
||||||
|
*.handlebars text
|
||||||
|
*.hbs text
|
||||||
|
*.hbt text
|
||||||
|
*.jade text
|
||||||
|
*.latte text
|
||||||
|
*.mustache text
|
||||||
|
*.njk text
|
||||||
|
*.phtml text
|
||||||
|
*.svelte text
|
||||||
|
*.tmpl text
|
||||||
|
*.tpl text
|
||||||
|
*.twig text
|
||||||
|
*.vue text
|
||||||
|
|
||||||
|
# Configs
|
||||||
|
*.cnf text
|
||||||
|
*.conf text
|
||||||
|
*.config text
|
||||||
|
.editorconfig text
|
||||||
|
.env text
|
||||||
|
.gitattributes text
|
||||||
|
.gitconfig text
|
||||||
|
.htaccess text
|
||||||
|
*.lock text -diff
|
||||||
|
package.json text eol=lf
|
||||||
|
package-lock.json text eol=lf -diff
|
||||||
|
pnpm-lock.yaml text eol=lf -diff
|
||||||
|
.prettierrc text
|
||||||
|
yarn.lock text -diff
|
||||||
|
*.toml text
|
||||||
|
*.yaml text
|
||||||
|
*.yml text
|
||||||
|
browserslist text
|
||||||
|
Makefile text
|
||||||
|
makefile text
|
||||||
|
# Fixes syntax highlighting on GitHub to allow comments
|
||||||
|
tsconfig.json linguist-language=JSON-with-Comments
|
||||||
|
|
||||||
|
# Heroku
|
||||||
|
Procfile text
|
||||||
|
|
||||||
|
# Graphics
|
||||||
|
*.ai binary
|
||||||
|
*.bmp binary
|
||||||
|
*.eps binary
|
||||||
|
*.gif binary
|
||||||
|
*.gifv binary
|
||||||
|
*.ico binary
|
||||||
|
*.jng binary
|
||||||
|
*.jp2 binary
|
||||||
|
*.jpg binary
|
||||||
|
*.jpeg binary
|
||||||
|
*.jpx binary
|
||||||
|
*.jxr binary
|
||||||
|
*.pdf binary
|
||||||
|
*.png binary
|
||||||
|
*.psb binary
|
||||||
|
*.psd binary
|
||||||
|
# SVG treated as an asset (binary) by default.
|
||||||
|
*.svg text
|
||||||
|
# If you want to treat it as binary,
|
||||||
|
# use the following line instead.
|
||||||
|
# *.svg binary
|
||||||
|
*.svgz binary
|
||||||
|
*.tif binary
|
||||||
|
*.tiff binary
|
||||||
|
*.wbmp binary
|
||||||
|
*.webp binary
|
||||||
|
|
||||||
|
# Audio
|
||||||
|
*.kar binary
|
||||||
|
*.m4a binary
|
||||||
|
*.mid binary
|
||||||
|
*.midi binary
|
||||||
|
*.mp3 binary
|
||||||
|
*.ogg binary
|
||||||
|
*.ra binary
|
||||||
|
|
||||||
|
# Video
|
||||||
|
*.3gpp binary
|
||||||
|
*.3gp binary
|
||||||
|
*.as binary
|
||||||
|
*.asf binary
|
||||||
|
*.asx binary
|
||||||
|
*.avi binary
|
||||||
|
*.fla binary
|
||||||
|
*.flv binary
|
||||||
|
*.m4v binary
|
||||||
|
*.mng binary
|
||||||
|
*.mov binary
|
||||||
|
*.mp4 binary
|
||||||
|
*.mpeg binary
|
||||||
|
*.mpg binary
|
||||||
|
*.ogv binary
|
||||||
|
*.swc binary
|
||||||
|
*.swf binary
|
||||||
|
*.webm binary
|
||||||
|
|
||||||
|
# Archives
|
||||||
|
*.7z binary
|
||||||
|
*.gz binary
|
||||||
|
*.jar binary
|
||||||
|
*.rar binary
|
||||||
|
*.tar binary
|
||||||
|
*.zip binary
|
||||||
|
|
||||||
|
# Fonts
|
||||||
|
*.ttf binary
|
||||||
|
*.eot binary
|
||||||
|
*.otf binary
|
||||||
|
*.woff binary
|
||||||
|
*.woff2 binary
|
||||||
|
|
||||||
|
# Executables
|
||||||
|
*.exe binary
|
||||||
|
*.pyc binary
|
||||||
|
# Prevents massive diffs caused by vendored, minified files
|
||||||
|
**/.yarn/releases/** binary
|
||||||
|
**/.yarn/plugins/** binary
|
||||||
|
|
||||||
|
# RC files (like .babelrc or .eslintrc)
|
||||||
|
*.*rc text
|
||||||
|
|
||||||
|
# Ignore files (like .npmignore or .gitignore)
|
||||||
|
*.*ignore text
|
||||||
|
|
||||||
|
# Prevents massive diffs from built files
|
||||||
|
dist/* binary
|
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||||
|
</state>
|
||||||
|
</component>
|
@ -1,4 +1,5 @@
|
|||||||
export async function main(ns: NS) {
|
export async function main(ns: NS) {
|
||||||
|
ns.run("hackallservers.js")
|
||||||
ns.run("watcher.js")
|
ns.run("watcher.js")
|
||||||
ns.run("hacknet.js")
|
ns.run("hacknet.js")
|
||||||
}
|
}
|
@ -1,23 +1,14 @@
|
|||||||
export async function main(ns: NS) {
|
export async function main(ns: NS) {
|
||||||
const server: string = <string>ns.args[0];
|
const server: string = <string> ns.args[0]
|
||||||
while (true) {
|
while (true) {
|
||||||
/* This code checks conditions that are not needed with smart scheduling
|
// Guide https://darktechnomancer.github.io/#glossary-of-terms
|
||||||
const moneyThresh: number = <number>ns.args[1];
|
|
||||||
const securityThresh: number = <number>ns.args[2];
|
|
||||||
if (ns.getServerSecurityLevel(server) > securityThresh) {
|
|
||||||
await ns.weaken(server);
|
|
||||||
} else if (ns.getServerMoneyAvailable(server) < moneyThresh) {
|
|
||||||
await ns.grow(server);
|
|
||||||
} else {
|
|
||||||
await ns.hack(server);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Guide
|
if (ns.getServerSecurityLevel(server) > 5) {
|
||||||
// https://darktechnomancer.github.io/#glossary-of-terms
|
await ns.weaken(server)
|
||||||
await ns.weaken(server);
|
} else if (ns.getServerMoneyAvailable(server) < ns.getServerMaxMoney(server) * 0.95) {
|
||||||
await ns.grow(server);
|
await ns.grow(server)
|
||||||
await ns.weaken(server);
|
} else {
|
||||||
await ns.hack(server);
|
await ns.hack(server)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,15 +1,15 @@
|
|||||||
import {recursiveScan} from "./utils";
|
import { executeScriptOnServerFromAnother, recursiveScan } from "./utils"
|
||||||
import {executeScriptOnServerFromAnother} from "./utils";
|
|
||||||
export async function main(ns: NS) {
|
export async function main(ns: NS) {
|
||||||
let servers: string[] = recursiveScan(ns);
|
let servers: string[] = recursiveScan(ns)
|
||||||
|
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
// Commented out code is not needed with smart scheduling
|
// Guard clause for story servers, but hacking xp is nice. Can probably be enabled when XP is easy to get
|
||||||
//let moneyThresh = ns.getServerMaxMoney(server) * 0.75;
|
// if (ns.getServerMaxMoney(server) === 0) { continue }
|
||||||
//let securityThresh = ns.getServerMinSecurityLevel(server) + 5;
|
|
||||||
let numThreads = ns.getServerMaxRam(server) / ns.getScriptRam("hack.js")
|
let numThreads = ns.getServerMaxRam(server) / ns.getScriptRam("hack.js")
|
||||||
numThreads = Math.floor(numThreads);
|
numThreads = Math.floor(numThreads)
|
||||||
//executeScriptOnServerFromAnother(ns, server, "hack.js", numThreads, [server, moneyThresh, securityThresh])
|
numThreads = Math.max(numThreads, 1) // Make sure we have at least 1 thread
|
||||||
executeScriptOnServerFromAnother(ns, server, "hack.js", numThreads, [server])
|
executeScriptOnServerFromAnother(ns, server, "hack.js", numThreads, [server])
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,34 +13,35 @@
|
|||||||
* If the upgrade mps is less than the average mps, then buy a new node.
|
* If the upgrade mps is less than the average mps, then buy a new node.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
enum Type {
|
enum UpgradeType {
|
||||||
newNode = "node",
|
level = "level", ram = "ram", core = "code",
|
||||||
level = "level",
|
|
||||||
ram = "ram",
|
|
||||||
core = "code"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function main(ns: NS) {
|
export async function main(ns: NS) {
|
||||||
let timeout: number = <number>ns.args[0]
|
let timeout: number = <number> ns.args[0]
|
||||||
|
|
||||||
let nodes = ns.hacknet.numNodes()
|
let nodes = ns.hacknet.numNodes()
|
||||||
let costs: {type: Type, cost: number}[] = []
|
// If there are no nodes, buyUpgrade one
|
||||||
|
if (nodes === 0) {
|
||||||
|
ns.hacknet.purchaseNode()
|
||||||
|
nodes = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
let costs: { type: UpgradeType, cost: number }[] = []
|
||||||
while (true) {
|
while (true) {
|
||||||
costs = []
|
costs = []
|
||||||
// Go through each node and get the cheapest upgrade
|
// Go through each node and get the cheapest upgrade
|
||||||
for (let i = 0; i < nodes; i++) {
|
for (let i = 0; i < nodes; i++) {
|
||||||
costs.push(getCheapestCost(ns, i))
|
costs.push(getCheapestCost(ns, i))
|
||||||
}
|
}
|
||||||
// Buy the cheapest upgrade from all nodes
|
// Get the cheapest upgrade object
|
||||||
let cheapest = Math.min(...costs.map(c => c.cost))
|
let cheapest = costs.reduce((prev, curr) => prev.cost < curr.cost ? prev : curr)
|
||||||
// Find the index of the cheapest cost in the list
|
|
||||||
let index = costs.findIndex(c => c.cost === cheapest)
|
// Nodes have a lot more value, so only need node price to be 1/10th the cost of the cheapest upgrade
|
||||||
// Wait to buy the cheapest upgrade
|
if (ns.hacknet.getPurchaseNodeCost() / 10 < cheapest.cost) {
|
||||||
try {
|
await buyNode(ns, ns.hacknet.getPurchaseNodeCost(), timeout)
|
||||||
await buy(ns, costs[index].type, costs[index].cost, index, timeout)
|
} else {
|
||||||
} catch (e) {
|
await buyUpgrade(ns, cheapest.type, cheapest.cost, costs.indexOf(cheapest), timeout)
|
||||||
ns.tprint(e)
|
|
||||||
ns.exit()
|
|
||||||
}
|
}
|
||||||
// Make sure that the number of nodes is up-to-date
|
// Make sure that the number of nodes is up-to-date
|
||||||
nodes = ns.hacknet.numNodes()
|
nodes = ns.hacknet.numNodes()
|
||||||
@ -48,7 +49,7 @@ export async function main(ns: NS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wait until the player has enough money to buy something
|
* Wait until the player has enough money to buyUpgrade something
|
||||||
* @param ns Global NS object
|
* @param ns Global NS object
|
||||||
* @param money Amount of money to wait for
|
* @param money Amount of money to wait for
|
||||||
* @param timeout=-1 Number of seconds to wait before timing out.
|
* @param timeout=-1 Number of seconds to wait before timing out.
|
||||||
@ -61,43 +62,42 @@ async function waitUntilMoney(ns: NS, money: number, timeout: number = -1) {
|
|||||||
if (timeout == 0) {
|
if (timeout == 0) {
|
||||||
throw new Error("Timed out waiting for money")
|
throw new Error("Timed out waiting for money")
|
||||||
} else if (timeout > -1) {
|
} else if (timeout > -1) {
|
||||||
timeout--;
|
timeout--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buy(ns: NS, type: Type, cost: number, node: number, timeout: number) {
|
async function buyUpgrade(ns: NS, type: UpgradeType, cost: number, node: number, timeout: number) {
|
||||||
await waitUntilMoney(ns, cost, timeout)
|
await waitUntilMoney(ns, cost, timeout)
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Type.newNode:
|
case UpgradeType.level:
|
||||||
ns.hacknet.purchaseNode()
|
|
||||||
break
|
|
||||||
case Type.level:
|
|
||||||
ns.hacknet.upgradeLevel(node)
|
ns.hacknet.upgradeLevel(node)
|
||||||
break
|
break
|
||||||
case Type.ram:
|
case UpgradeType.ram:
|
||||||
ns.hacknet.upgradeRam(node)
|
ns.hacknet.upgradeRam(node)
|
||||||
break
|
break
|
||||||
case Type.core:
|
case UpgradeType.core:
|
||||||
ns.hacknet.upgradeCore(node)
|
ns.hacknet.upgradeCore(node)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function buyNode(ns: NS, cost: number, timeout: number) {
|
||||||
|
await waitUntilMoney(ns, cost, timeout)
|
||||||
|
ns.hacknet.purchaseNode()
|
||||||
|
}
|
||||||
|
|
||||||
function getCheapestCost(ns: NS, node: number) {
|
function getCheapestCost(ns: NS, node: number) {
|
||||||
let nodeCost = ns.hacknet.getPurchaseNodeCost()
|
|
||||||
let levelCost = ns.hacknet.getLevelUpgradeCost(node)
|
let levelCost = ns.hacknet.getLevelUpgradeCost(node)
|
||||||
let ramCost = ns.hacknet.getRamUpgradeCost(node)
|
let ramCost = ns.hacknet.getRamUpgradeCost(node)
|
||||||
let coreCost = ns.hacknet.getCoreUpgradeCost(node)
|
let coreCost = ns.hacknet.getCoreUpgradeCost(node)
|
||||||
let cheapest = Math.min(nodeCost, levelCost, ramCost, coreCost)
|
let cheapest = Math.min(levelCost, ramCost, coreCost)
|
||||||
switch (cheapest) {
|
switch (cheapest) {
|
||||||
case nodeCost:
|
|
||||||
return {type: Type.newNode, cost: nodeCost}
|
|
||||||
case levelCost:
|
case levelCost:
|
||||||
return {type: Type.level, cost: levelCost}
|
return { type: UpgradeType.level, cost: levelCost }
|
||||||
case ramCost:
|
case ramCost:
|
||||||
return {type: Type.ram, cost: ramCost}
|
return { type: UpgradeType.ram, cost: ramCost }
|
||||||
case coreCost:
|
case coreCost:
|
||||||
return {type: Type.core, cost: coreCost}
|
return { type: UpgradeType.core, cost: coreCost }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import {recursiveScan} from "./utils";
|
import { recursiveScan } from "./utils"
|
||||||
|
|
||||||
export async function main(ns: NS) {
|
export async function main(ns: NS) {
|
||||||
let servers: string[] = recursiveScan(ns)
|
let servers: string[] = recursiveScan(ns)
|
||||||
for (const server of servers) {
|
for (const server of servers) {
|
||||||
|
32
servers/home/programs.ts
Normal file
32
servers/home/programs.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { recursiveHackingRequired, recursiveScan, removeFilesOnAllServers } from "./utils"
|
||||||
|
|
||||||
|
export async function main(ns: NS) {
|
||||||
|
switch (ns.args[0]) {
|
||||||
|
case "getServers":
|
||||||
|
getServers(ns)
|
||||||
|
break
|
||||||
|
case "getHackingLevels":
|
||||||
|
getHackingLevels(ns)
|
||||||
|
break
|
||||||
|
case "removeFiles":
|
||||||
|
removeFilesOnAllServersFromArgs(ns)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
ns.tprint("Invalid program name")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getServers(ns: NS) {
|
||||||
|
ns.tprint(recursiveScan(ns))
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHackingLevels(ns: NS) {
|
||||||
|
ns.tprint(recursiveHackingRequired(ns))
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeFilesOnAllServersFromArgs(ns: NS) {
|
||||||
|
let args = ns.args.slice(1)
|
||||||
|
let files = args.map((file) => file.toString())
|
||||||
|
removeFilesOnAllServers(ns, files)
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
// noinspection JSUnusedGlobalSymbols
|
// noinspection JSUnusedGlobalSymbols
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively scans all servers connected to the current server, excluding home
|
* Recursively scans all servers connected to the current server, excluding home
|
||||||
* @param ns global NS object
|
* @param ns global NS object
|
||||||
@ -6,25 +7,38 @@
|
|||||||
*/
|
*/
|
||||||
export function recursiveScan(ns: NS) {
|
export function recursiveScan(ns: NS) {
|
||||||
// Starting case
|
// Starting case
|
||||||
let servers = ns.scan("home");
|
let servers = ns.scan("home")
|
||||||
// Add all servers to the list
|
// Add all servers to the list
|
||||||
let allServers: string[] = [];
|
let allServers: string[] = []
|
||||||
while (servers.length > 0) {
|
while (servers.length > 0) {
|
||||||
let server = servers.shift();
|
let server = servers.pop()
|
||||||
if(server) {
|
if (server) {
|
||||||
let newServers = ns.scan(server);
|
let newServers = ns.scan(server)
|
||||||
for (let newServer of newServers) {
|
for (const newServer of newServers) {
|
||||||
if (!allServers.includes(newServer)) {
|
if (!allServers.includes(newServer)) {
|
||||||
allServers.push(newServer);
|
allServers.push(newServer)
|
||||||
servers.push(newServer);
|
servers.push(newServer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Remove the current server
|
// Remove the home server from the list
|
||||||
allServers.splice(allServers.indexOf("home"), 1);
|
return allServers.filter(server => server !== "home").sort()
|
||||||
// Print all servers
|
}
|
||||||
return allServers;
|
|
||||||
|
/**
|
||||||
|
* Recursively scans all servers connected to the current server for the set of all levels that hackable servers require
|
||||||
|
* @param ns
|
||||||
|
* @returns A set of every hacking level required to hack a new server
|
||||||
|
*/
|
||||||
|
export function recursiveHackingRequired(ns: NS) {
|
||||||
|
let servers = recursiveScan(ns)
|
||||||
|
let levels: number[] = []
|
||||||
|
for (let server of servers) {
|
||||||
|
levels.push(ns.getServerRequiredHackingLevel(server))
|
||||||
|
}
|
||||||
|
// Sort and remove duplicates, need custom sort because built-in sort only works alphabetically 💀
|
||||||
|
return [...new Set(levels)].sort((a, b) => a - b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,8 +52,8 @@ export function recursiveScan(ns: NS) {
|
|||||||
* you will need to modify each file path to match the server you are removing it from.
|
* you will need to modify each file path to match the server you are removing it from.
|
||||||
*/
|
*/
|
||||||
export function removeFilesOnAllServers(ns: NS, files: string[]) {
|
export function removeFilesOnAllServers(ns: NS, files: string[]) {
|
||||||
let hosts = recursiveScan(ns);
|
let hosts = recursiveScan(ns)
|
||||||
for(const host of hosts) {
|
for (const host of hosts) {
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
ns.rm(file, host)
|
ns.rm(file, host)
|
||||||
}
|
}
|
||||||
@ -53,29 +67,31 @@ export function removeFilesOnAllServers(ns: NS, files: string[]) {
|
|||||||
* @returns The number of programs used to gain root access
|
* @returns The number of programs used to gain root access
|
||||||
*/
|
*/
|
||||||
export function rootServer(ns: NS, server: string) {
|
export function rootServer(ns: NS, server: string) {
|
||||||
let counter = 0;
|
let counter = 0
|
||||||
if (ns.fileExists("BruteSSH.exe", "home")) {
|
if (ns.fileExists("BruteSSH.exe", "home")) {
|
||||||
ns.brutessh(server);
|
ns.brutessh(server)
|
||||||
counter++;
|
counter++
|
||||||
}
|
}
|
||||||
if (ns.fileExists("FTPCrack.exe", "home")) {
|
if (ns.fileExists("FTPCrack.exe", "home")) {
|
||||||
ns.ftpcrack(server);
|
ns.ftpcrack(server)
|
||||||
counter++;
|
counter++
|
||||||
}
|
}
|
||||||
if (ns.fileExists("SMTPCrack.exe", "home")) {
|
if (ns.fileExists("relaySMTP.exe", "home")) {
|
||||||
ns.relaysmtp(server);
|
ns.relaysmtp(server)
|
||||||
counter++;
|
counter++
|
||||||
}
|
}
|
||||||
if (ns.fileExists("HTTPWorm.exe", "home")) {
|
if (ns.fileExists("HTTPWorm.exe", "home")) {
|
||||||
ns.httpworm(server);
|
ns.httpworm(server)
|
||||||
counter++;
|
counter++
|
||||||
}
|
}
|
||||||
if (ns.fileExists("SQLInject.exe", "home")) {
|
if (ns.fileExists("SQLInject.exe", "home")) {
|
||||||
ns.sqlinject(server);
|
ns.sqlinject(server)
|
||||||
counter++;
|
counter++
|
||||||
}
|
}
|
||||||
|
if (counter >= ns.getServerNumPortsRequired(server)) {
|
||||||
ns.nuke(server)
|
ns.nuke(server)
|
||||||
return counter;
|
}
|
||||||
|
return counter
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,23 +103,23 @@ export function rootServer(ns: NS, server: string) {
|
|||||||
* @returns The result of the function if it is performed or true if the function does not return anything, otherwise false
|
* @returns The result of the function if it is performed or true if the function does not return anything, otherwise false
|
||||||
*/
|
*/
|
||||||
export function performFunctionIfCapable(ns: NS, server: string, func: CallableFunction, args: any[]) {
|
export function performFunctionIfCapable(ns: NS, server: string, func: CallableFunction, args: any[]) {
|
||||||
|
ns.print(`Performing function on ${server}`)
|
||||||
if (ns.getHackingLevel() < ns.getServerRequiredHackingLevel(server)) {
|
if (ns.getHackingLevel() < ns.getServerRequiredHackingLevel(server)) {
|
||||||
return false;
|
ns.print(`Not enough hacking level to hack ${server}`)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
if (ns.getServerNumPortsRequired(server) < ns.getServer(server).openPortCount) {
|
if (ns.getServer(server).openPortCount <= ns.getServerNumPortsRequired(server)) {
|
||||||
|
ns.print(`Not enough ports, trying to root ${server}`)
|
||||||
if (rootServer(ns, server) < ns.getServerNumPortsRequired(server)) {
|
if (rootServer(ns, server) < ns.getServerNumPortsRequired(server)) {
|
||||||
return false;
|
ns.print(`Failed to root ${server}`)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!ns.hasRootAccess(server)) {
|
let result = func(...args)
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
let result = func(...args);
|
|
||||||
if (result === undefined) {
|
if (result === undefined) {
|
||||||
return true;
|
return true
|
||||||
} else {
|
} else {
|
||||||
return result;
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,13 +132,12 @@ export function performFunctionIfCapable(ns: NS, server: string, func: CallableF
|
|||||||
* @param args The arguments to pass to the script
|
* @param args The arguments to pass to the script
|
||||||
*/
|
*/
|
||||||
export function executeScriptOnServerFromAnother(ns: NS, server: string, script: string, threads: number = 1, args: any[]) {
|
export function executeScriptOnServerFromAnother(ns: NS, server: string, script: string, threads: number = 1, args: any[]) {
|
||||||
ns.scp(script, server);
|
ns.scp(script, server)
|
||||||
performFunctionIfCapable(ns, server, ns.exec, [script, server, threads, ...args])
|
performFunctionIfCapable(ns, server, ns.exec, [script, server, threads, ...args])
|
||||||
ns.atExit(
|
ns.atExit(() => {
|
||||||
() => {
|
// Remove the script from the server when the program exits
|
||||||
ns.rm(script, server);
|
// ns.rm(script, server)
|
||||||
}
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -131,11 +146,38 @@ export function executeScriptOnServerFromAnother(ns: NS, server: string, script:
|
|||||||
* @param time=5 The number of seconds to calculate the MPS over
|
* @param time=5 The number of seconds to calculate the MPS over
|
||||||
*/
|
*/
|
||||||
export async function calculateMPS(ns: NS, time: number = 5) {
|
export async function calculateMPS(ns: NS, time: number = 5) {
|
||||||
let start = ns.getServerMoneyAvailable("home");
|
let start = ns.getServerMoneyAvailable("home")
|
||||||
let data: number[] = [];
|
let data: number[] = []
|
||||||
for (let i = 0; i < time; i++) {
|
for (let i = 0; i < time; i++) {
|
||||||
await ns.sleep(1000);
|
await ns.sleep(1000)
|
||||||
data.push(ns.getServerMoneyAvailable("home") - start);
|
data.push(ns.getServerMoneyAvailable("home") - start)
|
||||||
}
|
}
|
||||||
return data.reduce((a, b) => a + b, 0) / time;
|
return data.reduce((a, b) => a + b, 0) / time
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type that represents a program and whether it exists on the home server
|
||||||
|
*/
|
||||||
|
export type ProgramState = {
|
||||||
|
program: string
|
||||||
|
exists: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if any of the programs passed in now exist on the home server, and updates the exists property of the program
|
||||||
|
* @param ns Global NS object
|
||||||
|
* @param programs The programs to check
|
||||||
|
* @returns true if any of the programs now exist, otherwise false
|
||||||
|
*/
|
||||||
|
export function checkForNewPrograms(ns: NS, programs: ProgramState[]) {
|
||||||
|
let result = false
|
||||||
|
for (const program of programs) {
|
||||||
|
if (program.exists == false) {
|
||||||
|
program.exists = ns.fileExists(program.program)
|
||||||
|
if (program.exists) {
|
||||||
|
result = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
@ -1,15 +1,42 @@
|
|||||||
|
import { checkForNewPrograms, ProgramState, recursiveHackingRequired } from "./utils"
|
||||||
|
|
||||||
export async function main(ns: NS) {
|
export async function main(ns: NS) {
|
||||||
let hackingLevel = ns.getHackingLevel();
|
let levels = recursiveHackingRequired(ns)
|
||||||
while (hackingLevel < 9999) {
|
let hackingLevel = ns.getHackingLevel()
|
||||||
let oldHackingLevel = hackingLevel;
|
|
||||||
hackingLevel = ns.getHackingLevel();
|
let state: ProgramState[] = [
|
||||||
if(oldHackingLevel !== hackingLevel) {
|
{ program: "BruteSSH.exe", exists: false },
|
||||||
ns.tprint(`Hacking level increased from ${oldHackingLevel} to ${hackingLevel}`);
|
{ program: "FTPCrack.exe", exists: false },
|
||||||
ns.run("killall.js");
|
{ program: "relaySMTP.exe", exists: false },
|
||||||
await ns.sleep(1000) // 1 second
|
{ program: "HTTPWorm.exe", exists: false },
|
||||||
ns.run("hackallservers.js");
|
{ program: "SQLInject.exe", exists: false },
|
||||||
|
]
|
||||||
|
// Update state with existing programs
|
||||||
|
checkForNewPrograms(ns, state)
|
||||||
|
|
||||||
|
// Remove levels that are already hacked
|
||||||
|
levels = levels.filter(level => level > hackingLevel)
|
||||||
|
|
||||||
|
do {
|
||||||
|
let restart = false
|
||||||
|
if (Math.min(...levels) <= hackingLevel) {
|
||||||
|
ns.tprint(`Hacking level increased to/past ${Math.min(...levels)}, is now ${hackingLevel}`)
|
||||||
|
ns.tprint(`Remaining levels to hack: ${levels}`)
|
||||||
|
// remove the level from the list, so we don't try to hack it again
|
||||||
|
levels = levels.filter(level => level > hackingLevel)
|
||||||
|
restart = true
|
||||||
}
|
}
|
||||||
|
if (checkForNewPrograms(ns, state)) {
|
||||||
|
ns.tprint(`New programs found: ${state.filter(program => program.exists).map(program => program.program)}`)
|
||||||
|
restart = true
|
||||||
|
}
|
||||||
|
if (restart) {
|
||||||
|
ns.run("killall.js")
|
||||||
|
await ns.sleep(1000) // 1 second
|
||||||
|
ns.run("hackallservers.js")
|
||||||
|
}
|
||||||
|
hackingLevel = ns.getHackingLevel()
|
||||||
// Wait 1 second before checking again
|
// Wait 1 second before checking again
|
||||||
await ns.sleep(1000)
|
await ns.sleep(1000)
|
||||||
}
|
} while (hackingLevel <= Math.max(...levels))
|
||||||
}
|
}
|
Reference in New Issue
Block a user