grow helpers improvement

This commit is contained in:
2023-09-05 00:58:08 +02:00
parent 673abd49b2
commit 7b14e98658
25 changed files with 359 additions and 136 deletions
+8
View File
@@ -0,0 +1,8 @@
/** @param {import(".").NS } ns */
export async function main(ns) {
// ns.disableLog('ALL');
ns.alterReality();
ns.rainbow('noodles');
}
+28 -14
View File
@@ -3,12 +3,24 @@
/**
* get all servers
* for servers ram > 0 get ram, get money
* home ram substract ram needed for bots
* get available threads for each server for hack/grow/weaken
* sum all money
* run with proportion to the money available
* remove write log
* loop
* get all servers
* nuke if possible
* send scripts hack, grow weaken
* backdoor factions
* buy grow servers
* start helpers if not running include home //remove from hacknet
* grow if needed
* weaken if needed
* hack if no grow or weaken
* do simple hack
* check if money available
* check threads
* run hack
* run grow to recover
* run weaken if security too high
* buy hack tools
*/
@@ -23,22 +35,20 @@ export async function main(ns) {
let hour = (timeNow.getHours() < 10 ? '0' : '') + timeNow.getHours();
let minute = (timeNow.getMinutes() < 10 ? '0' : '') + timeNow.getMinutes();
let second = (timeNow.getSeconds() < 10 ? '0' : '') + timeNow.getSeconds();
let timestamp = `${year}${month}${day}_${hour}${minute}${second}`;
await ns.tryWritePort(2, `t${timestamp}_${type} = ${obj};\n`);
let timestamp = `${year}.${month}.${day}_${hour}:${minute}:${second}`;
ns.print(`${type}_${timestamp} = ${obj};`);
if (['ERROR', 'TERMINAL'].indexOf(type) != -1) ns.tprint(`${timestamp} ${type} = ${obj}`);
if (['ERROR', 'TERMINAL'].indexOf(type) != -1) ns.tprint(`${type}_${timestamp} = ${obj};`);
}
async function runHack(server) {
let script = 'simple-hack.js';
async function runNuke(server) {
let serverStatus = analyzeServer(server);
await writeLog('ANALYZE', `{server: "${server}", status: ${JSON.stringify(serverStatus)}}`);
if (!serverStatus.rootAccess) {
if (serverStatus.nukeAvailable) {
await writeLog('NUKE', `"Nuking ${server}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"`);
for (let i = 0; i < maxPortsToHack(); ++i) {
for (let i = 0; i < maxPortsToHack(); ++i) { // TODO: change to try/catch
switch (EXPLOITS[i]) {
case 'BruteSSH.exe':
ns.brutessh(server);
@@ -64,9 +74,13 @@ export async function main(ns) {
}
ns.nuke(server);
}
// TODO: if faction > backdoor
}
}
async function runHack(server) {
let script = 'simple-hack.js';
serverStatus = analyzeServer(server);
let serverStatus = analyzeServer(server);
if (serverStatus.rootAccess) {
if (!ns.fileExists(script, 'home')) {
+52 -86
View File
@@ -66,48 +66,49 @@ export async function main(ns) {
* @param {string} server server to nuke and hack
* @returns {Promise<number>} exit code; if negative error, if positive hack script PID, if 0 already running
*/
async function runNuke(server) {
let serverStatus = analyzeServer(server);
ns.print('INFO ', `{server: "${server}", status: ${JSON.stringify(serverStatus)}}`);
if (!serverStatus.rootAccess && serverStatus.nukeAvailable) {
ns.print(`"Nuking ${server}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"`);
for (let i = 0; i < maxPortsToHack(); ++i) {
switch (EXPLOITS[i]) {
case 'BruteSSH.exe':
ns.brutessh(server);
break;
case 'FTPCrack.exe':
ns.ftpcrack(server);
break;
case 'relaySMTP.exe':
ns.relaysmtp(server);
break;
case 'HTTPWorm.exe':
ns.httpworm(server);
break;
case 'SQLInject.exe':
ns.sqlinject(server);
break;
}
}
ns.nuke(server);
}
}
async function runHack(server) {
let script = 'simple-hack.js';
let serverStatus = analyzeServer(server);
await writeLog('ANALYZE', `{server: "${server}", status: ${JSON.stringify(serverStatus)}}`);
ns.print('INFO ', `{server: "${server}", status: ${JSON.stringify(serverStatus)}}`);
if (!serverStatus.rootAccess) {
if (serverStatus.nukeAvailable) {
await writeLog('NUKE', `"Nuking ${server}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"`);
for (let i = 0; i < maxPortsToHack(); ++i) {
switch (EXPLOITS[i]) {
case 'BruteSSH.exe':
ns.brutessh(server);
break;
case 'FTPCrack.exe':
ns.ftpcrack(server);
break;
case 'relaySMTP.exe':
ns.relaysmtp(server);
break;
case 'HTTPWorm.exe':
ns.httpworm(server);
break;
case 'SQLInject.exe':
ns.sqlinject(server);
break;
}
}
ns.nuke(server);
}
}
serverStatus = analyzeServer(server);
if (serverStatus.rootAccess) {
if (serverStatus.rootAccess && serverStatus.nukeAvailable) {
if (!ns.fileExists(script, 'home')) {
await writeLog('ERROR', `"Script '${script}' doesn't exist!"`);
ns.print(`ERROR Script '${script}' doesn't exist!`);
// return -3;
}
ns.scp(script, server, 'home');
@@ -143,42 +144,6 @@ export async function main(ns) {
return -6;
}
// let nukedServers = ['home', 'CSEC', 'avmnite-02h'];
// /**
// * Recursively scan, try to nuke and hack servers in the network
// * @async
// * @param {string} server server to scan
// */
// async function scanServer(server, maxDepth = Number.MAX_SAFE_INTEGER, depth = 1) {
// if (depth <= maxDepth) {
// let availableServers = ns.scan(server);
// // hack servers in current scan
// for (let i = 0; i < availableServers.length; ++i) {
// await writeLog('SCAN', `{server: "${availableServers[i]}", index: ${nukedServers.indexOf(availableServers[i])}, available: ["${availableServers.toString().replaceAll(',','","')}"]}`);
// if (nukedServers.indexOf(availableServers[i]) == -1) {
// nukedServers.push(availableServers[i]);
// await scanServer(availableServers[i], maxDepth, depth + 1);
// let hackExitCode = await runHack(availableServers[i]);
// if (hackExitCode == 0) {
// await writeLog('HACK', `"Hack already running on ${availableServers[i]}"`);
// } if (hackExitCode == -6) {
// await writeLog('HACK', `"No root access to ${availableServers[i]}!"`);
// } else {
// if (hackExitCode < 0) {
// await writeLog('ERROR', `"Hack exec ERROR on '${availableServers[i]}': ${hackExitCode}!"`);
// } else {
// await writeLog('HACK', `"Hack started on '${availableServers[i]}'"`);
// }
// }
// }
// }
// }
// await ns.sleep(10);
// }
/**
* Recursively kill simple-hack.js running on servers in the network
* @async
@@ -191,22 +156,23 @@ export async function main(ns) {
let nextServer = availableServers[i];
if (nextServer != currentServer && nextServer != previousServer) {
await runNuke(nextServer);
if (EXCLUDE_SERVERS.indexOf(nextServer) == -1) {
let hackExitCode = await runHack(nextServer);
if (hackExitCode == 0) {
await writeLog('HACK', `"Hack already running on ${nextServer}"`);
} else if (hackExitCode == -6) {
await writeLog('HACK', `"No root access to ${nextServer}!"`);
} else if (hackExitCode == -4) {
await writeLog('HACK', `"Not enough RAM to run script on ${nextServer}!"`);
} else {
if (hackExitCode < 0) {
await writeLog('ERROR', `"Hack exec ERROR on '${nextServer}': ${hackExitCode}!"`);
} else {
await writeLog('HACK', `"Hack started on '${nextServer}'"`);
}
}
// if (hackExitCode == 0) {
// ns.print('INFO ' + `"Hack already running on ${nextServer}"`);
// } else if (hackExitCode == -6) {
// ns.print('ERROR ' + `"No root access to ${nextServer}!"`);
// } else if (hackExitCode == -4) {
// ns.print('WARN ' + `"Not enough RAM to run script on ${nextServer}!"`);
// } else {
// if (hackExitCode < 0) {
// ns.print('ERROR ' + `"Hack exec ERROR on '${nextServer}': ${hackExitCode}!"`);
// } else {
// ns.print('INFO ' + `"Hack started on '${nextServer}'"`);
// }
// }
}
await scanServer(nextServer, currentServer);
}
@@ -219,7 +185,7 @@ export async function main(ns) {
ns.tprint(`TERMINAL = "Running scan"`);
while (true) {
await writeLog('INFO', `"Running scan"`);
ns.print(`INFO Running scan`);
await scanServer('home');
await ns.sleep(60000);
}
+41
View File
@@ -0,0 +1,41 @@
/** @param {import(".").NS } ns */
const doc = eval('document');
export async function main(ns) {
// ns.disableLog('ALL');
const terminalInput = doc.getElementById("terminal-input");
const handler = Object.keys(terminalInput)[1];
async function scanServer(currentServer, previousServer = currentServer, connectString = '', scanLevel = 0) {
let availableServers = ns.scan(currentServer);
let nextConnectString = connectString + `connect ${currentServer}; `;
let backdoorCommand = nextConnectString;
backdoorCommand += 'run BruteSSH.exe; ';
backdoorCommand += 'run FTPCrack.exe; ';
backdoorCommand += 'run relaySMTP.exe; ';
backdoorCommand += 'run HTTPWorm.exe; ';
backdoorCommand += 'run SQLInject.exe; ';
backdoorCommand += 'run NUKE.exe; ';
backdoorCommand += 'backdoor';
terminalInput.value = backdoorCommand;
terminalInput[handler].onChange({ target: terminalInput });
terminalInput[handler].onKeyDown({ key: 'Enter', preventDefault: () => null });
await ns.sleep(60000)
for (let i = 0; i < availableServers.length; ++i) {
let nextServer = availableServers[i];
if (nextServer != currentServer && nextServer != previousServer) {
await scanServer(nextServer, currentServer, nextConnectString, scanLevel + 1);
}
}
}
await scanServer('home');
terminalInput.value = 'home';
terminalInput[handler].onChange({ target: terminalInput });
terminalInput[handler].onKeyDown({ key: 'Enter', preventDefault: () => null });
}
+5 -4
View File
@@ -1,4 +1,5 @@
/** @param {import(".").NS } ns */
const doc = eval('document');
export async function main(ns) {
// ns.disableLog('ALL');
@@ -9,7 +10,7 @@ export async function main(ns) {
* @param {string} currentServer server to scan
*/
function scanServer(currentServer, targetServer, previousServer = currentServer) {
ns.tprint(currentServer);
// ns.tprint(currentServer);
if (currentServer == targetServer) {
return [currentServer];
} else {
@@ -34,7 +35,7 @@ export async function main(ns) {
let targetPath = scanServer('home', ns.args[0]);
ns.tprint(targetPath);
const terminalInput = document.getElementById("terminal-input");
const terminalInput = doc.getElementById("terminal-input");
const handler = Object.keys(terminalInput)[1];
let backdoorCommand = '';
@@ -44,7 +45,7 @@ export async function main(ns) {
backdoorCommand += `connect ${server}; `;
}
ns.tprint(backdoorCommand);
// ns.tprint(backdoorCommand);
terminalInput.value = backdoorCommand;
terminalInput[handler].onChange({ target: terminalInput });
terminalInput[handler].onKeyDown({ key: 'Enter', preventDefault: () => null });
@@ -57,7 +58,7 @@ export async function main(ns) {
backdoorCommand += 'run NUKE.exe; ';
backdoorCommand += 'backdoor';
ns.tprint(backdoorCommand);
// ns.tprint(backdoorCommand);
terminalInput.value = backdoorCommand;
terminalInput[handler].onChange({ target: terminalInput });
terminalInput[handler].onKeyDown({ key: 'Enter', preventDefault: () => null });
+58
View File
@@ -1,7 +1,65 @@
/** @param {import(".").NS } ns */
const doc = eval('document');
export async function main(ns) {
// ns.disableLog('ALL');
/**
* Recursively kill simple-hack.js running on servers in the network
* @async
* @param {string} currentServer server to scan
*/
function scanServer(currentServer, targetServer, previousServer = currentServer) {
// ns.tprint(currentServer);
if (currentServer == targetServer) {
return [currentServer];
} else {
let availableServers = ns.scan(currentServer);
for (let i = 0; i < availableServers.length; ++i) {
let nextServer = availableServers[i];
if (nextServer != currentServer && nextServer != previousServer) {
let result = scanServer(nextServer, targetServer, currentServer);
if (result != null) {
return [currentServer].concat(result);
}
}
}
return null;
}
}
let targetPath = scanServer('home', ns.args[0]);
ns.tprint(targetPath);
const terminalInput = doc.getElementById("terminal-input");
const handler = Object.keys(terminalInput)[1];
let backdoorCommand = '';
for (let index = 1; index < targetPath.length; index++) {
const server = targetPath[index];
backdoorCommand += `connect ${server}; `;
}
// ns.tprint(backdoorCommand);
terminalInput.value = backdoorCommand;
terminalInput[handler].onChange({ target: terminalInput });
terminalInput[handler].onKeyDown({ key: 'Enter', preventDefault: () => null });
// backdoorCommand = 'run BruteSSH.exe; ';
// backdoorCommand += 'run FTPCrack.exe; ';
// backdoorCommand += 'run relaySMTP.exe; ';
// backdoorCommand += 'run HTTPWorm.exe; ';
// backdoorCommand += 'run SQLInject.exe; ';
// backdoorCommand += 'run NUKE.exe; ';
// backdoorCommand += 'backdoor';
// ns.tprint(backdoorCommand);
// terminalInput.value = backdoorCommand;
// terminalInput[handler].onChange({ target: terminalInput });
// terminalInput[handler].onKeyDown({ key: 'Enter', preventDefault: () => null });
}
+37 -4
View File
@@ -3,6 +3,14 @@
export const EXCLUDE_SERVERS = [
'home',
'darkweb',
'CSEC',
'avmnite-02h',
'I.I.I.I',
'run4theh111z'
];
export const FACTION_SERVERS = [
'CSEC',
'avmnite-02h',
'I.I.I.I',
@@ -30,11 +38,36 @@ const DARKWEB_PROGRAMS = [
const COMPLETED_FACTIONS = [
'CyberSec',
'Tian Di Hui',
'Netburners',
//'Shadows of Anarchy',
//'Sector-12',
'Chongquing',
'New Tokyo',
'Ishima',
'Aevum',
'Volhaven',
'NiteSec',
'The Black Hand',
'Aevum',
'Sector-12',
'Volhaven',
'Tian Di Hui'
//'BitRunners',
//'ECorp',
//'MegaCorp',
//'KuaiGong International',
//'Four Sigma',
//'NWO',
//'Blade Industries',
//'OmniTek Incorporated',
//'Bachman & Associates',
//'Clarke Incorporated',
//'Fulcrum Secret Technologies',
//'Slum Snakes',
//'Tetrads',
//'Silhouette',
//'Speakers for the Dead',
//'The Dark Army',
//'The Syndicate',
//'The Covenant',
//'Daedalus',
//'Illuminati',
//'',
];
+13
View File
@@ -0,0 +1,13 @@
/** @param {import(".").NS } ns */
const doc = eval('document');
export async function main(ns) {
// ns.disableLog('ALL');
const terminalInput = doc.getElementById("terminal-input");
const handler = Object.keys(terminalInput)[1];
terminalInput.value = "COMMAND";
terminalInput[handler].onChange({ target: terminalInput });
terminalInput[handler].onKeyDown({ key: 'Enter', preventDefault: () => null });
}
+4 -8
View File
@@ -11,13 +11,9 @@ export async function main(ns) {
let nextServer = availableServers[i];
if (nextServer != currentServer && nextServer != previousServer) {
if (ns.scriptRunning('simple-hack.js', nextServer)) {
let maxMoney = ns.getServerMaxMoney(nextServer);
let currentMoney = ns.getServerMoneyAvailable(nextServer);
if (currentMoney < 0.2 * maxMoney) {
await ns.grow(nextServer);
}
let currentMoney = ns.getServerMoneyAvailable(nextServer);
if (ns.hasRootAccess(nextServer) && currentMoney > 0) {
await ns.grow(nextServer);
}
await scanServer(nextServer, currentServer);
}
@@ -27,6 +23,6 @@ export async function main(ns) {
while (true) {
ns.print(`Running scan`);
await scanServer('home');
ns.sleep(50);
await ns.sleep(1000);
}
}
+1 -1
View File
@@ -3,5 +3,5 @@
export async function main(ns) {
// ns.disableLog('ALL');
await ns.grow(ns.args.length > 0 ? ns.args[0] : '');
}
+1 -1
View File
@@ -3,5 +3,5 @@
export async function main(ns) {
// ns.disableLog('ALL');
await ns.hack(ns.args.length > 0 ? ns.args[0] : '');
}
+7 -7
View File
@@ -7,7 +7,7 @@ export async function main(ns) {
const upgradeCostThreshold = ns.args.length > 1 ? ns.args[1] : 0.1;
const upgradeCount = ns.args.length > 2 ? ns.args[2] : 1;
const helperBuyThreshold = ns.args.length > 3 ? ns.args[3] : 0.2;
const nodeCap = 200;
const nodeCap = 24;
const levelCap = 200;
const ramCap = 64;
const coreCap = 16;
@@ -63,13 +63,13 @@ export async function main(ns) {
let logFiles = ['hack-log.js', 'nuke-log.js'];
// let logFiles = ['hack-log.js', 'nuke-log.js'];
for (let index = 0; index < logFiles.length; index++) {
const logFile = logFiles[index];
let portData = ns.readPort(index + 1);
if (portData != 'NULL PORT DATA') ns.write(logFile, portData, 'a');
}
// for (let index = 0; index < logFiles.length; index++) {
// const logFile = logFiles[index];
// let portData = ns.readPort(index + 1);
// if (portData != 'NULL PORT DATA') ns.write(logFile, portData, 'a');
// }
await ns.sleep(1000);
}
+2
View File
@@ -3,6 +3,8 @@
export async function main(ns) {
ns.disableLog('ALL');
ns.scriptKill('grow-helper.js', `home`);
for (let server = 0; ns.serverExists(`home-${server}`); server++) {
ns.scriptKill('grow-helper.js', `home-${server}`);
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -3
View File
@@ -26,8 +26,6 @@ export async function main(ns) {
while (maxMoney != 0) {
let currentMoney = ns.getServerMoneyAvailable(server);
let currentSecurity = ns.getServerSecurityLevel(server);
ns.print(`Money: ${currentMoney} / ${maxMoney}`);
ns.print(`Security: ${currentSecurity} / ${minSecurity}`);
let hackedMoney = 0;
if (currentMoney > 0.1 * maxMoney) {
@@ -48,7 +46,7 @@ export async function main(ns) {
currentSecurity = ns.getServerSecurityLevel(server);
}
await writeLog('LOG', `{server: '${server}', loop: ${++loop}, hack: ${Math.floor(hackedMoney)}, money: ${Math.floor(currentMoney)} / ${Math.floor(maxMoney)} == ${((currentMoney / maxMoney) * 100).toFixed(2)}, security: ${currentSecurity.toFixed(2)} / ${Math.floor(minSecurity)} == ${((currentSecurity / minSecurity) * 100).toFixed(4)}}`);
ns.print(`{loop: ${++loop}, hack: ${Math.floor(hackedMoney)}, money: ${Math.floor(currentMoney)} / ${Math.floor(maxMoney)} == ${((currentMoney / maxMoney) * 100).toFixed(2)}, security: ${currentSecurity.toFixed(2)} / ${Math.floor(minSecurity)} == ${((currentSecurity / minSecurity) * 100).toFixed(4)}}`);
await ns.sleep(50);
}
}
+16 -2
View File
@@ -2,9 +2,23 @@
export async function main(ns) {
ns.disableLog('ALL');
let script = 'grow-helper.js';
let serverMaxRam = ns.getServerMaxRam(`home`);
let serverUsedRam = ns.getServerUsedRam(`home`);
let serverFreeRam = serverMaxRam - serverUsedRam;
let scriptRam = ns.getScriptRam(script, `home`);
let maxThreads = Math.floor(serverFreeRam / scriptRam);
if (maxThreads > 0) ns.exec(script, `home`, maxThreads);
for (let server = 0; ns.serverExists(`home-${server}`); server++) {
ns.scp('grow-helper.js', `home-${server}`, 'home');
ns.exec('grow-helper.js', `home-${server}`, 10);
let serverMaxRam = ns.getServerMaxRam(`home-${server}`);
let serverUsedRam = ns.getServerUsedRam(`home-${server}`);
let serverFreeRam = serverMaxRam - serverUsedRam;
let scriptRam = ns.getScriptRam(script, `home-${server}`);
let maxThreads = Math.floor(serverFreeRam / scriptRam);
ns.scp(script, `home-${server}`, 'home');
ns.exec(script, `home-${server}`, maxThreads);
}
}
+75
View File
@@ -0,0 +1,75 @@
/** @param {import(".").NS } ns */
const doc = eval('document');
export async function main(ns) {
// ns.disableLog('ALL');
// const terminalInput = doc.getElementById("terminal-input");
// const handler = Object.keys(terminalInput)[1];
// terminalInput.value = "COMMAND";
// terminalInput[handler].onChange({ target: terminalInput });
// terminalInput[handler].onKeyDown({ key: 'Enter', preventDefault: () => null });
// const terminalButton = doc.querySelector();
let terminal;
let city;
let travel;
for (const elem of doc.querySelectorAll('div.MuiDrawer-root.MuiDrawer-docked p')) {
if (elem.textContent == 'Terminal') {
terminal = elem;
}
if (elem.textContent == 'City') {
city = elem;
}
if (elem.textContent == 'Travel') {
travel = elem;
}
}
travel.click(); await ns.sleep(100);
for (const aevum of doc.querySelectorAll('div#root span')) {
if (aevum.textContent == 'A') {
aevum.click(); await ns.sleep(100);
break;
}
}
for (const travelConfirm of doc.querySelectorAll('div[role="presentation"] p')) {
if (travelConfirm.textContent == 'Travel') {
travelConfirm.click(); await ns.sleep(100);
break;
}
}
const closeButton = doc.querySelector('div[role="presentation"] button');
if(!closeButton == undefined) closeButton.click();
city.click(); await ns.sleep(100);
for (const uni of doc.querySelectorAll('div#root span')) {
if (uni.textContent == 'U') {
uni.click(); await ns.sleep(100);
break;
}
}
for (const course of doc.querySelectorAll('div#root button')) {
if (course.textContent == 'Take Algorithms course ($-1.280k / sec)') {
course.click(); await ns.sleep(100);
break;
}
}
for (const closeCourse of doc.querySelectorAll('div#root button')) {
if (closeCourse.textContent == 'Do something else simultaneously') {
closeCourse.click(); await ns.sleep(100);
break;
}
}
await ns.sleep(1000);
console.log(terminal)
terminal.click(); await ns.sleep(100);
}
+1 -5
View File
@@ -3,9 +3,5 @@
export async function main(ns) {
// ns.disableLog('ALL');
let target;
if(ns.args.length == 1) {
target = JSON.parse(ns.args[0]);
}
await ns.weaken(ns.args.length > 0 ? ns.args[0] : '')
}