From 98add1768e26d5f93d25ad93735a2fd0c2cf1bf2 Mon Sep 17 00:00:00 2001 From: Wade Pedersen <415099+wmpedersen@users.noreply.github.com> Date: Mon, 28 Feb 2022 18:26:16 -0500 Subject: [PATCH 1/2] Fixes "Hacking Level not high enough' #15 Don't check you have root access before making sure you have the require hacking level --- src/Orchestrator/TargetManager/manager.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Orchestrator/TargetManager/manager.ts b/src/Orchestrator/TargetManager/manager.ts index 10ad19c..b24a29c 100644 --- a/src/Orchestrator/TargetManager/manager.ts +++ b/src/Orchestrator/TargetManager/manager.ts @@ -62,12 +62,8 @@ export async function main(ns) { } function checkHost(host: string): boolean { - if (ns.hasRootAccess(host)) { - // Already root - return true; - } - if (ns.getHackingLevel() >= ns.getServerRequiredHackingLevel(host)) { - const requiredPort: number = ns.getServerNumPortsRequired(host); + if (ns.getHackingLevel() >= ns.getServerRequiredHackingLevel(host) && !ns.hasRootAccess(host)) { + const requiredPort = ns.getServerNumPortsRequired(host); if (requiredPort <= portOpener.length) { // We have enough port cracker let portOpen = 0; @@ -75,14 +71,19 @@ export async function main(ns) { portOpener[portOpen](host); portOpen++; } - } else { + } + else { // Not enough port cracker return false; } // Can be hacked ns.nuke(host); return true; - } else { + } else if (ns.getHackingLevel() >= ns.getServerRequiredHackingLevel(host) && ns.hasRootAccess(host)) { + // Already root + return true; + } + else { // Not enough hacking level return false; } From 3c64def534060fc2f9f23bb08986065df25cb503 Mon Sep 17 00:00:00 2001 From: Wade Pedersen <415099+wmpedersen@users.noreply.github.com> Date: Mon, 28 Feb 2022 18:46:17 -0500 Subject: [PATCH 2/2] Keep coding style in line with existing code whitespace changes --- src/Orchestrator/TargetManager/manager.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Orchestrator/TargetManager/manager.ts b/src/Orchestrator/TargetManager/manager.ts index b24a29c..edf6ee8 100644 --- a/src/Orchestrator/TargetManager/manager.ts +++ b/src/Orchestrator/TargetManager/manager.ts @@ -71,8 +71,7 @@ export async function main(ns) { portOpener[portOpen](host); portOpen++; } - } - else { + } else { // Not enough port cracker return false; } @@ -82,8 +81,7 @@ export async function main(ns) { } else if (ns.getHackingLevel() >= ns.getServerRequiredHackingLevel(host) && ns.hasRootAccess(host)) { // Already root return true; - } - else { + } else { // Not enough hacking level return false; }