cleanup, download lit, log function

This commit is contained in:
2022-09-12 01:33:24 +02:00
parent 3529597fb0
commit 2963efd97b
13 changed files with 123 additions and 83 deletions
+30 -29
View File
@@ -3,7 +3,14 @@ export async function main(ns) {
ns.disableLog('ALL');
async function writeLog(type, obj) {
let timestamp = '';
let timeNow = new Date();
let year = timeNow.getFullYear().toString().substring(2);
let month = (timeNow.getMonth() < 9 ? '0' : '') + (timeNow.getMonth() + 1);
let day = (timeNow.getDate() < 10 ? '0' : '') + timeNow.getDate();
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`);
if (['ERROR', 'TERMINAL'].indexOf(type) != -1) ns.tprint(`${timestamp} ${type} = ${obj}`);
@@ -180,49 +187,43 @@ export async function main(ns) {
* @async
* @param {string} currentServer server to scan
*/
async function scanServer(currentServer, maxDepth = Number.MAX_SAFE_INTEGER, depth = 1, previousServer = currentServer) {
if (depth <= maxDepth) {
let availableServers = ns.scan(currentServer);
async function scanServer(currentServer, previousServer = currentServer) {
let availableServers = ns.scan(currentServer);
for (let i = 0; i < availableServers.length; ++i) {
let nextServer = availableServers[i];
for (let i = 0; i < availableServers.length; ++i) {
let nextServer = availableServers[i];
if (nextServer != currentServer && nextServer != previousServer) {
if (excludeServers.indexOf(nextServer) == -1) {
let hackExitCode = await runHack(nextServer);
if (nextServer != currentServer && nextServer != previousServer) {
if (excludeServers.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}!"`);
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 {
if (hackExitCode < 0) {
await writeLog('ERROR', `"Hack exec ERROR on '${nextServer}': ${hackExitCode}!"`);
} else {
await writeLog('HACK', `"Hack started on '${nextServer}'"`);
}
await writeLog('HACK', `"Hack started on '${nextServer}'"`);
}
}
await scanServer(nextServer, maxDepth, depth + 1, currentServer);
}
await scanServer(nextServer, currentServer);
}
}
await ns.sleep(10);
}
let runDepth = ns.args.length ? ns.args[0] : 1;
ns.write('nuke-log.js', '', 'w');
if (!ns.scriptRunning('simple-hack.js', 'n00dles')) ns.write('hack-log.js', '', 'w');
ns.tprint(`TERMINAL = "Running scan depth: ${runDepth}"`);
ns.tprint(`TERMINAL = "Running scan"`);
while (true) {
await writeLog('INFO', `"Running scan depth: ${runDepth}"`);
await scanServer('home',);
await ns.sleep(600000);
await writeLog('INFO', `"Running scan"`);
await scanServer('home');
await ns.sleep(60000);
}
}