-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgo.js
59 lines (50 loc) · 1.55 KB
/
go.js
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
48
49
50
51
52
53
54
55
56
57
58
59
import HackableBaseServer from "./if.server.hackable"
import BasePlayer from "./if.player";
import { dpList } from "./lib.utils";
function execHackingScript(ns, servers) {
let home = new HackableBaseServer(ns, "home")
let home_pids = home.pids;
let hacking_scripts = home_pids.filter(p => p.filename.startsWith("sbin.hack"))
let hacking_script;
if (hacking_scripts.length > 1) {
throw "Two hacking scripts are running";
} else {
try { hacking_script = hacking_scripts[0]; } catch {}
}
let command = ns.peek(1);
if (command == "NULL PORT DATA") { command = "sbin.hack.hwgw.js" }
if (hacking_script) {
if (hacking_script.filename !== command) {
ns.kill(hacking_script.pid);
servers.map(s => s.pids).flat().filter(proc => proc.filename.startsWith("bin.")).forEach(proc => ns.kill(proc.pid));
ns.exec(command, "home");
}
} else {
ns.exec(command, "home");
}
}
/** @param {NS} ns **/
export async function main(ns) {
let player = new BasePlayer(ns, "player");
let servers = [];
let slist = dpList(ns);
for (let s of slist) {
servers.push(new HackableBaseServer(ns, s))
}
ns.tprint("add files to servers")
ns.tprint(slist.length)
ns.tprint(servers.length)
for (let server of servers) {
await ns.scp(["bin.wk.js", "bin.hk.js", "bin.gr.js"], server.id, "home")
}
while (true) {
for (let server of servers) {
if (!server.admin && server.ports.required <= player.ports) {
server.sudo();
await ns.scp(["bin.wk.js", "bin.hk.js", "bin.gr.js"], server.id, "home")
}
}
execHackingScript(ns, servers);
await ns.sleep(10);
}
}