README.md: update. kill.js: fix argument parser. lshw.js: add `-p` option. increase information given. main.js: fix error message. set saner defaults. hacker.js: split some functions into "lib_time.js" and "lib_score.js". ram.js: fix.

[?]
Apr 28, 2020, 10:07 PM
2WOLGB42T4EO7ZKLA5KFUYWVPTR6I3ET3FPJT4BSJFL43RRFRUBAC

Dependencies

  • [2] MKHG4OQB make worker scripts and worker script executor time-aware.
  • [3] BKG7YVUV main.js, hacker.js, servers.js, ram.js: refactor.
  • [4] SLSWBNYT added ram utilisation logic to `ram.js` and `servers.js`. split and refactored redundant code into separate library files.
  • [5] Y5OWMCQR 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.
  • [6] VMXI7PS4 added action cap. improved scoring system. fixed parts of security and cash predictors. made lshw loopable.
  • [7] AXGQ7FML split and refactor hacking logic to "hacker.js" and argument parsing and script execution logic to "main.js". update "README.md".
  • [8] 4ACCU75N improve and refactor scheduling logic.
  • [9] 6MBUKAG6 remove unneeded functions and comments. update readme.
  • [10] 7SRULDRF minor refactoring.
  • [11] NQ22FUSW add more options to `main.js`. update `README.md`.
  • [12] HSNSECD5 all: refactor. main.js: fix call to `void_kill_script_named_server_named`.
  • [13] P6ZJC2SH hacker.js: normalise factors used in server scoring function.
  • [14] 3NFCZ6IP fixed the ram utilisation logic. added flags to `main.js` that can prevent the execution of helpers.
  • [15] 2BKHJI2S init
  • [16] DJDWBCCQ add missing "nop.js". killall.js: rename to kill.js. add `--script` and `--server` options.
  • [17] CJBGAILA add optional `--target` parameter for `main.js`. update `README.md`.
  • [18] RWMZ7DVL split and refactor various logics. update "README.md".

Change contents

  • replacement in sbin/ram.js at line 7
    [4.5418][4.5418:5436](),[4.5436][3.854:928](),[3.928][4.5436:5515](),[4.5436][4.5436:5515]()
    for (
    ;
    ns.getServerMoneyAvailable("home") >= ns.getUpgradeHomeRamCost() &&
    float_get_network_ram_utilisation(ns) > float_ram_utilisation_threshold;
    [4.5418]
    [4.7945]
    try {
    for (
    ;
    ns.getServerMoneyAvailable("home") >= ns.getUpgradeHomeRamCost() &&
    float_get_network_ram_utilisation(ns) > float_ram_utilisation_threshold;
  • replacement in sbin/ram.js at line 13
    [4.7946][3.929:937](),[3.937][4.8087:8099](),[4.5522][4.8087:8099](),[4.8087][4.8087:8099]()
    ) {
    try {
    [4.7946]
    [3.938]
    )
  • replacement in sbin/ram.js at line 15
    [3.967][4.5703:5727](),[4.5703][4.5703:5727](),[4.5727][3.968:1009](),[4.98][4.8287:8295](),[3.1009][4.8287:8295](),[4.5804][4.8287:8295](),[4.8287][4.8287:8295](),[4.8295][3.1010:1052]()
    } catch (error) {
    ns.print(JSON.stringify(error));
    }
    await ns.sleep(float_period_check);
    [3.967]
    [3.1052]
    } catch (error) {
    ns.print(JSON.stringify(error));
  • replacement in sbin/hacker.js at line 1
    [4.14850][3.1063:1093]()
    /* hacker.js - 8.25GB - TODO:
    [4.14850]
    [4.11]
    /* hacker.js - 8.75GB - TODO:
  • edit in sbin/hacker.js at line 7
    [4.15444][4.6360:6416]()
    import { array_get_servers_rooted } from "lib_root.js";
  • edit in sbin/hacker.js at line 11
    [4.6487]
    [4.6487]
    import {
    float_get_time_hack,
    float_get_time_grow,
    float_get_time_weaken,
    } from "lib_time.js";
  • edit in sbin/hacker.js at line 17
    [4.6562]
    [3.1094]
    import {
    float_get_server_score,
    array_get_servers_hackable,
    } from "lib_score.js";
  • edit in sbin/hacker.js at line 157
    [4.19640][4.19640:20287]()
    const object_get_stats = function(ns) {
    // try {
    // return ns.getStats();
    // }
    // catch (error) {
    // ns.tprint(JSON.stringify(error));
    // return {
    // hacking: ns.getHackingLevel(),
    // strength: 1,
    // defense: 1,
    // dexterity: 1,
    // agility: 1,
    // charisma: 1,
    // intelligence: 1
    // };
    // }
    return {
    hacking: ns.getHackingLevel(),
    strength: 1,
    defense: 1,
    dexterity: 1,
    agility: 1,
    charisma: 1,
    intelligence: 1
    };
    };
  • edit in sbin/hacker.js at line 171
    [4.20998][4.20998:21058]()
    // player stats
    object_stats: object_get_stats(ns),
  • replacement in bin/main.js at line 37
    [4.10384][4.10384:10451]()
    throw (ns.tprint(`ERROR: `), new Error(string_message_error));
    [4.10384]
    [4.2879]
    throw (ns.tprint(`ERROR: ${integer_threads_nop}`), new Error(string_message_error));
  • replacement in bin/main.js at line 42
    [2.1887][2.1887:1917]()
    let integer_job_cap = 2000;
    [2.1887]
    [4.3080]
    let integer_job_cap = 1000;
  • replacement in bin/main.js at line 44
    [4.3111][2.1918:1953]()
    let float_padding_seconds = 0.5;
    [4.3111]
    [4.3144]
    let float_padding_seconds = 1;
  • replacement in bin/lshw.js at line 1
    [4.3795203][4.18173:18242]()
    // lshw.js - 2.45GB - Display information about one or more servers.
    [4.3795203]
    [4.18242]
    // lshw.js - 7.25GB - Display information about one or more servers. TODO:
    // * add flags that prevent certain information from being displayed.
    import { object_parse_arguments } from "lib_minimist.js";
    import {
    float_get_time_hack,
    float_get_time_grow,
    float_get_time_weaken,
    } from "lib_time.js";
    import { float_get_server_score } from "lib_score.js";
  • replacement in bin/lshw.js at line 13
    [4.18292][4.18292:18368]()
    let array_arguments = ns.args,
    float_sleep_duration = 0;
    for (;;) {
    [4.18292]
    [4.18368]
    // variables
    let float_sleep_duration = 0,
    integer_precision = 2,
    array_servers = [];
    // argument parsing
    const object_arguments = object_parse_arguments(ns.args);
    for (const string_argument in object_arguments)
    if (object_arguments.hasOwnProperty(string_argument)) {
    const argument_value = object_arguments[string_argument];
    switch (string_argument) {
    case "d":
    // fall-through
    case "delay":
    float_sleep_duration = 1e3 * argument_value;
    break;
    case "p":
    // fall-through
    case "precision":
    integer_precision = argument_value;
    break;
    case "_":
    array_servers = argument_value;
    break;
    default:
    const string_message_error = `Unknown argument passed: "${string_argument}".`;
    throw (ns.tprint(`ERROR: ${string_message_error}`), new Error(string_message_error));
    }
    }
    // main
    for (0 === array_servers.length && array_servers.push(ns.getHostName()); ; ) {
  • replacement in bin/lshw.js at line 46
    [4.18411][4.18411:18461]()
    integer_indices_0 < array_arguments.length;
    [4.18411]
    [4.18461]
    integer_indices_0 < array_servers.length;
  • replacement in bin/lshw.js at line 49
    [4.18495][4.18495:18765]()
    const string_argument = array_arguments[integer_indices_0];
    ("--delay" !== string_argument && "-d" !== string_argument) ||
    ((float_sleep_duration = 1e3 * array_arguments[integer_indices_0 + 1]),
    array_arguments.splice(integer_indices_0, 2));
    [4.18495]
    [4.18765]
    const string_server = array_servers[integer_indices_0];
  • replacement in bin/lshw.js at line 51
    [4.18777][4.18777:18830]()
    void_print_information(ns, string_argument);
    [4.18777]
    [4.18830]
    void_print_information(ns, string_server, integer_precision);
  • replacement in bin/lshw.js at line 62
    [4.19014][4.11905:11967](),[4.3795203][4.11905:11967]()
    const void_print_information = function (ns, string_server) {
    [4.19014]
    [4.11967]
    const void_print_information = function (ns, string_server, integer_precision) {
  • replacement in bin/lshw.js at line 79
    [4.12629][4.12629:12716](),[4.12716][4.19187:19265](),[4.19265][4.12792:12880](),[4.12792][4.12792:12880]()
    Maximum cash ($): ${float_cash_max}
    Current cash ($): ${float_cash_current.toFixed(2)}
    Current cash (%): ${((float_cash_current * 100) / float_cash_max).toFixed(2)}
    Minimum security: ${float_security_minimum}
    Current security: ${float_security_current}
    [4.12629]
    [4.19266]
    Maximum cash ($): ${float_cash_max.toFixed(integer_precision)}
    Current cash ($): ${float_cash_current.toFixed(integer_precision)}
    Current cash (%): ${((float_cash_current * 100) / float_cash_max).toFixed(integer_precision)}
    Minimum security: ${float_security_minimum.toFixed(integer_precision)}
    Current security: ${float_security_current.toFixed(integer_precision)}
  • replacement in bin/lshw.js at line 86
    [4.19346][4.19346:19364]()
    ).toFixed(2)}
    [4.19346]
    [4.12966]
    ).toFixed(integer_precision)}
  • replacement in bin/lshw.js at line 88
    [4.13017][4.13017:13091]()
    Hacking level needed: ${ns.getServerRequiredHackingLevel(string_server)}
    [4.13017]
    [4.13091]
    hack() time (s): ${float_get_time_hack(ns, string_server, float_security_current).toFixed(integer_precision)}
    grow() time (s): ${float_get_time_grow(ns, string_server, float_security_current).toFixed(integer_precision)}
    weaken() time (s): ${float_get_time_weaken(ns, string_server, float_security_current).toFixed(integer_precision)}
    Hacking level needed: ${ns.getServerRequiredHackingLevel(string_server)}
    Score: ${float_get_server_score(ns, string_server).toFixed(integer_precision)}
  • replacement in bin/lshw.js at line 94
    [4.13161][4.13161:13242](),[4.13242][4.19365:19437](),[4.19437][4.13312:13357](),[4.13312][4.13312:13357](),[4.13357][4.19438:19510]()
    RAM total (GB): ${float_ram_total}
    RAM used (GB): ${float_ram_used.toFixed(2)}
    RAM used (%): ${((float_ram_used * 100) / float_ram_total).toFixed(2)}
    RAM free (GB): ${float_ram_free.toFixed(2)}
    RAM free (%): ${((float_ram_free * 100) / float_ram_total).toFixed(2)}
    [4.13161]
    [4.13427]
    RAM total (GB): ${float_ram_total.toFixed(integer_precision)}
    RAM used (GB): ${float_ram_used.toFixed(integer_precision)}
    RAM used (%): ${((float_ram_used * 100) / float_ram_total).toFixed(integer_precision)}
    RAM free (GB): ${float_ram_free.toFixed(integer_precision)}
    RAM free (%): ${((float_ram_free * 100) / float_ram_total).toFixed(integer_precision)}
  • replacement in bin/kill.js at line 4
    [4.3798939][4.3798939:3798993]()
    import {
    array_get_servers
    }
    from "lib_servers.js";
    [4.3798939]
    [4.3798993]
    import { array_get_servers } from "lib_servers.js";
    import { void_kill_script_named_server_named } from "lib_kill.js";
    import { object_parse_arguments } from "lib_minimist.js";
  • edit in bin/kill.js at line 8
    [4.3798994][4.3798994:3799125]()
    import {
    void_kill_script_named_server_named
    }
    from "lib_kill.js";
    import {
    object_parse_arguments
    }
    from "lib_minimist.js";
  • replacement in bin/kill.js at line 22
    [4.3799590][4.3799590:3799632]()
    array_scripts = argument_value;
    [4.3799590]
    [4.3799632]
    array_scripts.push(argument_value);
  • replacement in bin/kill.js at line 27
    [4.3799714][4.3799714:3799756]()
    array_servers = argument_value;
    [4.3799714]
    [4.3799756]
    array_servers.push(argument_value);
  • replacement in README.md at line 11
    [4.4253][3.3521:3594]()
    * Reserve at least enough RAM to be able to run "hacker.js" (8.25 GB).
    [4.4253]
    [4.2728]
    * Reserve at least enough RAM to be able to run "hacker.js" (8.75 GB).
  • replacement in README.md at line 35
    [4.3600][2.2046:2168]()
    * SECONDS = The duration of delay between each job, in seconds. Should be a floating-point number > 0. Defaults to 0.5.
    [4.3600]
    [4.3722]
    * SECONDS = The duration of delay between each job, in seconds. Should be a floating-point number > 0. Defaults to 1.
  • replacement in README.md at line 43
    [4.3500][2.2169:2275]()
    * CAP = The maximum amount of jobs to execute per schedule. Should be an integer > 0. Defaults to 2000.
    [4.3500]
    [4.4162]
    * CAP = The maximum amount of jobs to execute per schedule. Should be an integer > 0. Defaults to 1000.
  • replacement in README.md at line 130
    [4.5552][4.45288:45312]()
    ### "lshw.js" (2.45 GB)
    [4.5552]
    [4.3600]
    ### "lshw.js" (7.25 GB)
  • replacement in README.md at line 135
    [4.5651][4.5651:5703]()
    `run lshw.js [OPTIONS] <ARGUMENT [ARGUMENT ...]>`
    [4.5651]
    [4.5703]
    `run lshw.js [OPTIONS ...] <ARGUMENT [ARGUMENT ...]>`
  • edit in README.md at line 144
    [4.6023]
    [4.6023]
    `-p, --precision <INTEGER>`
    * INTEGER = The decimal places to display floating point values with. Should be an integer >= 0. Defaults to 2.
  • replacement in README.md at line 149
    [4.6037][4.4903:4940]()
    `run lshw.js -d 1 home foodnstuff`
    [4.6037]
    [4.6077]
    `run lshw.js -d 1 --precision=4 home foodnstuff`
  • replacement in README.md at line 151
    [4.6078][4.6078:6191]()
    * Causes the terminal to output up-to-date information about the "home" and "foodnstuff" servers every second.
    [4.6078]
    [4.6191]
    * Causes the terminal to output up-to-date information about the "home" and "foodnstuff" servers every second, using 4 decimal places for the floating point values it displays.