asdf
This commit is contained in:
parent
3a3ebb321f
commit
c81b66610e
22
.eslintrc
22
.eslintrc
|
|
@ -3,17 +3,29 @@
|
|||
"browser": 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",
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.json",
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"ignorePatterns": ["node_modules/**", "dist/**", "NetscriptDefinitions.d.ts"],
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"ignorePatterns": [
|
||||
"node_modules/**",
|
||||
"dist/**",
|
||||
"NetscriptDefinitions.d.ts"
|
||||
],
|
||||
"rules": {
|
||||
"no-constant-condition": ["off"],
|
||||
"no-constant-condition": [
|
||||
"off"
|
||||
],
|
||||
"@typescript-eslint/no-floating-promises": "error"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
"quoteProps": "consistent",
|
||||
"semi": true,
|
||||
"singleAttributePerLine": true,
|
||||
"singleQuote": true,
|
||||
"singleQuote": false,
|
||||
"tabWidth": 2,
|
||||
"trailingComma": "all",
|
||||
"useTabs": false
|
||||
|
|
|
|||
2
package-lock.json
generated
2
package-lock.json
generated
|
|
@ -4127,4 +4127,4 @@
|
|||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,4 +18,4 @@
|
|||
"viteburner": "^0.5.3"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
import { NS } from '@ns';
|
||||
import { NS } from "@ns";
|
||||
|
||||
export const main = async (ns: NS) => {
|
||||
if (ns.args.length !== 1) {
|
||||
ns.tprint('Usage: run super.js [target]');
|
||||
ns.tprint("Usage: run super.js [target]");
|
||||
return;
|
||||
}
|
||||
|
||||
const target = ns.args[0].toString();
|
||||
|
||||
ns.tprint('Target selected: ' + target);
|
||||
ns.tprint("Target selected: " + target);
|
||||
|
||||
const maxMoneyThresh = ns.getServerMaxMoney(target);
|
||||
const minSecurityThresh = ns.getServerMinSecurityLevel(target);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { NS } from '@ns';
|
||||
import { scan } from './utils/scan';
|
||||
import { startall } from './utils/startall';
|
||||
import { kill } from './utils/kill';
|
||||
import { NS } from "@ns";
|
||||
import { scan } from "./utils/scan";
|
||||
import { startall } from "./utils/startall";
|
||||
import { kill } from "./utils/kill";
|
||||
|
||||
export const main = (ns: NS) => {
|
||||
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) => {
|
||||
// get a list of all the running processes on the specified host
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { NS } from '@ns';
|
||||
import { scan } from './scan';
|
||||
import { NS } from "@ns";
|
||||
import { scan } from "./scan";
|
||||
|
||||
export const killall = (ns: NS): void => {
|
||||
const allHosts = scan(ns);
|
||||
|
|
@ -8,7 +8,7 @@ export const killall = (ns: NS): void => {
|
|||
|
||||
allHosts.forEach((host) => {
|
||||
// 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
|
||||
const runningProcesses = ns.ps(host).length;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { NS } from '@ns';
|
||||
import { scan } from './scan';
|
||||
import { NS } from "@ns";
|
||||
import { scan } from "./scan";
|
||||
|
||||
// get root access to all the servers that we can
|
||||
// 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 {
|
||||
rootAccess?: boolean;
|
||||
|
|
@ -12,7 +12,7 @@ export const scan = (ns: NS, options: ScanOptions = {}): string[] => {
|
|||
const { rootAccess, requiredHackingSkill, portsForNuke, ram } = options;
|
||||
|
||||
// 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
|
||||
allHosts.forEach((h) => {
|
||||
|
|
@ -20,7 +20,7 @@ export const scan = (ns: NS, options: ScanOptions = {}): string[] => {
|
|||
});
|
||||
|
||||
// remove home from the set
|
||||
allHosts.delete('home');
|
||||
allHosts.delete("home");
|
||||
|
||||
// now we start the filtering into another new list
|
||||
const filteredHosts = Array.from(allHosts).filter((host: string) => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { NS } from '@ns';
|
||||
import { scan } from './scan';
|
||||
import { NS } from "@ns";
|
||||
import { scan } from "./scan";
|
||||
|
||||
export const scriptCleanup = (ns: NS) => {
|
||||
// get all hosts with root access
|
||||
|
|
@ -12,7 +12,7 @@ export const scriptCleanup = (ns: NS) => {
|
|||
rootedHosts.forEach((host) => {
|
||||
let scriptsDeleted = 0;
|
||||
|
||||
const remoteScripts: string[] = ns.ls(host, '.js');
|
||||
const remoteScripts: string[] = ns.ls(host, ".js");
|
||||
remoteScripts.forEach((script) => {
|
||||
ns.rm(script, host);
|
||||
scriptsDeleted++;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { NS } from '@ns';
|
||||
import { scan } from './scan';
|
||||
import { NS } from "@ns";
|
||||
import { scan } from "./scan";
|
||||
|
||||
export const scriptPropagator = (ns: NS) => {
|
||||
// get all hosts with root access
|
||||
const rootedHosts: string[] = scan(ns, { rootAccess: true });
|
||||
|
||||
// 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;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { NS } from '@ns';
|
||||
import { scan } from './scan';
|
||||
import { NS } from "@ns";
|
||||
import { scan } from "./scan";
|
||||
|
||||
interface StartOptions {
|
||||
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
|
||||
// assume that the script is already on all the hosts that we want to run it in
|
||||
// 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
|
||||
rootedHosts.forEach((host) => {
|
||||
if (host === 'home') return;
|
||||
if (host === "home") return;
|
||||
|
||||
// calculate how many threads we can run based on the options provided
|
||||
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) => {
|
||||
// get the arguments from the command line
|
||||
const args = ns.args as string[];
|
||||
startall(ns, 'super.js', { args: args });
|
||||
startall(ns, "super.js", { args: args });
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,8 +2,13 @@
|
|||
"compilerOptions": {
|
||||
"module": "esnext",
|
||||
"target": "esnext",
|
||||
"lib": ["esnext", "dom"],
|
||||
"types": ["vite/client"],
|
||||
"lib": [
|
||||
"esnext",
|
||||
"dom"
|
||||
],
|
||||
"types": [
|
||||
"vite/client"
|
||||
],
|
||||
"strict": true,
|
||||
"allowJs": true,
|
||||
"noEmit": true,
|
||||
|
|
@ -15,10 +20,22 @@
|
|||
"resolveJsonModule": true,
|
||||
"skipLibCheck": true,
|
||||
"paths": {
|
||||
"@/*": ["./src/*"],
|
||||
"/src/*": ["./src/*"],
|
||||
"@ns": ["./NetscriptDefinitions.d.ts"]
|
||||
"@/*": [
|
||||
"./src/*"
|
||||
],
|
||||
"/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 */
|
||||
import { defineConfig } from 'viteburner';
|
||||
import { resolve } from 'path';
|
||||
import { defineConfig } from "viteburner";
|
||||
import { resolve } from "path";
|
||||
|
||||
export default defineConfig({
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': resolve(__dirname, 'src'),
|
||||
'/src': resolve(__dirname, 'src'),
|
||||
"@": resolve(__dirname, "src"),
|
||||
"/src": resolve(__dirname, "src"),
|
||||
},
|
||||
},
|
||||
build: {
|
||||
outDir: 'dist',
|
||||
outDir: "dist",
|
||||
emptyOutDir: true,
|
||||
minify: false,
|
||||
},
|
||||
viteburner: {
|
||||
watch: [{ pattern: 'src/**/*.{js,ts,jsx,tsx}', transform: true }, { pattern: 'src/**/*.{script,txt}' }],
|
||||
sourcemap: 'inline',
|
||||
watch: [{ pattern: "src/**/*.{js,ts,jsx,tsx}", transform: true }, { pattern: "src/**/*.{script,txt}" }],
|
||||
sourcemap: "inline",
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue