SLSWBNYTIFKBFLKXZTMONGDMEOHSOOCOSU4KVJCONZG2DK3BBIUQC YXH7ERRNAV2FHHAFREYBN7VJZZMGH3UJOXGM4IKS2USVKI543TFQC 2BKHJI2SJ3VXTFBK2BWNN3I3BDNMUU5YTJGKTQCOXV66VVRHCGKAC RWMZ7DVLOVPLR4FCIAVSABA5OESYUIEQ2OOZUYNPCNFEBYK5627AC CJBGAILAK7G3WXYUBNUZMUMM3U5CPHWVK6ZAJWYBL4IOB5SZN32AC FA3U4WUJ3YT2G2WIAXBHEZ4O4RWXX55BBFYQKODHUMF7I6Z37XUAC BZ6FC2BTR7M7T6KQX5OJEFY4B3OWAKCOALYOF7GYBXZ4ZNSGSCYQC BCM3TZOSIZSGCROXIWDIZBZPMWDAPUVYVFS6LJNMLMEI5AOMHFAQC NQ22FUSWN6CBJKJ5H7UV5N2KEXBIXVNQDNL2EK6UJ3E7RFLWNVDQC NC66CZ5JPP3RPFCWAJE2ZBPFLA5ILKBNGTQLXDCRIUTIEWE74R4AC 4ACCU75NFJ4ZD5CMHBBYCFLBWL2XQH4RS65FTR4JDJPBHTABYJZAC // servers.js - 8.55GB - continually buys the best server with cash available, unless there are 25 servers already, in which case deletes the worst server, unless all 25 have ram == PurchasedServerMaxRam
// servers.js - 8.85GB - continually buys the best server with cash available if ram utilisation of the network is over threshold, unless there are 25 servers already, in which case deletes the worst server, unless all 25 have RAM == PurchasedServerMaxRam.import {float_get_network_ram_utilisation,float_get_server_ram_total}from "lib_ram.js";
const string_servers_bought_name = ns.args[0];const object_get_constants = function(ns) {const object_constants = {// cost of server per 1 GB of RAMBaseCostFor1GBOfRamServer: 55000,// maximum amount of purchased servers allowedPurchasedServerLimit: 25,// minimum ram of purchased servers possibleinteger_server_ram_min: 2,// maximum ram of purchased servers possible. 2^20PurchasedServerMaxRam: 1048576,};return object_constants;};// returns the total ram of a serverconst integer_get_server_ram_total = function(ns, string_server) {return (ns.getServerRam(string_server))[0];};
const string_servers_bought_name = ns.args[1];const float_ram_utilisation_threshold = ns.args[2];
// true if all bought servers have ram == PurchasedServerMaxRamconst boolean_servers_bought_all_max = function(ns) {const array_servers_bought = ns.getPurchasedServers();if (array_servers_bought.length > 0) {let boolean_tripwire = true;for (let integer_indices_0 = 0; integer_indices_0 < array_servers_bought.length; ++integer_indices_0) {if (integer_get_server_ram_total(ns, array_servers_bought[integer_indices_0]) < object_get_constants(ns).PurchasedServerMaxRam) {boolean_tripwire = false;}
while (!boolean_servers_bought_all_max(ns)) {while (float_get_network_ram_utilisation(ns) > float_ram_utilisation_threshold) {while (boolean_conditions_server_delete_purchase(ns)) {ns.deleteServer(string_get_server_bought_smallest(ns));ns.purchaseServer(string_servers_bought_name, integer_get_server_ram_biggest_afforded(ns));
return boolean_tripwire;}};// returns bought server with smallest RAMconst string_get_server_bought_smallest = function(ns) {const array_servers_bought = ns.getPurchasedServers();if (array_servers_bought.length > 0) {let string_server_smallest;let integer_size_smallest = object_get_constants(ns).PurchasedServerMaxRam;for (let integer_indices_0 = 0; integer_indices_0 < array_servers_bought.length; ++integer_indices_0) {let integer_server_ram_total = integer_get_server_ram_total(ns, array_servers_bought[integer_indices_0]);if (integer_server_ram_total < integer_size_smallest) {string_server_smallest = array_servers_bought[integer_indices_0];integer_size_smallest = integer_server_ram_total;}
while (boolean_conditions_server_purchase_3(ns) ||boolean_conditions_server_purchase_2(ns) ||boolean_conditions_server_purchase_1(ns)) {ns.purchaseServer(string_servers_bought_name, integer_get_server_ram_biggest_afforded(ns));
// returns bought server with biggest RAMconst string_get_server_bought_biggest = function(ns) {const array_servers_bought = ns.getPurchasedServers();if (array_servers_bought.length > 0) {let string_server_biggest;let integer_size_biggest = object_get_constants(ns).integer_server_ram_min;for (let integer_indices_0 = 0; integer_indices_0 < array_servers_bought.length; ++integer_indices_0) {let integer_server_ram_total = integer_get_server_ram_total(ns, array_servers_bought[integer_indices_0]);if (integer_server_ram_total > integer_size_biggest) {string_server_biggest = array_servers_bought[integer_indices_0];integer_size_biggest = integer_server_ram_total;}}return string_server_biggest;}};
// functions
// return the RAM of the server with the biggest RAM that you can affordconst integer_get_server_ram_biggest_afforded = function(ns) {const object_constants = object_get_constants(ns);let integer_server_ram_biggest_afforded = Math.pow(2, Math.trunc(Math.log2(ns.getServerMoneyAvailable("home") / object_constants.BaseCostFor1GBOfRamServer) / Math.log2(2)));if (integer_server_ram_biggest_afforded > object_constants.PurchasedServerMaxRam) {integer_server_ram_biggest_afforded = object_constants.PurchasedServerMaxRam;}return integer_server_ram_biggest_afforded;
const object_get_constants = function(ns) {const object_constants = {// cost of server per 1 GB of RAMBaseCostFor1GBOfRamServer: 55000,// maximum amount of purchased servers allowedPurchasedServerLimit: 25,// minimum RAM of purchased servers possibleinteger_server_ram_min: 2,// maximum RAM of purchased servers possible. 2^20PurchasedServerMaxRam: 1048576,
const boolean_conditions_server_purchase_1 = function(ns) {const integer_server_ram_biggest_afforded = integer_get_server_ram_biggest_afforded(ns);const object_constants = object_get_constants(ns);if (// you have no bought servers yet(ns.getPurchasedServers().length === 0) &&// ram is at least equal to the minimum ram possible for purchased servers(integer_server_ram_biggest_afforded >= object_constants.integer_server_ram_min) &&// ram is at least equal to the ram of "home" (probably a bad idea to hardcode this since the string_name of "home" might change in the future) or max ram.(integer_server_ram_biggest_afforded >= integer_get_server_ram_total(ns, "home") ||integer_server_ram_biggest_afforded >= object_constants.PurchasedServerMaxRam)) {return true;
// true if all bought servers have RAM == PurchasedServerMaxRamconst boolean_servers_bought_all_max = function(ns) {const array_servers_bought = ns.getPurchasedServers();if (array_servers_bought.length > 0) {let boolean_tripwire = true;for (let integer_indices_0 = 0; integer_indices_0 < array_servers_bought.length; ++integer_indices_0) {if (float_get_server_ram_total(ns, array_servers_bought[integer_indices_0]) < object_get_constants(ns).PurchasedServerMaxRam) {boolean_tripwire = false;}
};const boolean_conditions_server_purchase_2 = function(ns) {const integer_servers_bought_amount = ns.getPurchasedServers().length;const object_constants = object_get_constants(ns);if (// you have one or more servers already(integer_servers_bought_amount > 0) &&// you currently own less than the maximum amount of purchased servers allowed(integer_servers_bought_amount < object_constants.PurchasedServerLimit)) {const float_ram_server_bought_biggest = integer_get_server_ram_total(ns, string_get_server_bought_biggest(ns));if (// you dont own a server with max ram yet, buy a server with ram greater than the ram of your biggest bought server(float_ram_server_bought_biggest != object_constants.PurchasedServerMaxRam) &&(float_ram_server_bought_biggest < integer_get_server_ram_biggest_afforded(ns))) {return true;
return boolean_tripwire;}};// returns bought server with smallest RAMconst string_get_server_bought_smallest = function(ns) {const array_servers_bought = ns.getPurchasedServers();if (array_servers_bought.length > 0) {let string_server_smallest;let integer_size_smallest = object_get_constants(ns).PurchasedServerMaxRam;for (let integer_indices_0 = 0; integer_indices_0 < array_servers_bought.length; ++integer_indices_0) {let integer_server_ram_total = float_get_server_ram_total(ns, array_servers_bought[integer_indices_0]);if (integer_server_ram_total < integer_size_smallest) {string_server_smallest = array_servers_bought[integer_indices_0];integer_size_smallest = integer_server_ram_total;
};const boolean_conditions_server_purchase_3 = function(ns) {const integer_servers_bought_amount = ns.getPurchasedServers().length;const object_constants = object_get_constants(ns);const float_ram_server_bought_maximum = object_constants.PurchasedServerMaxRam;if (// you have one or more servers already(integer_servers_bought_amount > 0) &&// you currently own less than the maximum amount of purchased servers allowed(integer_servers_bought_amount < object_constants.PurchasedServerLimit)) {if (// you already bought a server with max ram, buy another server the max possible ram(integer_get_server_ram_total(ns, string_get_server_bought_biggest(ns)) == float_ram_server_bought_maximum) &&(integer_get_server_ram_biggest_afforded(ns) >= float_ram_server_bought_maximum)) {return true;
return string_server_smallest;}};// returns bought server with biggest RAMconst string_get_server_bought_biggest = function(ns) {const array_servers_bought = ns.getPurchasedServers();if (array_servers_bought.length > 0) {let string_server_biggest;let integer_size_biggest = object_get_constants(ns).integer_server_ram_min;for (let integer_indices_0 = 0; integer_indices_0 < array_servers_bought.length; ++integer_indices_0) {let integer_server_ram_total = float_get_server_ram_total(ns, array_servers_bought[integer_indices_0]);if (integer_server_ram_total > integer_size_biggest) {string_server_biggest = array_servers_bought[integer_indices_0];integer_size_biggest = integer_server_ram_total;
};const boolean_conditions_server_delete_purchase = function(ns) {const object_constants = object_get_constants(ns);if (// you currently own the maximum amount of purchased servers allowed(ns.getPurchasedServers().length == object_constants.PurchasedServerLimit) &&// your servers do not all have the maximum ram possible for purchased servers!(boolean_servers_bought_all_max(ns, object_constants.PurchasedServerMaxRam)) &&// is cash at least equal to the price of the cheapest server bought + the next highest server after that, which is twice the price of the former, thus 3. this check is so that a server with the same ram as before isn't bought.(ns.getServerMoneyAvailable("home") >= 3 * object_constants.BaseCostFor1GBOfRamServer * integer_get_server_ram_total(ns, string_get_server_bought_smallest(ns)))
return string_server_biggest;}};// return the RAM of the server with the biggest RAM that you can affordconst integer_get_server_ram_biggest_afforded = function(ns) {const object_constants = object_get_constants(ns);let integer_server_ram_biggest_afforded = Math.pow(2, Math.trunc(Math.log2(ns.getServerMoneyAvailable("home") / object_constants.BaseCostFor1GBOfRamServer) / Math.log2(2)));if (integer_server_ram_biggest_afforded > object_constants.PurchasedServerMaxRam) {integer_server_ram_biggest_afforded = object_constants.PurchasedServerMaxRam;}return integer_server_ram_biggest_afforded;};const boolean_conditions_server_purchase_1 = function(ns) {const integer_server_ram_biggest_afforded = integer_get_server_ram_biggest_afforded(ns);const object_constants = object_get_constants(ns);if (// you have no bought servers yet(ns.getPurchasedServers().length === 0) &&// RAM is at least equal to the minimum RAM possible for purchased servers(integer_server_ram_biggest_afforded >= object_constants.integer_server_ram_min) &&// RAM is at least equal to the RAM of "home" (probably a bad idea to hardcode this since the string_name of "home" might change in the future) or max ram.(integer_server_ram_biggest_afforded >= float_get_server_ram_total(ns, "home") ||integer_server_ram_biggest_afforded >= object_constants.PurchasedServerMaxRam)) {return true;}};const boolean_conditions_server_purchase_2 = function(ns) {const integer_servers_bought_amount = ns.getPurchasedServers().length;const object_constants = object_get_constants(ns);if (// you have one or more servers already(integer_servers_bought_amount > 0) &&// you currently own less than the maximum amount of purchased servers allowed(integer_servers_bought_amount < object_constants.PurchasedServerLimit)) {const float_ram_server_bought_biggest = float_get_server_ram_total(ns, string_get_server_bought_biggest(ns));if (// you dont own a server with max RAM yet, buy a server with RAM greater than the RAM of your biggest bought server(float_ram_server_bought_biggest != object_constants.PurchasedServerMaxRam) &&(float_ram_server_bought_biggest < integer_get_server_ram_biggest_afforded(ns))
while (!boolean_servers_bought_all_max(ns)) {while (boolean_conditions_server_delete_purchase(ns)) {ns.deleteServer(string_get_server_bought_smallest(ns));ns.purchaseServer(string_servers_bought_name, integer_get_server_ram_biggest_afforded(ns));}while (boolean_conditions_server_purchase_3(ns) ||boolean_conditions_server_purchase_2(ns) ||boolean_conditions_server_purchase_1(ns)
const boolean_conditions_server_purchase_3 = function(ns) {const integer_servers_bought_amount = ns.getPurchasedServers().length;const object_constants = object_get_constants(ns);const float_ram_server_bought_maximum = object_constants.PurchasedServerMaxRam;if (// you have one or more servers already(integer_servers_bought_amount > 0) &&// you currently own less than the maximum amount of purchased servers allowed(integer_servers_bought_amount < object_constants.PurchasedServerLimit)) {if (// you already bought a server with max ram, buy another server the max possible ram(float_get_server_ram_total(ns, string_get_server_bought_biggest(ns)) == float_ram_server_bought_maximum) &&(integer_get_server_ram_biggest_afforded(ns) >= float_ram_server_bought_maximum)
await ns.sleep(float_period_check);
const boolean_conditions_server_delete_purchase = function(ns) {const object_constants = object_get_constants(ns);if (// you currently own the maximum amount of purchased servers allowed(ns.getPurchasedServers().length == object_constants.PurchasedServerLimit) &&// your servers do not all have the maximum RAM possible for purchased servers!(boolean_servers_bought_all_max(ns, object_constants.PurchasedServerMaxRam)) &&// is cash at least equal to the price of the cheapest server bought + the next highest server after that, which is twice the price of the former, thus 3. this check is so that a server with the same RAM as before isn't bought.(ns.getServerMoneyAvailable("home") >= 3 * object_constants.BaseCostFor1GBOfRamServer * float_get_server_ram_total(ns, string_get_server_bought_smallest(ns)))) {return true;}else {return false;
// ram.js - 6.2GB - tries to continually buy ram as long as you have sufficient cash
// ram.js - 6.6GB - tries to continually upgrade the RAM of "home" as long as the ram utilisation of your network is over threshold and you have sufficient cash.import {float_get_network_ram_utilisation}from "lib_ram.js";
try {while (ns.getServerMoneyAvailable("home") >= ns.getUpgradeHomeRamCost()) {ns.upgradeHomeRam();
while(float_get_network_ram_utilisation(ns) > float_ram_utilisation_threshold) {try {while (ns.getServerMoneyAvailable("home") >= ns.getUpgradeHomeRamCost()) {ns.upgradeHomeRam();}
// botnet.js - 2.15GB - opens ports and nukes any unrooted servers if the player's hacking level is high enough to do so and the appropriate number of object_exploits are present
// botnet.js - 2.2GB - opens ports and nukes any unrooted servers if the player's hacking level is high enough to do so and the appropriate number of object_exploits are presentimport {array_get_servers_unrooted}from "lib_root.js";
const object_get_constants = function(ns) {// object_constants are from https://github.com/danielyxie/bitburner/blob/master/src/Constants.jsconst object_constants = {// filenames and related functions of exploitsarray_exploits: [ns.brutessh, ns.ftpcrack, ns.relaysmtp, ns.httpworm, ns.sqlinject],// name of current host (usually "home")string_host: "home" // or ns.getHostname()};return object_constants;
const array_get_exploits = function(ns) {return [ns.brutessh,ns.ftpcrack,ns.relaysmtp,ns.httpworm,ns.sqlinject];
// returns an array of all servers in the gameconst array_get_servers = function(ns) {const string_host = object_get_constants(ns).string_host;const array_servers = [string_host];for (let integer_indices_0 = 0; integer_indices_0 < array_servers.length; ++integer_indices_0) {const array_scan_results = ns.scan(array_servers[integer_indices_0]);for (let integer_indices_1 = 0; integer_indices_1 < array_scan_results.length; ++integer_indices_1) {if (array_servers.indexOf(array_scan_results[integer_indices_1]) === -1) {array_servers.push(array_scan_results[integer_indices_1]);}}}return array_servers;};// returns an array of all servers that are yet to be rootedconst array_get_servers_unrooted = function(ns) {const array_servers = array_get_servers(ns);const array_servers_unrooted = [];for (let integer_indices_0 = 0; integer_indices_0 < array_servers.length; ++integer_indices_0) {if (!ns.hasRootAccess(array_servers[integer_indices_0])) {array_servers_unrooted.push(array_servers[integer_indices_0]);}}return array_servers_unrooted;};
// returns an array of all servers in the gameconst array_get_servers = function(ns) {const string_host = ns.getHostname();const array_servers = [string_host];for (let integer_indices_0 = 0; integer_indices_0 < array_servers.length; ++integer_indices_0) {const array_scan_results = ns.scan(array_servers[integer_indices_0]);for (let integer_indices_1 = 0; integer_indices_1 < array_scan_results.length; ++integer_indices_1) {if (array_servers.indexOf(array_scan_results[integer_indices_1]) === -1) {array_servers.push(array_scan_results[integer_indices_1]);}}}return array_servers;};// returns the total ram of a serverconst integer_get_server_ram_total = function(ns, string_server) {return (ns.getServerRam(string_server))[0];};// returns the used ram of a serverconst float_get_server_ram_used = function(ns, string_server) {return (ns.getServerRam(string_server))[1];};// returns the amount of free ram of a serverconst float_get_server_ram_free = function(ns, string_server) {return integer_get_server_ram_total(ns, string_server) - float_get_server_ram_used(ns, string_server);};// returns an array of all rooted serversconst array_get_servers_rooted = function(ns) {const array_servers = array_get_servers(ns);const array_servers_rooted = [];for (let integer_indices_0 = 0; integer_indices_0 < array_servers.length; ++integer_indices_0) {if (ns.hasRootAccess(array_servers[integer_indices_0])) {array_servers_rooted.push(array_servers[integer_indices_0]);}}return array_servers_rooted;};
return array_servers.sort((string_element_0, string_element_1) => (integer_get_server_ram_total(ns, string_element_0) - integer_get_server_ram_total(ns, string_element_1)));
return array_servers.sort((string_element_0, string_element_1) => (float_get_server_ram_total(ns, string_element_0) - float_get_server_ram_total(ns, string_element_1)));
// returns an array of all servers in the gameconst array_get_servers = function(ns) {const array_servers = [ns.getHostname()];for (let integer_indices_0 = 0; integer_indices_0 < array_servers.length; ++integer_indices_0) {const array_scan_results = ns.scan(array_servers[integer_indices_0]);for (let integer_indices_1 = 0; integer_indices_1 < array_scan_results.length; ++integer_indices_1) {if (array_servers.indexOf(array_scan_results[integer_indices_1]) === -1) {array_servers.push(array_scan_results[integer_indices_1]);}}}return array_servers;};
import {array_get_servers}from "lib_servers.js";
// returns an array of all servers in the gameconst array_get_servers = function(ns) {const array_servers = [ns.getHostname()];for (let integer_indices_0 = 0; integer_indices_0 < array_servers.length; ++integer_indices_0) {const array_scan_results = ns.scan(array_servers[integer_indices_0]);for (let integer_indices_1 = 0; integer_indices_1 < array_scan_results.length; ++integer_indices_1) {if (array_servers.indexOf(array_scan_results[integer_indices_1]) === -1) {array_servers.push(array_scan_results[integer_indices_1]);}}}return array_servers;};
// cp.js - 2.65GBimport {array_get_servers}from "lib_servers.js";
### "main.js" (8.75 [+6.2] [+8.55] [+2.15] GB)* Run helper scripts that should:
### "main.js" (8.75 [+6.6] [+8.85] [+2.2] GB)* Run the helper scripts "ram.js", "servers.js" and "botnet.js" that should, respectively:
`-r, --ram-utilisation <THRESHOLD>`* THRESHOLD = The botnet's ram utilisation threshold after which upgrades/replacements should be bought for servers and the RAM of "home". Should be a floating point number >= 0 <= 1. Values closer to 0 will result in attempting more frequent upgrades/replacements at the cost of less efficient RAM utilisation to cash spenditure ratios. Defaults to 0.9.
* Runs the script with up to 4000 jobs, targetting "harakiri-sushi" and stealing only up to 50% of it's cash per "hack.js" job that finishes executing, whilst the remaining variables are set to defaults.
* Runs the script with up to 4000 jobs, targetting "harakiri-sushi", only upgrading/replacing RAM and servers when at least 0.7 of your network's total RAM is being used, and stealing only up to 50% of harakiri-sushi's cash per "hack.js" job that finishes executing, whilst the remaining variables are set to defaults.
This Work is distributed and dual-licensed under the terms of both the [MIT License](LICENSE-MIT) and the [Apache License 2.0](LICENSE-APACHE).
This Work is distributed and dual-licensed under the terms of both the [MIT License](https://nest.pijul.com/nicoty/bitburner_scripts:master/4bb17ded7a86f7decd) and the [Apache License 2.0](https://nest.pijul.com/nicoty/bitburner_scripts:master/4bb17ded7a86f7de02).