-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchargeRest.js
More file actions
47 lines (42 loc) · 1.62 KB
/
Copy pathchargeRest.js
File metadata and controls
47 lines (42 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { getAllServers } from "ze-lib.js";
/** @param {NS} ns */
export async function main(ns) {
ns.disableLog('sleep'); ns.clearLog();
const fileName = "charge_marked.js",
startTime = performance.now(),
launchMessages = [],
workers = [];
ns.exec("superNuker.js", "home");
while (ns.isRunning("superNuker.js", ns.getHostname())) await ns.sleep(0);
ns.exec("marker.js", "home");
while (ns.isRunning("marker.js", ns.getHostname())) await ns.sleep(0);
if (ns.args.includes("tail")) ns.tail();
for (const server of getAllServers(ns)) {
for (const script of ns.ps(server)) {
if (script.pid === ns.pid) continue;
ns.kill(script.pid); // death to all the others.
}
if (!ns.hasRootAccess(server) || ns.getServerMaxRam(server) < 2) continue;
const availableRam = ns.getServerMaxRam(server) - ns.getServerUsedRam(server), threads = Math.floor(availableRam / 2);
if (availableRam < 2) continue;
if (ns.scp(fileName, server)) {
const p = ns.exec(fileName, server, threads);
if (p) {
launchMessages.push(`PID: (${p}) File: ${fileName} started on ${server} with ${threads} threads.`);
workers.push(p);
}
}
}
ns.atExit(() => {
workers.forEach(w => ns.kill(w));
ns.write("giftLayouts/chargeTimestamp.txt", Date.now(), "w");
if (ns.args.includes("ai")) ns.exec("ai.js", "home"); // script name can be whatever you want ai.js is my start script
});
while (1) {
ns.clearLog();
ns.print(launchMessages.join("\n"));
ns.print(`PIDS: ${workers.join(", ")}.`);
await ns.sleep(1000); // to keep running
if (Number.isInteger(ns.args[0]) && performance.now() > startTime + ns.args[0]) ns.kill(ns.pid);
}
}