Compare commits
2 Commits
92ad2da7b7
...
6c6f8b0b70
Author | SHA1 | Date | |
---|---|---|---|
6c6f8b0b70 | |||
90fef7e53a |
@ -1,4 +1,5 @@
|
||||
export async function main(ns: NS) {
|
||||
ns.run('watcher.js')
|
||||
ns.run('hacknet.js')
|
||||
ns.run("hackallservers.js")
|
||||
ns.run("watcher.js")
|
||||
ns.run("hacknet.js")
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -3,19 +3,21 @@ import { recursiveHackingRequired, recursiveScan } from "./utils"
|
||||
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
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { recursiveHackingRequired } from "./utils"
|
||||
|
||||
export async function main(ns: NS) {
|
||||
ns.run('hackallservers.js')
|
||||
let levels = recursiveHackingRequired(ns)
|
||||
let hackingLevel: number
|
||||
do {
|
||||
@ -10,9 +9,9 @@ export async function main(ns: NS) {
|
||||
// remove the level from the list, so we don't try to hack it again
|
||||
levels.splice(levels.indexOf(hackingLevel), 1)
|
||||
ns.tprint(`Hacking level increased to ${hackingLevel}`)
|
||||
ns.run('killall.js')
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user