Formatting changes
This commit is contained in:
parent
90fef7e53a
commit
6c6f8b0b70
@ -1,11 +1,11 @@
|
||||
import { executeScriptOnServerFromAnother, recursiveScan } from './utils'
|
||||
import { executeScriptOnServerFromAnother, recursiveScan } from "./utils"
|
||||
|
||||
export async function main(ns: NS) {
|
||||
let servers: string[] = recursiveScan(ns)
|
||||
|
||||
for (const server of servers) {
|
||||
let numThreads = ns.getServerMaxRam(server) / ns.getScriptRam('hack.js')
|
||||
let numThreads = ns.getServerMaxRam(server) / ns.getScriptRam("hack.js")
|
||||
numThreads = Math.floor(numThreads)
|
||||
executeScriptOnServerFromAnother(ns, server, 'hack.js', numThreads, [server])
|
||||
executeScriptOnServerFromAnother(ns, server, "hack.js", numThreads, [server])
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
enum Type {
|
||||
newNode = 'node', level = 'level', ram = 'ram', core = 'code',
|
||||
newNode = "node", level = "level", ram = "ram", core = "code",
|
||||
}
|
||||
|
||||
export async function main(ns: NS) {
|
||||
@ -59,10 +59,10 @@ 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--
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { recursiveScan } from './utils'
|
||||
import { recursiveScan } from "./utils"
|
||||
|
||||
export async function main(ns: NS) {
|
||||
let servers: string[] = recursiveScan(ns)
|
||||
|
@ -1,21 +1,23 @@
|
||||
import { recursiveHackingRequired, recursiveScan } from "./utils"
|
||||
|
||||
export async function main(ns: NS){
|
||||
export async function main(ns: NS) {
|
||||
switch (ns.args[0]) {
|
||||
case "getServers":
|
||||
getServers(ns);
|
||||
break;
|
||||
getServers(ns)
|
||||
break
|
||||
case "getHackingLevels":
|
||||
getHackingLevels(ns);
|
||||
break;
|
||||
getHackingLevels(ns)
|
||||
break
|
||||
default:
|
||||
ns.tprint("Invalid program name");
|
||||
break;
|
||||
ns.tprint("Invalid program name")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function getServers(ns: NS) {
|
||||
ns.tprint(recursiveScan(ns));
|
||||
ns.tprint(recursiveScan(ns))
|
||||
}
|
||||
|
||||
function getHackingLevels(ns: NS) {
|
||||
ns.tprint(recursiveHackingRequired(ns))
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
export function recursiveScan(ns: NS) {
|
||||
// Starting case
|
||||
let servers = ns.scan('home')
|
||||
let servers = ns.scan("home")
|
||||
// Add all servers to the list
|
||||
let allServers: string[] = []
|
||||
while (servers.length > 0) {
|
||||
@ -23,7 +23,7 @@ export function recursiveScan(ns: NS) {
|
||||
}
|
||||
}
|
||||
// Remove the current server
|
||||
allServers.splice(allServers.indexOf('home'), 1)
|
||||
allServers.splice(allServers.indexOf("home"), 1)
|
||||
// Print all servers
|
||||
return allServers
|
||||
}
|
||||
@ -70,23 +70,23 @@ export function removeFilesOnAllServers(ns: NS, files: string[]) {
|
||||
*/
|
||||
export function rootServer(ns: NS, server: string) {
|
||||
let counter = 0
|
||||
if (ns.fileExists('BruteSSH.exe', 'home')) {
|
||||
if (ns.fileExists("BruteSSH.exe", "home")) {
|
||||
ns.brutessh(server)
|
||||
counter++
|
||||
}
|
||||
if (ns.fileExists('FTPCrack.exe', 'home')) {
|
||||
if (ns.fileExists("FTPCrack.exe", "home")) {
|
||||
ns.ftpcrack(server)
|
||||
counter++
|
||||
}
|
||||
if (ns.fileExists('SMTPCrack.exe', 'home')) {
|
||||
if (ns.fileExists("SMTPCrack.exe", "home")) {
|
||||
ns.relaysmtp(server)
|
||||
counter++
|
||||
}
|
||||
if (ns.fileExists('HTTPWorm.exe', 'home')) {
|
||||
if (ns.fileExists("HTTPWorm.exe", "home")) {
|
||||
ns.httpworm(server)
|
||||
counter++
|
||||
}
|
||||
if (ns.fileExists('SQLInject.exe', 'home')) {
|
||||
if (ns.fileExists("SQLInject.exe", "home")) {
|
||||
ns.sqlinject(server)
|
||||
counter++
|
||||
}
|
||||
@ -151,11 +151,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 start = ns.getServerMoneyAvailable("home")
|
||||
let data: number[] = []
|
||||
for (let i = 0; i < time; i++) {
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user