YXH7ERRNAV2FHHAFREYBN7VJZZMGH3UJOXGM4IKS2USVKI543TFQC NC66CZ5JPP3RPFCWAJE2ZBPFLA5ILKBNGTQLXDCRIUTIEWE74R4AC 2BKHJI2SJ3VXTFBK2BWNN3I3BDNMUU5YTJGKTQCOXV66VVRHCGKAC VMXI7PS4GFDOWPFLHQ7TYKJ5K3K7FXNPJCBEVYHTTRN7YB5ZHEQAC CJBGAILAK7G3WXYUBNUZMUMM3U5CPHWVK6ZAJWYBL4IOB5SZN32AC NQ22FUSWN6CBJKJ5H7UV5N2KEXBIXVNQDNL2EK6UJ3E7RFLWNVDQC HHZNTFCTPVDB5GIBDLZFZPDKR62SD47HQ5QALRBSP5UN52M6GLEAC RWMZ7DVLOVPLR4FCIAVSABA5OESYUIEQ2OOZUYNPCNFEBYK5627AC // main.js - 8.7GB - TODO: Separate logic that requires source files so that they are only ran when you have the required source file - need a cheap way to check if you have source file? Maybe make a cache script that saves runtime constants like max money of servers to a cache file to potentially reduce RAM usage further. Maybe add functionality that allows on-the-fly hot loading of settings from a file.
// main.js - 8.75GB - TODO: Separate logic that requires source files so that they are only ran when you have the required source file - need a cheap way to check if you have source file? Maybe make a cache script that saves runtime constants like max money of servers to a cache file to potentially reduce RAM usage further. Maybe add functionality that allows on-the-fly hot loading of settings from a file.
for (let integer_indices_0 = 0; integer_indices_0 < array_arguments.length; ++integer_indices_0) {const string_argument = array_arguments[integer_indices_0];if ((string_argument === "--server-name") ||(string_argument === "-n")) {string_servers_bought_name = array_arguments[integer_indices_0 + 1];
let array_arguments = Array.from(ns.args);let boolean_end_loop_arguments = false;while (!boolean_end_loop_arguments) {if (array_arguments.length === 0) {boolean_end_loop_arguments = true;break;
if ((string_argument === "--job-cap") ||(string_argument === "-j")) {integer_job_cap = array_arguments[integer_indices_0 + 1];}if ((string_argument === "--job-delay") ||(string_argument === "-d")) {float_padding_seconds = array_arguments[integer_indices_0 + 1];
const string_argument = array_arguments[0];const string_argument_value = array_arguments[1];switch (string_argument) {case "-c":// fall-throughcase "--check-delay":float_period_check_seconds = string_argument_value;array_arguments.splice(0, 2);break;case "-d":// fall-throughcase "--job-delay":float_padding_seconds = string_argument_value;array_arguments.splice(0, 2);break;case "-i":// fall-throughcase "--target":string_server_target = string_argument_value;array_arguments.splice(0, 2);break;case "-j":// fall-throughcase "--job-cap":integer_job_cap = string_argument_value;array_arguments.splice(0, 2);break;case "-n":// fall-throughcase "--server-name":string_servers_bought_name = string_argument_value;array_arguments.splice(0, 2);break;case "-p":// fall-throughcase "--precision":float_precision = string_argument_value;array_arguments.splice(0, 2);break;case "-s":// fall-throughcase "--steal-cap":float_steal_cap = string_argument_value;array_arguments.splice(0, 2);break;default:throw new Error(`Unknown argument: ${string_argument}.`);
if ((string_argument === "--precision") ||(string_argument === "-p")) {float_precision = array_arguments[integer_indices_0 + 1];}if ((string_argument === "--steal-cap") ||(string_argument === "-s")) {float_steal_cap = array_arguments[integer_indices_0 + 1];}if ((string_argument === "--check-delay") ||(string_argument === "-c")) {float_period_check_seconds = array_arguments[integer_indices_0 + 1];}if ((string_argument === "--target") ||(string_argument === "-i")) {string_server_target = array_arguments[integer_indices_0 + 1];}
const array_scripts = [// // uncomment if you have source-file 4// {// file: "ram.js",// ram: 6.2,// threads: 1,// arguments: [float_period_check_seconds]// },{file: "servers.js",ram: 8.55,threads: 1,arguments: [float_period_check_seconds, string_servers_bought_name]},{file: "botnet.js",ram: 2.15,threads: 1,arguments: [float_period_check_seconds]}];await void_script_executor(ns, array_scripts);
integer_time_finishes = await void_runner(ns, string_servers_bought_name, integer_job_cap, float_precision, float_steal_cap, float_padding_seconds, string_server_target, float_period_check_seconds) + Date.now();
integer_time_finishes = await void_runner(ns, integer_job_cap, float_precision, float_steal_cap, float_padding_seconds, string_server_target) + Date.now();
};// 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;};// returns true if a script is running on any serverconst boolean_script_running = function(ns, string_script) {const array_servers = array_get_servers(ns);for (let integer_indices_0 = 0; integer_indices_0 < array_servers.length; ++integer_indices_0) {const string_server = array_servers[integer_indices_0];const array_scripts_running = ns.ps(string_server);if (array_scripts_running.length > 0) {for (let integer_indices_1 = 0; integer_indices_1 < array_scripts_running.length; ++integer_indices_1) {const object_script = array_scripts_running[integer_indices_1];const string_script_to_check = object_script.filename;if (string_script_to_check == string_script) {return true;}}}}return false;};// copies files to all rooted serversconst void_copy_files_to_string_servers_rooted = function(ns, array_files, string_source) {const array_servers_rooted = array_get_servers_rooted(ns);for (let integer_indices_0 = 0; integer_indices_0 < array_servers_rooted.length; ++integer_indices_0) {for (let integer_indices_1 = 0; integer_indices_1 < array_files.length; ++integer_indices_1) {ns.scp(array_files[integer_indices_1], string_source, array_servers_rooted[integer_indices_0]);}}
// copies and runs scripts on any server that has enough available RAMconst void_script_executor = async function(ns, array_scripts) {const array_servers_rooted_sorted_by_ram = array_get_servers_rooted_sorted_by_ram(ns);for (let integer_indices_0 = 0; integer_indices_0 < array_scripts.length; ++integer_indices_0) {const object_script = array_scripts[integer_indices_0];const string_file = object_script.file;const float_ram = object_script.ram;const integer_threads = object_script.threads;const array_arguments = object_script.arguments;// copy script to rooted serversvoid_copy_files_to_string_servers_rooted(ns, [string_file], ns.getHostname());if (!boolean_script_running(ns, string_file)) {// use servers with the biggest rams firstfor (let integer_indices_0 = array_servers_rooted_sorted_by_ram.length - 1; integer_indices_0 >= 0; --integer_indices_0) {const string_server_used = array_servers_rooted_sorted_by_ram[integer_indices_0];let float_server_used_ram_free_current = float_get_server_ram_free(ns, string_server_used);if (float_server_used_ram_free_current >= float_ram * integer_threads) {try {await ns.exec(string_file, string_server_used, integer_threads, ...array_arguments);} catch (error) {ns.tprint(JSON.stringify(error));}break;}}}}};
// 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;};
}};// copies files to all rooted serversconst void_copy_files_to_string_servers_rooted = function(ns, array_files, string_source) {const array_servers_rooted = array_get_servers_rooted(ns);for (let integer_indices_0 = 0; integer_indices_0 < array_servers_rooted.length; ++integer_indices_0) {for (let integer_indices_1 = 0; integer_indices_1 < array_files.length; ++integer_indices_1) {ns.scp(array_files[integer_indices_1], string_source, array_servers_rooted[integer_indices_0]);}
// remove schedule items near the end that cause security to not equal minimum. in other words, the target should have minimum security when the cycle finishes. this is to make the next cycle of jobs run as quick as possible. TODO: make it so that we don't have to do this deleting step, instead, the array making steps above should already take into this into account and don't make more items than is needed.
// remove jobs near the end that cause security to not equal minimum. in other words, the target should have minimum security when the schedule finishes. this is to make the jobs in the next schedule run as quick as possible. TODO: make it so that we don't have to do this deleting step, instead, the array making steps above should already take into this into account and don't make more items than is needed.
const boolean_script_running = function(ns, string_script) {const array_servers = array_get_servers(ns);for (let integer_indices_0 = 0; integer_indices_0 < array_servers.length; ++integer_indices_0) {const string_server = array_servers[integer_indices_0];const array_scripts_running = ns.ps(string_server);if (array_scripts_running.length > 0) {for (let integer_indices_1 = 0; integer_indices_1 < array_scripts_running.length; ++integer_indices_1) {const object_script = array_scripts_running[integer_indices_1];const string_script_to_check = object_script.filename;if (string_script_to_check == string_script) {return true;}}}}return false;};const void_script_executor = async function(ns, array_scripts) {const array_servers_rooted_sorted_by_ram = array_get_servers_rooted_sorted_by_ram(ns);for (let integer_indices_0 = 0; integer_indices_0 < array_scripts.length; ++integer_indices_0) {const object_script = array_scripts[integer_indices_0];const string_path = object_script.file;const float_ram = object_script.ram;const integer_threads = object_script.threads;const array_arguments = object_script.arguments;if (!boolean_script_running(ns, string_path)) {// use servers with the biggest rams firstfor (let integer_indices_0 = array_servers_rooted_sorted_by_ram.length - 1; integer_indices_0 >= 0; --integer_indices_0) {const string_server_used = array_servers_rooted_sorted_by_ram[integer_indices_0];let float_server_used_ram_free_current = float_get_server_ram_free(ns, string_server_used);if (float_server_used_ram_free_current >= float_ram * integer_threads) {try {await ns.exec(string_path, string_server_used, integer_threads, ...array_arguments);} catch (error) {ns.tprint(JSON.stringify(error));}break;}}}}};
export const void_runner = async function(ns, string_servers_bought_name, integer_job_cap, float_precision, float_steal_cap, float_padding_seconds, string_server_target_argument, float_period_check_seconds) {
const void_runner = async function(ns, integer_job_cap, float_precision, float_steal_cap, float_padding_seconds, string_server_target_argument) {
// should probably merge this into constants?const array_scripts = [// // uncomment if you have source-file 4// {// file: "ram.js",// ram: 6.2,// threads: 1,// arguments: [float_period_check_seconds]// },{file: "servers.js",ram: 8.55,threads: 1,arguments: [float_period_check_seconds, string_servers_bought_name]},{file: "botnet.js",ram: 2.15,threads: 1,arguments: [float_period_check_seconds]}];await void_script_executor(ns, array_scripts);// copy object_scripts to rooted servers
// copy scripts to rooted servers