/** @param {import(".").NS } ns */
import { EXCLUDE_SERVERS } from "./constants.js";

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, previousServer = currentServer) {
        let availableServers = ns.scan(currentServer);

        for (let i = 0; i < availableServers.length; ++i) {
            let nextServer = availableServers[i];

            if (nextServer != currentServer && nextServer != previousServer) {
                if (EXCLUDE_SERVERS.indexOf(nextServer) == -1) ns.scriptKill('simple-hack.js', nextServer);
                scanServer(nextServer, currentServer);
            }
        }
    }

    ns.tprint(`Running scan`);
    scanServer('home');
}
