Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function serverAppend(serverList, toAppend, ns) {
- //for each server in toAppend
- toAppend.forEach(function(item, index, array) {
- //if serverList does not contain the new server and server isn't already being hacked
- if ( (!(serverList.includes(item))) && (!(ns.isRunning("basic_hack.ns", item)))) {
- //then add the new server to serverList
- serverList.push(item);
- }
- });
- }
- async function checkList(ns, serverList) {
- //for each server in the list
- await serverList.forEach(async function(item, index, array) {
- //if the number of ports required to open is less than or equal to the number of port-busting programs owned and the server is hackable currently
- if (item == "home") {
- serverList.splice(serverList.indexOf("home"));
- } else {
- await ns.run("required_ports_open.ns", 1, item);
- if ((ns.read(2) === true) && (ns.getHackingLevel() >= ns.getServerRequiredHackingLevel(item))) {
- //run infect.ns
- await ns.run("infect.ns", 1, item);
- serverList.splice(serverList.indexOf(item), 1);
- }
- }
- });
- }
- export async function main(ns) {
- await ns.run ("first_write.ns");
- let serverList = [];
- //test: serverList will be empty and a few things will be written into port 1
- //While true
- while (true) {
- //Check port 1 for more servers
- if (ns.peek(1) != "NULL PORT DATA") {
- let serversToRead = ns.read(1);
- serverAppend(serverList, serversToRead, ns);
- }
- await checkList(ns, serverList);
- //await ns.print(serverList);
- //wait 5 seconds
- await ns.sleep(5000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement