cleanup, download lit, log function
This commit is contained in:
Vendored
+20
-4
@@ -32,10 +32,6 @@
|
||||
"",
|
||||
"export async function main(ns) {",
|
||||
" // ns.disableLog('ALL');",
|
||||
"",
|
||||
" async function writeLog(obj) {",
|
||||
" await ns.tryWritePort($1, obj + '\\n');",
|
||||
" }",
|
||||
" ",
|
||||
" $2",
|
||||
"}"
|
||||
@@ -60,6 +56,26 @@
|
||||
],
|
||||
"description": "NS terminal print"
|
||||
},
|
||||
"writelog": {
|
||||
"scope": "",
|
||||
"prefix": "writelog",
|
||||
"body": [
|
||||
"async function writeLog(type, obj) {",
|
||||
" 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($1, `t\\${timestamp}_\\${type} = \\${obj};\\n`);",
|
||||
" ",
|
||||
" if (['ERROR', 'TERMINAL'].indexOf(type) != -1) ns.tprint(`\\${timestamp} \\${type} = \\${obj}`);",
|
||||
"}"
|
||||
],
|
||||
"description": "writelog function definition"
|
||||
},
|
||||
"log": {
|
||||
"scope": "",
|
||||
"prefix": "log",
|
||||
|
||||
+14
-13
@@ -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,8 +187,7 @@ 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) {
|
||||
async function scanServer(currentServer, previousServer = currentServer) {
|
||||
let availableServers = ns.scan(currentServer);
|
||||
|
||||
for (let i = 0; i < availableServers.length; ++i) {
|
||||
@@ -205,24 +211,19 @@ export async function main(ns) {
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,4 @@ export async function main(ns) {
|
||||
ns.tprint(`Exec 'grow-helper.js' exit code: ${execExitCode}`);
|
||||
}
|
||||
}
|
||||
|
||||
await ns.sleep(10);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/** @param {import(".").NS } ns */
|
||||
|
||||
export async function main(ns) {
|
||||
// ns.disableLog('ALL');
|
||||
|
||||
function scanServer(currentServer, previousServer = currentServer) {
|
||||
// ns.tprint(currentServer);
|
||||
let availableServers = ns.scan(currentServer);
|
||||
|
||||
for (let i = 0; i < availableServers.length; ++i) {
|
||||
let nextServer = availableServers[i];
|
||||
|
||||
if (nextServer != currentServer && nextServer != previousServer) {
|
||||
let litFiles = ns.ls(nextServer, 'lit');
|
||||
ns.tprint(`Download from '${nextServer}': ${litFiles}`);
|
||||
if (ns.args[0] && litFiles.length) {
|
||||
ns.scp(litFiles, 'home', nextServer);
|
||||
}
|
||||
|
||||
scanServer(nextServer, currentServer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scanServer('home');
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
CyberSec
|
||||
Netburners
|
||||
+4
-9
@@ -1,7 +1,7 @@
|
||||
/** @param {import(".").NS } ns */
|
||||
|
||||
export async function main(ns) {
|
||||
ns.disableLog('ALL');
|
||||
// ns.disableLog('ALL');
|
||||
|
||||
let excludeServers = ['home'];
|
||||
for (let index = 0; index < 25; index++) {
|
||||
@@ -10,8 +10,7 @@ export async function main(ns) {
|
||||
excludeServers.push('CSEC');
|
||||
excludeServers.push('avmnite-02h');
|
||||
|
||||
async function scanServer(currentServer, maxDepth = Number.MAX_SAFE_INTEGER, depth = 1, previousServer = currentServer) {
|
||||
if (depth <= maxDepth) {
|
||||
async function scanServer(currentServer, previousServer = currentServer) {
|
||||
let availableServers = ns.scan(currentServer);
|
||||
|
||||
for (let i = 0; i < availableServers.length; ++i) {
|
||||
@@ -30,13 +29,9 @@ export async function main(ns) {
|
||||
}
|
||||
}
|
||||
}
|
||||
await ns.sleep(10);
|
||||
}
|
||||
let runDepth = ns.args.length ? ns.args[0] : 1;
|
||||
|
||||
while (true) {
|
||||
|
||||
ns.print(`Running scan depth: ${runDepth}`);
|
||||
await scanServer('home', runDepth);
|
||||
ns.print(`Running scan`);
|
||||
await scanServer('home');
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -9,7 +9,7 @@ export async function main(ns) {
|
||||
let levelCap = 150;
|
||||
let ramCap = 64;
|
||||
let coreCap = 4;
|
||||
let nodeCap = 15;
|
||||
let nodeCap = 18;
|
||||
ns.tprint(`Bot started {nodeCostThreshold: ${nodeCostThreshold}, upgradeCostThreshold: ${upgradeCostThreshold}, upgradeCount: ${upgradeCount}}`);
|
||||
|
||||
while (true) {
|
||||
@@ -62,6 +62,6 @@ export async function main(ns) {
|
||||
if (portData != 'NULL PORT DATA') ns.write(logFile, portData, 'a');
|
||||
}
|
||||
|
||||
await ns.sleep(10);
|
||||
await ns.sleep(50);
|
||||
}
|
||||
}
|
||||
+5
-15
@@ -15,8 +15,7 @@ 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) {
|
||||
function scanServer(currentServer, previousServer = currentServer) {
|
||||
let availableServers = ns.scan(currentServer);
|
||||
|
||||
for (let i = 0; i < availableServers.length; ++i) {
|
||||
@@ -24,20 +23,11 @@ export async function main(ns) {
|
||||
|
||||
if (nextServer != currentServer && nextServer != previousServer) {
|
||||
if (excludeServers.indexOf(nextServer) == -1) ns.scriptKill('simple-hack.js', nextServer);
|
||||
await scanServer(nextServer, maxDepth, depth + 1, currentServer);
|
||||
scanServer(nextServer, currentServer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
await ns.sleep(10);
|
||||
}
|
||||
|
||||
|
||||
let runDepth = ns.args.length ? ns.args[0] : 1;
|
||||
ns.tprint(`Running scan depth: ${runDepth}`);
|
||||
await scanServer('home', runDepth);
|
||||
|
||||
|
||||
await ns.sleep(10);
|
||||
ns.tprint(`Running scan`);
|
||||
scanServer('home');
|
||||
}
|
||||
|
||||
@@ -4,5 +4,4 @@ export async function main(ns) {
|
||||
ns.disableLog('ALL');
|
||||
|
||||
ns.scriptKill('hacknet-bot.js', 'home');
|
||||
await ns.sleep(10);
|
||||
}
|
||||
@@ -4,5 +4,4 @@ export async function main(ns) {
|
||||
ns.disableLog('ALL');
|
||||
|
||||
ns.scriptKill('auto-nuke.js', 'home');
|
||||
await ns.sleep(10);
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
+14
-5
@@ -3,8 +3,18 @@
|
||||
export async function main(ns) {
|
||||
ns.disableLog('ALL');
|
||||
|
||||
async function writeLog(obj) {
|
||||
await ns.tryWritePort(1, obj + '\n');
|
||||
async function writeLog(type, obj) {
|
||||
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(1, `t${timestamp}_${type} = ${obj};\n`);
|
||||
|
||||
if (['ERROR', 'TERMINAL'].indexOf(type) != -1) ns.tprint(`${timestamp} ${type} = ${obj}`);
|
||||
}
|
||||
|
||||
let server = ns.args[0];
|
||||
@@ -38,8 +48,7 @@ export async function main(ns) {
|
||||
currentSecurity = ns.getServerSecurityLevel(server);
|
||||
}
|
||||
|
||||
await writeLog(`${server.replaceAll('-', '_')} = {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(10);
|
||||
await writeLog('LOG', `${server.replaceAll('-', '_')} = {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);
|
||||
}
|
||||
await ns.sleep(10);
|
||||
}
|
||||
@@ -8,3 +8,7 @@ export async function main(ns) {
|
||||
ns.exec('grow-helper.js', `home-${server}`, 5, 20);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user