asdf
This commit is contained in:
parent
3a3ebb321f
commit
c81b66610e
22
.eslintrc
22
.eslintrc
|
|
@ -3,17 +3,29 @@
|
||||||
"browser": true,
|
"browser": true,
|
||||||
"es2021": true
|
"es2021": true
|
||||||
},
|
},
|
||||||
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
|
"extends": [
|
||||||
|
"eslint:recommended",
|
||||||
|
"plugin:@typescript-eslint/recommended",
|
||||||
|
"plugin:prettier/recommended"
|
||||||
|
],
|
||||||
"parser": "@typescript-eslint/parser",
|
"parser": "@typescript-eslint/parser",
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"project": "./tsconfig.json",
|
"project": "./tsconfig.json",
|
||||||
"ecmaVersion": "latest",
|
"ecmaVersion": "latest",
|
||||||
"sourceType": "module"
|
"sourceType": "module"
|
||||||
},
|
},
|
||||||
"plugins": ["@typescript-eslint"],
|
"plugins": [
|
||||||
"ignorePatterns": ["node_modules/**", "dist/**", "NetscriptDefinitions.d.ts"],
|
"@typescript-eslint"
|
||||||
|
],
|
||||||
|
"ignorePatterns": [
|
||||||
|
"node_modules/**",
|
||||||
|
"dist/**",
|
||||||
|
"NetscriptDefinitions.d.ts"
|
||||||
|
],
|
||||||
"rules": {
|
"rules": {
|
||||||
"no-constant-condition": ["off"],
|
"no-constant-condition": [
|
||||||
|
"off"
|
||||||
|
],
|
||||||
"@typescript-eslint/no-floating-promises": "error"
|
"@typescript-eslint/no-floating-promises": "error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
"quoteProps": "consistent",
|
"quoteProps": "consistent",
|
||||||
"semi": true,
|
"semi": true,
|
||||||
"singleAttributePerLine": true,
|
"singleAttributePerLine": true,
|
||||||
"singleQuote": true,
|
"singleQuote": false,
|
||||||
"tabWidth": 2,
|
"tabWidth": 2,
|
||||||
"trailingComma": "all",
|
"trailingComma": "all",
|
||||||
"useTabs": false
|
"useTabs": false
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
[tools]
|
[tools]
|
||||||
|
deno = "latest"
|
||||||
node = "latest"
|
node = "latest"
|
||||||
|
|
|
||||||
2
package-lock.json
generated
2
package-lock.json
generated
|
|
@ -4127,4 +4127,4 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -18,4 +18,4 @@
|
||||||
"viteburner": "^0.5.3"
|
"viteburner": "^0.5.3"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
import { NS } from '@ns';
|
import { NS } from "@ns";
|
||||||
|
|
||||||
export const main = async (ns: NS) => {
|
export const main = async (ns: NS) => {
|
||||||
if (ns.args.length !== 1) {
|
if (ns.args.length !== 1) {
|
||||||
ns.tprint('Usage: run super.js [target]');
|
ns.tprint("Usage: run super.js [target]");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const target = ns.args[0].toString();
|
const target = ns.args[0].toString();
|
||||||
|
|
||||||
ns.tprint('Target selected: ' + target);
|
ns.tprint("Target selected: " + target);
|
||||||
|
|
||||||
const maxMoneyThresh = ns.getServerMaxMoney(target);
|
const maxMoneyThresh = ns.getServerMaxMoney(target);
|
||||||
const minSecurityThresh = ns.getServerMinSecurityLevel(target);
|
const minSecurityThresh = ns.getServerMinSecurityLevel(target);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
import { NS } from '@ns';
|
import { NS } from "@ns";
|
||||||
import { scan } from './utils/scan';
|
import { scan } from "./utils/scan";
|
||||||
import { startall } from './utils/startall';
|
import { startall } from "./utils/startall";
|
||||||
import { kill } from './utils/kill';
|
import { kill } from "./utils/kill";
|
||||||
|
|
||||||
export const main = (ns: NS) => {
|
export const main = (ns: NS) => {
|
||||||
ns.tprint(ns.getPurchasedServerCost(256));
|
ns.tprint(ns.getPurchasedServerCost(256));
|
||||||
|
console.log(ns.getPlayer());
|
||||||
};
|
};
|
||||||
|
|
|
||||||
29
src/utils/analyze.ts
Normal file
29
src/utils/analyze.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
import { NS, Server } from "@ns";
|
||||||
|
|
||||||
|
// define a new interface for the new analysis results
|
||||||
|
interface ServerAnalysis {
|
||||||
|
hostname: string;
|
||||||
|
hasRootAccess: boolean;
|
||||||
|
requiredHackingSkill: number;
|
||||||
|
portsRequiredForNuke: number;
|
||||||
|
maxRam: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const analyze = (ns: NS, hostnames: string[]) => {
|
||||||
|
hostnames.forEach((hostname) => {
|
||||||
|
// get the server object for the hostname
|
||||||
|
const server: Server = ns.getServer(hostname);
|
||||||
|
// create a new object that matches the ServerAnalysis interface
|
||||||
|
const analysis: ServerAnalysis = {
|
||||||
|
hostname: server.hostname,
|
||||||
|
hasRootAccess: server.hasAdminRights,
|
||||||
|
requiredHackingSkill: server.requiredHackingSkill ?? 0,
|
||||||
|
portsRequiredForNuke: server.numOpenPortsRequired ?? 0,
|
||||||
|
maxRam: server.maxRam,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const main = (ns: NS) => {
|
||||||
|
analyze(ns, ["nectar-net"]);
|
||||||
|
};
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { NS } from '@ns';
|
import { NS } from "@ns";
|
||||||
|
|
||||||
export const kill = (ns: NS, hostname: string) => {
|
export const kill = (ns: NS, hostname: string) => {
|
||||||
// get a list of all the running processes on the specified host
|
// get a list of all the running processes on the specified host
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { NS } from '@ns';
|
import { NS } from "@ns";
|
||||||
import { scan } from './scan';
|
import { scan } from "./scan";
|
||||||
|
|
||||||
export const killall = (ns: NS): void => {
|
export const killall = (ns: NS): void => {
|
||||||
const allHosts = scan(ns);
|
const allHosts = scan(ns);
|
||||||
|
|
@ -8,7 +8,7 @@ export const killall = (ns: NS): void => {
|
||||||
|
|
||||||
allHosts.forEach((host) => {
|
allHosts.forEach((host) => {
|
||||||
// do not kill any scripts on home
|
// do not kill any scripts on home
|
||||||
if (host === 'home') return;
|
if (host === "home") return;
|
||||||
|
|
||||||
// check if there are any running scripts on this host
|
// check if there are any running scripts on this host
|
||||||
const runningProcesses = ns.ps(host).length;
|
const runningProcesses = ns.ps(host).length;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { NS } from '@ns';
|
import { NS } from "@ns";
|
||||||
import { scan } from './scan';
|
import { scan } from "./scan";
|
||||||
|
|
||||||
// get root access to all the servers that we can
|
// get root access to all the servers that we can
|
||||||
// then return a list of all the servers we have root access to
|
// then return a list of all the servers we have root access to
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { NS } from '@ns';
|
import { NS } from "@ns";
|
||||||
|
|
||||||
interface ScanOptions {
|
interface ScanOptions {
|
||||||
rootAccess?: boolean;
|
rootAccess?: boolean;
|
||||||
|
|
@ -12,7 +12,7 @@ export const scan = (ns: NS, options: ScanOptions = {}): string[] => {
|
||||||
const { rootAccess, requiredHackingSkill, portsForNuke, ram } = options;
|
const { rootAccess, requiredHackingSkill, portsForNuke, ram } = options;
|
||||||
|
|
||||||
// initialize a new set to store a list of all hosts
|
// initialize a new set to store a list of all hosts
|
||||||
const allHosts = new Set<string>(['home']);
|
const allHosts = new Set<string>(["home"]);
|
||||||
|
|
||||||
// for each host in the set, scan it and add all of its neighbors to the set
|
// for each host in the set, scan it and add all of its neighbors to the set
|
||||||
allHosts.forEach((h) => {
|
allHosts.forEach((h) => {
|
||||||
|
|
@ -20,7 +20,7 @@ export const scan = (ns: NS, options: ScanOptions = {}): string[] => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove home from the set
|
// remove home from the set
|
||||||
allHosts.delete('home');
|
allHosts.delete("home");
|
||||||
|
|
||||||
// now we start the filtering into another new list
|
// now we start the filtering into another new list
|
||||||
const filteredHosts = Array.from(allHosts).filter((host: string) => {
|
const filteredHosts = Array.from(allHosts).filter((host: string) => {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { NS } from '@ns';
|
import { NS } from "@ns";
|
||||||
import { scan } from './scan';
|
import { scan } from "./scan";
|
||||||
|
|
||||||
export const scriptCleanup = (ns: NS) => {
|
export const scriptCleanup = (ns: NS) => {
|
||||||
// get all hosts with root access
|
// get all hosts with root access
|
||||||
|
|
@ -12,7 +12,7 @@ export const scriptCleanup = (ns: NS) => {
|
||||||
rootedHosts.forEach((host) => {
|
rootedHosts.forEach((host) => {
|
||||||
let scriptsDeleted = 0;
|
let scriptsDeleted = 0;
|
||||||
|
|
||||||
const remoteScripts: string[] = ns.ls(host, '.js');
|
const remoteScripts: string[] = ns.ls(host, ".js");
|
||||||
remoteScripts.forEach((script) => {
|
remoteScripts.forEach((script) => {
|
||||||
ns.rm(script, host);
|
ns.rm(script, host);
|
||||||
scriptsDeleted++;
|
scriptsDeleted++;
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import { NS } from '@ns';
|
import { NS } from "@ns";
|
||||||
import { scan } from './scan';
|
import { scan } from "./scan";
|
||||||
|
|
||||||
export const scriptPropagator = (ns: NS) => {
|
export const scriptPropagator = (ns: NS) => {
|
||||||
// get all hosts with root access
|
// get all hosts with root access
|
||||||
const rootedHosts: string[] = scan(ns, { rootAccess: true });
|
const rootedHosts: string[] = scan(ns, { rootAccess: true });
|
||||||
|
|
||||||
// get all the script files, only the js files
|
// get all the script files, only the js files
|
||||||
const allScripts: string[] = ns.ls('home', '.js');
|
const allScripts: string[] = ns.ls("home", ".js");
|
||||||
|
|
||||||
let totalSynced = 0;
|
let totalSynced = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { NS } from '@ns';
|
import { NS } from "@ns";
|
||||||
import { scan } from './scan';
|
import { scan } from "./scan";
|
||||||
|
|
||||||
interface StartOptions {
|
interface StartOptions {
|
||||||
threads?: number; // explicit thread count
|
threads?: number; // explicit thread count
|
||||||
|
|
@ -16,11 +16,11 @@ export const startall = (ns: NS, scriptName: string, options: StartOptions = {})
|
||||||
// get the ram required to run one thread of the script
|
// get the ram required to run one thread of the script
|
||||||
// assume that the script is already on all the hosts that we want to run it in
|
// assume that the script is already on all the hosts that we want to run it in
|
||||||
// should be ran after propagation
|
// should be ran after propagation
|
||||||
const ramPerThread = ns.getScriptRam(scriptName, 'home');
|
const ramPerThread = ns.getScriptRam(scriptName, "home");
|
||||||
|
|
||||||
// iterate through all the rooted hosts and start the script
|
// iterate through all the rooted hosts and start the script
|
||||||
rootedHosts.forEach((host) => {
|
rootedHosts.forEach((host) => {
|
||||||
if (host === 'home') return;
|
if (host === "home") return;
|
||||||
|
|
||||||
// calculate how many threads we can run based on the options provided
|
// calculate how many threads we can run based on the options provided
|
||||||
const availableRam = ns.getServerMaxRam(host) - ns.getServerUsedRam(host);
|
const availableRam = ns.getServerMaxRam(host) - ns.getServerUsedRam(host);
|
||||||
|
|
@ -56,5 +56,5 @@ export const startall = (ns: NS, scriptName: string, options: StartOptions = {})
|
||||||
export const main = (ns: NS) => {
|
export const main = (ns: NS) => {
|
||||||
// get the arguments from the command line
|
// get the arguments from the command line
|
||||||
const args = ns.args as string[];
|
const args = ns.args as string[];
|
||||||
startall(ns, 'super.js', { args: args });
|
startall(ns, "super.js", { args: args });
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,13 @@
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
"target": "esnext",
|
"target": "esnext",
|
||||||
"lib": ["esnext", "dom"],
|
"lib": [
|
||||||
"types": ["vite/client"],
|
"esnext",
|
||||||
|
"dom"
|
||||||
|
],
|
||||||
|
"types": [
|
||||||
|
"vite/client"
|
||||||
|
],
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
|
|
@ -15,10 +20,22 @@
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["./src/*"],
|
"@/*": [
|
||||||
"/src/*": ["./src/*"],
|
"./src/*"
|
||||||
"@ns": ["./NetscriptDefinitions.d.ts"]
|
],
|
||||||
|
"/src/*": [
|
||||||
|
"./src/*"
|
||||||
|
],
|
||||||
|
"@ns": [
|
||||||
|
"./NetscriptDefinitions.d.ts"
|
||||||
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["src/**/*.ts", "src/**/*.js", "NetscriptDefinitions.d.ts", "vite.config.ts", "vite.config.js"]
|
"include": [
|
||||||
}
|
"src/**/*.ts",
|
||||||
|
"src/**/*.js",
|
||||||
|
"NetscriptDefinitions.d.ts",
|
||||||
|
"vite.config.ts",
|
||||||
|
"vite.config.js"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -1,21 +1,21 @@
|
||||||
/* eslint-env node */
|
/* eslint-env node */
|
||||||
import { defineConfig } from 'viteburner';
|
import { defineConfig } from "viteburner";
|
||||||
import { resolve } from 'path';
|
import { resolve } from "path";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve(__dirname, 'src'),
|
"@": resolve(__dirname, "src"),
|
||||||
'/src': resolve(__dirname, 'src'),
|
"/src": resolve(__dirname, "src"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
outDir: 'dist',
|
outDir: "dist",
|
||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
minify: false,
|
minify: false,
|
||||||
},
|
},
|
||||||
viteburner: {
|
viteburner: {
|
||||||
watch: [{ pattern: 'src/**/*.{js,ts,jsx,tsx}', transform: true }, { pattern: 'src/**/*.{script,txt}' }],
|
watch: [{ pattern: "src/**/*.{js,ts,jsx,tsx}", transform: true }, { pattern: "src/**/*.{script,txt}" }],
|
||||||
sourcemap: 'inline',
|
sourcemap: "inline",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue