fixed bug that prevented helper scripts running if the "home" server does not have RAM bigger than the rest of the rooted servers.
[?]
Apr 21, 2020, 10:44 AM
YXH7ERRNAV2FHHAFREYBN7VJZZMGH3UJOXGM4IKS2USVKI543TFQCDependencies
- [2]
NC66CZ5Jrename certain variables that had the same names as ns functions to prevent the RAM checker from triggering. - [3]
6MBUKAG6remove unneeded functions and comments. update readme. - [4]
RWMZ7DVLsplit and refactor various logics. update "README.md". - [5]
VMXI7PS4added action cap. improved scoring system. fixed parts of security and cash predictors. made lshw loopable. - [6]
3TYF4BJStarget only hackable servers. replace servers continually. - [7]
CJBGAILAadd optional `--target` parameter for `main.js`. update `README.md`. - [8]
2LU5Y77Ofixed optimum percentage to steal calculator. - [9]
4ACCU75Nimprove and refactor scheduling logic. - [10]
BZ6FC2BTadd `cp.js`. - [11]
2BKHJI2Sinit - [12]
NQ22FUSWadd more options to `main.js`. update `README.md`. - [13]
HHZNTFCTremove `-t` flag for `main.js` which conflicted with the same flag for the `run` command.
Change contents
- replacement in bin/main.js at line 1
// 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. - edit in bin/main.js at line 6
const array_arguments = Array.from(ns.args); - replacement in bin/main.js at line 22
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; - replacement in bin/main.js at line 29
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}.`); - edit in bin/main.js at line 77[3.2338]→[3.2338:2930](∅→∅),[3.2930]→[3.2631:2714](∅→∅),[3.4011]→[3.2631:2714](∅→∅),[3.2631]→[3.2631:2714](∅→∅)
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];} - edit in bin/main.js at line 80
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); - replacement in bin/main.js at line 107
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(); - replacement in bin/main.js at line 290
},// name of current host (usually "home")string_host: "home" // or ns.getHostname()} - replacement in bin/main.js at line 297
const string_host = object_get_constants(ns).string_host;const string_host = ns.getHostname(); - edit in bin/main.js at line 323
};// 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]);}} - edit in bin/main.js at line 367
// 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;}}}}}; - edit in bin/main.js at line 417
// 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;}; - edit in bin/main.js at line 602
}};// 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]);} - replacement in bin/main.js at line 864
// 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. - edit in bin/main.js at line 890
- edit in bin/main.js at line 917
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;}}}}}; - replacement in bin/main.js at line 918
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) { - replacement in bin/main.js at line 925
// 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 - replacement in bin/main.js at line 930
], object_constants.string_host);], ns.getHostname()); - replacement in README.md at line 10
### "main.js" (8.7 [+6.2] [+8.55] [+2.15] GB)### "main.js" (8.75 [+6.2] [+8.55] [+2.15] GB)