all: remove unecessary uses of `exec`. refactor. main.js: add RAM reservation logic. lib_ram.js: renamed to lib_ram_server.js. README.js: update.

[?]
Apr 27, 2020, 1:55 PM
Y5OWMCQRLGQ56HMM53HR6CVZEMAHOEKDYMFLBDEQOJ4HLUJL7HUAC

Dependencies

  • [2] 44JNP7VZ fix schedule making and running logic.
  • [3] V4DMWF25 remove redundant preparation steps in "hacker.js".
  • [4] SLSWBNYT added ram utilisation logic to `ram.js` and `servers.js`. split and refactored redundant code into separate library files.
  • [5] HLC2L3NJ add "tor.js" and "programs.js". use `minimist` for "main.js" argument parsing.
  • [6] AXGQ7FML split and refactor hacking logic to "hacker.js" and argument parsing and script execution logic to "main.js". update "README.md".
  • [7] NQ22FUSW add more options to `main.js`. update `README.md`.
  • [8] 2BKHJI2S init
  • [9] 3NFCZ6IP fixed the ram utilisation logic. added flags to `main.js` that can prevent the execution of helpers.
  • [10] RWMZ7DVL split and refactor various logics. update "README.md".
  • [11] FA3U4WUJ more `README.md` changes.
  • [12] YXH7ERRN fixed bug that prevented helper scripts running if the "home" server does not have RAM bigger than the rest of the rooted servers.
  • [13] NC66CZ5J rename certain variables that had the same names as ns functions to prevent the RAM checker from triggering.

Change contents

  • replacement in sbin/servers.js at line 6
    [4.340][4.340:359]()
    from "lib_ram.js";
    [4.340]
    [4.359]
    from "lib_ram_server.js";
  • replacement in sbin/ram.js at line 5
    [4.7926][4.7926:7945]()
    from "lib_ram.js";
    [4.7926]
    [4.7945]
    from "lib_ram_server.js";
  • replacement in sbin/hacker.js at line 16
    [4.15585][4.15585:15604]()
    from "lib_ram.js";
    [4.15585]
    [4.15604]
    from "lib_ram_server.js";
    import {
    boolean_can_server_run_script_threads
    }
    from "lib_ram_script.js";
  • replacement in sbin/hacker.js at line 30
    [4.15810][4.15810:15905]()
    integer_time_finishes = await void_runner(ns, ...array_arguments.slice(1)) + Date.now();
    [4.15810]
    [4.15905]
    integer_time_finishes = void_runner(ns, ...array_arguments.slice(1)) + Date.now();
  • edit in sbin/hacker.js at line 443
    [4.37675][4.37675:37928]()
    }
    };
    const boolean_can_server_run_script_threads = function(ns, float_server_used_ram_free, float_script_ram, integer_threads) {
    if (float_script_ram * integer_threads > float_server_used_ram_free) {
    return false;
    }
    else {
    return true;
  • replacement in sbin/hacker.js at line 514
    [2.146][2.146:270]()
    if (boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, ns.getScriptRam(string_weaken), 1)) {
    [2.146]
    [2.270]
    if (boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, string_weaken, 1)) {
  • replacement in sbin/hacker.js at line 534
    [4.42473][4.42473:42604]()
    if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, ns.getScriptRam(string_weaken), 1)) {
    [4.42473]
    [4.42604]
    if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, string_weaken, 1)) {
  • replacement in sbin/hacker.js at line 567
    [4.44105][4.44105:44234]()
    if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, ns.getScriptRam(string_grow), 1)) {
    [4.44105]
    [4.44234]
    if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, string_grow, 1)) {
  • replacement in sbin/hacker.js at line 607
    [4.46227][4.46227:46356]()
    if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, ns.getScriptRam(string_hack), 1)) {
    [4.46227]
    [4.46356]
    if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, string_hack, 1)) {
  • replacement in sbin/hacker.js at line 685
    [4.49755][4.49755:49821]()
    const void_schedule_runner = async function(ns, array_schedule) {
    [4.49755]
    [4.49821]
    const void_schedule_runner = function(ns, array_schedule) {
  • replacement in sbin/hacker.js at line 709
    [4.50755][4.50755:50893]()
    await ns.exec(string_script, string_server_used, integer_threads, string_server_used, string_server_target, float_delay, identifier);
    [4.50755]
    [4.50893]
    ns.exec(string_script, string_server_used, integer_threads, string_server_used, string_server_target, float_delay, identifier);
  • replacement in sbin/hacker.js at line 714
    [4.50963][4.50963:51109]()
    const void_runner = async function(ns, integer_job_cap, float_precision, float_steal_cap, float_padding_seconds, string_server_target_argument) {
    [4.50963]
    [3.11]
    const void_runner = function(ns, integer_job_cap, float_precision, float_steal_cap, float_padding_seconds, string_server_target_argument) {
  • replacement in sbin/hacker.js at line 721
    [3.411][3.411:461]()
    await void_schedule_runner(ns, array_schedule);
    [3.411]
    [3.461]
    void_schedule_runner(ns, array_schedule);
  • file deletion: lib_ram.js (----------)
    [4.3711246][4.3724522:3724556](),[4.3724556][4.3722765:3722765]()
    // lib_ram.js - 2GB
    import {
    array_get_servers_rooted
    }
    from "lib_root.js";
    // returns the total ram of a server
    export const float_get_server_ram_total = function(ns, string_server) {
    return (ns.getServerRam(string_server))[0];
    };
    // returns the used ram of a server
    const float_get_server_ram_used = function(ns, string_server) {
    return (ns.getServerRam(string_server))[1];
    };
    // returns the amount of free ram of a server
    export const float_get_server_ram_free = function(ns, string_server) {
    return float_get_server_ram_total(ns, string_server) - float_get_server_ram_used(ns, string_server);
    };
    // returns the total RAM from all the servers you have root access to
    const float_get_network_ram_total = function (ns) {
    const array_servers_rooted = array_get_servers_rooted(ns);
    let float_network_ram_total = 0;
    for (let integer_indices_0 = 0; integer_indices_0 < array_servers_rooted.length; ++integer_indices_0) {
    float_network_ram_total += float_get_server_ram_total(ns, array_servers_rooted[integer_indices_0]);
    }
    return float_network_ram_total;
    };
    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) {
    }
    };
    // returns the RAM utilisation of the botnet as a decimal
    export const float_get_network_ram_utilisation = function (ns) {
    return float_get_network_ram_used(ns) / float_get_network_ram_total(ns);
    };
    // sort an array of servers by their amounts of RAM, from lowest to highest
    const void_sort_by_server_ram = function(ns, array_servers) {
    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)));
    };
    export const array_get_servers_rooted_sorted_by_ram = function(ns) {
    let array_servers_rooted = array_get_servers_rooted(ns);
    void_sort_by_server_ram(ns, array_servers_rooted);
    return array_servers_rooted;
    };
    return float_network_ram_used;
    float_network_ram_used += float_get_server_ram_used(ns, array_servers_rooted[integer_indices_0]);
    let float_network_ram_used = 0;
    // returns the total RAM used from all the servers you have root access to
    const float_get_network_ram_used = function (ns) {
  • replacement in lib/lib_servers.js at line 4
    [4.3713867][4.3713867:3714093]()
    export const 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) {
    [4.3713867]
    [4.3714093]
    export const array_get_servers = function (ns) {
    const string_host = ns.getHostname(),
    array_servers = [string_host];
    for (
    let integer_indices_0 = 0;
    integer_indices_0 < array_servers.length;
    ++integer_indices_0
    ) {
  • replacement in lib/lib_servers.js at line 13
    [4.3714167][4.3714167:3714354]()
    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) {
    [4.3714167]
    [4.3714354]
    for (
    let integer_indices_1 = 0;
    integer_indices_1 < array_scan_results.length;
    ++integer_indices_1
    )
    -1 === array_servers.indexOf(array_scan_results[integer_indices_1]) &&
  • edit in lib/lib_servers.js at line 20
    [4.3714421][4.3714421:3714435]()
    }
    }
  • replacement in lib/lib_root.js at line 8
    [4.3719010][4.3719010:3719308]()
    export const 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])) {
    [4.3719010]
    [4.3719308]
    export const array_get_servers_rooted = function (ns) {
    const array_servers = array_get_servers(ns),
    array_servers_rooted = [];
    for (
    let integer_indices_0 = 0;
    integer_indices_0 < array_servers.length;
    ++integer_indices_0
    )
    ns.hasRootAccess(array_servers[integer_indices_0]) &&
  • edit in lib/lib_root.js at line 18
    [4.3719375][4.3719375:3719385]()
    }
    }
  • replacement in lib/lib_root.js at line 22
    [4.3719481][4.3719481:3719784]()
    export const 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])) {
    [4.3719481]
    [4.3719784]
    export const array_get_servers_unrooted = function (ns) {
    const array_servers = array_get_servers(ns),
    array_servers_unrooted = [];
    for (
    let integer_indices_0 = 0;
    integer_indices_0 < array_servers.length;
    ++integer_indices_0
    )
    ns.hasRootAccess(array_servers[integer_indices_0]) ||
  • edit in lib/lib_root.js at line 32
    [4.3719853][4.3719853:3719863]()
    }
    }
  • replacement in lib/lib_ls.js at line 3
    [4.3733690][4.3733690:3733784]()
    export const array_get_files_to_copy = function(ns, string_server_source, string_substring) {
    [4.3733690]
    [4.3733784]
    export const array_get_files_to_copy = function (
    ns,
    string_server_source,
    string_substring
    ) {
  • replacement in lib/lib_ls.js at line 10
    [4.3733877][4.3733877:3733984]()
    for (let integer_indices_0 = 0; integer_indices_0 < array_files_in_server.length; ++integer_indices_0) {
    [4.3733877]
    [4.3733984]
    for (
    let integer_indices_0 = 0;
    integer_indices_0 < array_files_in_server.length;
    ++integer_indices_0
    ) {
  • replacement in lib/lib_ls.js at line 16
    [4.3734050][4.3734050:3734100]()
    if (string_file.includes(string_substring)) {
    [4.3734050]
    [4.3734100]
    string_file.includes(string_substring) &&
  • edit in lib/lib_ls.js at line 18
    [4.3734145][4.3734145:3734151]()
    }
  • replacement in bin/killall.js at line 1
    [4.3797120][4.11223:11347]()
    // killall.js - 3.05GB - TODO: implement a loop that repeats logic until all appropriate scripts have actually been killed.
    [4.3797120]
    [4.1683]
    // killall.js - 3.05GB - TODO:
    // * implement a loop that repeats logic until all appropriate scripts have actually been killed.
    // * use kill instead of scriptKill. maybe separate that into a lib file that main.js will also use.
  • replacement in README.md at line 10
    [4.3289][4.2704:2728]()
    ### "main.js" (8.05 GB)
    [4.3289]
    [4.2728]
    ### "main.js" (6.9 GB)
    * Reserve at least enough RAM to be able to run "hacker.js" (8.05 GB).
  • replacement in README.md at line 19
    [4.6016][4.2956:3025]()
    * Kill itself by spawning "hacker.js" (8.05 GB) which should then:
    [4.6016]
    [3.2193]
    * Kill itself by spawning "hacker.js" which should then:
  • replacement in README.md at line 71
    [4.7560][4.7560:7684]()
    * Prevents the "servers.js" script from being started which is responsible for the purchasing and replacement of servers.
    [4.7560]
    [4.7684]
    * Prevents the "servers.js" script from being started which is responsible for buying and replacing bought servers.
  • replacement in README.md at line 79
    [4.6239][4.6239:6337]()
    * Prevents the "tor.js" script from being started which is responsible for buyinh a TOR Router.
    [4.6239]
    [4.6337]
    * Prevents the "tor.js" script from being started which is responsible for buying a TOR Router.