diff --git a/src/ezgame/formulas/test.ts b/src/ezgame/formulas/test.ts index f7fed2f..a738a4c 100644 --- a/src/ezgame/formulas/test.ts +++ b/src/ezgame/formulas/test.ts @@ -1,7 +1,7 @@ -import { ezgame } from "@/ezgame"; import { getNormalServer } from "@/ezgame/get-normal-server"; import { utils } from "@/utils/utils"; import { NS } from "@ns"; +import { formulas } from "."; interface TestCase { name: string; @@ -23,7 +23,7 @@ const gangTests = (ns: NS, serverName: string): TestCase[] => [ name: "gang.ascensionMultiplier", fn: (ns, serverName) => { const points = utils.randomNumber(0, 1e9); - const testResult = roundTo5Decimals(ezgame.formulas.gang.ascensionMultiplier(points)); + const testResult = roundTo5Decimals(formulas.gang.ascensionMultiplier(points)); const actualResult = roundTo5Decimals(ns.formulas.gang.ascensionMultiplier(points)); if (testResult !== actualResult) { throw new Error(`expected ${actualResult}, got ${testResult}`); @@ -34,7 +34,7 @@ const gangTests = (ns: NS, serverName: string): TestCase[] => [ name: "gang.ascensionPointsGain", fn: (ns, serverName) => { const exp = utils.randomNumber(0, 1e9); - const testResult = roundTo5Decimals(ezgame.formulas.gang.ascensionPointsGain(exp)); + const testResult = roundTo5Decimals(formulas.gang.ascensionPointsGain(exp)); const actualResult = roundTo5Decimals(ns.formulas.gang.ascensionPointsGain(exp)); if (testResult !== actualResult) { throw new Error(`expected ${actualResult}, got ${testResult}`); @@ -56,7 +56,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [ const player = ns.getPlayer(); const threads = utils.randomNumber(1, 100); const cores = utils.randomNumber(1, 16); - const testResult = roundTo5Decimals(ezgame.formulas.hacking.growAmount(server, player, threads, cores)); + const testResult = roundTo5Decimals(formulas.hacking.growAmount(server, player, threads, cores)); const actualResult = roundTo5Decimals(ns.formulas.hacking.growAmount(server, player, threads, cores)); if (testResult !== actualResult) { throw new Error(`expected ${actualResult}, got ${testResult}`); @@ -70,7 +70,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [ const threads = utils.randomNumber(1, 100); const player = ns.getPlayer(); const cores = utils.randomNumber(1, 16); - const testResult = roundTo5Decimals(ezgame.formulas.hacking.growPercent(server, threads, player, cores)); + const testResult = roundTo5Decimals(formulas.hacking.growPercent(server, threads, player, cores)); const actualResult = roundTo5Decimals(ns.formulas.hacking.growPercent(server, threads, player, cores)); if (testResult !== actualResult) { throw new Error(`expected ${actualResult}, got ${testResult}`); @@ -86,7 +86,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [ // anyways if it is above moneyMax, the function should clamp it to the max (hopefully) const targetMoney = server.moneyMax ?? 1e120; const cores = utils.randomNumber(1, 16); - const testResult = roundTo5Decimals(ezgame.formulas.hacking.growThreads(server, player, targetMoney, cores)); + const testResult = roundTo5Decimals(formulas.hacking.growThreads(server, player, targetMoney, cores)); const actualResult = roundTo5Decimals(ns.formulas.hacking.growThreads(server, player, targetMoney, cores)); if (testResult !== actualResult) { throw new Error(`expected ${actualResult}, got ${testResult}`); @@ -98,7 +98,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [ fn: (ns, serverName) => { const server = getNormalServer(ns, serverName); const player = ns.getPlayer(); - const testResult = roundTo5Decimals(ezgame.formulas.hacking.growTime(server, player)); + const testResult = roundTo5Decimals(formulas.hacking.growTime(server, player)); const actualResult = roundTo5Decimals(ns.formulas.hacking.growTime(server, player)); if (testResult !== actualResult) { throw new Error(`expected ${actualResult}, got ${testResult}`); @@ -110,7 +110,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [ fn: (ns, serverName) => { const server = getNormalServer(ns, serverName); const player = ns.getPlayer(); - const testResult = roundTo5Decimals(ezgame.formulas.hacking.hackChance(server, player)); + const testResult = roundTo5Decimals(formulas.hacking.hackChance(server, player)); const actualResult = roundTo5Decimals(ns.formulas.hacking.hackChance(server, player)); if (testResult !== actualResult) { throw new Error(`expected ${actualResult}, got ${testResult}`); @@ -122,7 +122,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [ fn: (ns, serverName) => { const server = getNormalServer(ns, serverName); const player = ns.getPlayer(); - const testResult = roundTo5Decimals(ezgame.formulas.hacking.hackExp(server, player)); + const testResult = roundTo5Decimals(formulas.hacking.hackExp(server, player)); const actualResult = roundTo5Decimals(ns.formulas.hacking.hackExp(server, player)); if (testResult !== actualResult) { throw new Error(`expected ${actualResult}, got ${testResult}`); @@ -134,7 +134,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [ fn: (ns, serverName) => { const server = getNormalServer(ns, serverName); const player = ns.getPlayer(); - const testResult = roundTo5Decimals(ezgame.formulas.hacking.hackPercent(server, player)); + const testResult = roundTo5Decimals(formulas.hacking.hackPercent(server, player)); const actualResult = roundTo5Decimals(ns.formulas.hacking.hackPercent(server, player)); if (testResult !== actualResult) { throw new Error(`expected ${actualResult}, got ${testResult}`); @@ -146,7 +146,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [ fn: (ns, serverName) => { const server = getNormalServer(ns, serverName); const player = ns.getPlayer(); - const testResult = roundTo5Decimals(ezgame.formulas.hacking.hackTime(server, player)); + const testResult = roundTo5Decimals(formulas.hacking.hackTime(server, player)); const actualResult = roundTo5Decimals(ns.formulas.hacking.hackTime(server, player)); if (testResult !== actualResult) { throw new Error(`expected ${actualResult}, got ${testResult}`); @@ -158,7 +158,7 @@ const hackingTests = (ns: NS, serverName: string): TestCase[] => [ fn: (ns, serverName) => { const server = getNormalServer(ns, serverName); const player = ns.getPlayer(); - const testResult = roundTo5Decimals(ezgame.formulas.hacking.weakenTime(server, player)); + const testResult = roundTo5Decimals(formulas.hacking.weakenTime(server, player)); const actualResult = roundTo5Decimals(ns.formulas.hacking.weakenTime(server, player)); if (testResult !== actualResult) { throw new Error(`expected ${actualResult}, got ${testResult}`); diff --git a/src/ezgame/scan-analyze.ts b/src/ezgame/scan-analyze.ts index b512d60..25119a0 100644 --- a/src/ezgame/scan-analyze.ts +++ b/src/ezgame/scan-analyze.ts @@ -49,8 +49,10 @@ export const scanAnalyze = (ns: NS, options: ScanAnalyzeOptions = {}): Map, prefix: string[] = [" "], @@ -71,14 +74,14 @@ const printTree = ( const titlePrefix = prefix.slice(0, prefix.length - 1).join("") + (isLast ? "┗ " : "┣ "); const infoPrefix = prefix.join("") + (node.children.length > 0 ? "┃ " : " "); - ns.tprint(`* ${titlePrefix}${node.hostname}`); - ns.tprint( - `* ${infoPrefix}Root Access: ${server.hasAdminRights ? "YES" : "NO"}, Required hacking skill: ${ + lines.push(`${titlePrefix}${node.hostname}`); + lines.push( + `${infoPrefix}Root Access: ${server.hasAdminRights ? "YES" : "NO"}, Required hacking skill: ${ server.requiredHackingSkill ?? 0 }`, ); - ns.tprint(`* ${infoPrefix}Number of open ports required to NUKE: ${server.numOpenPortsRequired ?? 0}`); - ns.tprint(`* ${infoPrefix}RAM: ${utils.format.ram(server.maxRam)}, Player purchased: ${server.purchasedByPlayer}`); + lines.push(`${infoPrefix}Number of open ports required to NUKE: ${server.numOpenPortsRequired ?? 0}`); + lines.push(`${infoPrefix}RAM: ${utils.format.ram(server.maxRam)}, Player purchased: ${server.purchasedByPlayer}`); // recursive node.children.forEach((childName, i) => { @@ -88,7 +91,7 @@ const printTree = ( throw new Error(`Child node ${childName} not found in tree`); } const childIsLast = i === node.children.length - 1; - printTree(ns, childNode, tree, [...prefix, childIsLast ? " " : "┃ "], childIsLast); + printTree(ns, lines, childNode, tree, [...prefix, childIsLast ? " " : "┃ "], childIsLast); }); }; diff --git a/src/ezgame/script-propagator.ts b/src/ezgame/script-propagator.ts index 3ca3b27..0d96bec 100644 --- a/src/ezgame/script-propagator.ts +++ b/src/ezgame/script-propagator.ts @@ -27,6 +27,6 @@ export const scriptPropagator = (ns: NS) => { return rootedHosts; }; -// export const main = (ns: NS) => { -// scriptPropagator(ns); -// }; +export const main = (ns: NS) => { + scriptPropagator(ns); +}; diff --git a/src/ezgame/startall.ts b/src/ezgame/startall.ts index 037ab02..c10abf2 100644 --- a/src/ezgame/startall.ts +++ b/src/ezgame/startall.ts @@ -40,7 +40,11 @@ export const startall = (ns: NS, scriptName: string, options: StartOptions = {}) } if (threadsToUse > 0) { - ns.exec(scriptName, host, threadsToUse, ...args); + const pid = ns.exec(scriptName, host, threadsToUse, ...args); + if (pid === 0) { + ns.tprint(`${host}: Process not started. Did you check if the script exists on the server?`); + return; + } ns.tprint(`Started ${scriptName} on ${host} with ${threadsToUse} threads`); totalThreadsStarted += threadsToUse; hostsStartedOn++; diff --git a/src/test.ts b/src/test.ts index 9e16d83..8f6ae75 100644 --- a/src/test.ts +++ b/src/test.ts @@ -1,6 +1,6 @@ import { NS } from "@ns"; export const main = async (ns: NS) => { - const bruh = await ns.prompt("hello", { type: "text", choices: ["asdf1", "asdf2"] }); - console.log(bruh); + const electron = eval(`require("electron")`); + ns.tprint(JSON.stringify(Object.keys(electron))); };