This commit is contained in:
Vomitblood 2026-05-01 20:01:43 +08:00
parent 3a3ebb321f
commit c81b66610e
18 changed files with 1193 additions and 49 deletions

View file

@ -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"
}
}

View file

@ -11,7 +11,7 @@
"quoteProps": "consistent",
"semi": true,
"singleAttributePerLine": true,
"singleQuote": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false

1084
deno.lock Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,2 +1,3 @@
[tools]
deno = "latest"
node = "latest"

View file

@ -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);

View file

@ -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
View 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"]);
};

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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) => {

View file

@ -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++;

View file

@ -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;

View file

@ -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 });
};

View file

@ -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"
]
}

View file

@ -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",
},
});