-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
142 lines (130 loc) · 6.02 KB
/
map.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* Script based on: https://www.reddit.com/r/Bitburner/comments/rmpgn5/map_code/ by u/Ravery-net
2022-02-03
- Added Help menu
- Added colored Symbols, Backdoor indicator, Required Ports for Hack and Maximum Server Money
- Switches for added information (Change constants at the beginning of code to (de)-activate them individually)
- Information if Server is hackable now checks also required Server ports against player capability
*/
// Switches (Change constants to change design of Tree)
const controlSymbolTypeColor = true; // True = Colored Root Access Symbols / False = Asscii Art
const controlPortsRequiredIndicator = true; // True = Required Ports will be shown after Server Hacking Level Requirement / False = Hidden
const controlBackdoorIndicator = true; // True = Backdoor Indecator active / False = Hidden
const controlMaxMoneyIndicator = true; // True = Show Max Money of Server / False = Hidden
var _ns;
export async function main(ns) {
var seenList = [];
_ns = ns;
let input = ns.args[0];
// Help Menu
if (input === "-h" || input === "-help" || input === "help" || input === "-?" || input === "?") {
ns.tprint("");
ns.tprint("**************************************************** Help Menu ****************************************************");
ns.tprint('Mapping: "Root access", [Backdoor], "Server name", ("Server Level", [Required Ports]), [Max. Money Server], [Hacking possible]');
if (controlSymbolTypeColor) {
ns.tprint("- \u2705 = Root access / \u274C = No root access ");
ns.tprint("- [Optional] Backdoor: [BD] = Backdoor installed / [x] = No Backdoor");
ns.tprint("- [Optional] Port Info: Variable behind Servername (Required Hacking Level - Required Server Ports)");
ns.tprint('- If "!!!!!!" at the end is shown, your hacking and port hacking level is above the');
ns.tprint(' requirements of the server but you dont have root access yet.');
} else {
ns.tprint("- ██ = Root access / [ ] = No root access ");
ns.tprint("- [Optional] Backdoor: [BD] = Backdoor installed / [NO BD] = No Backdoor");
ns.tprint("- [Optional] Port Info: Variable behind Servername (Required Hacking Level - Required Server Ports)");
ns.tprint('- "!!!!!!" at the end indicates, that your hacking and port hacking level is above the');
ns.tprint(' requirements of the server but you dont have root access yet.');
}
ns.tprint("");
ns.tprint("Note: Colored Symbols, Required Server Ports, Backdoor Indicator and Max. Money can be ");
ns.tprint(" (de)activated by changing the constants at the beginning of the script")
ns.tprint("*********************************************************************************************************************");
} else {
ScanServer("home", seenList, 0, "");
ns.tprint("Note: Add -h to function call to open help");
}
}
function ScanServer(serverName, seenList, indent, prefix) {
if (seenList.includes(serverName)) return;
seenList.push(serverName);
var serverList = _ns.scan(serverName);
serverList = serverList.filter(function (item) { return seenList.indexOf(item) === -1; });
serverList = serverList.sort(ChildCountCompare);
for (var i = 0; i < serverList.length; i++) {
var newServer = serverList[i];
if (seenList.includes(newServer)) continue;
if (i != serverList.length - 1) {
PrintServerInfo(newServer, indent, prefix + "├─")
ScanServer(newServer, seenList, indent + 1, prefix + "│ ");
}
else {
PrintServerInfo(newServer, indent, prefix + "└─")
ScanServer(newServer, seenList, indent + 1, prefix + " ");
}
}
}
function ChildCountCompare(a, b) {
var ax = ChildCount(a);
var bx = ChildCount(b);
return ChildCount(a) > ChildCount(b) ? 1 : -1;
}
function ChildCount(serverName) {
var count = 0;
var serverList = _ns.scan(serverName);
for (var i = 1; i < serverList.length; i++) {
count += ChildCount(serverList[i]) + 1;
}
return count;
}
function PrintServerInfo(serverName, indent, prefix) {
var indentString = prefix;
var serverinfo = _ns.getServer(serverName); //Interface of requested server
// Definition of Root Access Symbols
if (controlSymbolTypeColor) {
var hacked = (serverinfo.hasAdminRights) ? "\u2705" : "\u274C";
} else {
var hacked = (serverinfo.hasAdminRights) ? " \u2611 " : " \u2612 ";
}
var serverHackingLevel = serverinfo.requiredHackingSkill;
var serverPortLevel = serverinfo.numOpenPortsRequired;
var canHackIndicator = "";
var backdoorIndicator = "";
var portReqIndicator = "";
var maxMoneyIndicator = "";
if (_ns.getHackingLevel() >= serverHackingLevel && HackablePortsPlayer() >= serverPortLevel && !serverinfo.hasAdminRights) {
canHackIndicator = " >> !!!!!!!!! CAN HACK !!!!!!!!!"
}
// Definition of Backdoor Symbols
if (controlBackdoorIndicator && controlSymbolTypeColor) {
backdoorIndicator = (serverinfo.backdoorInstalled) ? " [BD] " : " [X] ";
} else if (controlBackdoorIndicator && !controlSymbolTypeColor) {
backdoorIndicator = (serverinfo.backdoorInstalled) ? " [BD] " : " [NO BD] ";
}
// Definition of required Port Level indicator
if (controlPortsRequiredIndicator) {
portReqIndicator = " P" + serverPortLevel;
}
// Definition of Maximum Money Indicator
if (controlMaxMoneyIndicator) {
maxMoneyIndicator = " [Max Money" + _ns.nFormat(serverinfo.moneyMax, "($ 0.00a)") + "] ";
}
_ns.tprint(indentString + hacked + backdoorIndicator + serverName + " (" + serverHackingLevel + portReqIndicator + ")" + maxMoneyIndicator + canHackIndicator);
}
function HackablePortsPlayer() {
let hackablePortsPlayer = 0;
if (_ns.fileExists("BruteSSH.exe", "home")) {
hackablePortsPlayer = hackablePortsPlayer + 1;
}
if (_ns.fileExists("FTPCrack.exe", "home")) {
hackablePortsPlayer = hackablePortsPlayer + 1;
}
if (_ns.fileExists("HTTPWorm.exe", "home")) {
hackablePortsPlayer = hackablePortsPlayer + 1;
}
if (_ns.fileExists("relaySMTP.exe", "home")) {
hackablePortsPlayer = hackablePortsPlayer + 1;
}
if (_ns.fileExists("SQLInject.exe", "home")) {
hackablePortsPlayer = hackablePortsPlayer + 1;
}
return hackablePortsPlayer;
}
//var hacked = (_ns.hasRootAccess(serverName)) ? "██ " : "[] ";