-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsitrep.js
96 lines (79 loc) · 2.58 KB
/
sitrep.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { GetAllServers, GetServerPath } from 'utils.js'
import { UpdateBankCache } from 'bank.js'
import { MemoryMap } from 'ram.js'
// sitrep.js: This script caches information on the current situation for use by other scripts
// The main goal is to isolate the gathering of information ram cost.
// X Find coding contracts
// X Find how many program(s) we need to buy
// X Find servers that need ports cracked/nuking
// X Determine how many sleeves we have to work with
// X Determine current karma
// X Determine if we have a gang going or not
// X Save the server tree/paths
// X Determine if any server needs backdooring
// ?Determine if we have 4S access?
// ?Determine if we have stock investments?
/** @param {NS} ns */
export async function main(ns) {
//const bank = UpdateBankCache(ns);
const report = {
servers: [],
portCrackers: 0,
karma: ns.heart.break(),
money: ns.getServerMoneyAvailable('home'),
daemonSkill: 3000 * ns.getBitNodeMultipliers().WorldDaemonDifficulty,
hackSkill: ns.getHackingLevel(),
// balance: {
// install: bank.install,
// node: bank.node
// }
//sleeveCount: ns.sleeve.getNumSleeves(),
//has4S: ns.stock.has4SDataTIXAPI(),
};
const joes = ns.getServer('joesguns');
joes.hackDifficulty = joes.minDifficulty;
report.canHackJoe = ns.formulas.hacking.weakenTime(joes, ns.getPlayer()) >= 120;
try { report.hasGang = ns.gang.inGang(); } catch { }
const PROGRAMS = [
'BruteSSH',
'FTPCrack',
'relaySMTP',
'HTTPWorm',
'SQLInject'
];
const MAX_PORTS = PROGRAMS.filter(s => ns.fileExists(s + '.exe')).length;
report.portCrackers = MAX_PORTS;
//ns.tprint('INFO: We have access to ' + MAX_PORTS + ' port crackers.');
report.ram = { ...new MemoryMap(ns, true) };
const servers = GetAllServers(ns);
for (const server of servers) {
const so = ns.getServer(server);
// Basic information, server name and path
const entry = {
name: server,
path: GetServerPath(ns, server)
};
// Check for coding contracts
const contracts = ns.ls(server, '.cct');
entry.contracts = contracts;
// Check the ports/nuke/backdoor situation
entry.ports = {
open: so.openPortCount,
needed: so.numOpenPortsRequired,
nuked: so.hasAdminRights,
backdoored: so.backdoorInstalled
};
// Difficulty situation
entry.difficulty = {
required: so.requiredHackingSkill,
current: ns.getHackingLevel()
};
// Add the server to the report
report.servers.push(entry);
}
ns.write('sitrep.txt', JSON.stringify(report, null, 2), 'w');
//ns.tprint(JSON.stringify(report));
}
export function GetSitRep(ns) {
return JSON.parse(ns.read('sitrep.txt'));
}