Add scripts
This commit is contained in:
parent
e2d45cb490
commit
8733556ac2
@ -1,29 +0,0 @@
|
||||
/** @param {NS} ns */
|
||||
export async function main(ns) {
|
||||
let files = [
|
||||
"run-script-on-all-servers.js",
|
||||
"recursive-run.js",
|
||||
"recursive-copy.js",
|
||||
"recursive-kill.js",
|
||||
"hack-args.js",
|
||||
"hack.js",
|
||||
"root.js",
|
||||
"recursive-root.js"
|
||||
]
|
||||
let hosts = [
|
||||
"zb-institute",
|
||||
"comptek",
|
||||
"nectar-net",
|
||||
"neo-net",
|
||||
"max-hardware",
|
||||
"omega-net",
|
||||
"avmnite-02h",
|
||||
"CSEC"
|
||||
]
|
||||
|
||||
for(const host of hosts) {
|
||||
for (const file of files) {
|
||||
ns.rm(file, host)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
/** @param {NS} ns */
|
||||
export async function main(ns) {
|
||||
ns.tprint("Hello World!");
|
||||
}
|
19
servers/home/remove-files-from-servers.ts
Normal file
19
servers/home/remove-files-from-servers.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import {NS} from "NetscriptDefinitions";
|
||||
import {recursiveScan} from "./utils";
|
||||
|
||||
export async function main(ns: NS, servers: string[]) {
|
||||
let hosts = recursiveScan(ns);
|
||||
|
||||
let folderPrefix = "no-ports/";
|
||||
let files = ns.ls("home", folderPrefix).map((file) => {
|
||||
return file.substring(folderPrefix.length, file.length);
|
||||
});
|
||||
|
||||
ns.tprint("Files to be removed: ", JSON.stringify(files));
|
||||
|
||||
for(const host of hosts) {
|
||||
for (const file of files) {
|
||||
ns.rm(file, host)
|
||||
}
|
||||
}
|
||||
}
|
23
servers/home/utils.ts
Normal file
23
servers/home/utils.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import {NS} from "NetscriptDefinitions";
|
||||
export function recursiveScan(ns: NS) {
|
||||
// Starting case
|
||||
let servers = ns.scan(ns.getHostname());
|
||||
// Add all servers to the list
|
||||
let allServers: string[] = [];
|
||||
while (servers.length > 0) {
|
||||
let server = servers.shift();
|
||||
if(server) {
|
||||
let newServers = ns.scan(server);
|
||||
for (let newServer of newServers) {
|
||||
if (!allServers.includes(newServer)) {
|
||||
allServers.push(newServer);
|
||||
servers.push(newServer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Remove the current server
|
||||
allServers.splice(allServers.indexOf(ns.getHostname()), 1);
|
||||
// Print all servers
|
||||
return allServers;
|
||||
}
|
Loading…
Reference in New Issue
Block a user