Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const PWN_SCRIPT = "pwn-server.js";
- const HACK_SCRIPT = "hack-script.js";
- const SERVER_TO_HACK = "joesguns";
- let infectedServers = [];
- /** @param {NS} ns */
- export async function main(ns) {
- infectChildServers(ns, "home", 0);
- }
- export async function infectChildServers(ns, serverWhoseChildrenShouldBeInfected, functionDepth) {
- //Since this server is going to get infected, add it to the list of infected servers:
- infectedServers.push(serverWhoseChildrenShouldBeInfected);
- ns.tprint("Servers infected: " + infectedServers);
- let childrenOfServer = ns.scan(serverWhoseChildrenShouldBeInfected);
- for(let currentChildServer of childrenOfServer) {
- //If we've already infected the server, then just move on. This shouldn't ever happen, but if loops are introduced, this will save us.
- if(infectedServers.indexOf(currentChildServer) != -1) {
- ns.tprint("Server " + currentChildServer + " is already infected, so it's being skipped.");
- continue;
- }
- //If we don't have root access, try to PWN it.
- if(!ns.hasRootAccess(currentChildServer)) {
- ns.exec(PWN_SCRIPT, "home", 1, currentChildServer);
- }
- //If we still don't have root access after trying to PWN it, just move on:
- if(!ns.hasRootAccess(currentChildServer)) {
- continue;
- }
- //Otherwise, clear any current running scripts, then copy our latest hack script over and run it:
- else {
- ns.tprint("Killing all scripts on " + currentChildServer);
- ns.killall(currentChildServer);
- ns.tprint("Copying hack script to " + currentChildServer);
- await ns.scp(HACK_SCRIPT, "home", currentChildServer);
- let numberThreadsToHackWith = determineMaxPossibleHackScriptThreads(ns, currentChildServer);
- ns.tprint("Starting hack script on " + currentChildServer + " with " + numberThreadsToHackWith + " threads.");
- ns.exec(HACK_SCRIPT, currentChildServer, numberThreadsToHackWith, SERVER_TO_HACK);
- //TODO: Make this recursive. For now, this should only go one layer deep.
- }
- }
- }
- function determineMaxPossibleHackScriptThreads(ns, serverToRunScriptOn) {
- let scriptRamRequirements = ns.getScriptRam(HACK_SCRIPT);
- let currentAvailableRamOnServer = ns.getServerMaxRam(serverToRunScriptOn) - ns.getServerUsedRam(serverToRunScriptOn);
- return Math.floor(currentAvailableRamOnServer / scriptRamRequirements);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement