Reformat files
This commit is contained in:
parent
683daff911
commit
22ddbbde5d
@ -1,4 +1,4 @@
|
|||||||
export async function main(ns: NS) {
|
export async function main(ns: NS) {
|
||||||
ns.run("watcher.js")
|
ns.run('watcher.js')
|
||||||
ns.run("hacknet.js")
|
ns.run('hacknet.js')
|
||||||
}
|
}
|
@ -1,23 +1,10 @@
|
|||||||
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];
|
await ns.weaken(server)
|
||||||
const securityThresh: number = <number>ns.args[2];
|
await ns.grow(server)
|
||||||
if (ns.getServerSecurityLevel(server) > securityThresh) {
|
await ns.weaken(server)
|
||||||
await ns.weaken(server);
|
await ns.hack(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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,15 +1,11 @@
|
|||||||
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
|
let numThreads = ns.getServerMaxRam(server) / ns.getScriptRam('hack.js')
|
||||||
//let moneyThresh = ns.getServerMaxMoney(server) * 0.75;
|
numThreads = Math.floor(numThreads)
|
||||||
//let securityThresh = ns.getServerMinSecurityLevel(server) + 5;
|
executeScriptOnServerFromAnother(ns, server, 'hack.js', numThreads, [server])
|
||||||
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])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,10 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
enum Type {
|
enum Type {
|
||||||
newNode = "node",
|
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) {
|
||||||
@ -56,12 +53,12 @@ export async function main(ns: NS) {
|
|||||||
* @note This function will wait forever by default
|
* @note This function will wait forever by default
|
||||||
*/
|
*/
|
||||||
async function waitUntilMoney(ns: NS, money: number, timeout: number = -1) {
|
async function waitUntilMoney(ns: NS, money: number, timeout: number = -1) {
|
||||||
while (ns.getServerMoneyAvailable("home") < money) {
|
while (ns.getServerMoneyAvailable('home') < money) {
|
||||||
await ns.sleep(1000)
|
await ns.sleep(1000)
|
||||||
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--
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
@ -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,25 @@
|
|||||||
*/
|
*/
|
||||||
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.shift()
|
||||||
if (server) {
|
if (server) {
|
||||||
let newServers = ns.scan(server);
|
let newServers = ns.scan(server)
|
||||||
for (let newServer of newServers) {
|
for (let 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 current server
|
||||||
allServers.splice(allServers.indexOf("home"), 1);
|
allServers.splice(allServers.indexOf('home'), 1)
|
||||||
// Print all servers
|
// Print all servers
|
||||||
return allServers;
|
return allServers
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,7 +39,7 @@ 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 +54,29 @@ 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('SMTPCrack.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++
|
||||||
}
|
}
|
||||||
ns.nuke(server)
|
ns.nuke(server)
|
||||||
return counter;
|
return counter
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,22 +89,22 @@ export function rootServer(ns: NS, server: string) {
|
|||||||
*/
|
*/
|
||||||
export function performFunctionIfCapable(ns: NS, server: string, func: CallableFunction, args: any[]) {
|
export function performFunctionIfCapable(ns: NS, server: string, func: CallableFunction, args: any[]) {
|
||||||
if (ns.getHackingLevel() < ns.getServerRequiredHackingLevel(server)) {
|
if (ns.getHackingLevel() < ns.getServerRequiredHackingLevel(server)) {
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
if (ns.getServerNumPortsRequired(server) < ns.getServer(server).openPortCount) {
|
if (ns.getServerNumPortsRequired(server) < ns.getServer(server).openPortCount) {
|
||||||
if (rootServer(ns, server) < ns.getServerNumPortsRequired(server)) {
|
if (rootServer(ns, server) < ns.getServerNumPortsRequired(server)) {
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!ns.hasRootAccess(server)) {
|
if (!ns.hasRootAccess(server)) {
|
||||||
return false;
|
return false
|
||||||
|
|
||||||
}
|
}
|
||||||
let result = func(...args);
|
let result = func(...args)
|
||||||
if (result === undefined) {
|
if (result === undefined) {
|
||||||
return true;
|
return true
|
||||||
} else {
|
} else {
|
||||||
return result;
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,13 +117,11 @@ 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(() => {
|
||||||
() => {
|
ns.rm(script, server)
|
||||||
ns.rm(script, server);
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -131,11 +130,11 @@ 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
|
||||||
}
|
}
|
@ -1,13 +1,14 @@
|
|||||||
export async function main(ns: NS) {
|
export async function main(ns: NS) {
|
||||||
let hackingLevel = ns.getHackingLevel();
|
ns.run('hackallservers.js')
|
||||||
|
let hackingLevel = ns.getHackingLevel()
|
||||||
while (hackingLevel < 9999) {
|
while (hackingLevel < 9999) {
|
||||||
let oldHackingLevel = hackingLevel;
|
let oldHackingLevel = hackingLevel
|
||||||
hackingLevel = ns.getHackingLevel();
|
hackingLevel = ns.getHackingLevel()
|
||||||
if (oldHackingLevel !== hackingLevel) {
|
if (oldHackingLevel !== hackingLevel) {
|
||||||
ns.tprint(`Hacking level increased from ${oldHackingLevel} to ${hackingLevel}`);
|
ns.tprint(`Hacking level increased from ${oldHackingLevel} to ${hackingLevel}`)
|
||||||
ns.run("killall.js");
|
ns.run('killall.js')
|
||||||
await ns.sleep(1000) // 1 second
|
await ns.sleep(1000) // 1 second
|
||||||
ns.run("hackallservers.js");
|
ns.run('hackallservers.js')
|
||||||
}
|
}
|
||||||
// Wait 1 second before checking again
|
// Wait 1 second before checking again
|
||||||
await ns.sleep(1000)
|
await ns.sleep(1000)
|
||||||
|
Loading…
Reference in New Issue
Block a user