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) {
|
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) {
|
||||||
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])
|
executeScriptOnServerFromAnother(ns, server, "hack.js", numThreads, [server])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
enum Type {
|
enum Type {
|
||||||
newNode = 'node', level = 'level', ram = 'ram', core = 'code',
|
newNode = "node", level = "level", ram = "ram", core = "code",
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function main(ns: NS) {
|
export async function main(ns: NS) {
|
||||||
@ -59,10 +59,10 @@ 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,4 @@
|
|||||||
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)
|
||||||
|
@ -1,21 +1,23 @@
|
|||||||
import { recursiveHackingRequired, recursiveScan } from "./utils"
|
import { recursiveHackingRequired, recursiveScan } from "./utils"
|
||||||
|
|
||||||
export async function main(ns: NS){
|
export async function main(ns: NS) {
|
||||||
switch (ns.args[0]) {
|
switch (ns.args[0]) {
|
||||||
case "getServers":
|
case "getServers":
|
||||||
getServers(ns);
|
getServers(ns)
|
||||||
break;
|
break
|
||||||
case "getHackingLevels":
|
case "getHackingLevels":
|
||||||
getHackingLevels(ns);
|
getHackingLevels(ns)
|
||||||
break;
|
break
|
||||||
default:
|
default:
|
||||||
ns.tprint("Invalid program name");
|
ns.tprint("Invalid program name")
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getServers(ns: NS) {
|
function getServers(ns: NS) {
|
||||||
ns.tprint(recursiveScan(ns));
|
ns.tprint(recursiveScan(ns))
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHackingLevels(ns: NS) {
|
function getHackingLevels(ns: NS) {
|
||||||
ns.tprint(recursiveHackingRequired(ns))
|
ns.tprint(recursiveHackingRequired(ns))
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
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) {
|
||||||
@ -23,7 +23,7 @@ export function recursiveScan(ns: NS) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 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
|
||||||
}
|
}
|
||||||
@ -70,23 +70,23 @@ export function removeFilesOnAllServers(ns: NS, files: string[]) {
|
|||||||
*/
|
*/
|
||||||
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++
|
||||||
}
|
}
|
||||||
@ -151,11 +151,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
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user