Compare commits

..

No commits in common. "22ddbbde5df5646f30f8e51d41e89467464ebce9" and "b40c4d07e8afabcc7dc7bf027324eda18f1f1fec" have entirely different histories.

10 changed files with 308 additions and 519 deletions

View File

@ -1,10 +0,0 @@
# 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
View File

@ -1,215 +0,0 @@
## 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

View File

@ -1,5 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>

View File

@ -1,4 +1,4 @@
export async function main(ns: NS) {
ns.run('watcher.js')
ns.run('hacknet.js')
ns.run("watcher.js")
ns.run("hacknet.js")
}

View File

@ -1,10 +1,23 @@
export async function main(ns: NS) {
const server: string = <string> ns.args[0]
const server: string = <string>ns.args[0];
while (true) {
// Guide https://darktechnomancer.github.io/#glossary-of-terms
await ns.weaken(server)
await ns.grow(server)
await ns.weaken(server)
await ns.hack(server)
/* This code checks conditions that are not needed with smart scheduling
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
// https://darktechnomancer.github.io/#glossary-of-terms
await ns.weaken(server);
await ns.grow(server);
await ns.weaken(server);
await ns.hack(server);
}
}

View File

@ -1,11 +1,15 @@
import { executeScriptOnServerFromAnother, recursiveScan } from './utils'
import {recursiveScan} from "./utils";
import {executeScriptOnServerFromAnother} from "./utils";
export async function main(ns: NS) {
let servers: string[] = recursiveScan(ns)
let servers: string[] = recursiveScan(ns);
for (const server of servers) {
let numThreads = ns.getServerMaxRam(server) / ns.getScriptRam('hack.js')
numThreads = Math.floor(numThreads)
executeScriptOnServerFromAnother(ns, server, 'hack.js', numThreads, [server])
// Commented out code is not needed with smart scheduling
//let moneyThresh = ns.getServerMaxMoney(server) * 0.75;
//let securityThresh = ns.getServerMinSecurityLevel(server) + 5;
let numThreads = ns.getServerMaxRam(server) / ns.getScriptRam("hack.js")
numThreads = Math.floor(numThreads);
//executeScriptOnServerFromAnother(ns, server, "hack.js", numThreads, [server, moneyThresh, securityThresh])
executeScriptOnServerFromAnother(ns, server, "hack.js", numThreads, [server])
}
}

View File

@ -14,14 +14,17 @@
*/
enum Type {
newNode = 'node', level = 'level', ram = 'ram', core = 'code',
newNode = "node",
level = "level",
ram = "ram",
core = "code"
}
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 costs: { type: Type, cost: number }[] = []
let costs: {type: Type, cost: number}[] = []
while (true) {
costs = []
// Go through each node and get the cheapest upgrade
@ -53,12 +56,12 @@ export async function main(ns: NS) {
* @note This function will wait forever by default
*/
async function waitUntilMoney(ns: NS, money: number, timeout: number = -1) {
while (ns.getServerMoneyAvailable('home') < money) {
while (ns.getServerMoneyAvailable("home") < money) {
await ns.sleep(1000)
if (timeout == 0) {
throw new Error('Timed out waiting for money')
throw new Error("Timed out waiting for money")
} else if (timeout > -1) {
timeout--
timeout--;
}
}
}
@ -89,12 +92,12 @@ function getCheapestCost(ns: NS, node: number) {
let cheapest = Math.min(nodeCost, levelCost, ramCost, coreCost)
switch (cheapest) {
case nodeCost:
return { type: Type.newNode, cost: nodeCost }
return {type: Type.newNode, cost: nodeCost}
case levelCost:
return { type: Type.level, cost: levelCost }
return {type: Type.level, cost: levelCost}
case ramCost:
return { type: Type.ram, cost: ramCost }
return {type: Type.ram, cost: ramCost}
case coreCost:
return { type: Type.core, cost: coreCost }
return {type: Type.core, cost: coreCost}
}
}

View File

@ -1,5 +1,4 @@
import { recursiveScan } from './utils'
import {recursiveScan} from "./utils";
export async function main(ns: NS) {
let servers: string[] = recursiveScan(ns)
for (const server of servers) {

View File

@ -1,31 +1,30 @@
// noinspection JSUnusedGlobalSymbols
/**
* Recursively scans all servers connected to the current server, excluding home
* @param ns global NS object
* @returns A list of all servers connected to the current server
*/
export function recursiveScan(ns: NS) {
// Starting case
let servers = ns.scan('home')
// Add all servers to the list
let allServers: string[] = []
while (servers.length > 0) {
let server = servers.shift()
if (server) {
let newServers = ns.scan(server)
for (let newServer of newServers) {
if (!allServers.includes(newServer)) {
allServers.push(newServer)
servers.push(newServer)
}
}
}
}
// Remove the current server
allServers.splice(allServers.indexOf('home'), 1)
// Print all servers
return allServers
// Starting case
let servers = ns.scan("home");
// Add all servers to the list
let allServers: string[] = [];
while (servers.length > 0) {
let server = servers.shift();
if(server) {
let newServers = ns.scan(server);
for (let newServer of newServers) {
if (!allServers.includes(newServer)) {
allServers.push(newServer);
servers.push(newServer);
}
}
}
}
// Remove the current server
allServers.splice(allServers.indexOf("home"), 1);
// Print all servers
return allServers;
}
/**
@ -39,12 +38,12 @@ export function recursiveScan(ns: NS) {
* you will need to modify each file path to match the server you are removing it from.
*/
export function removeFilesOnAllServers(ns: NS, files: string[]) {
let hosts = recursiveScan(ns)
for (const host of hosts) {
for (const file of files) {
ns.rm(file, host)
}
}
let hosts = recursiveScan(ns);
for(const host of hosts) {
for (const file of files) {
ns.rm(file, host)
}
}
}
/**
@ -54,29 +53,29 @@ export function removeFilesOnAllServers(ns: NS, files: string[]) {
* @returns The number of programs used to gain root access
*/
export function rootServer(ns: NS, server: string) {
let counter = 0
if (ns.fileExists('BruteSSH.exe', 'home')) {
ns.brutessh(server)
counter++
}
if (ns.fileExists('FTPCrack.exe', 'home')) {
ns.ftpcrack(server)
counter++
}
if (ns.fileExists('SMTPCrack.exe', 'home')) {
ns.relaysmtp(server)
counter++
}
if (ns.fileExists('HTTPWorm.exe', 'home')) {
ns.httpworm(server)
counter++
}
if (ns.fileExists('SQLInject.exe', 'home')) {
ns.sqlinject(server)
counter++
}
ns.nuke(server)
return counter
let counter = 0;
if (ns.fileExists("BruteSSH.exe", "home")) {
ns.brutessh(server);
counter++;
}
if (ns.fileExists("FTPCrack.exe", "home")) {
ns.ftpcrack(server);
counter++;
}
if (ns.fileExists("SMTPCrack.exe", "home")) {
ns.relaysmtp(server);
counter++;
}
if (ns.fileExists("HTTPWorm.exe", "home")) {
ns.httpworm(server);
counter++;
}
if (ns.fileExists("SQLInject.exe", "home")) {
ns.sqlinject(server);
counter++;
}
ns.nuke(server)
return counter;
}
/**
@ -88,24 +87,24 @@ 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
*/
export function performFunctionIfCapable(ns: NS, server: string, func: CallableFunction, args: any[]) {
if (ns.getHackingLevel() < ns.getServerRequiredHackingLevel(server)) {
return false
}
if (ns.getServerNumPortsRequired(server) < ns.getServer(server).openPortCount) {
if (rootServer(ns, server) < ns.getServerNumPortsRequired(server)) {
return false
}
}
if (!ns.hasRootAccess(server)) {
return false
if (ns.getHackingLevel() < ns.getServerRequiredHackingLevel(server)) {
return false;
}
if (ns.getServerNumPortsRequired(server) < ns.getServer(server).openPortCount) {
if (rootServer(ns, server) < ns.getServerNumPortsRequired(server)) {
return false;
}
}
if (!ns.hasRootAccess(server)) {
return false;
}
let result = func(...args)
if (result === undefined) {
return true
} else {
return result
}
}
let result = func(...args);
if (result === undefined) {
return true;
} else {
return result;
}
}
/**
@ -117,11 +116,13 @@ export function performFunctionIfCapable(ns: NS, server: string, func: CallableF
* @param args The arguments to pass to the script
*/
export function executeScriptOnServerFromAnother(ns: NS, server: string, script: string, threads: number = 1, args: any[]) {
ns.scp(script, server)
performFunctionIfCapable(ns, server, ns.exec, [script, server, threads, ...args])
ns.atExit(() => {
ns.rm(script, server)
})
ns.scp(script, server);
performFunctionIfCapable(ns, server, ns.exec, [script, server, threads, ...args])
ns.atExit(
() => {
ns.rm(script, server);
}
)
}
/**
@ -130,11 +131,11 @@ export function executeScriptOnServerFromAnother(ns: NS, server: string, script:
* @param time=5 The number of seconds to calculate the MPS over
*/
export async function calculateMPS(ns: NS, time: number = 5) {
let start = ns.getServerMoneyAvailable('home')
let data: number[] = []
for (let i = 0; i < time; i++) {
await ns.sleep(1000)
data.push(ns.getServerMoneyAvailable('home') - start)
}
return data.reduce((a, b) => a + b, 0) / time
let start = ns.getServerMoneyAvailable("home");
let data: number[] = [];
for (let i = 0; i < time; i++) {
await ns.sleep(1000);
data.push(ns.getServerMoneyAvailable("home") - start);
}
return data.reduce((a, b) => a + b, 0) / time;
}

View File

@ -1,14 +1,13 @@
export async function main(ns: NS) {
ns.run('hackallservers.js')
let hackingLevel = ns.getHackingLevel()
let hackingLevel = ns.getHackingLevel();
while (hackingLevel < 9999) {
let oldHackingLevel = hackingLevel
hackingLevel = ns.getHackingLevel()
if (oldHackingLevel !== hackingLevel) {
ns.tprint(`Hacking level increased from ${oldHackingLevel} to ${hackingLevel}`)
ns.run('killall.js')
let oldHackingLevel = hackingLevel;
hackingLevel = ns.getHackingLevel();
if(oldHackingLevel !== hackingLevel) {
ns.tprint(`Hacking level increased from ${oldHackingLevel} to ${hackingLevel}`);
ns.run("killall.js");
await ns.sleep(1000) // 1 second
ns.run('hackallservers.js')
ns.run("hackallservers.js");
}
// Wait 1 second before checking again
await ns.sleep(1000)