-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmastershare.js
More file actions
39 lines (34 loc) · 1.31 KB
/
mastershare.js
File metadata and controls
39 lines (34 loc) · 1.31 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
import {fetchServers} from 'serverdata.js'
import {autoKill} from 'autokill.js'
import {autoScp} from 'autoscp.js'
/*
do something, cmon
*/
export function distributeShare(ns) {
const fetchFlag = "--share";
const shareClientScript = "shareclient.js";
const scpSource = "home";
const thisScriptName = ns.getScriptName();
const ramMaxUsage = 1.0;
let serverResult = fetchServers(ns, fetchFlag, true);
autoScp(ns, serverResult, shareClientScript, scpSource, true);
autoKill(ns, serverResult, shareClientScript, true);
for(let i = 0; i < serverResult.length; i++) {
let hostName = serverResult[i];
let serverMaxRam = ns.getServerMaxRam(hostName);
let serverRam = ns.getServerUsedRam(hostName);
let serverRamAvailable = (serverMaxRam - serverRam) * ramMaxUsage;
let scriptRam = ns.getScriptRam(shareClientScript);
let threadCount = Math.floor(serverRamAvailable / scriptRam);
let ramUsage = Math.floor(scriptRam * threadCount);
if(threadCount < 1) {
continue;
}
let pidNumber = ns.exec(shareClientScript, hostName, threadCount);
ns.tprintf("%s -> %s exec pid %i -> %s --t %i (RAM %s)", thisScriptName, hostName, pidNumber, shareClientScript, threadCount, ns.formatRam(ramUsage));
}
}
/** @param {NS} ns */
export async function main(ns) {
distributeShare(ns);
}