From 770c8a65abb80d26766af189e7c1925eda425387 Mon Sep 17 00:00:00 2001 From: Naga Ouroboros Date: Wed, 26 Feb 2025 20:45:36 -0500 Subject: [PATCH 01/11] TERMINAL: Fix 'connect' command not accepting an IP Address as the argument + print IP Address on connect if an IP address was the argument --- src/Terminal/Terminal.ts | 5 +++-- src/Terminal/commands/connect.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Terminal/Terminal.ts b/src/Terminal/Terminal.ts index cc94f48ad..74f274ef8 100644 --- a/src/Terminal/Terminal.ts +++ b/src/Terminal/Terminal.ts @@ -84,6 +84,7 @@ import { FilePath, isFilePath, resolveFilePath } from "../Paths/FilePath"; import { hasTextExtension } from "../Paths/TextFilePath"; import { ContractFilePath } from "../Paths/ContractFilePath"; import { ServerConstants } from "../Server/data/Constants"; +import { isIPAddress } from "../Types/strings"; export const TerminalCommands: Record void> = { "scan-analyze": scananalyze, @@ -593,11 +594,11 @@ export class Terminal { return; } Player.getCurrentServer().isConnectedTo = false; - Player.currentServer = hostname; + Player.currentServer = server.hostname; server.isConnectedTo = true; this.setcwd(root); if (!singularity) { - this.print("Connected to " + server.hostname); + this.print("Connected to " + `${isIPAddress(hostname) ? server.ip : server.hostname}`); if (Player.getCurrentServer().hostname == "darkweb") { checkIfConnectedToDarkweb(); // Posts a 'help' message if connecting to dark web } diff --git a/src/Terminal/commands/connect.ts b/src/Terminal/commands/connect.ts index c1a28ad81..e561171bc 100644 --- a/src/Terminal/commands/connect.ts +++ b/src/Terminal/commands/connect.ts @@ -30,7 +30,7 @@ export function connect(args: (string | number | boolean)[], server: BaseServer) ); return; } - if (other.hostname === hostname) { + if (other.hostname === target.hostname) { Terminal.connectToServer(hostname); return; } From 4fb5677682aef1e68c05751c11c402a1fab26436 Mon Sep 17 00:00:00 2001 From: Naga Ouroboros Date: Wed, 26 Feb 2025 20:52:14 -0500 Subject: [PATCH 02/11] TERMINAL: Add 'ipaddr' command --- src/Terminal/HelpText.ts | 2 ++ src/Terminal/Terminal.ts | 2 ++ src/Terminal/commands/ipaddr.ts | 10 ++++++++++ 3 files changed, 14 insertions(+) create mode 100644 src/Terminal/commands/ipaddr.ts diff --git a/src/Terminal/HelpText.ts b/src/Terminal/HelpText.ts index 6314cc51b..06a83613f 100644 --- a/src/Terminal/HelpText.ts +++ b/src/Terminal/HelpText.ts @@ -24,6 +24,7 @@ export const TerminalHelpText: string[] = [ " history [-c] Display the terminal history", " home Connect to home computer", " hostname Displays the hostname of the machine", + " ipaddr Displays the IP address of the machine", " kill [script/pid] [args...] Stops the specified script on the current server ", " killall Stops all running scripts on the current machine", " ls [dir] [--grep pattern] Displays all files on the machine", @@ -313,6 +314,7 @@ export const HelpTexts: Record = { " ", ], hostname: ["Usage: hostname", " ", "Prints the hostname of the current server", " "], + ipaddr: ["Usage: ipaddr", " ", "Prints the IP address of the current server", " "], kill: [ "Usage: kill [script name] [args...] or kill [pid]", " ", diff --git a/src/Terminal/Terminal.ts b/src/Terminal/Terminal.ts index 74f274ef8..8be2cd779 100644 --- a/src/Terminal/Terminal.ts +++ b/src/Terminal/Terminal.ts @@ -53,6 +53,7 @@ import { help } from "./commands/help"; import { history } from "./commands/history"; import { home } from "./commands/home"; import { hostname } from "./commands/hostname"; +import { ipaddr } from "./commands/ipaddr" import { kill } from "./commands/kill"; import { killall } from "./commands/killall"; import { ls } from "./commands/ls"; @@ -110,6 +111,7 @@ export const TerminalCommands: Record Date: Thu, 27 Feb 2025 23:09:58 -0500 Subject: [PATCH 03/11] NETSCRIPT: Add 'scanByIP', 'getIP', 'dnsLookup', and 'getPurchasedServersByIP' methods to the NS namespace. --- src/Netscript/RamCostGenerator.ts | 4 +++ src/NetscriptFunctions.ts | 33 +++++++++++++++++ src/ScriptEditor/NetscriptDefinitions.d.ts | 42 ++++++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index 924ab0edc..a282ead2e 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -498,6 +498,7 @@ export const RamCosts: RamCostTree = { sprintf: 0, vsprintf: 0, scan: RamCostConstants.Scan, + scanByIP: RamCostConstants.Scan, hack: RamCostConstants.Hack, hackAnalyzeThreads: RamCostConstants.HackAnalyze, hackAnalyze: RamCostConstants.HackAnalyze, @@ -542,6 +543,7 @@ export const RamCosts: RamCostTree = { getRecentScripts: RamCostConstants.RecentScripts, hasRootAccess: RamCostConstants.HasRootAccess, getHostname: RamCostConstants.GetHostname, + getIP: RamCostConstants.GetHostname, getHackingLevel: RamCostConstants.GetHackingLevel, getHackingMultipliers: 0.25, getHacknetMultipliers: 0.25, @@ -557,6 +559,7 @@ export const RamCosts: RamCostTree = { getServerNumPortsRequired: RamCostConstants.GetServer, getServerMaxRam: RamCostConstants.GetServerMaxRam, getServerUsedRam: RamCostConstants.GetServerUsedRam, + dnsLookup: RamCostConstants.GetHostname, serverExists: RamCostConstants.GetServer, fileExists: RamCostConstants.FileExists, isRunning: RamCostConstants.IsRunning, @@ -565,6 +568,7 @@ export const RamCosts: RamCostTree = { getPurchasedServerCost: RamCostConstants.GetPurchaseServer, getPurchasedServerUpgradeCost: 0.1, getPurchasedServers: 1.05, + getPurchasedServersByIP: 1.05, upgradePurchasedServer: 0.25, renamePurchasedServer: 0, purchaseServer: RamCostConstants.PurchaseServer, diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 65b2c0053..1764b1b1e 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -112,6 +112,7 @@ import { assertFunctionWithNSContext } from "./Netscript/TypeAssertion"; import { Router } from "./ui/GameRoot"; import { Page } from "./ui/Router"; import { canAccessBitNodeFeature, validBitNodes } from "./BitNode/BitNodeUtils"; +import { isIPAddress } from "./Types/strings"; export const enums: NSEnums = { CityName, @@ -174,6 +175,20 @@ export const ns: InternalAPI = { helpers.log(ctx, () => `returned ${server.serversOnNetwork.length} connections for ${server.hostname}`); return out; }, + scanByIP: (ctx) => (_hostname) => { + const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname; + const server = helpers.getServer(ctx, hostname); + const out: string[] = []; + for (let i = 0; i < server.serversOnNetwork.length; i++) { + const s = getServerOnNetwork(server, i); + if (s === null) continue; + const entry = s.ip; + if (entry === null) continue; + out.push(entry); + } + helpers.log(ctx, () => `returned ${server.serversOnNetwork.length} connections for ${server.ip}`); + return out; + }, hasTorRouter: () => () => Player.hasTorRouter(), hack: (ctx) => (_hostname, opts?) => { const hostname = helpers.string(ctx, "hostname", _hostname); @@ -945,6 +960,11 @@ export const ns: InternalAPI = { return server.hasAdminRights; }, getHostname: (ctx) => () => ctx.workerScript.hostname, + getIP: (ctx) => () => { + const hostname = ctx.workerScript.hostname; + const server = helpers.getServer(ctx, hostname); + return server.ip; + }, getHackingLevel: (ctx) => () => { Player.updateSkillLevels(); helpers.log(ctx, () => `returned ${Player.skills.hacking}`); @@ -1136,6 +1156,11 @@ export const ns: InternalAPI = { helpers.log(ctx, () => `returned ${formatRam(server.ramUsed)}`); return server.ramUsed; }, + dnsLookup: (ctx) => (_host) => { + const identifier = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, identifier); + return isIPAddress(identifier) ? server.hostname : server.ip; + }, serverExists: (ctx) => (_hostname) => { const hostname = helpers.string(ctx, "hostname", _hostname); const server = GetServer(hostname); @@ -1352,6 +1377,14 @@ export const ns: InternalAPI = { }); return res; }, + getPurchasedServersByIP: (ctx) => (): string[] => { + const res: string[] = []; + Player.purchasedServers.forEach(function (hostname) { + const server = helpers.getServer(ctx, hostname) + res.push(server.ip) + }); + return res; + }, writePort: (ctx) => (_portNumber, data) => { const portNumber = helpers.portNumber(ctx, _portNumber); return writePort(portNumber, data); diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index edbbe140c..f39fd63ae 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -6775,6 +6775,22 @@ export interface NS { */ scan(host?: string): string[]; + /** + * Get the list of servers connected to a server. + * @remarks + * RAM cost: 0.2 GB + * + * Returns an array containing the IP addresses of all servers that are one + * node way from the specified target server. The IP addresses in the returned + * array are strings. + * + * Works identically to {@link NS.scan | ns.scan}. + * + * @param host - Optional. Hostname of the server to scan, default to current server. + * @returns Returns an array of IP addresses + */ + scanByIP(host?: string): string[]; + /** Returns whether the player has access to the darkweb. * @remarks * RAM cost: 0.05GB @@ -7164,6 +7180,15 @@ export interface NS { */ getHostname(): string; + /** + * Returns a string with the IP address of the server that the script is running on. + * + * @remarks + * RAM cost: 0.05 GB + * @returns IP address of the server that the script runs on. + */ + getIP(): string + /** * Returns the player’s current hacking level. * @@ -7340,6 +7365,15 @@ export interface NS { */ getServerNumPortsRequired(host: string): number; + /** + * Given a hostname, returns an IP address, + * Given an IP address, returns a hostname + * + * @remarks RAM cost: 0.05 GB + * @param host - Hostname or IP address of target server. + */ + dnsLookup(host: string): string + /** * Returns a boolean denoting whether or not the specified server exists. * @@ -7555,6 +7589,14 @@ export interface NS { */ getPurchasedServers(): string[]; + /** + * Returns an array with the IP addresses of all of the servers you have purchased. + * + * @remarks 1.05 GB + * @returns Returns an array with the IP addresses of all of the servers you have purchased. + */ + getPurchasedServersByIP(): string[] + /** * Returns the maximum number of servers you can purchase. * From 1bab9d93386b78d0958451761e082d42f33deae5 Mon Sep 17 00:00:00 2001 From: Naga Ouroboros Date: Sat, 1 Mar 2025 01:15:24 -0500 Subject: [PATCH 04/11] NETSCRIPT: Set 'dnsLookup' method RAM cost to 0 --- src/Netscript/RamCostGenerator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index a282ead2e..3a25682bc 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -559,7 +559,7 @@ export const RamCosts: RamCostTree = { getServerNumPortsRequired: RamCostConstants.GetServer, getServerMaxRam: RamCostConstants.GetServerMaxRam, getServerUsedRam: RamCostConstants.GetServerUsedRam, - dnsLookup: RamCostConstants.GetHostname, + dnsLookup: 0, serverExists: RamCostConstants.GetServer, fileExists: RamCostConstants.FileExists, isRunning: RamCostConstants.IsRunning, From 324796826749c017ff233db4ebbcf750f2207150 Mon Sep 17 00:00:00 2001 From: Naga Ouroboros Date: Sat, 1 Mar 2025 01:18:10 -0500 Subject: [PATCH 05/11] NETSCRIPT: Detailed pass over documentation and player-facing code to ensure consistent use of 'host', 'hostname', and 'ip'. Added guards where hostnames are required to prevent the use of IPs --- src/NetscriptFunctions.ts | 326 ++++++++++----------- src/NetscriptFunctions/CodingContract.ts | 40 +-- src/NetscriptFunctions/Singularity.ts | 18 +- src/NetscriptFunctions/UserInterface.ts | 8 +- src/ScriptEditor/NetscriptDefinitions.d.ts | 170 +++++------ src/Server/ServerPurchases.ts | 5 +- 6 files changed, 285 insertions(+), 282 deletions(-) diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 1764b1b1e..e3812c289 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -161,9 +161,9 @@ export const ns: InternalAPI = { } return vsprintf(format, _args); }, - scan: (ctx) => (_hostname) => { - const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname; - const server = helpers.getServer(ctx, hostname); + scan: (ctx) => (_host) => { + const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname; + const server = helpers.getServer(ctx, host); const out: string[] = []; for (let i = 0; i < server.serversOnNetwork.length; i++) { const s = getServerOnNetwork(server, i); @@ -175,9 +175,9 @@ export const ns: InternalAPI = { helpers.log(ctx, () => `returned ${server.serversOnNetwork.length} connections for ${server.hostname}`); return out; }, - scanByIP: (ctx) => (_hostname) => { - const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname; - const server = helpers.getServer(ctx, hostname); + scanByIP: (ctx) => (_host) => { + const host = _host ? helpers.string(ctx, "hostname", _host) : ctx.workerScript.hostname; + const server = helpers.getServer(ctx, host); const out: string[] = []; for (let i = 0; i < server.serversOnNetwork.length; i++) { const s = getServerOnNetwork(server, i); @@ -190,16 +190,16 @@ export const ns: InternalAPI = { return out; }, hasTorRouter: () => () => Player.hasTorRouter(), - hack: (ctx) => (_hostname, opts?) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - return helpers.hack(ctx, hostname, false, opts); + hack: (ctx) => (_host, opts?) => { + const host = helpers.string(ctx, "host", _host); + return helpers.hack(ctx, host, false, opts); }, - hackAnalyzeThreads: (ctx) => (_hostname, _hackAmount) => { - const hostname = helpers.string(ctx, "hostname", _hostname); + hackAnalyzeThreads: (ctx) => (_host, _hackAmount) => { + const host = helpers.string(ctx, "host", _host); const hackAmount = helpers.number(ctx, "hackAmount", _hackAmount); // Check argument validity - const server = helpers.getServer(ctx, hostname); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return -1; @@ -225,10 +225,10 @@ export const ns: InternalAPI = { return hackAmount / (server.moneyAvailable * percentHacked); }, - hackAnalyze: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); + hackAnalyze: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); - const server = helpers.getServer(ctx, hostname); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return 0; @@ -236,11 +236,11 @@ export const ns: InternalAPI = { return calculatePercentMoneyHacked(server, Player); }, - hackAnalyzeSecurity: (ctx) => (_threads, _hostname?) => { + hackAnalyzeSecurity: (ctx) => (_threads, _host?) => { let threads = helpers.number(ctx, "threads", _threads); - if (_hostname) { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + if (_host) { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return 0; @@ -256,10 +256,10 @@ export const ns: InternalAPI = { return ServerConstants.ServerFortifyAmount * threads; }, - hackAnalyzeChance: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); + hackAnalyzeChance: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); - const server = helpers.getServer(ctx, hostname); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return 0; @@ -283,11 +283,11 @@ export const ns: InternalAPI = { helpers.log(ctx, () => `Sleeping for ${convertTimeMsToTimeElapsedString(time, true)}.`); return new Promise((resolve) => setTimeout(() => resolve(true), time)); }, - grow: (ctx) => (_hostname, opts?) => { - const hostname = helpers.string(ctx, "hostname", _hostname); + grow: (ctx) => (_host, opts?) => { + const host = helpers.string(ctx, "host", _host); const { threads, stock, additionalMsec } = helpers.validateHGWOptions(ctx, opts); - const server = helpers.getServer(ctx, hostname); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { throw helpers.errorMessage(ctx, "Cannot be executed on this server."); } @@ -308,12 +308,12 @@ export const ns: InternalAPI = { )} (t=${formatThreads(threads)}).`, ); return helpers.netscriptDelay(ctx, growTime * 1000).then(function () { - const host = GetServer(ctx.workerScript.hostname); - if (host === null) { + const scripthost = GetServer(ctx.workerScript.hostname); + if (scripthost === null) { throw helpers.errorMessage(ctx, `Cannot find host of WorkerScript. Hostname: ${ctx.workerScript.hostname}.`); } const moneyBefore = server.moneyAvailable; - const growth = processSingleServerGrowth(server, threads, host.cpuCores); + const growth = processSingleServerGrowth(server, threads, scripthost.cpuCores); const moneyAfter = server.moneyAvailable; ctx.workerScript.scriptRef.recordGrow(server.hostname, threads); const expGain = calculateHackingExpGain(server, Player) * threads; @@ -358,12 +358,12 @@ export const ns: InternalAPI = { }, growthAnalyzeSecurity: (ctx) => - (_threads, _hostname?, _cores = 1) => { + (_threads, _host?, _cores = 1) => { let threads = helpers.number(ctx, "threads", _threads); - if (_hostname) { + if (_host) { const cores = helpers.number(ctx, "cores", _cores); - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); @@ -379,11 +379,11 @@ export const ns: InternalAPI = { return 2 * ServerConstants.ServerFortifyAmount * threads; }, - weaken: (ctx) => async (_hostname, opts?) => { - const hostname = helpers.string(ctx, "hostname", _hostname); + weaken: (ctx) => async (_host, opts?) => { + const host = helpers.string(ctx, "host", _host); const { threads, additionalMsec } = helpers.validateHGWOptions(ctx, opts); - const server = helpers.getServer(ctx, hostname); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { throw helpers.errorMessage(ctx, "Cannot be executed on this server."); } @@ -404,11 +404,11 @@ export const ns: InternalAPI = { )} (t=${formatThreads(threads)})`, ); return helpers.netscriptDelay(ctx, weakenTime * 1000).then(function () { - const host = GetServer(ctx.workerScript.hostname); - if (host === null) { + const scripthost = GetServer(ctx.workerScript.hostname); + if (scripthost === null) { throw helpers.errorMessage(ctx, `Cannot find host of WorkerScript. Hostname: ${ctx.workerScript.hostname}.`); } - const weakenAmt = getWeakenEffect(threads, host.cpuCores); + const weakenAmt = getWeakenEffect(threads, scripthost.cpuCores); const securityBeforeWeaken = server.hackDifficulty; server.weaken(weakenAmt); const securityAfterWeaken = server.hackDifficulty; @@ -562,8 +562,8 @@ export const ns: InternalAPI = { }, getScriptLogs: (ctx) => - (scriptID, hostname, ...scriptArgs) => { - const ident = helpers.scriptIdentifier(ctx, scriptID, hostname, scriptArgs); + (scriptID, host, ...scriptArgs) => { + const ident = helpers.scriptIdentifier(ctx, scriptID, host, scriptArgs); const runningScriptObj = helpers.getRunningScript(ctx, ident); if (runningScriptObj == null) { helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(ident)); @@ -602,10 +602,10 @@ export const ns: InternalAPI = { deprecationWarning("ns.setTitle", "Use ns.ui.setTailTitle instead."); ns.ui.setTailTitle(ctx)(title, _pid); }, - nuke: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); + nuke: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); - const server = helpers.getServer(ctx, hostname); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return false; @@ -624,9 +624,9 @@ export const ns: InternalAPI = { helpers.log(ctx, () => `Executed NUKE.exe virus on '${server.hostname}' to gain root access.`); return true; }, - brutessh: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + brutessh: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return false; @@ -643,9 +643,9 @@ export const ns: InternalAPI = { } return true; }, - ftpcrack: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + ftpcrack: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return false; @@ -662,9 +662,9 @@ export const ns: InternalAPI = { } return true; }, - relaysmtp: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + relaysmtp: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return false; @@ -681,9 +681,9 @@ export const ns: InternalAPI = { } return true; }, - httpworm: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + httpworm: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return false; @@ -700,9 +700,9 @@ export const ns: InternalAPI = { } return true; }, - sqlinject: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + sqlinject: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return false; @@ -731,12 +731,12 @@ export const ns: InternalAPI = { }, exec: (ctx) => - (_scriptname, _hostname, _thread_or_opt = 1, ..._args) => { + (_scriptname, _host, _thread_or_opt = 1, ..._args) => { const path = helpers.scriptPath(ctx, "scriptname", _scriptname); - const hostname = helpers.string(ctx, "hostname", _hostname); + const host = helpers.string(ctx, "host", _host); const runOpts = helpers.runOptions(ctx, _thread_or_opt); const args = helpers.scriptArgs(ctx, _args); - const server = helpers.getServer(ctx, hostname); + const server = helpers.getServer(ctx, host); return runScriptFromScript("exec", server, path, args, ctx.workerScript, runOpts); }, spawn: @@ -784,8 +784,8 @@ export const ns: InternalAPI = { }, kill: (ctx) => - (scriptID, hostname = ctx.workerScript.hostname, ...scriptArgs) => { - const ident = helpers.scriptIdentifier(ctx, scriptID, hostname, scriptArgs); + (scriptID, host = ctx.workerScript.hostname, ...scriptArgs) => { + const ident = helpers.scriptIdentifier(ctx, scriptID, host, scriptArgs); let res; const killByPid = typeof ident === "number"; if (killByPid) { @@ -813,7 +813,7 @@ export const ns: InternalAPI = { if (killByPid) { helpers.log(ctx, () => `Killing script with PID ${ident}`); } else { - helpers.log(ctx, () => `Killing '${scriptID}' on '${hostname}' with args: ${arrayToString(scriptArgs)}.`); + helpers.log(ctx, () => `Killing '${scriptID}' on '${host}' with args: ${arrayToString(scriptArgs)}.`); } return true; } else { @@ -822,7 +822,7 @@ export const ns: InternalAPI = { } else { helpers.log( ctx, - () => `Internal error killing '${scriptID}' on '${hostname}' with args: ${arrayToString(scriptArgs)}`, + () => `Internal error killing '${scriptID}' on '${host}' with args: ${arrayToString(scriptArgs)}`, ); } return false; @@ -830,10 +830,10 @@ export const ns: InternalAPI = { }, killall: (ctx) => - (_hostname = ctx.workerScript.hostname, _safetyGuard = true) => { - const hostname = helpers.string(ctx, "hostname", _hostname); + (_host = ctx.workerScript.hostname, _safetyGuard = true) => { + const host = helpers.string(ctx, "host", _host); const safetyGuard = !!_safetyGuard; - const server = helpers.getServer(ctx, hostname); + const server = helpers.getServer(ctx, host); let scriptsKilled = 0; @@ -913,10 +913,10 @@ export const ns: InternalAPI = { } return noFailures; }, - ls: (ctx) => (_hostname, _substring) => { - const hostname = helpers.string(ctx, "hostname", _hostname); + ls: (ctx) => (_host, _substring) => { + const host = helpers.string(ctx, "host", _host); const substring = helpers.string(ctx, "substring", _substring ?? ""); - const server = helpers.getServer(ctx, hostname); + const server = helpers.getServer(ctx, host); const allFilenames = [ ...server.contracts.map((contract) => contract.fn), @@ -937,9 +937,9 @@ export const ns: InternalAPI = { }, ps: (ctx) => - (_hostname = ctx.workerScript.hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + (_host = ctx.workerScript.hostname) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); const processes: ProcessInfo[] = []; for (const byPid of server.runningScriptMap.values()) { for (const script of byPid.values()) { @@ -954,9 +954,9 @@ export const ns: InternalAPI = { } return processes; }, - hasRootAccess: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + hasRootAccess: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); return server.hasAdminRights; }, getHostname: (ctx) => () => ctx.workerScript.hostname, @@ -1005,9 +1005,9 @@ export const ns: InternalAPI = { return Object.assign({}, getBitNodeMultipliers(n, lvl)); }, - getServer: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname ?? ctx.workerScript.hostname); - const server = helpers.getServer(ctx, hostname); + getServer: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host ?? ctx.workerScript.hostname); + const server = helpers.getServer(ctx, host); return { hostname: server.hostname, ip: server.ip, @@ -1035,9 +1035,9 @@ export const ns: InternalAPI = { serverGrowth: server.serverGrowth, }; }, - getServerMoneyAvailable: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + getServerMoneyAvailable: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return 0; @@ -1053,9 +1053,9 @@ export const ns: InternalAPI = { helpers.log(ctx, () => `returned ${formatMoney(server.moneyAvailable)} for '${server.hostname}'`); return server.moneyAvailable; }, - getServerSecurityLevel: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + getServerSecurityLevel: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return 1; @@ -1066,9 +1066,9 @@ export const ns: InternalAPI = { helpers.log(ctx, () => `returned ${formatSecurity(server.hackDifficulty)} for '${server.hostname}'`); return server.hackDifficulty; }, - getServerBaseSecurityLevel: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + getServerBaseSecurityLevel: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return 1; @@ -1079,9 +1079,9 @@ export const ns: InternalAPI = { helpers.log(ctx, () => `returned ${formatSecurity(server.baseDifficulty)} for '${server.hostname}'`); return server.baseDifficulty; }, - getServerMinSecurityLevel: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + getServerMinSecurityLevel: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return 1; @@ -1092,9 +1092,9 @@ export const ns: InternalAPI = { helpers.log(ctx, () => `returned ${formatSecurity(server.minDifficulty)} for ${server.hostname}`); return server.minDifficulty; }, - getServerRequiredHackingLevel: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + getServerRequiredHackingLevel: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return 1; @@ -1105,9 +1105,9 @@ export const ns: InternalAPI = { helpers.log(ctx, () => `returned ${formatNumberNoSuffix(server.requiredHackingSkill, 0)} for '${server.hostname}'`); return server.requiredHackingSkill; }, - getServerMaxMoney: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + getServerMaxMoney: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return 0; @@ -1118,9 +1118,9 @@ export const ns: InternalAPI = { helpers.log(ctx, () => `returned ${formatMoney(server.moneyMax)} for '${server.hostname}'`); return server.moneyMax; }, - getServerGrowth: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + getServerGrowth: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return 1; @@ -1131,9 +1131,9 @@ export const ns: InternalAPI = { helpers.log(ctx, () => `returned ${server.serverGrowth} for '${server.hostname}'`); return server.serverGrowth; }, - getServerNumPortsRequired: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + getServerNumPortsRequired: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "Cannot be executed on this server."); return 5; @@ -1144,15 +1144,15 @@ export const ns: InternalAPI = { helpers.log(ctx, () => `returned ${server.numOpenPortsRequired} for '${server.hostname}'`); return server.numOpenPortsRequired; }, - getServerMaxRam: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + getServerMaxRam: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); helpers.log(ctx, () => `returned ${formatRam(server.maxRam)}`); return server.maxRam; }, - getServerUsedRam: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + getServerUsedRam: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); helpers.log(ctx, () => `returned ${formatRam(server.ramUsed)}`); return server.ramUsed; }, @@ -1161,15 +1161,15 @@ export const ns: InternalAPI = { const server = helpers.getServer(ctx, identifier); return isIPAddress(identifier) ? server.hostname : server.ip; }, - serverExists: (ctx) => (_hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = GetServer(hostname); + serverExists: (ctx) => (_host) => { + const host = helpers.string(ctx, "host", _host); + const server = GetServer(host); return server !== null && (server.serversOnNetwork.length > 0 || server.hostname === "home"); }, - fileExists: (ctx) => (_filename, _hostname) => { + fileExists: (ctx) => (_filename, _host) => { const filename = helpers.string(ctx, "filename", _filename); - const hostname = helpers.string(ctx, "hostname", _hostname ?? ctx.workerScript.hostname); - const server = helpers.getServer(ctx, hostname); + const host = helpers.string(ctx, "host", _host ?? ctx.workerScript.hostname); + const server = helpers.getServer(ctx, host); const path = resolveFilePath(filename, ctx.workerScript.name); if (!path) return false; if (hasScriptExtension(path)) return server.scripts.has(path); @@ -1182,8 +1182,8 @@ export const ns: InternalAPI = { }, isRunning: (ctx) => - (fn, hostname, ...scriptArgs) => { - const ident = helpers.scriptIdentifier(ctx, fn, hostname, scriptArgs); + (fn, host, ...scriptArgs) => { + const ident = helpers.scriptIdentifier(ctx, fn, host, scriptArgs); return helpers.getRunningScript(ctx, ident) !== null; }, getPurchasedServerLimit: () => () => { @@ -1212,7 +1212,7 @@ export const ns: InternalAPI = { const ram = helpers.number(ctx, "ram", _ram); let hostnameStr = String(name); hostnameStr = hostnameStr.replace(/\s+/g, ""); - if (hostnameStr == "") { + if (hostnameStr == "" || isIPAddress(hostnameStr)) { helpers.log(ctx, () => `Invalid argument: hostname='${hostnameStr}'`); return ""; } @@ -1265,22 +1265,22 @@ export const ns: InternalAPI = { return newServ.hostname; }, - getPurchasedServerUpgradeCost: (ctx) => (_hostname, _ram) => { - const hostname = helpers.string(ctx, "hostname", _hostname); + getPurchasedServerUpgradeCost: (ctx) => (_host, _ram) => { + const host = helpers.string(ctx, "host", _host); const ram = helpers.number(ctx, "ram", _ram); try { - return getPurchasedServerUpgradeCost(hostname, ram); + return getPurchasedServerUpgradeCost(host, ram); } catch (err) { helpers.log(ctx, () => String(err)); return -1; } }, - upgradePurchasedServer: (ctx) => (_hostname, _ram) => { - const hostname = helpers.string(ctx, "hostname", _hostname); + upgradePurchasedServer: (ctx) => (_host, _ram) => { + const host = helpers.string(ctx, "host", _host); const ram = helpers.number(ctx, "ram", _ram); try { - upgradePurchasedServer(hostname, ram); + upgradePurchasedServer(host, ram); return true; } catch (err) { helpers.log(ctx, () => String(err)); @@ -1458,10 +1458,10 @@ export const ns: InternalAPI = { const portNumber = helpers.portNumber(ctx, _portNumber); return portHandle(portNumber); }, - rm: (ctx) => (_fn, _hostname) => { + rm: (ctx) => (_fn, _host) => { const filepath = helpers.filePath(ctx, "fn", _fn); - const hostname = helpers.string(ctx, "hostname", _hostname ?? ctx.workerScript.hostname); - const s = helpers.getServer(ctx, hostname); + const host = helpers.string(ctx, "host", _host ?? ctx.workerScript.hostname); + const s = helpers.getServer(ctx, host); if (!filepath) { helpers.log(ctx, () => `Error while parsing filepath ${filepath}`); return false; @@ -1474,16 +1474,16 @@ export const ns: InternalAPI = { return status.res; }, - scriptRunning: (ctx) => (_scriptname, _hostname) => { + scriptRunning: (ctx) => (_scriptname, _host) => { const scriptname = helpers.scriptPath(ctx, "scriptname", _scriptname); - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); return server.isRunning(scriptname); }, - scriptKill: (ctx) => (_scriptname, _hostname) => { + scriptKill: (ctx) => (_scriptname, _host) => { const path = helpers.scriptPath(ctx, "scriptname", _scriptname); - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); let suc = false; const pattern = matchScriptPathExact(escapeRegExp(path)); @@ -1497,23 +1497,23 @@ export const ns: InternalAPI = { return suc; }, getScriptName: (ctx) => () => ctx.workerScript.name, - getScriptRam: (ctx) => (_scriptname, _hostname) => { + getScriptRam: (ctx) => (_scriptname, _host) => { const path = helpers.scriptPath(ctx, "scriptname", _scriptname); - const hostname = helpers.string(ctx, "hostname", _hostname ?? ctx.workerScript.hostname); - const server = helpers.getServer(ctx, hostname); + const host = helpers.string(ctx, "hostname", _host ?? ctx.workerScript.hostname); + const server = helpers.getServer(ctx, host); const script = server.scripts.get(path); if (!script) return 0; const ramUsage = script.getRamUsage(server.scripts); if (!ramUsage) { - helpers.log(ctx, () => `Could not calculate ram usage for ${path} on ${hostname}.`); + helpers.log(ctx, () => `Could not calculate ram usage for ${path} on ${host}.`); return 0; } return ramUsage; }, getRunningScript: (ctx) => - (fn, hostname, ...args) => { - const ident = helpers.scriptIdentifier(ctx, fn, hostname, args); + (fn, host, ...args) => { + const ident = helpers.scriptIdentifier(ctx, fn, host, args); const runningScript = helpers.getRunningScript(ctx, ident); if (runningScript === null) return null; // Need to look this up again, because we only have ident-based lookup @@ -1547,9 +1547,9 @@ export const ns: InternalAPI = { }, getHackTime: (ctx) => - (_hostname = ctx.workerScript.hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + (_host = ctx.workerScript.hostname) => { + const host = helpers.string(ctx, "hostname", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "invalid for this kind of server"); return Infinity; @@ -1562,9 +1562,9 @@ export const ns: InternalAPI = { }, getGrowTime: (ctx) => - (_hostname = ctx.workerScript.hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + (_host = ctx.workerScript.hostname) => { + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "invalid for this kind of server"); return Infinity; @@ -1577,9 +1577,9 @@ export const ns: InternalAPI = { }, getWeakenTime: (ctx) => - (_hostname = ctx.workerScript.hostname) => { - const hostname = helpers.string(ctx, "hostname", _hostname); - const server = helpers.getServer(ctx, hostname); + (_host = ctx.workerScript.hostname) => { + const host = helpers.string(ctx, "hostname", _host); + const server = helpers.getServer(ctx, host); if (!(server instanceof Server)) { helpers.log(ctx, () => "invalid for this kind of server"); return Infinity; @@ -1605,8 +1605,8 @@ export const ns: InternalAPI = { }, getScriptIncome: (ctx) => - (fn, hostname, ...args) => { - const ident = helpers.scriptIdentifier(ctx, fn, hostname, args); + (fn, host, ...args) => { + const ident = helpers.scriptIdentifier(ctx, fn, host, args); const runningScript = helpers.getRunningScript(ctx, ident); if (runningScript == null) { helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(ident)); @@ -1623,8 +1623,8 @@ export const ns: InternalAPI = { }, getScriptExpGain: (ctx) => - (fn, hostname, ...args) => { - const ident = helpers.scriptIdentifier(ctx, fn, hostname, args); + (fn, host, ...args) => { + const ident = helpers.scriptIdentifier(ctx, fn, host, args); const runningScript = helpers.getRunningScript(ctx, ident); if (runningScript == null) { helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(ident)); @@ -1729,11 +1729,11 @@ export const ns: InternalAPI = { }); }); }, - wget: (ctx) => async (_url, _target, _hostname) => { + wget: (ctx) => async (_url, _target, _host) => { const url = helpers.string(ctx, "url", _url); const target = helpers.filePath(ctx, "target", _target); - const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname; - const server = helpers.getServer(ctx, hostname); + const host = _host ? helpers.string(ctx, "hostname", _host) : ctx.workerScript.hostname; + const server = helpers.getServer(ctx, host); if (!target || (!hasTextExtension(target) && !hasScriptExtension(target))) { helpers.log(ctx, () => `Invalid target file: '${target}'. Must be a script or text file.`); return false; @@ -1760,9 +1760,9 @@ export const ns: InternalAPI = { } const writeResult = server.writeToContentFile(target, await response.text()); if (writeResult.overwritten) { - helpers.log(ctx, () => `Successfully retrieved content and overwrote '${target}' on '${hostname}'`); + helpers.log(ctx, () => `Successfully retrieved content and overwrote '${target}' on '${host}'`); } else { - helpers.log(ctx, () => `Successfully retrieved content to new file '${target}' on '${hostname}'`); + helpers.log(ctx, () => `Successfully retrieved content to new file '${target}' on '${host}'`); } return true; }, @@ -1816,8 +1816,8 @@ export const ns: InternalAPI = { ctx.workerScript.atExit.set(id, callback); }, mv: (ctx) => (_host, _source, _destination) => { - const hostname = helpers.string(ctx, "host", _host); - const server = helpers.getServer(ctx, hostname); + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); const sourcePath = helpers.filePath(ctx, "source", _source); const destinationPath = helpers.filePath(ctx, "destination", _destination); @@ -1833,13 +1833,13 @@ export const ns: InternalAPI = { } const sourceContentFile = server.getContentFile(sourcePath); if (!sourceContentFile) { - throw helpers.errorMessage(ctx, `Source text file ${sourcePath} does not exist on ${hostname}`); + throw helpers.errorMessage(ctx, `Source text file ${sourcePath} does not exist on ${host}`); } const success = sourceContentFile.deleteFromServer(server); if (success) { const { overwritten } = server.writeToContentFile(destinationPath, sourceContentFile.content); - if (overwritten) helpers.log(ctx, () => `WARNING: Overwriting file ${destinationPath} on ${hostname}`); - helpers.log(ctx, () => `Moved ${sourcePath} to ${destinationPath} on ${hostname}`); + if (overwritten) helpers.log(ctx, () => `WARNING: Overwriting file ${destinationPath} on ${host}`); + helpers.log(ctx, () => `Moved ${sourcePath} to ${destinationPath} on ${host}`); return; } helpers.log(ctx, () => `ERROR: Failed. Was unable to remove file ${sourcePath} from its original location.`); diff --git a/src/NetscriptFunctions/CodingContract.ts b/src/NetscriptFunctions/CodingContract.ts index 0e71dacc0..ba1a019ff 100644 --- a/src/NetscriptFunctions/CodingContract.ts +++ b/src/NetscriptFunctions/CodingContract.ts @@ -49,10 +49,10 @@ export function NetscriptCodingContract(): InternalAPI { } return { - attempt: (ctx) => (answer, _filename, _hostname?) => { + attempt: (ctx) => (answer, _filename, _host?) => { const filename = helpers.string(ctx, "filename", _filename); - const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname; - const contract = getCodingContract(ctx, hostname, filename); + const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname; + const contract = getCodingContract(ctx, host, filename); if (!contract.isValid(answer)) throw helpers.errorMessage( @@ -60,27 +60,27 @@ export function NetscriptCodingContract(): InternalAPI { `Answer is not in the right format for contract '${contract.type}'. Got: ${answer}`, ); - const serv = helpers.getServer(ctx, hostname); + const serv = helpers.getServer(ctx, host); return attemptContract(ctx, serv, contract, answer); }, - getContractType: (ctx) => (_filename, _hostname?) => { + getContractType: (ctx) => (_filename, _host?) => { const filename = helpers.string(ctx, "filename", _filename); - const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname; - const contract = getCodingContract(ctx, hostname, filename); + const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname; + const contract = getCodingContract(ctx, host, filename); return contract.getType(); }, - getData: (ctx) => (_filename, _hostname?) => { + getData: (ctx) => (_filename, _host?) => { const filename = helpers.string(ctx, "filename", _filename); - const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname; - const contract = getCodingContract(ctx, hostname, filename); + const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname; + const contract = getCodingContract(ctx, host, filename); return structuredClone(contract.getData()); }, - getContract: (ctx) => (_filename, _hostname?) => { + getContract: (ctx) => (_filename, _host?) => { const filename = helpers.string(ctx, "filename", _filename); - const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname; - const server = helpers.getServer(ctx, hostname); - const contract = getCodingContract(ctx, hostname, filename); + const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname; + const server = helpers.getServer(ctx, host); + const contract = getCodingContract(ctx, host, filename); // asserting type here is required, since it is not feasible to properly type getData return { type: contract.type, @@ -96,16 +96,16 @@ export function NetscriptCodingContract(): InternalAPI { }, } as CodingContractObject; }, - getDescription: (ctx) => (_filename, _hostname?) => { + getDescription: (ctx) => (_filename, _host?) => { const filename = helpers.string(ctx, "filename", _filename); - const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname; - const contract = getCodingContract(ctx, hostname, filename); + const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname; + const contract = getCodingContract(ctx, host, filename); return contract.getDescription(); }, - getNumTriesRemaining: (ctx) => (_filename, _hostname?) => { + getNumTriesRemaining: (ctx) => (_filename, _host?) => { const filename = helpers.string(ctx, "filename", _filename); - const hostname = _hostname ? helpers.string(ctx, "hostname", _hostname) : ctx.workerScript.hostname; - const contract = getCodingContract(ctx, hostname, filename); + const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname; + const contract = getCodingContract(ctx, host, filename); return contract.getMaxNumTries() - contract.tries; }, createDummyContract: (ctx) => (_type) => { diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index c4764488f..bf950b80f 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -467,16 +467,16 @@ export function NetscriptSingularity(): InternalAPI { helpers.checkSingularityAccess(ctx); return Player.getCurrentServer().hostname; }, - connect: (ctx) => (_hostname) => { + connect: (ctx) => (_host) => { helpers.checkSingularityAccess(ctx); - const hostname = helpers.string(ctx, "hostname", _hostname); - if (!hostname) { - throw helpers.errorMessage(ctx, `Invalid hostname: '${hostname}'`); + const host = helpers.string(ctx, "host", _host); + if (!host) { + throw helpers.errorMessage(ctx, `Invalid hostname: '${host}'`); } - const target = GetServer(hostname); + const target = GetServer(host); if (target == null) { - throw helpers.errorMessage(ctx, `Invalid hostname: '${hostname}'`); + throw helpers.errorMessage(ctx, `Invalid hostname: '${host}'`); } // Adjacent servers @@ -491,8 +491,8 @@ export function NetscriptSingularity(): InternalAPI { ); return false; } - if (other.hostname === hostname) { - Terminal.connectToServer(hostname, true); + if (other.hostname === target.hostname) { + Terminal.connectToServer(host, true); return true; } } @@ -502,7 +502,7 @@ export function NetscriptSingularity(): InternalAPI { * is true. */ if (target.backdoorInstalled || target.purchasedByPlayer) { - Terminal.connectToServer(hostname, true); + Terminal.connectToServer(host, true); return true; } diff --git a/src/NetscriptFunctions/UserInterface.ts b/src/NetscriptFunctions/UserInterface.ts index aac53d881..5cb96d752 100644 --- a/src/NetscriptFunctions/UserInterface.ts +++ b/src/NetscriptFunctions/UserInterface.ts @@ -15,8 +15,8 @@ export function NetscriptUserInterface(): InternalAPI { return { openTail: (ctx) => - (scriptID, hostname, ...scriptArgs) => { - const ident = helpers.scriptIdentifier(ctx, scriptID, hostname, scriptArgs); + (scriptID, host, ...scriptArgs) => { + const ident = helpers.scriptIdentifier(ctx, scriptID, host, scriptArgs); const runningScriptObj = helpers.getRunningScript(ctx, ident); if (runningScriptObj == null) { helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(ident)); @@ -89,8 +89,8 @@ export function NetscriptUserInterface(): InternalAPI { setTailFontSize: (ctx) => - (_pixel, scriptID, hostname, ...scriptArgs) => { - const ident = helpers.scriptIdentifier(ctx, scriptID, hostname, scriptArgs); + (_pixel, scriptID, host, ...scriptArgs) => { + const ident = helpers.scriptIdentifier(ctx, scriptID, host, scriptArgs); const runningScriptObj = helpers.getRunningScript(ctx, ident); if (runningScriptObj == null) { helpers.log(ctx, () => helpers.getCannotFindRunningScriptErrorMessage(ident)); diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index f39fd63ae..48096e753 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -2662,11 +2662,11 @@ export interface Singularity { * RAM cost: 2 GB * 16/4/1 * * - * Run the connect HOSTNAME command in the terminal. Can only connect to neighbors. + * Run the connect HOSTNAME/IP command in the terminal. Can only connect to neighbors. * * @returns True if the connect command was successful, false otherwise. */ - connect(hostname: string): boolean; + connect(host: string): boolean; /** * Run the hack command in the terminal. @@ -3079,7 +3079,7 @@ export interface Hacknet { * * The name of the upgrade must be an exact match. * The `upgTarget` argument is used for upgrades such as `Reduce Minimum Security`, which applies to a specific server. - * In this case, the `upgTarget` argument must be the hostname of the server. + * In this case, the `upgTarget` argument must be the hostname or IP of the server. * * @example * ```js @@ -3898,7 +3898,7 @@ export interface CodingContract { * * @param answer - Attempted solution for the contract. This can be a string formatted like submitting manually, or the answer in the format of the specific contract type. * @param filename - Filename of the contract. - * @param host - Hostname of the server containing the contract. Optional. Defaults to current server if not + * @param host - Hostname/IP of the server containing the contract. Optional. Defaults to current server if not * provided. * @returns A reward description string on success, or an empty string on failure. */ @@ -3913,7 +3913,7 @@ export interface CodingContract { * (e.g. Find Largest Prime Factor, Total Ways to Sum, etc.) * * @param filename - Filename of the contract. - * @param host - Hostname of the server containing the contract. Optional. Defaults to current server if not provided. + * @param host - Hostname/IP of the server containing the contract. Optional. Defaults to current server if not provided. * @returns Name describing the type of problem posed by the Coding Contract. */ getContractType(filename: string, host?: string): `${CodingContractName}`; @@ -3926,7 +3926,7 @@ export interface CodingContract { * Get the full text description for the problem posed by the Coding Contract. * * @param filename - Filename of the contract. - * @param host - Hostname of the server containing the contract. Optional. Defaults to current server if not provided. + * @param host - Hostname/IP of the server containing the contract. Optional. Defaults to current server if not provided. * @returns Contract’s text description. */ getDescription(filename: string, host?: string): string; @@ -3941,7 +3941,7 @@ export interface CodingContract { * This is just the data that the contract wants you to act on in order to solve the contract. * * @param filename - Filename of the contract. - * @param host - Host of the server containing the contract. Optional. Defaults to current server if not provided. + * @param host - Hostname/IP of the server containing the contract. Optional. Defaults to current server if not provided. * @returns The specified contract’s data, data type depends on contract type. */ getData(filename: string, host?: string): any; @@ -3965,7 +3965,7 @@ export interface CodingContract { * ``` * * @param filename - Filename of the contract. - * @param host - Host of the server containing the contract. Optional. Default to the current server if not provided. + * @param host - Hostname/IP of the server containing the contract. Optional. Default to the current server if not provided. * @returns An object containing various data about the contract specified. */ getContract(filename: string, host?: string): CodingContractObject; @@ -3978,7 +3978,7 @@ export interface CodingContract { * Get the number of tries remaining on the contract before it self-destructs. * * @param filename - Filename of the contract. - * @param host - Hostname of the server containing the contract. Optional. Defaults to current server if not provided. + * @param host - Hostname/IP of the server containing the contract. Optional. Defaults to current server if not provided. * @returns How many attempts are remaining for the contract. */ getNumTriesRemaining(filename: string, host?: string): number; @@ -5771,7 +5771,7 @@ interface UserInterface { * ns.tail("foo.js", "foodnstuff", 1, "test"); * ``` * @param fn - Optional. Filename or PID of the script being tailed. If omitted, the current script is tailed. - * @param host - Optional. Hostname of the script being tailed. Defaults to the server this script is running on. If args are specified, this is not optional. + * @param host - Optional. Hostname/IP of the script being tailed. Defaults to the server this script is running on. If args are specified, this is not optional. * @param args - Arguments for the script being tailed. */ openTail(fn?: FilenameOrPID, host?: string, ...args: ScriptArg[]): void; @@ -5871,7 +5871,7 @@ interface UserInterface { * * @param pixel - Optional. The new font size in pixels. If omitted, the default tail font size is used. * @param fn - Optional. Filename or PID of the target script. If omitted, the current script is used. - * @param host - Optional. Hostname of the target script. Defaults to the server this script is running on. If args are specified, this is not optional. + * @param host - Optional. Hostname/IP of the target script. Defaults to the server this script is running on. If args are specified, this is not optional. * @param args - Arguments for the target script. */ setTailFontSize(pixel?: number, fn?: FilenameOrPID, host?: string, ...args: ScriptArg[]): void; @@ -6112,7 +6112,7 @@ export interface NS { * ```js * let earnedMoney = await ns.hack("foodnstuff"); * ``` - * @param host - Hostname of the target server to hack. + * @param host - Hostname/IP of the target server to hack. * @param opts - Optional parameters for configuring function behavior. * @returns A promise that resolves to the amount of money stolen (which is zero if the hack is unsuccessful). */ @@ -6158,7 +6158,7 @@ export interface NS { * let currentMoney = ns.getServerMoneyAvailable("n00dles"); * currentMoney *= await ns.grow("n00dles"); * ``` - * @param host - Hostname of the target server to grow. + * @param host - Hostname/IP of the target server to grow. * @param opts - Optional parameters for configuring function behavior. * @returns The total effective multiplier that was applied to the server's money (after both additive and multiplicative growth). */ @@ -6185,7 +6185,7 @@ export interface NS { * let currentSecurity = ns.getServerSecurityLevel("foodnstuff"); * currentSecurity -= await ns.weaken("foodnstuff"); * ``` - * @param host - Hostname of the target server to weaken. + * @param host - Hostname/IP of the target server to weaken. * @param opts - Optional parameters for configuring function behavior. * @returns A promise that resolves to the value by which security was reduced. */ @@ -6247,7 +6247,7 @@ export interface NS { * const hackAmount = ns.hackAnalyze("foodnstuff"); * //This means that if hack the foodnstuff server using a single thread, then you will steal 1%, or 0.01 of its total money. If you hack using N threads, then you will steal N*0.01 times its total money. * ``` - * @param host - Hostname of the target server. + * @param host - Hostname/IP of the target server. * @returns The part of money you will steal from the target server with a single thread hack. */ hackAnalyze(host: string): number; @@ -6260,10 +6260,10 @@ export interface NS { * Returns the security increase that would occur if a hack with this many threads happened. * * @param threads - Amount of threads that will be used. - * @param hostname - Hostname of the target server. The number of threads is limited to the number needed to hack the server's maximum amount of money. + * @param host - Hostname/IP of the target server. The number of threads is limited to the number needed to hack the server's maximum amount of money. * @returns The security increase. */ - hackAnalyzeSecurity(threads: number, hostname?: string): number; + hackAnalyzeSecurity(threads: number, host?: string): number; /** * Get the chance of successfully hacking a server. @@ -6277,7 +6277,7 @@ export interface NS { * Like other basic hacking analysis functions, this calculation uses the current status of the player and server. * To calculate using hypothetical server or player status, obtain access to the Formulas API and use {@link HackingFormulas.hackChance | formulas.hacking.hackChance}. * - * @param host - Hostname of the target server. + * @param host - Hostname/IP of the target server. * @returns The chance you have of successfully hacking the target server. */ hackAnalyzeChance(host: string): number; @@ -6307,7 +6307,7 @@ export interface NS { * // When using the thread count to launch a script, it needs to be converted to an integer. * ns.run("noodleGrow.js", Math.ceil(growThreads)); * ``` - * @param host - Hostname of the target server. + * @param host - Hostname/IP of the target server. * @param multiplier - Multiplier that will be applied to a server's money after applying additive growth. Decimal form. * @param cores - Number of cores on the host running the grow function. Optional, defaults to 1. * @returns Decimal number of grow threads needed for the specified multiplicative growth factor (does not include additive growth). @@ -6322,11 +6322,11 @@ export interface NS { * Returns the security increase that would occur if a grow with this many threads happened. * * @param threads - Amount of threads that will be used. - * @param hostname - Optional. Hostname of the target server. If provided, security increase is limited by the number of threads needed to reach maximum money. + * @param host - Optional. Hostname/IP of the target server. If provided, security increase is limited by the number of threads needed to reach maximum money. * @param cores - Optional. The number of cores of the server that would run grow. * @returns The security increase. */ - growthAnalyzeSecurity(threads: number, hostname?: string, cores?: number): number; + growthAnalyzeSecurity(threads: number, host?: string, cores?: number): number; readonly heart: { /** @@ -6578,7 +6578,7 @@ export interface NS { * ns.getScriptLogs("foo.js", "foodnstuff", 1, "test"); * ``` * @param fn - Optional. Filename or PID of script to get logs from. - * @param host - Optional. Hostname of the server that the script is on. + * @param host - Optional. Hostname/IP of the server that the script is on. * @param args - Arguments to identify which scripts to get logs for. * @returns Returns a string array, where each line is an element in the array. The most recently logged line is at the end of the array. */ @@ -6770,7 +6770,7 @@ export interface NS { * } * ``` * - * @param host - Optional. Hostname of the server to scan, default to current server. + * @param host - Optional. Hostname/IP of the server to scan, default to current server. * @returns Returns an array of hostnames. */ scan(host?: string): string[]; @@ -6786,7 +6786,7 @@ export interface NS { * * Works identically to {@link NS.scan | ns.scan}. * - * @param host - Optional. Hostname of the server to scan, default to current server. + * @param host - Optional. Hostname/IP of the server to scan, default to current server. * @returns Returns an array of IP addresses */ scanByIP(host?: string): string[]; @@ -6823,7 +6823,7 @@ export interface NS { * ```js * ns.nuke("foodnstuff"); * ``` - * @param host - Hostname of the target server. + * @param host - Hostname/IP of the target server. * @returns True if the player runs the program successfully, and false otherwise. */ nuke(host: string): boolean; @@ -6839,7 +6839,7 @@ export interface NS { * ```js * ns.brutessh("foodnstuff"); * ``` - * @param host - Hostname of the target server. + * @param host - Hostname/IP of the target server. * @returns True if the player runs the program successfully, and false otherwise. */ brutessh(host: string): boolean; @@ -6855,7 +6855,7 @@ export interface NS { * ```js * ns.ftpcrack("foodnstuff"); * ``` - * @param host - Hostname of the target server. + * @param host - Hostname/IP of the target server. * @returns True if the player runs the program successfully, and false otherwise. */ ftpcrack(host: string): boolean; @@ -6871,7 +6871,7 @@ export interface NS { * ```js * ns.relaysmtp("foodnstuff"); * ``` - * @param host - Hostname of the target server. + * @param host - Hostname/IP of the target server. * @returns True if the player runs the program successfully, and false otherwise. */ relaysmtp(host: string): boolean; @@ -6887,7 +6887,7 @@ export interface NS { * ```js * ns.httpworm("foodnstuff"); * ``` - * @param host - Hostname of the target server. + * @param host - Hostname/IP of the target server. * @returns True if the player runs the program successfully, and false otherwise. */ httpworm(host: string): boolean; @@ -6903,7 +6903,7 @@ export interface NS { * ```js * ns.sqlinject("foodnstuff"); * ``` - * @param host - Hostname of the target server. + * @param host - Hostname/IP of the target server. * @returns True if the player runs the program successfully, and false otherwise. */ sqlinject(host: string): boolean; @@ -6979,12 +6979,12 @@ export interface NS { * ns.exec("foo.js", "foodnstuff", 5, 1, "test"); * ``` * @param script - Filename of script to execute. This file must already exist on the target server. - * @param hostname - Hostname of the `target server` on which to execute the script. + * @param host - Hostname/IP of the `target server` on which to execute the script. * @param threadOrOptions - Either an integer number of threads for new script, or a {@link RunOptions} object. Threads defaults to 1. * @param args - Additional arguments to pass into the new script that is being run. Note that if any arguments are being passed into the new script, then the third argument threadOrOptions must be filled in with a value. * @returns Returns the PID of a successfully started script, and 0 otherwise. */ - exec(script: string, hostname: string, threadOrOptions?: number | RunOptions, ...args: ScriptArg[]): number; + exec(script: string, host: string, threadOrOptions?: number | RunOptions, ...args: ScriptArg[]): number; /** * Terminate current script and start another in a defined number of milliseconds. @@ -7027,7 +7027,7 @@ export interface NS { * RAM cost: 0.5 GB * * Kills the script with the provided PID. - * To instead kill a script using its filename, hostname, and args, see {@link NS.(kill:2) | the other ns.kill entry}. + * To instead kill a script using its filename, host, and args, see {@link NS.(kill:2) | the other ns.kill entry}. * * @example * ```js @@ -7041,7 +7041,7 @@ export interface NS { kill(pid: number): boolean; /** - * Terminate the script(s) with the provided filename, hostname, and script arguments. + * Terminate the script(s) with the provided filename, host, and script arguments. * @remarks * RAM cost: 0.5 GB * @@ -7060,11 +7060,11 @@ export interface NS { * ns.kill("foo.js", ns.getHostname(), 1, "foodnstuff", false); * ``` * @param filename - Filename of the script to kill. - * @param hostname - Hostname where the script to kill is running. Defaults to the current server. + * @param host - Hostname/IP where the script to kill is running. Defaults to the current server. * @param args - Arguments of the script to kill. * @returns True if the scripts were successfully killed, and false otherwise. */ - kill(filename: string, hostname?: string, ...args: ScriptArg[]): boolean; + kill(filename: string, host?: string, ...args: ScriptArg[]): boolean; /** * Terminate all scripts on a server. @@ -7076,7 +7076,7 @@ export interface NS { * true if there are any scripts running on the target server. * If no host is defined, it will kill all scripts, where the script is running. * - * @param host - IP or hostname of the server on which to kill all scripts. + * @param host - Hostname/IP of the server on which to kill all scripts. * @param safetyGuard - Skips the script that calls this function * @returns True if any scripts were killed, and false otherwise. */ @@ -7113,8 +7113,8 @@ export interface NS { * ns.scp(files, server, "home"); * ``` * @param files - Filename or an array of filenames of script/literature files to copy. Note that if a file is located in a subdirectory, the filename must include the leading `/`. - * @param destination - Hostname of the destination server, which is the server to which the file will be copied. - * @param source - Hostname of the source server, which is the server from which the file will be copied. This argument is optional and if it’s omitted the source will be the current server. + * @param destination - Hostname/IP of the destination server, which is the server to which the file will be copied. + * @param source - Hostname/IP of the source server, which is the server from which the file will be copied. This argument is optional and if it’s omitted the source will be the current server. * @returns True if the file is successfully copied over and false otherwise. If the files argument is an array then this function will return false if any of the operations failed. */ scp(files: string | string[], destination: string, source?: string): boolean; @@ -7127,7 +7127,7 @@ export interface NS { * Returns an array with the filenames of all files on the specified server * (as strings). The returned array is sorted in alphabetic order. * - * @param host - Hostname of the target server. + * @param host - Hostname/IP of the target server. * @param substring - A substring to search for in the filename. * @returns Array with the filenames of all files on the specified server. */ @@ -7148,7 +7148,7 @@ export interface NS { * ns.tprint(script.args); * } * ``` - * @param host - Host address of the target server. If not specified, it will be the current server’s IP by default. + * @param host - Hostname/IP of the target server. If not specified, it will be the current server’s IP by default. * @returns Array with general information about all scripts running on the specified target server. */ ps(host?: string): ProcessInfo[]; @@ -7166,7 +7166,7 @@ export interface NS { * ns.nuke("foodnstuff"); * } * ``` - * @param host - Hostname of the target server. + * @param host - Hostname/IP of the target server. * @returns True if player has root access to the specified target server, and false otherwise. */ hasRootAccess(host: string): boolean; @@ -7241,7 +7241,7 @@ export interface NS { * * @remarks * RAM cost: 2 GB - * @param host - Optional. Hostname for the requested server object. + * @param host - Optional. Hostname/IP for the requested server object. * @returns The requested server object. */ getServer(host?: string): Server; @@ -7259,7 +7259,7 @@ export interface NS { * ns.getServerMoneyAvailable("foodnstuff"); * ns.getServerMoneyAvailable("home"); // Returns player's money * ``` - * @param host - Hostname of target server. + * @param host - Hostname/IP of target server. * @returns Amount of money available on the server. */ getServerMoneyAvailable(host: string): number; @@ -7271,7 +7271,7 @@ export interface NS { * * Returns the maximum amount of money that can be available on a server. * - * @param host - Hostname of target server. + * @param host - Hostname/IP of target server. * @returns Maximum amount of money available on the server. */ getServerMaxMoney(host: string): number; @@ -7288,7 +7288,7 @@ export interface NS { * grow function. A higher growth parameter will result in a * higher percentage increase from grow. * - * @param host - Hostname of target server. + * @param host - Hostname/IP of target server. * @returns Parameter that affects the percentage by which the server’s money is increased when using the grow function. */ getServerGrowth(host: string): number; @@ -7302,7 +7302,7 @@ export interface NS { * level is denoted by a number, typically between 1 and 100 * (but it can go above 100). * - * @param host - Hostname of target server. + * @param host - Hostname/IP of target server. * @returns Security level of the target server. */ getServerSecurityLevel(host: string): number; @@ -7311,7 +7311,7 @@ export interface NS { * Returns the minimum security level of the target server. * * @remarks RAM cost: 0.1 GB - * @param host - Hostname of target server. + * @param host - Hostname/IP of target server. * @returns Minimum security level of the target server. */ getServerMinSecurityLevel(host: string): number; @@ -7323,7 +7323,7 @@ export interface NS { * Returns the base security level of the target server. * For the server's actual security level, use {@link NS.getServerSecurityLevel | ns.getServerSecurityLevel}. * - * @param host - Host of target server. + * @param host - Hostname/IP of target server. * @returns Base security level of the target server. */ getServerBaseSecurityLevel(host: string): number; @@ -7333,7 +7333,7 @@ export interface NS { * @remarks * RAM cost: 0.05 GB * - * @param host - Hostname of the target server. + * @param host - Hostname/IP of the target server. * @returns The maximum amount of RAM (GB) a server can have. */ getServerMaxRam(host: string): number; @@ -7342,7 +7342,7 @@ export interface NS { * @remarks * RAM cost: 0.05 GB * - * @param host - Hostname of the target server. + * @param host - Hostname/IP of the target server. * @returns The amount of used RAM (GB) on the specified server. */ getServerUsedRam(host: string): number; @@ -7351,7 +7351,7 @@ export interface NS { * Returns the required hacking level of the target server. * * @remarks RAM cost: 0.1 GB - * @param host - Hostname of target server. + * @param host - Hostname/IP of target server. * @returns The required hacking level of the target server. */ getServerRequiredHackingLevel(host: string): number; @@ -7360,7 +7360,7 @@ export interface NS { * Returns the number of open ports required to successfully run NUKE.exe on the specified server. * * @remarks RAM cost: 0.1 GB - * @param host - Hostname of target server. + * @param host - Hostname/IP of target server. * @returns The number of open ports required to successfully run NUKE.exe on the specified server. */ getServerNumPortsRequired(host: string): number; @@ -7369,8 +7369,8 @@ export interface NS { * Given a hostname, returns an IP address, * Given an IP address, returns a hostname * - * @remarks RAM cost: 0.05 GB - * @param host - Hostname or IP address of target server. + * @remarks RAM cost: 0 GB + * @param host - Hostname/IP of target server. */ dnsLookup(host: string): string @@ -7378,7 +7378,7 @@ export interface NS { * Returns a boolean denoting whether or not the specified server exists. * * @remarks RAM cost: 0.1 GB - * @param host - Hostname of target server. + * @param host - Hostname/IP of target server. * @returns True if the specified server exists, and false otherwise. */ serverExists(host: string): boolean; @@ -7402,7 +7402,7 @@ export interface NS { * ns.fileExists("ftpcrack.exe"); * ``` * @param filename - Filename of file to check. - * @param host - Host of target server. Optional, defaults to the server the script is running on. + * @param host - Hostname/IP of target server. Optional, defaults to the server the script is running on. * @returns True if specified file exists, and false otherwise. */ fileExists(filename: string, host?: string): boolean; @@ -7413,8 +7413,8 @@ export interface NS { * RAM cost: 0.1 GB * * Returns a boolean indicating whether the specified script is running on the target server. - * If you use a PID instead of a filename, the hostname and args parameters are unnecessary. - * If hostname is omitted while filename is used as the first parameter, hostname defaults to the server the calling script is running on. + * If you use a PID instead of a filename, the host and args parameters are unnecessary. + * If host is omitted while filename is used as the first parameter, host defaults to the server the calling script is running on. * Remember that a script is semi-uniquely identified by both its name and its arguments. * (You can run multiple copies of scripts with the same arguments, but for the purposes of * functions like this that check based on filename, the filename plus arguments forms the key.) @@ -7431,7 +7431,7 @@ export interface NS { * ns.isRunning("foo.js", "joesguns", 1, 5, "test"); * ``` * @param script - Filename or PID of script to check. This is case-sensitive. - * @param host - Hostname of target server. Optional, defaults to the server the calling script is running on. + * @param host - Hostname/IP of target server. Optional, defaults to the server the calling script is running on. * @param args - Arguments to specify/identify the script. Optional, when looking for scripts run without arguments. * @returns True if the specified script is running on the target server, and false otherwise. */ @@ -7443,18 +7443,18 @@ export interface NS { * RAM cost: 0.3 GB * * Running with no args returns current script. - * If you use a PID as the first parameter, the hostname and args parameters are unnecessary. - * If hostname is omitted while filename is used as the first parameter, hostname defaults to the server the calling script is running on. + * If you use a PID as the first parameter, the host and args parameters are unnecessary. + * If host is omitted while filename is used as the first parameter, host defaults to the server the calling script is running on. * Remember that a script is semi-uniquely identified by both its name and its arguments. * (You can run multiple copies of scripts with the same arguments, but for the purposes of * functions like this that check based on filename, the filename plus arguments forms the key.) * * @param filename - Optional. Filename or PID of the script. - * @param hostname - Hostname of target server. Optional, defaults to the server the calling script is running on. + * @param host - Hostname/IP of target server. Optional, defaults to the server the calling script is running on. * @param args - Arguments to specify/identify the script. Optional, when looking for scripts run without arguments. * @returns The info about the running script if found, and null otherwise. */ - getRunningScript(filename?: FilenameOrPID, hostname?: string, ...args: ScriptArg[]): RunningScript | null; + getRunningScript(filename?: FilenameOrPID, host?: string, ...args: ScriptArg[]): RunningScript | null; /** * Change the current static RAM allocation of the script. @@ -7501,9 +7501,9 @@ export interface NS { * Purchase a server with the specified hostname and amount of RAM. * * The hostname argument can be any data type, but it will be converted to a string - * and have whitespace removed. Anything that resolves to an empty string will cause - * the function to fail. If there is already a server with the specified hostname, - * then the function will automatically append a number at the end of the hostname + * and have whitespace removed. Anything that resolves to an empty string or IP address + * will cause the function to fail. If there is already a server with the specified + * hostname, then the function will automatically append a number at the end of the hostname * argument value until it finds a unique hostname. For example, if the script calls * `purchaseServer(“foo”, 4)` but a server named “foo” already exists, then it will * automatically change the hostname to `foo-0`. If there is already a server with the @@ -7537,22 +7537,22 @@ export interface NS { * @remarks * RAM cost: 0.1 GB * - * @param hostname - Hostname of the server to upgrade. + * @param host - Hostname/IP of the server to upgrade. * @param ram - Amount of RAM of the purchased server, in GB. Must be a power of 2 (2, 4, 8, 16, etc.). Maximum value of 1048576 (2^20). - * @returns The price to upgrade or -1 if either input is not valid, i.e. hostname is not the name of a purchased server or ram is not a valid amount. + * @returns The price to upgrade or -1 if either input is not valid, i.e. host is not the name of a purchased server or ram is not a valid amount. */ - getPurchasedServerUpgradeCost(hostname: string, ram: number): number; + getPurchasedServerUpgradeCost(host: string, ram: number): number; /** * Upgrade a purchased server's RAM. * @remarks * RAM cost: 0.25 GB * - * @param hostname - Hostname of the server to upgrade. + * @param host - Hostname/IP of the server to upgrade. * @param ram - Amount of RAM of the purchased server, in GB. Must be a power of 2 (2, 4, 8, 16, etc.). Maximum value of 1048576 (2^20). * @returns True if the upgrade succeeded, and false otherwise. */ - upgradePurchasedServer(hostname: string, ram: number): boolean; + upgradePurchasedServer(host: string, ram: number): boolean; /** * Rename a purchased server. @@ -7570,13 +7570,13 @@ export interface NS { * @remarks * 2.25 GB * - * Deletes one of your purchased servers, which is specified by its hostname. + * Deletes one of your purchased servers, which is specified by its hostname/ip. * - * The hostname argument can be any data type, but it will be converted to a string. + * The host argument can be any data type, but it will be converted to a string. * Whitespace is automatically removed from the string. This function will not delete a * server that still has scripts running on it. * - * @param host - Hostname of the server to delete. + * @param host - Hostname/IP of the server to delete. * @returns True if successful, and false otherwise. */ deleteServer(host: string): boolean; @@ -7763,7 +7763,7 @@ export interface NS { * type except message (.msg) files. * * @param name - Filename of file to remove. Must include the extension. - * @param host - Hostname of the server on which to delete the file. Optional. Defaults to current server. + * @param host - Hostname/IP of the server on which to delete the file. Optional. Defaults to current server. * @returns True if it successfully deletes the file, and false otherwise. */ rm(name: string, host?: string): boolean; @@ -7788,7 +7788,7 @@ export interface NS { * ns.scriptRunning("foo.js", ns.getHostname()); * ``` * @param script - Filename of script to check. This is case-sensitive. - * @param host - Hostname of target server. + * @param host - Hostname/IP of target server. * @returns True if the specified script is running, and false otherwise. */ scriptRunning(script: string, host: string): boolean; @@ -7802,7 +7802,7 @@ export interface NS { * regardless of arguments. * * @param script - Filename of script to kill. This is case-sensitive. - * @param host - Hostname of target server. + * @param host - Hostname/IP of target server. * @returns True if one or more scripts were successfully killed, and false if none were. */ scriptKill(script: string, host: string): boolean; @@ -7824,7 +7824,7 @@ export interface NS { * Returns 0 if the script does not exist. * * @param script - Filename of script. This is case-sensitive. - * @param host - Hostname of target server the script is located on. This is optional. If it is not specified then the function will use the current server as the target server. + * @param host - Hostname/IP of target server the script is located on. This is optional. If it is not specified then the function will use the current server as the target server. * @returns Amount of RAM (in GB) required to run the specified script on the target server, and 0 if the script does not exist. */ getScriptRam(script: string, host?: string): number; @@ -7838,7 +7838,7 @@ export interface NS { * Returns the amount of time in milliseconds it takes to execute the {@link NS.hack | hack} Netscript function on the target server. * The required time is increased by the security level of the target server and decreased by the player's hacking level. * - * @param host - Hostname of target server. + * @param host - Hostname/IP of target server. * @returns Returns the amount of time in milliseconds it takes to execute the {@link NS.hack | hack} Netscript function. */ getHackTime(host: string): number; @@ -7851,7 +7851,7 @@ export interface NS { * Returns the amount of time in milliseconds it takes to execute the grow Netscript function on the target server. * The required time is increased by the security level of the target server and decreased by the player's hacking level. * - * @param host - Hostname of target server. + * @param host - Hostname/IP of target server. * @returns Returns the amount of time in milliseconds it takes to execute the grow Netscript function. */ getGrowTime(host: string): number; @@ -7864,7 +7864,7 @@ export interface NS { * Returns the amount of time in milliseconds it takes to execute the {@link NS.weaken | weaken} Netscript function on the target server. * The required time is increased by the security level of the target server and decreased by the player's hacking level. * - * @param host - Hostname of target server. + * @param host - Hostname/IP of target server. * @returns Returns the amount of time in milliseconds it takes to execute the {@link NS.weaken | weaken} Netscript function. */ getWeakenTime(host: string): number; @@ -7895,7 +7895,7 @@ export interface NS { * those same arguments in the same order in this function call. * * @param script - Filename of script. - * @param host - Server on which script is running. + * @param host - Hostname/IP of the server on which script is running. * @param args - Arguments that the script is running with. * @returns Amount of income the specified script generates while online. */ @@ -7923,7 +7923,7 @@ export interface NS { * scripts by running the function with no arguments. * * @param script - Filename of script. - * @param host - Server on which script is running. + * @param host - Hostname/IP of the server on which script is running. * @param args - Arguments that the script is running with. * @returns Amount of hacking experience the specified script generates while online. */ @@ -8245,7 +8245,7 @@ export interface NS { * * This function can also be used to rename files. * - * @param host - Hostname of target server. + * @param host - Hostname/IP of target server. * @param source - Filename of the source file. * @param destination - Filename of the destination file. */ diff --git a/src/Server/ServerPurchases.ts b/src/Server/ServerPurchases.ts index 0e763c247..5e52a0826 100644 --- a/src/Server/ServerPurchases.ts +++ b/src/Server/ServerPurchases.ts @@ -12,6 +12,7 @@ import { Player } from "@player"; import { dialogBoxCreate } from "../ui/React/DialogBox"; import { isPowerOfTwo } from "../utils/helpers/isPowerOfTwo"; import { workerScripts } from "../Netscript/WorkerScripts"; +import { isIPAddress } from "src/Types/strings"; // Returns the cost of purchasing a server with the given RAM // Returns Infinity for invalid 'ram' arguments @@ -43,7 +44,7 @@ export function getPurchaseServerCost(ram: number): number { export const getPurchasedServerUpgradeCost = (hostname: string, ram: number): number => { const server = GetServer(hostname); if (!server) throw new Error(`Server '${hostname}' not found.`); - if (!Player.purchasedServers.includes(hostname)) throw new Error(`Server '${hostname}' not a purchased server.`); + if (!Player.purchasedServers.includes(server.hostname)) throw new Error(`Server '${hostname}' not a purchased server.`); if (isNaN(ram) || !isPowerOfTwo(ram) || !(Math.sign(ram) === 1)) throw new Error(`${ram} is not a positive power of 2`); if (server.maxRam >= ram) @@ -61,8 +62,10 @@ export const upgradePurchasedServer = (hostname: string, ram: number): void => { }; export const renamePurchasedServer = (hostname: string, newName: string): void => { + if (isIPAddress(hostname)) throw new Error(`${hostname} is an IP address, not a hostname.`) const server = GetServer(hostname); if (!server) throw new Error(`Server '${hostname}' doesn't exists.`); + if (newName == "" || isIPAddress(newName)) throw new Error(`${newName} is an invalid hostname.`) if (GetServer(newName)) throw new Error(`Server '${newName}' already exists.`); if (!Player.purchasedServers.includes(hostname)) throw new Error(`Server '${hostname}' is not a player server.`); if (newName.startsWith("hacknet-node-") || newName.startsWith("hacknet-server-")) { From 6d9cd8d2ffcb8b189c47cd41baf3c32892ecfeee Mon Sep 17 00:00:00 2001 From: Naga Ouroboros Date: Sat, 1 Mar 2025 02:00:23 -0500 Subject: [PATCH 06/11] FIX: Correct bad import path --- src/Server/ServerPurchases.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Server/ServerPurchases.ts b/src/Server/ServerPurchases.ts index 5e52a0826..a8904ebe4 100644 --- a/src/Server/ServerPurchases.ts +++ b/src/Server/ServerPurchases.ts @@ -12,7 +12,7 @@ import { Player } from "@player"; import { dialogBoxCreate } from "../ui/React/DialogBox"; import { isPowerOfTwo } from "../utils/helpers/isPowerOfTwo"; import { workerScripts } from "../Netscript/WorkerScripts"; -import { isIPAddress } from "src/Types/strings"; +import { isIPAddress } from "../Types/strings"; // Returns the cost of purchasing a server with the given RAM // Returns Infinity for invalid 'ram' arguments From f0aee770d0d7698f2e8f9cbc1055786d2d2933b4 Mon Sep 17 00:00:00 2001 From: Naga Ouroboros Date: Sun, 2 Mar 2025 05:53:25 -0500 Subject: [PATCH 07/11] CHORE: Run tests, format, lint, and documentation tasks --- markdown/bitburner.codingcontract.attempt.md | 2 +- .../bitburner.codingcontract.getcontract.md | 2 +- ...itburner.codingcontract.getcontracttype.md | 2 +- markdown/bitburner.codingcontract.getdata.md | 2 +- ...bitburner.codingcontract.getdescription.md | 2 +- ...ner.codingcontract.getnumtriesremaining.md | 2 +- markdown/bitburner.hacknet.spendhashes.md | 2 +- markdown/bitburner.ns.brutessh.md | 2 +- markdown/bitburner.ns.deleteserver.md | 6 ++-- markdown/bitburner.ns.dnslookup.md | 28 +++++++++++++++ markdown/bitburner.ns.exec.md | 4 +-- markdown/bitburner.ns.fileexists.md | 2 +- markdown/bitburner.ns.ftpcrack.md | 2 +- markdown/bitburner.ns.getgrowtime.md | 2 +- markdown/bitburner.ns.gethacktime.md | 2 +- markdown/bitburner.ns.getip.md | 23 +++++++++++++ .../bitburner.ns.getpurchasedserversbyip.md | 23 +++++++++++++ ...burner.ns.getpurchasedserverupgradecost.md | 6 ++-- markdown/bitburner.ns.getrunningscript.md | 6 ++-- markdown/bitburner.ns.getscriptexpgain.md | 2 +- markdown/bitburner.ns.getscriptincome.md | 2 +- markdown/bitburner.ns.getscriptlogs.md | 2 +- markdown/bitburner.ns.getscriptram.md | 2 +- markdown/bitburner.ns.getserver.md | 2 +- ...bitburner.ns.getserverbasesecuritylevel.md | 2 +- markdown/bitburner.ns.getservergrowth.md | 2 +- markdown/bitburner.ns.getservermaxmoney.md | 2 +- markdown/bitburner.ns.getservermaxram.md | 2 +- .../bitburner.ns.getserverminsecuritylevel.md | 2 +- .../bitburner.ns.getservermoneyavailable.md | 2 +- .../bitburner.ns.getservernumportsrequired.md | 2 +- ...burner.ns.getserverrequiredhackinglevel.md | 2 +- .../bitburner.ns.getserversecuritylevel.md | 2 +- markdown/bitburner.ns.getserverusedram.md | 2 +- markdown/bitburner.ns.getweakentime.md | 2 +- markdown/bitburner.ns.grow.md | 2 +- markdown/bitburner.ns.growthanalyze.md | 2 +- .../bitburner.ns.growthanalyzesecurity.md | 4 +-- markdown/bitburner.ns.hack.md | 2 +- markdown/bitburner.ns.hackanalyze.md | 2 +- markdown/bitburner.ns.hackanalyzechance.md | 2 +- markdown/bitburner.ns.hackanalyzesecurity.md | 4 +-- markdown/bitburner.ns.hasrootaccess.md | 2 +- markdown/bitburner.ns.httpworm.md | 2 +- markdown/bitburner.ns.isrunning.md | 4 +-- markdown/bitburner.ns.kill.md | 2 +- markdown/bitburner.ns.kill_1.md | 6 ++-- markdown/bitburner.ns.killall.md | 2 +- markdown/bitburner.ns.ls.md | 2 +- markdown/bitburner.ns.md | 18 ++++++---- markdown/bitburner.ns.mv.md | 2 +- markdown/bitburner.ns.nuke.md | 2 +- markdown/bitburner.ns.ps.md | 2 +- markdown/bitburner.ns.purchaseserver.md | 2 +- markdown/bitburner.ns.relaysmtp.md | 2 +- markdown/bitburner.ns.rm.md | 2 +- markdown/bitburner.ns.scan.md | 2 +- markdown/bitburner.ns.scanbyip.md | 34 +++++++++++++++++++ markdown/bitburner.ns.scp.md | 4 +-- markdown/bitburner.ns.scriptkill.md | 2 +- markdown/bitburner.ns.scriptrunning.md | 2 +- markdown/bitburner.ns.serverexists.md | 2 +- markdown/bitburner.ns.sqlinject.md | 2 +- .../bitburner.ns.upgradepurchasedserver.md | 4 +-- markdown/bitburner.ns.weaken.md | 2 +- markdown/bitburner.singularity.connect.md | 6 ++-- markdown/bitburner.singularity.md | 2 +- markdown/bitburner.userinterface.opentail.md | 2 +- ...bitburner.userinterface.settailfontsize.md | 2 +- src/NetscriptFunctions.ts | 6 ++-- src/ScriptEditor/NetscriptDefinitions.d.ts | 16 ++++----- src/Server/ServerPurchases.ts | 7 ++-- src/Terminal/Terminal.ts | 2 +- 73 files changed, 215 insertions(+), 102 deletions(-) create mode 100644 markdown/bitburner.ns.dnslookup.md create mode 100644 markdown/bitburner.ns.getip.md create mode 100644 markdown/bitburner.ns.getpurchasedserversbyip.md create mode 100644 markdown/bitburner.ns.scanbyip.md diff --git a/markdown/bitburner.codingcontract.attempt.md b/markdown/bitburner.codingcontract.attempt.md index 984768d59..d903bc41f 100644 --- a/markdown/bitburner.codingcontract.attempt.md +++ b/markdown/bitburner.codingcontract.attempt.md @@ -18,7 +18,7 @@ attempt(answer: any, filename: string, host?: string): string; | --- | --- | --- | | answer | any | Attempted solution for the contract. This can be a string formatted like submitting manually, or the answer in the format of the specific contract type. | | filename | string | Filename of the contract. | -| host | string | _(Optional)_ Hostname of the server containing the contract. Optional. Defaults to current server if not provided. | +| host | string | _(Optional)_ Hostname/IP of the server containing the contract. Optional. Defaults to current server if not provided. | **Returns:** diff --git a/markdown/bitburner.codingcontract.getcontract.md b/markdown/bitburner.codingcontract.getcontract.md index b6c2cfdf9..f64cb9842 100644 --- a/markdown/bitburner.codingcontract.getcontract.md +++ b/markdown/bitburner.codingcontract.getcontract.md @@ -17,7 +17,7 @@ getContract(filename: string, host?: string): CodingContractObject; | Parameter | Type | Description | | --- | --- | --- | | filename | string | Filename of the contract. | -| host | string | _(Optional)_ Host of the server containing the contract. Optional. Default to the current server if not provided. | +| host | string | _(Optional)_ Hostname/IP of the server containing the contract. Optional. Default to the current server if not provided. | **Returns:** diff --git a/markdown/bitburner.codingcontract.getcontracttype.md b/markdown/bitburner.codingcontract.getcontracttype.md index 8735daacc..9c5e3815c 100644 --- a/markdown/bitburner.codingcontract.getcontracttype.md +++ b/markdown/bitburner.codingcontract.getcontracttype.md @@ -17,7 +17,7 @@ getContractType(filename: string, host?: string): `${CodingContractName}`; | Parameter | Type | Description | | --- | --- | --- | | filename | string | Filename of the contract. | -| host | string | _(Optional)_ Hostname of the server containing the contract. Optional. Defaults to current server if not provided. | +| host | string | _(Optional)_ Hostname/IP of the server containing the contract. Optional. Defaults to current server if not provided. | **Returns:** diff --git a/markdown/bitburner.codingcontract.getdata.md b/markdown/bitburner.codingcontract.getdata.md index f033b8eac..f69df8d52 100644 --- a/markdown/bitburner.codingcontract.getdata.md +++ b/markdown/bitburner.codingcontract.getdata.md @@ -17,7 +17,7 @@ getData(filename: string, host?: string): any; | Parameter | Type | Description | | --- | --- | --- | | filename | string | Filename of the contract. | -| host | string | _(Optional)_ Host of the server containing the contract. Optional. Defaults to current server if not provided. | +| host | string | _(Optional)_ Hostname/IP of the server containing the contract. Optional. Defaults to current server if not provided. | **Returns:** diff --git a/markdown/bitburner.codingcontract.getdescription.md b/markdown/bitburner.codingcontract.getdescription.md index 3fcfb4ae3..7919e82cc 100644 --- a/markdown/bitburner.codingcontract.getdescription.md +++ b/markdown/bitburner.codingcontract.getdescription.md @@ -17,7 +17,7 @@ getDescription(filename: string, host?: string): string; | Parameter | Type | Description | | --- | --- | --- | | filename | string | Filename of the contract. | -| host | string | _(Optional)_ Hostname of the server containing the contract. Optional. Defaults to current server if not provided. | +| host | string | _(Optional)_ Hostname/IP of the server containing the contract. Optional. Defaults to current server if not provided. | **Returns:** diff --git a/markdown/bitburner.codingcontract.getnumtriesremaining.md b/markdown/bitburner.codingcontract.getnumtriesremaining.md index 821734b69..73176a942 100644 --- a/markdown/bitburner.codingcontract.getnumtriesremaining.md +++ b/markdown/bitburner.codingcontract.getnumtriesremaining.md @@ -17,7 +17,7 @@ getNumTriesRemaining(filename: string, host?: string): number; | Parameter | Type | Description | | --- | --- | --- | | filename | string | Filename of the contract. | -| host | string | _(Optional)_ Hostname of the server containing the contract. Optional. Defaults to current server if not provided. | +| host | string | _(Optional)_ Hostname/IP of the server containing the contract. Optional. Defaults to current server if not provided. | **Returns:** diff --git a/markdown/bitburner.hacknet.spendhashes.md b/markdown/bitburner.hacknet.spendhashes.md index 1f2a824bf..1d9d64701 100644 --- a/markdown/bitburner.hacknet.spendhashes.md +++ b/markdown/bitburner.hacknet.spendhashes.md @@ -34,7 +34,7 @@ This function is only applicable for Hacknet Servers (the upgraded version of a Spend the hashes generated by your Hacknet Servers on an upgrade. Returns a boolean value - true if the upgrade is successfully purchased, and false otherwise. -The name of the upgrade must be an exact match. The `upgTarget` argument is used for upgrades such as `Reduce Minimum Security`, which applies to a specific server. In this case, the `upgTarget` argument must be the hostname of the server. +The name of the upgrade must be an exact match. The `upgTarget` argument is used for upgrades such as `Reduce Minimum Security`, which applies to a specific server. In this case, the `upgTarget` argument must be the hostname or IP of the server. ## Example diff --git a/markdown/bitburner.ns.brutessh.md b/markdown/bitburner.ns.brutessh.md index f54b9a928..9b2b7e51c 100644 --- a/markdown/bitburner.ns.brutessh.md +++ b/markdown/bitburner.ns.brutessh.md @@ -16,7 +16,7 @@ brutessh(host: string): boolean; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server. | +| host | string | Hostname/IP of the target server. | **Returns:** diff --git a/markdown/bitburner.ns.deleteserver.md b/markdown/bitburner.ns.deleteserver.md index b2634328c..c346414ba 100644 --- a/markdown/bitburner.ns.deleteserver.md +++ b/markdown/bitburner.ns.deleteserver.md @@ -16,7 +16,7 @@ deleteServer(host: string): boolean; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the server to delete. | +| host | string | Hostname/IP of the server to delete. | **Returns:** @@ -28,7 +28,7 @@ True if successful, and false otherwise. 2.25 GB -Deletes one of your purchased servers, which is specified by its hostname. +Deletes one of your purchased servers, which is specified by its hostname/ip. -The hostname argument can be any data type, but it will be converted to a string. Whitespace is automatically removed from the string. This function will not delete a server that still has scripts running on it. +The host argument can be any data type, but it will be converted to a string. Whitespace is automatically removed from the string. This function will not delete a server that still has scripts running on it. diff --git a/markdown/bitburner.ns.dnslookup.md b/markdown/bitburner.ns.dnslookup.md new file mode 100644 index 000000000..4a43b7f87 --- /dev/null +++ b/markdown/bitburner.ns.dnslookup.md @@ -0,0 +1,28 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [dnsLookup](./bitburner.ns.dnslookup.md) + +## NS.dnsLookup() method + +Given a hostname, returns an IP address, Given an IP address, returns a hostname + +**Signature:** + +```typescript +dnsLookup(host: string): string; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| host | string | Hostname/IP of target server. | + +**Returns:** + +string + +## Remarks + +RAM cost: 0 GB + diff --git a/markdown/bitburner.ns.exec.md b/markdown/bitburner.ns.exec.md index f47ed17a7..539994282 100644 --- a/markdown/bitburner.ns.exec.md +++ b/markdown/bitburner.ns.exec.md @@ -9,7 +9,7 @@ Start another script on any server. **Signature:** ```typescript -exec(script: string, hostname: string, threadOrOptions?: number | RunOptions, ...args: ScriptArg[]): number; +exec(script: string, host: string, threadOrOptions?: number | RunOptions, ...args: ScriptArg[]): number; ``` ## Parameters @@ -17,7 +17,7 @@ exec(script: string, hostname: string, threadOrOptions?: number | RunOptions, .. | Parameter | Type | Description | | --- | --- | --- | | script | string | Filename of script to execute. This file must already exist on the target server. | -| hostname | string | Hostname of the target server on which to execute the script. | +| host | string | Hostname/IP of the target server on which to execute the script. | | threadOrOptions | number \| [RunOptions](./bitburner.runoptions.md) | _(Optional)_ Either an integer number of threads for new script, or a [RunOptions](./bitburner.runoptions.md) object. Threads defaults to 1. | | args | [ScriptArg](./bitburner.scriptarg.md)\[\] | Additional arguments to pass into the new script that is being run. Note that if any arguments are being passed into the new script, then the third argument threadOrOptions must be filled in with a value. | diff --git a/markdown/bitburner.ns.fileexists.md b/markdown/bitburner.ns.fileexists.md index 620217cce..1c8294707 100644 --- a/markdown/bitburner.ns.fileexists.md +++ b/markdown/bitburner.ns.fileexists.md @@ -17,7 +17,7 @@ fileExists(filename: string, host?: string): boolean; | Parameter | Type | Description | | --- | --- | --- | | filename | string | Filename of file to check. | -| host | string | _(Optional)_ Host of target server. Optional, defaults to the server the script is running on. | +| host | string | _(Optional)_ Hostname/IP of target server. Optional, defaults to the server the script is running on. | **Returns:** diff --git a/markdown/bitburner.ns.ftpcrack.md b/markdown/bitburner.ns.ftpcrack.md index 6c3de89bb..6461751c9 100644 --- a/markdown/bitburner.ns.ftpcrack.md +++ b/markdown/bitburner.ns.ftpcrack.md @@ -16,7 +16,7 @@ ftpcrack(host: string): boolean; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server. | +| host | string | Hostname/IP of the target server. | **Returns:** diff --git a/markdown/bitburner.ns.getgrowtime.md b/markdown/bitburner.ns.getgrowtime.md index 2a39a5cdf..46690896f 100644 --- a/markdown/bitburner.ns.getgrowtime.md +++ b/markdown/bitburner.ns.getgrowtime.md @@ -16,7 +16,7 @@ getGrowTime(host: string): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of target server. | +| host | string | Hostname/IP of target server. | **Returns:** diff --git a/markdown/bitburner.ns.gethacktime.md b/markdown/bitburner.ns.gethacktime.md index ca4a508d4..3b0750eaa 100644 --- a/markdown/bitburner.ns.gethacktime.md +++ b/markdown/bitburner.ns.gethacktime.md @@ -16,7 +16,7 @@ getHackTime(host: string): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of target server. | +| host | string | Hostname/IP of target server. | **Returns:** diff --git a/markdown/bitburner.ns.getip.md b/markdown/bitburner.ns.getip.md new file mode 100644 index 000000000..9826e53f8 --- /dev/null +++ b/markdown/bitburner.ns.getip.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [getIP](./bitburner.ns.getip.md) + +## NS.getIP() method + +Returns a string with the IP address of the server that the script is running on. + +**Signature:** + +```typescript +getIP(): string; +``` +**Returns:** + +string + +IP address of the server that the script runs on. + +## Remarks + +RAM cost: 0.05 GB + diff --git a/markdown/bitburner.ns.getpurchasedserversbyip.md b/markdown/bitburner.ns.getpurchasedserversbyip.md new file mode 100644 index 000000000..060c04aac --- /dev/null +++ b/markdown/bitburner.ns.getpurchasedserversbyip.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [getPurchasedServersByIP](./bitburner.ns.getpurchasedserversbyip.md) + +## NS.getPurchasedServersByIP() method + +Returns an array with the IP addresses of all of the servers you have purchased. + +**Signature:** + +```typescript +getPurchasedServersByIP(): string[]; +``` +**Returns:** + +string\[\] + +Returns an array with the IP addresses of all of the servers you have purchased. + +## Remarks + +1.05 GB + diff --git a/markdown/bitburner.ns.getpurchasedserverupgradecost.md b/markdown/bitburner.ns.getpurchasedserverupgradecost.md index fec2fa7df..04d22feeb 100644 --- a/markdown/bitburner.ns.getpurchasedserverupgradecost.md +++ b/markdown/bitburner.ns.getpurchasedserverupgradecost.md @@ -9,21 +9,21 @@ Get cost of upgrading a purchased server to the given ram. **Signature:** ```typescript -getPurchasedServerUpgradeCost(hostname: string, ram: number): number; +getPurchasedServerUpgradeCost(host: string, ram: number): number; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| hostname | string | Hostname of the server to upgrade. | +| host | string | Hostname/IP of the server to upgrade. | | ram | number | Amount of RAM of the purchased server, in GB. Must be a power of 2 (2, 4, 8, 16, etc.). Maximum value of 1048576 (2^20). | **Returns:** number -The price to upgrade or -1 if either input is not valid, i.e. hostname is not the name of a purchased server or ram is not a valid amount. +The price to upgrade or -1 if either input is not valid, i.e. host is not the name of a purchased server or ram is not a valid amount. ## Remarks diff --git a/markdown/bitburner.ns.getrunningscript.md b/markdown/bitburner.ns.getrunningscript.md index 5fc05e748..81eb0a610 100644 --- a/markdown/bitburner.ns.getrunningscript.md +++ b/markdown/bitburner.ns.getrunningscript.md @@ -9,7 +9,7 @@ Get general info about a running script. **Signature:** ```typescript -getRunningScript(filename?: FilenameOrPID, hostname?: string, ...args: ScriptArg[]): RunningScript | null; +getRunningScript(filename?: FilenameOrPID, host?: string, ...args: ScriptArg[]): RunningScript | null; ``` ## Parameters @@ -17,7 +17,7 @@ getRunningScript(filename?: FilenameOrPID, hostname?: string, ...args: ScriptArg | Parameter | Type | Description | | --- | --- | --- | | filename | [FilenameOrPID](./bitburner.filenameorpid.md) | _(Optional)_ Optional. Filename or PID of the script. | -| hostname | string | _(Optional)_ Hostname of target server. Optional, defaults to the server the calling script is running on. | +| host | string | _(Optional)_ Hostname/IP of target server. Optional, defaults to the server the calling script is running on. | | args | [ScriptArg](./bitburner.scriptarg.md)\[\] | Arguments to specify/identify the script. Optional, when looking for scripts run without arguments. | **Returns:** @@ -30,5 +30,5 @@ The info about the running script if found, and null otherwise. RAM cost: 0.3 GB -Running with no args returns current script. If you use a PID as the first parameter, the hostname and args parameters are unnecessary. If hostname is omitted while filename is used as the first parameter, hostname defaults to the server the calling script is running on. Remember that a script is semi-uniquely identified by both its name and its arguments. (You can run multiple copies of scripts with the same arguments, but for the purposes of functions like this that check based on filename, the filename plus arguments forms the key.) +Running with no args returns current script. If you use a PID as the first parameter, the host and args parameters are unnecessary. If host is omitted while filename is used as the first parameter, host defaults to the server the calling script is running on. Remember that a script is semi-uniquely identified by both its name and its arguments. (You can run multiple copies of scripts with the same arguments, but for the purposes of functions like this that check based on filename, the filename plus arguments forms the key.) diff --git a/markdown/bitburner.ns.getscriptexpgain.md b/markdown/bitburner.ns.getscriptexpgain.md index cb2f773e5..08628a1d9 100644 --- a/markdown/bitburner.ns.getscriptexpgain.md +++ b/markdown/bitburner.ns.getscriptexpgain.md @@ -17,7 +17,7 @@ getScriptExpGain(script: string, host: string, ...args: ScriptArg[]): number; | Parameter | Type | Description | | --- | --- | --- | | script | string | Filename of script. | -| host | string | Server on which script is running. | +| host | string | Hostname/IP of the server on which script is running. | | args | [ScriptArg](./bitburner.scriptarg.md)\[\] | Arguments that the script is running with. | **Returns:** diff --git a/markdown/bitburner.ns.getscriptincome.md b/markdown/bitburner.ns.getscriptincome.md index d9cc82f8a..93a3badf2 100644 --- a/markdown/bitburner.ns.getscriptincome.md +++ b/markdown/bitburner.ns.getscriptincome.md @@ -17,7 +17,7 @@ getScriptIncome(script: string, host: string, ...args: ScriptArg[]): number; | Parameter | Type | Description | | --- | --- | --- | | script | string | Filename of script. | -| host | string | Server on which script is running. | +| host | string | Hostname/IP of the server on which script is running. | | args | [ScriptArg](./bitburner.scriptarg.md)\[\] | Arguments that the script is running with. | **Returns:** diff --git a/markdown/bitburner.ns.getscriptlogs.md b/markdown/bitburner.ns.getscriptlogs.md index d1ab18e8f..e7fcd3a26 100644 --- a/markdown/bitburner.ns.getscriptlogs.md +++ b/markdown/bitburner.ns.getscriptlogs.md @@ -17,7 +17,7 @@ getScriptLogs(fn?: FilenameOrPID, host?: string, ...args: ScriptArg[]): string[] | Parameter | Type | Description | | --- | --- | --- | | fn | [FilenameOrPID](./bitburner.filenameorpid.md) | _(Optional)_ Optional. Filename or PID of script to get logs from. | -| host | string | _(Optional)_ Optional. Hostname of the server that the script is on. | +| host | string | _(Optional)_ Optional. Hostname/IP of the server that the script is on. | | args | [ScriptArg](./bitburner.scriptarg.md)\[\] | Arguments to identify which scripts to get logs for. | **Returns:** diff --git a/markdown/bitburner.ns.getscriptram.md b/markdown/bitburner.ns.getscriptram.md index abfc4fd2b..c7af39268 100644 --- a/markdown/bitburner.ns.getscriptram.md +++ b/markdown/bitburner.ns.getscriptram.md @@ -17,7 +17,7 @@ getScriptRam(script: string, host?: string): number; | Parameter | Type | Description | | --- | --- | --- | | script | string | Filename of script. This is case-sensitive. | -| host | string | _(Optional)_ Hostname of target server the script is located on. This is optional. If it is not specified then the function will use the current server as the target server. | +| host | string | _(Optional)_ Hostname/IP of target server the script is located on. This is optional. If it is not specified then the function will use the current server as the target server. | **Returns:** diff --git a/markdown/bitburner.ns.getserver.md b/markdown/bitburner.ns.getserver.md index 5f6af7975..8bd044a22 100644 --- a/markdown/bitburner.ns.getserver.md +++ b/markdown/bitburner.ns.getserver.md @@ -16,7 +16,7 @@ getServer(host?: string): Server; | Parameter | Type | Description | | --- | --- | --- | -| host | string | _(Optional)_ Optional. Hostname for the requested server object. | +| host | string | _(Optional)_ Optional. Hostname/IP for the requested server object. | **Returns:** diff --git a/markdown/bitburner.ns.getserverbasesecuritylevel.md b/markdown/bitburner.ns.getserverbasesecuritylevel.md index c7ee44f15..0b028aafb 100644 --- a/markdown/bitburner.ns.getserverbasesecuritylevel.md +++ b/markdown/bitburner.ns.getserverbasesecuritylevel.md @@ -16,7 +16,7 @@ getServerBaseSecurityLevel(host: string): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Host of target server. | +| host | string | Hostname/IP of target server. | **Returns:** diff --git a/markdown/bitburner.ns.getservergrowth.md b/markdown/bitburner.ns.getservergrowth.md index faf4eef7a..d2ce5dbbd 100644 --- a/markdown/bitburner.ns.getservergrowth.md +++ b/markdown/bitburner.ns.getservergrowth.md @@ -16,7 +16,7 @@ getServerGrowth(host: string): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of target server. | +| host | string | Hostname/IP of target server. | **Returns:** diff --git a/markdown/bitburner.ns.getservermaxmoney.md b/markdown/bitburner.ns.getservermaxmoney.md index 2f581ca6c..d35b0688d 100644 --- a/markdown/bitburner.ns.getservermaxmoney.md +++ b/markdown/bitburner.ns.getservermaxmoney.md @@ -16,7 +16,7 @@ getServerMaxMoney(host: string): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of target server. | +| host | string | Hostname/IP of target server. | **Returns:** diff --git a/markdown/bitburner.ns.getservermaxram.md b/markdown/bitburner.ns.getservermaxram.md index 988657733..bd9d6a0ba 100644 --- a/markdown/bitburner.ns.getservermaxram.md +++ b/markdown/bitburner.ns.getservermaxram.md @@ -16,7 +16,7 @@ getServerMaxRam(host: string): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server. | +| host | string | Hostname/IP of the target server. | **Returns:** diff --git a/markdown/bitburner.ns.getserverminsecuritylevel.md b/markdown/bitburner.ns.getserverminsecuritylevel.md index 76cce08fd..fdeeaf0e8 100644 --- a/markdown/bitburner.ns.getserverminsecuritylevel.md +++ b/markdown/bitburner.ns.getserverminsecuritylevel.md @@ -16,7 +16,7 @@ getServerMinSecurityLevel(host: string): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of target server. | +| host | string | Hostname/IP of target server. | **Returns:** diff --git a/markdown/bitburner.ns.getservermoneyavailable.md b/markdown/bitburner.ns.getservermoneyavailable.md index 48fe386eb..90ba01799 100644 --- a/markdown/bitburner.ns.getservermoneyavailable.md +++ b/markdown/bitburner.ns.getservermoneyavailable.md @@ -16,7 +16,7 @@ getServerMoneyAvailable(host: string): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of target server. | +| host | string | Hostname/IP of target server. | **Returns:** diff --git a/markdown/bitburner.ns.getservernumportsrequired.md b/markdown/bitburner.ns.getservernumportsrequired.md index 299bdbd46..386bd586d 100644 --- a/markdown/bitburner.ns.getservernumportsrequired.md +++ b/markdown/bitburner.ns.getservernumportsrequired.md @@ -16,7 +16,7 @@ getServerNumPortsRequired(host: string): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of target server. | +| host | string | Hostname/IP of target server. | **Returns:** diff --git a/markdown/bitburner.ns.getserverrequiredhackinglevel.md b/markdown/bitburner.ns.getserverrequiredhackinglevel.md index 24e3535fb..cb0b0cfaa 100644 --- a/markdown/bitburner.ns.getserverrequiredhackinglevel.md +++ b/markdown/bitburner.ns.getserverrequiredhackinglevel.md @@ -16,7 +16,7 @@ getServerRequiredHackingLevel(host: string): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of target server. | +| host | string | Hostname/IP of target server. | **Returns:** diff --git a/markdown/bitburner.ns.getserversecuritylevel.md b/markdown/bitburner.ns.getserversecuritylevel.md index 4a3853fe7..dd618d5c6 100644 --- a/markdown/bitburner.ns.getserversecuritylevel.md +++ b/markdown/bitburner.ns.getserversecuritylevel.md @@ -16,7 +16,7 @@ getServerSecurityLevel(host: string): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of target server. | +| host | string | Hostname/IP of target server. | **Returns:** diff --git a/markdown/bitburner.ns.getserverusedram.md b/markdown/bitburner.ns.getserverusedram.md index 192d55bcf..bae3f47fb 100644 --- a/markdown/bitburner.ns.getserverusedram.md +++ b/markdown/bitburner.ns.getserverusedram.md @@ -16,7 +16,7 @@ getServerUsedRam(host: string): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server. | +| host | string | Hostname/IP of the target server. | **Returns:** diff --git a/markdown/bitburner.ns.getweakentime.md b/markdown/bitburner.ns.getweakentime.md index 896185287..193d2b6bd 100644 --- a/markdown/bitburner.ns.getweakentime.md +++ b/markdown/bitburner.ns.getweakentime.md @@ -16,7 +16,7 @@ getWeakenTime(host: string): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of target server. | +| host | string | Hostname/IP of target server. | **Returns:** diff --git a/markdown/bitburner.ns.grow.md b/markdown/bitburner.ns.grow.md index 81ff24cd2..e8254ca50 100644 --- a/markdown/bitburner.ns.grow.md +++ b/markdown/bitburner.ns.grow.md @@ -16,7 +16,7 @@ grow(host: string, opts?: BasicHGWOptions): Promise; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server to grow. | +| host | string | Hostname/IP of the target server to grow. | | opts | [BasicHGWOptions](./bitburner.basichgwoptions.md) | _(Optional)_ Optional parameters for configuring function behavior. | **Returns:** diff --git a/markdown/bitburner.ns.growthanalyze.md b/markdown/bitburner.ns.growthanalyze.md index 037e66716..a19465b02 100644 --- a/markdown/bitburner.ns.growthanalyze.md +++ b/markdown/bitburner.ns.growthanalyze.md @@ -16,7 +16,7 @@ growthAnalyze(host: string, multiplier: number, cores?: number): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server. | +| host | string | Hostname/IP of the target server. | | multiplier | number | Multiplier that will be applied to a server's money after applying additive growth. Decimal form. | | cores | number | _(Optional)_ Number of cores on the host running the grow function. Optional, defaults to 1. | diff --git a/markdown/bitburner.ns.growthanalyzesecurity.md b/markdown/bitburner.ns.growthanalyzesecurity.md index 5b7f8afe6..ec4ec5143 100644 --- a/markdown/bitburner.ns.growthanalyzesecurity.md +++ b/markdown/bitburner.ns.growthanalyzesecurity.md @@ -9,7 +9,7 @@ Calculate the security increase for a number of grow threads. **Signature:** ```typescript -growthAnalyzeSecurity(threads: number, hostname?: string, cores?: number): number; +growthAnalyzeSecurity(threads: number, host?: string, cores?: number): number; ``` ## Parameters @@ -17,7 +17,7 @@ growthAnalyzeSecurity(threads: number, hostname?: string, cores?: number): numbe | Parameter | Type | Description | | --- | --- | --- | | threads | number | Amount of threads that will be used. | -| hostname | string | _(Optional)_ Optional. Hostname of the target server. If provided, security increase is limited by the number of threads needed to reach maximum money. | +| host | string | _(Optional)_ Optional. Hostname/IP of the target server. If provided, security increase is limited by the number of threads needed to reach maximum money. | | cores | number | _(Optional)_ Optional. The number of cores of the server that would run grow. | **Returns:** diff --git a/markdown/bitburner.ns.hack.md b/markdown/bitburner.ns.hack.md index 25846ca97..cbecb0705 100644 --- a/markdown/bitburner.ns.hack.md +++ b/markdown/bitburner.ns.hack.md @@ -16,7 +16,7 @@ hack(host: string, opts?: BasicHGWOptions): Promise; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server to hack. | +| host | string | Hostname/IP of the target server to hack. | | opts | [BasicHGWOptions](./bitburner.basichgwoptions.md) | _(Optional)_ Optional parameters for configuring function behavior. | **Returns:** diff --git a/markdown/bitburner.ns.hackanalyze.md b/markdown/bitburner.ns.hackanalyze.md index 13d810edf..f7c235d0f 100644 --- a/markdown/bitburner.ns.hackanalyze.md +++ b/markdown/bitburner.ns.hackanalyze.md @@ -16,7 +16,7 @@ hackAnalyze(host: string): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server. | +| host | string | Hostname/IP of the target server. | **Returns:** diff --git a/markdown/bitburner.ns.hackanalyzechance.md b/markdown/bitburner.ns.hackanalyzechance.md index 10192f4fa..bd4190686 100644 --- a/markdown/bitburner.ns.hackanalyzechance.md +++ b/markdown/bitburner.ns.hackanalyzechance.md @@ -16,7 +16,7 @@ hackAnalyzeChance(host: string): number; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server. | +| host | string | Hostname/IP of the target server. | **Returns:** diff --git a/markdown/bitburner.ns.hackanalyzesecurity.md b/markdown/bitburner.ns.hackanalyzesecurity.md index 5d2505a50..ec969d564 100644 --- a/markdown/bitburner.ns.hackanalyzesecurity.md +++ b/markdown/bitburner.ns.hackanalyzesecurity.md @@ -9,7 +9,7 @@ Get the security increase for a number of threads. **Signature:** ```typescript -hackAnalyzeSecurity(threads: number, hostname?: string): number; +hackAnalyzeSecurity(threads: number, host?: string): number; ``` ## Parameters @@ -17,7 +17,7 @@ hackAnalyzeSecurity(threads: number, hostname?: string): number; | Parameter | Type | Description | | --- | --- | --- | | threads | number | Amount of threads that will be used. | -| hostname | string | _(Optional)_ Hostname of the target server. The number of threads is limited to the number needed to hack the server's maximum amount of money. | +| host | string | _(Optional)_ Hostname/IP of the target server. The number of threads is limited to the number needed to hack the server's maximum amount of money. | **Returns:** diff --git a/markdown/bitburner.ns.hasrootaccess.md b/markdown/bitburner.ns.hasrootaccess.md index fbfc2fcc8..c709a0cec 100644 --- a/markdown/bitburner.ns.hasrootaccess.md +++ b/markdown/bitburner.ns.hasrootaccess.md @@ -16,7 +16,7 @@ hasRootAccess(host: string): boolean; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server. | +| host | string | Hostname/IP of the target server. | **Returns:** diff --git a/markdown/bitburner.ns.httpworm.md b/markdown/bitburner.ns.httpworm.md index 97129846c..0542ee64a 100644 --- a/markdown/bitburner.ns.httpworm.md +++ b/markdown/bitburner.ns.httpworm.md @@ -16,7 +16,7 @@ httpworm(host: string): boolean; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server. | +| host | string | Hostname/IP of the target server. | **Returns:** diff --git a/markdown/bitburner.ns.isrunning.md b/markdown/bitburner.ns.isrunning.md index 686d7d13f..58cb42244 100644 --- a/markdown/bitburner.ns.isrunning.md +++ b/markdown/bitburner.ns.isrunning.md @@ -17,7 +17,7 @@ isRunning(script: FilenameOrPID, host?: string, ...args: ScriptArg[]): boolean; | Parameter | Type | Description | | --- | --- | --- | | script | [FilenameOrPID](./bitburner.filenameorpid.md) | Filename or PID of script to check. This is case-sensitive. | -| host | string | _(Optional)_ Hostname of target server. Optional, defaults to the server the calling script is running on. | +| host | string | _(Optional)_ Hostname/IP of target server. Optional, defaults to the server the calling script is running on. | | args | [ScriptArg](./bitburner.scriptarg.md)\[\] | Arguments to specify/identify the script. Optional, when looking for scripts run without arguments. | **Returns:** @@ -30,7 +30,7 @@ True if the specified script is running on the target server, and false otherwis RAM cost: 0.1 GB -Returns a boolean indicating whether the specified script is running on the target server. If you use a PID instead of a filename, the hostname and args parameters are unnecessary. If hostname is omitted while filename is used as the first parameter, hostname defaults to the server the calling script is running on. Remember that a script is semi-uniquely identified by both its name and its arguments. (You can run multiple copies of scripts with the same arguments, but for the purposes of functions like this that check based on filename, the filename plus arguments forms the key.) +Returns a boolean indicating whether the specified script is running on the target server. If you use a PID instead of a filename, the host and args parameters are unnecessary. If host is omitted while filename is used as the first parameter, host defaults to the server the calling script is running on. Remember that a script is semi-uniquely identified by both its name and its arguments. (You can run multiple copies of scripts with the same arguments, but for the purposes of functions like this that check based on filename, the filename plus arguments forms the key.) ## Example diff --git a/markdown/bitburner.ns.kill.md b/markdown/bitburner.ns.kill.md index 1d1329d2f..01f00973f 100644 --- a/markdown/bitburner.ns.kill.md +++ b/markdown/bitburner.ns.kill.md @@ -28,7 +28,7 @@ True if the script is successfully killed, and false otherwise. RAM cost: 0.5 GB -Kills the script with the provided PID. To instead kill a script using its filename, hostname, and args, see [the other ns.kill entry](./bitburner.ns.kill_1.md). +Kills the script with the provided PID. To instead kill a script using its filename, host, and args, see [the other ns.kill entry](./bitburner.ns.kill_1.md). ## Example diff --git a/markdown/bitburner.ns.kill_1.md b/markdown/bitburner.ns.kill_1.md index d1e00574d..a915d12e8 100644 --- a/markdown/bitburner.ns.kill_1.md +++ b/markdown/bitburner.ns.kill_1.md @@ -4,12 +4,12 @@ ## NS.kill() method -Terminate the script(s) with the provided filename, hostname, and script arguments. +Terminate the script(s) with the provided filename, host, and script arguments. **Signature:** ```typescript -kill(filename: string, hostname?: string, ...args: ScriptArg[]): boolean; +kill(filename: string, host?: string, ...args: ScriptArg[]): boolean; ``` ## Parameters @@ -17,7 +17,7 @@ kill(filename: string, hostname?: string, ...args: ScriptArg[]): boolean; | Parameter | Type | Description | | --- | --- | --- | | filename | string | Filename of the script to kill. | -| hostname | string | _(Optional)_ Hostname where the script to kill is running. Defaults to the current server. | +| host | string | _(Optional)_ Hostname/IP where the script to kill is running. Defaults to the current server. | | args | [ScriptArg](./bitburner.scriptarg.md)\[\] | Arguments of the script to kill. | **Returns:** diff --git a/markdown/bitburner.ns.killall.md b/markdown/bitburner.ns.killall.md index 2a0683c30..f8ab5bb83 100644 --- a/markdown/bitburner.ns.killall.md +++ b/markdown/bitburner.ns.killall.md @@ -16,7 +16,7 @@ killall(host?: string, safetyGuard?: boolean): boolean; | Parameter | Type | Description | | --- | --- | --- | -| host | string | _(Optional)_ IP or hostname of the server on which to kill all scripts. | +| host | string | _(Optional)_ Hostname/IP of the server on which to kill all scripts. | | safetyGuard | boolean | _(Optional)_ Skips the script that calls this function | **Returns:** diff --git a/markdown/bitburner.ns.ls.md b/markdown/bitburner.ns.ls.md index 673138917..90f51e336 100644 --- a/markdown/bitburner.ns.ls.md +++ b/markdown/bitburner.ns.ls.md @@ -16,7 +16,7 @@ ls(host: string, substring?: string): string[]; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server. | +| host | string | Hostname/IP of the target server. | | substring | string | _(Optional)_ A substring to search for in the filename. | **Returns:** diff --git a/markdown/bitburner.ns.md b/markdown/bitburner.ns.md index f55a87174..086c06d98 100644 --- a/markdown/bitburner.ns.md +++ b/markdown/bitburner.ns.md @@ -64,8 +64,9 @@ export async function main(ns) { | [closeTail(pid)](./bitburner.ns.closetail.md) | Close the tail window of a script. This function is deprecated and will be removed in a later version. | | [deleteServer(host)](./bitburner.ns.deleteserver.md) | Delete a purchased server. | | [disableLog(fn)](./bitburner.ns.disablelog.md) | Disables logging for the given NS function. | +| [dnsLookup(host)](./bitburner.ns.dnslookup.md) | Given a hostname, returns an IP address, Given an IP address, returns a hostname | | [enableLog(fn)](./bitburner.ns.enablelog.md) | Enables logging for the given NS function. | -| [exec(script, hostname, threadOrOptions, args)](./bitburner.ns.exec.md) | Start another script on any server. | +| [exec(script, host, threadOrOptions, args)](./bitburner.ns.exec.md) | Start another script on any server. | | [exit()](./bitburner.ns.exit.md) | Terminates the current script immediately. | | [fileExists(filename, host)](./bitburner.ns.fileexists.md) | Check if a file exists. | | [flags(schema)](./bitburner.ns.flags.md) | Parse command line flags. | @@ -82,6 +83,7 @@ export async function main(ns) { | [getHacknetMultipliers()](./bitburner.ns.gethacknetmultipliers.md) | Get hacknet related multipliers. | | [getHackTime(host)](./bitburner.ns.gethacktime.md) | Get the execution time of a hack() call. | | [getHostname()](./bitburner.ns.gethostname.md) | Returns a string with the hostname of the server that the script is running on. | +| [getIP()](./bitburner.ns.getip.md) | Returns a string with the IP address of the server that the script is running on. | | [getMoneySources()](./bitburner.ns.getmoneysources.md) | Get information about the sources of income for this run. | | [getPlayer()](./bitburner.ns.getplayer.md) | Get information about the player. | | [getPortHandle(portNumber)](./bitburner.ns.getporthandle.md) | Get all data on a port. | @@ -89,10 +91,11 @@ export async function main(ns) { | [getPurchasedServerLimit()](./bitburner.ns.getpurchasedserverlimit.md) | Returns the maximum number of servers you can purchase. | | [getPurchasedServerMaxRam()](./bitburner.ns.getpurchasedservermaxram.md) | Returns the maximum RAM that a purchased server can have. | | [getPurchasedServers()](./bitburner.ns.getpurchasedservers.md) | Returns an array with the hostnames of all of the servers you have purchased. | -| [getPurchasedServerUpgradeCost(hostname, ram)](./bitburner.ns.getpurchasedserverupgradecost.md) | Get cost of upgrading a purchased server to the given ram. | +| [getPurchasedServersByIP()](./bitburner.ns.getpurchasedserversbyip.md) | Returns an array with the IP addresses of all of the servers you have purchased. | +| [getPurchasedServerUpgradeCost(host, ram)](./bitburner.ns.getpurchasedserverupgradecost.md) | Get cost of upgrading a purchased server to the given ram. | | [getRecentScripts()](./bitburner.ns.getrecentscripts.md) | Get an array of recently killed scripts across all servers. | | [getResetInfo()](./bitburner.ns.getresetinfo.md) | Get information about resets. | -| [getRunningScript(filename, hostname, args)](./bitburner.ns.getrunningscript.md) | Get general info about a running script. | +| [getRunningScript(filename, host, args)](./bitburner.ns.getrunningscript.md) | Get general info about a running script. | | [getScriptExpGain(script, host, args)](./bitburner.ns.getscriptexpgain.md) | Get the exp gain of a script. | | [getScriptIncome(script, host, args)](./bitburner.ns.getscriptincome.md) | Get the income of a script. | | [getScriptLogs(fn, host, args)](./bitburner.ns.getscriptlogs.md) | Get all the logs of a script. | @@ -116,11 +119,11 @@ export async function main(ns) { | [getWeakenTime(host)](./bitburner.ns.getweakentime.md) | Get the execution time of a weaken() call. | | [grow(host, opts)](./bitburner.ns.grow.md) | Spoof money in a server's bank account, increasing the amount available. | | [growthAnalyze(host, multiplier, cores)](./bitburner.ns.growthanalyze.md) | Calculate the number of grow threads needed for a given multiplicative growth factor. | -| [growthAnalyzeSecurity(threads, hostname, cores)](./bitburner.ns.growthanalyzesecurity.md) | Calculate the security increase for a number of grow threads. | +| [growthAnalyzeSecurity(threads, host, cores)](./bitburner.ns.growthanalyzesecurity.md) | Calculate the security increase for a number of grow threads. | | [hack(host, opts)](./bitburner.ns.hack.md) | Steal a server's money. | | [hackAnalyze(host)](./bitburner.ns.hackanalyze.md) | Get the part of money stolen with a single thread. | | [hackAnalyzeChance(host)](./bitburner.ns.hackanalyzechance.md) | Get the chance of successfully hacking a server. | -| [hackAnalyzeSecurity(threads, hostname)](./bitburner.ns.hackanalyzesecurity.md) | Get the security increase for a number of threads. | +| [hackAnalyzeSecurity(threads, host)](./bitburner.ns.hackanalyzesecurity.md) | Get the security increase for a number of threads. | | [hackAnalyzeThreads(host, hackAmount)](./bitburner.ns.hackanalyzethreads.md) | Calculate the decimal number of threads needed to hack a specified amount of money from a target host. | | [hasRootAccess(host)](./bitburner.ns.hasrootaccess.md) | Check if you have root access on a server. | | [hasTorRouter()](./bitburner.ns.hastorrouter.md) | Returns whether the player has access to the darkweb. | @@ -128,7 +131,7 @@ export async function main(ns) { | [isLogEnabled(fn)](./bitburner.ns.islogenabled.md) | Checks the status of the logging for the given NS function. | | [isRunning(script, host, args)](./bitburner.ns.isrunning.md) | Check if a script is running. | | [kill(pid)](./bitburner.ns.kill.md) | Terminate the script with the provided PID. | -| [kill(filename, hostname, args)](./bitburner.ns.kill_1.md) | Terminate the script(s) with the provided filename, hostname, and script arguments. | +| [kill(filename, host, args)](./bitburner.ns.kill_1.md) | Terminate the script(s) with the provided filename, host, and script arguments. | | [killall(host, safetyGuard)](./bitburner.ns.killall.md) | Terminate all scripts on a server. | | [ls(host, substring)](./bitburner.ns.ls.md) | List files on a server. | | [moveTail(x, y, pid)](./bitburner.ns.movetail.md) | Move a tail window. This function is deprecated and will be removed in a later version. | @@ -152,6 +155,7 @@ export async function main(ns) { | [rm(name, host)](./bitburner.ns.rm.md) | Delete a file. | | [run(script, threadOrOptions, args)](./bitburner.ns.run.md) | Start another script on the current server. | | [scan(host)](./bitburner.ns.scan.md) | Get the list of servers connected to a server. | +| [scanByIP(host)](./bitburner.ns.scanbyip.md) | Get the list of servers connected to a server. | | [scp(files, destination, source)](./bitburner.ns.scp.md) | Copy file between servers. | | [scriptKill(script, host)](./bitburner.ns.scriptkill.md) | Kill all scripts with a filename. | | [scriptRunning(script, host)](./bitburner.ns.scriptrunning.md) | Check if any script with a filename is running. | @@ -170,7 +174,7 @@ export async function main(ns) { | [tprintf(format, values)](./bitburner.ns.tprintf.md) | Prints a raw value or a variable to the Terminal. | | [tprintRaw(node)](./bitburner.ns.tprintraw.md) | Prints a ReactNode to the terminal. | | [tryWritePort(portNumber, data)](./bitburner.ns.trywriteport.md) | Attempt to write to a port. | -| [upgradePurchasedServer(hostname, ram)](./bitburner.ns.upgradepurchasedserver.md) | Upgrade a purchased server's RAM. | +| [upgradePurchasedServer(host, ram)](./bitburner.ns.upgradepurchasedserver.md) | Upgrade a purchased server's RAM. | | [vsprintf(format, args)](./bitburner.ns.vsprintf.md) | Format a string with an array of arguments. | | [weaken(host, opts)](./bitburner.ns.weaken.md) | Reduce a server's security level. | | [weakenAnalyze(threads, cores)](./bitburner.ns.weakenanalyze.md) | Predict the effect of weaken. | diff --git a/markdown/bitburner.ns.mv.md b/markdown/bitburner.ns.mv.md index 1e267fa29..c3a389eb7 100644 --- a/markdown/bitburner.ns.mv.md +++ b/markdown/bitburner.ns.mv.md @@ -16,7 +16,7 @@ mv(host: string, source: string, destination: string): void; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of target server. | +| host | string | Hostname/IP of target server. | | source | string | Filename of the source file. | | destination | string | Filename of the destination file. | diff --git a/markdown/bitburner.ns.nuke.md b/markdown/bitburner.ns.nuke.md index 6bffa4960..9e5d109b5 100644 --- a/markdown/bitburner.ns.nuke.md +++ b/markdown/bitburner.ns.nuke.md @@ -16,7 +16,7 @@ nuke(host: string): boolean; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server. | +| host | string | Hostname/IP of the target server. | **Returns:** diff --git a/markdown/bitburner.ns.ps.md b/markdown/bitburner.ns.ps.md index e77b50afb..259b5a745 100644 --- a/markdown/bitburner.ns.ps.md +++ b/markdown/bitburner.ns.ps.md @@ -16,7 +16,7 @@ ps(host?: string): ProcessInfo[]; | Parameter | Type | Description | | --- | --- | --- | -| host | string | _(Optional)_ Host address of the target server. If not specified, it will be the current server’s IP by default. | +| host | string | _(Optional)_ Hostname/IP of the target server. If not specified, it will be the current server’s IP by default. | **Returns:** diff --git a/markdown/bitburner.ns.purchaseserver.md b/markdown/bitburner.ns.purchaseserver.md index 4bb096b7f..07f5aad35 100644 --- a/markdown/bitburner.ns.purchaseserver.md +++ b/markdown/bitburner.ns.purchaseserver.md @@ -31,7 +31,7 @@ The hostname of the newly purchased server. Purchase a server with the specified hostname and amount of RAM. -The hostname argument can be any data type, but it will be converted to a string and have whitespace removed. Anything that resolves to an empty string will cause the function to fail. If there is already a server with the specified hostname, then the function will automatically append a number at the end of the hostname argument value until it finds a unique hostname. For example, if the script calls `purchaseServer(“foo”, 4)` but a server named “foo” already exists, then it will automatically change the hostname to `foo-0`. If there is already a server with the hostname `foo-0`, then it will change the hostname to `foo-1`, and so on. +The hostname argument can be any data type, but it will be converted to a string and have whitespace removed. Anything that resolves to an empty string or IP address will cause the function to fail. If there is already a server with the specified hostname, then the function will automatically append a number at the end of the hostname argument value until it finds a unique hostname. For example, if the script calls `purchaseServer(“foo”, 4)` but a server named “foo” already exists, then it will automatically change the hostname to `foo-0`. If there is already a server with the hostname `foo-0`, then it will change the hostname to `foo-1`, and so on. Note that there is a maximum limit to the amount of servers you can purchase. diff --git a/markdown/bitburner.ns.relaysmtp.md b/markdown/bitburner.ns.relaysmtp.md index 3ae007bd2..7e110f954 100644 --- a/markdown/bitburner.ns.relaysmtp.md +++ b/markdown/bitburner.ns.relaysmtp.md @@ -16,7 +16,7 @@ relaysmtp(host: string): boolean; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server. | +| host | string | Hostname/IP of the target server. | **Returns:** diff --git a/markdown/bitburner.ns.rm.md b/markdown/bitburner.ns.rm.md index c39b74885..7b18971e1 100644 --- a/markdown/bitburner.ns.rm.md +++ b/markdown/bitburner.ns.rm.md @@ -17,7 +17,7 @@ rm(name: string, host?: string): boolean; | Parameter | Type | Description | | --- | --- | --- | | name | string | Filename of file to remove. Must include the extension. | -| host | string | _(Optional)_ Hostname of the server on which to delete the file. Optional. Defaults to current server. | +| host | string | _(Optional)_ Hostname/IP of the server on which to delete the file. Optional. Defaults to current server. | **Returns:** diff --git a/markdown/bitburner.ns.scan.md b/markdown/bitburner.ns.scan.md index ff2d154bc..9bfa1dd4c 100644 --- a/markdown/bitburner.ns.scan.md +++ b/markdown/bitburner.ns.scan.md @@ -16,7 +16,7 @@ scan(host?: string): string[]; | Parameter | Type | Description | | --- | --- | --- | -| host | string | _(Optional)_ Optional. Hostname of the server to scan, default to current server. | +| host | string | _(Optional)_ Optional. Hostname/IP of the server to scan, default to current server. | **Returns:** diff --git a/markdown/bitburner.ns.scanbyip.md b/markdown/bitburner.ns.scanbyip.md new file mode 100644 index 000000000..8942cff8e --- /dev/null +++ b/markdown/bitburner.ns.scanbyip.md @@ -0,0 +1,34 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [scanByIP](./bitburner.ns.scanbyip.md) + +## NS.scanByIP() method + +Get the list of servers connected to a server. + +**Signature:** + +```typescript +scanByIP(host?: string): string[]; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| host | string | _(Optional)_ Optional. Hostname/IP of the server to scan, default to current server. | + +**Returns:** + +string\[\] + +Returns an array of IP addresses + +## Remarks + +RAM cost: 0.2 GB + +Returns an array containing the IP addresses of all servers that are one node way from the specified target server. The IP addresses in the returned array are strings. + +Works identically to [ns.scan](./bitburner.ns.scan.md). + diff --git a/markdown/bitburner.ns.scp.md b/markdown/bitburner.ns.scp.md index 4cb69b645..2e4d7b915 100644 --- a/markdown/bitburner.ns.scp.md +++ b/markdown/bitburner.ns.scp.md @@ -17,8 +17,8 @@ scp(files: string | string[], destination: string, source?: string): boolean; | Parameter | Type | Description | | --- | --- | --- | | files | string \| string\[\] | Filename or an array of filenames of script/literature files to copy. Note that if a file is located in a subdirectory, the filename must include the leading /. | -| destination | string | Hostname of the destination server, which is the server to which the file will be copied. | -| source | string | _(Optional)_ Hostname of the source server, which is the server from which the file will be copied. This argument is optional and if it’s omitted the source will be the current server. | +| destination | string | Hostname/IP of the destination server, which is the server to which the file will be copied. | +| source | string | _(Optional)_ Hostname/IP of the source server, which is the server from which the file will be copied. This argument is optional and if it’s omitted the source will be the current server. | **Returns:** diff --git a/markdown/bitburner.ns.scriptkill.md b/markdown/bitburner.ns.scriptkill.md index d256b2e12..a9935a1ef 100644 --- a/markdown/bitburner.ns.scriptkill.md +++ b/markdown/bitburner.ns.scriptkill.md @@ -17,7 +17,7 @@ scriptKill(script: string, host: string): boolean; | Parameter | Type | Description | | --- | --- | --- | | script | string | Filename of script to kill. This is case-sensitive. | -| host | string | Hostname of target server. | +| host | string | Hostname/IP of target server. | **Returns:** diff --git a/markdown/bitburner.ns.scriptrunning.md b/markdown/bitburner.ns.scriptrunning.md index b249f3456..ed8a99601 100644 --- a/markdown/bitburner.ns.scriptrunning.md +++ b/markdown/bitburner.ns.scriptrunning.md @@ -17,7 +17,7 @@ scriptRunning(script: string, host: string): boolean; | Parameter | Type | Description | | --- | --- | --- | | script | string | Filename of script to check. This is case-sensitive. | -| host | string | Hostname of target server. | +| host | string | Hostname/IP of target server. | **Returns:** diff --git a/markdown/bitburner.ns.serverexists.md b/markdown/bitburner.ns.serverexists.md index 2f287a41a..d2c645f8a 100644 --- a/markdown/bitburner.ns.serverexists.md +++ b/markdown/bitburner.ns.serverexists.md @@ -16,7 +16,7 @@ serverExists(host: string): boolean; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of target server. | +| host | string | Hostname/IP of target server. | **Returns:** diff --git a/markdown/bitburner.ns.sqlinject.md b/markdown/bitburner.ns.sqlinject.md index 51cc65d9b..e793cab2a 100644 --- a/markdown/bitburner.ns.sqlinject.md +++ b/markdown/bitburner.ns.sqlinject.md @@ -16,7 +16,7 @@ sqlinject(host: string): boolean; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server. | +| host | string | Hostname/IP of the target server. | **Returns:** diff --git a/markdown/bitburner.ns.upgradepurchasedserver.md b/markdown/bitburner.ns.upgradepurchasedserver.md index d36f2e877..3e0b58065 100644 --- a/markdown/bitburner.ns.upgradepurchasedserver.md +++ b/markdown/bitburner.ns.upgradepurchasedserver.md @@ -9,14 +9,14 @@ Upgrade a purchased server's RAM. **Signature:** ```typescript -upgradePurchasedServer(hostname: string, ram: number): boolean; +upgradePurchasedServer(host: string, ram: number): boolean; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| hostname | string | Hostname of the server to upgrade. | +| host | string | Hostname/IP of the server to upgrade. | | ram | number | Amount of RAM of the purchased server, in GB. Must be a power of 2 (2, 4, 8, 16, etc.). Maximum value of 1048576 (2^20). | **Returns:** diff --git a/markdown/bitburner.ns.weaken.md b/markdown/bitburner.ns.weaken.md index f5ffb1674..be17725b5 100644 --- a/markdown/bitburner.ns.weaken.md +++ b/markdown/bitburner.ns.weaken.md @@ -16,7 +16,7 @@ weaken(host: string, opts?: BasicHGWOptions): Promise; | Parameter | Type | Description | | --- | --- | --- | -| host | string | Hostname of the target server to weaken. | +| host | string | Hostname/IP of the target server to weaken. | | opts | [BasicHGWOptions](./bitburner.basichgwoptions.md) | _(Optional)_ Optional parameters for configuring function behavior. | **Returns:** diff --git a/markdown/bitburner.singularity.connect.md b/markdown/bitburner.singularity.connect.md index 320313e3d..84f9d6148 100644 --- a/markdown/bitburner.singularity.connect.md +++ b/markdown/bitburner.singularity.connect.md @@ -9,14 +9,14 @@ Connect to a server. **Signature:** ```typescript -connect(hostname: string): boolean; +connect(host: string): boolean; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| hostname | string | | +| host | string | | **Returns:** @@ -28,5 +28,5 @@ True if the connect command was successful, false otherwise. RAM cost: 2 GB \* 16/4/1 -Run the connect HOSTNAME command in the terminal. Can only connect to neighbors. +Run the connect HOSTNAME/IP command in the terminal. Can only connect to neighbors. diff --git a/markdown/bitburner.singularity.md b/markdown/bitburner.singularity.md index ad4965ebc..4b35f26b7 100644 --- a/markdown/bitburner.singularity.md +++ b/markdown/bitburner.singularity.md @@ -24,7 +24,7 @@ This API requires Source-File 4 to use. The RAM cost of all these functions is m | [b1tflum3(nextBN, callbackScript, bitNodeOptions)](./bitburner.singularity.b1tflum3.md) | b1t\_flum3 into a different BN. | | [checkFactionInvitations()](./bitburner.singularity.checkfactioninvitations.md) | List all current faction invitations. | | [commitCrime(crime, focus)](./bitburner.singularity.commitcrime.md) | Commit a crime. | -| [connect(hostname)](./bitburner.singularity.connect.md) | Connect to a server. | +| [connect(host)](./bitburner.singularity.connect.md) | Connect to a server. | | [createProgram(program, focus)](./bitburner.singularity.createprogram.md) | Create a program. | | [destroyW0r1dD43m0n(nextBN, callbackScript, bitNodeOptions)](./bitburner.singularity.destroyw0r1dd43m0n.md) | Destroy the w0r1d\_d43m0n and move on to the next BN. | | [donateToFaction(faction, amount)](./bitburner.singularity.donatetofaction.md) | Donate to a faction. | diff --git a/markdown/bitburner.userinterface.opentail.md b/markdown/bitburner.userinterface.opentail.md index db6bb2d59..8c0989600 100644 --- a/markdown/bitburner.userinterface.opentail.md +++ b/markdown/bitburner.userinterface.opentail.md @@ -17,7 +17,7 @@ openTail(fn?: FilenameOrPID, host?: string, ...args: ScriptArg[]): void; | Parameter | Type | Description | | --- | --- | --- | | fn | [FilenameOrPID](./bitburner.filenameorpid.md) | _(Optional)_ Optional. Filename or PID of the script being tailed. If omitted, the current script is tailed. | -| host | string | _(Optional)_ Optional. Hostname of the script being tailed. Defaults to the server this script is running on. If args are specified, this is not optional. | +| host | string | _(Optional)_ Optional. Hostname/IP of the script being tailed. Defaults to the server this script is running on. If args are specified, this is not optional. | | args | [ScriptArg](./bitburner.scriptarg.md)\[\] | Arguments for the script being tailed. | **Returns:** diff --git a/markdown/bitburner.userinterface.settailfontsize.md b/markdown/bitburner.userinterface.settailfontsize.md index 25be1e1ce..d08986dea 100644 --- a/markdown/bitburner.userinterface.settailfontsize.md +++ b/markdown/bitburner.userinterface.settailfontsize.md @@ -18,7 +18,7 @@ setTailFontSize(pixel?: number, fn?: FilenameOrPID, host?: string, ...args: Scri | --- | --- | --- | | pixel | number | _(Optional)_ Optional. The new font size in pixels. If omitted, the default tail font size is used. | | fn | [FilenameOrPID](./bitburner.filenameorpid.md) | _(Optional)_ Optional. Filename or PID of the target script. If omitted, the current script is used. | -| host | string | _(Optional)_ Optional. Hostname of the target script. Defaults to the server this script is running on. If args are specified, this is not optional. | +| host | string | _(Optional)_ Optional. Hostname/IP of the target script. Defaults to the server this script is running on. If args are specified, this is not optional. | | args | [ScriptArg](./bitburner.scriptarg.md)\[\] | Arguments for the target script. | **Returns:** diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index e3812c289..60502cd48 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -176,7 +176,7 @@ export const ns: InternalAPI = { return out; }, scanByIP: (ctx) => (_host) => { - const host = _host ? helpers.string(ctx, "hostname", _host) : ctx.workerScript.hostname; + const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname; const server = helpers.getServer(ctx, host); const out: string[] = []; for (let i = 0; i < server.serversOnNetwork.length; i++) { @@ -1380,8 +1380,8 @@ export const ns: InternalAPI = { getPurchasedServersByIP: (ctx) => (): string[] => { const res: string[] = []; Player.purchasedServers.forEach(function (hostname) { - const server = helpers.getServer(ctx, hostname) - res.push(server.ip) + const server = helpers.getServer(ctx, hostname); + res.push(server.ip); }); return res; }, diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 48096e753..3f1a8fa8b 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -6779,13 +6779,13 @@ export interface NS { * Get the list of servers connected to a server. * @remarks * RAM cost: 0.2 GB - * + * * Returns an array containing the IP addresses of all servers that are one * node way from the specified target server. The IP addresses in the returned * array are strings. - * + * * Works identically to {@link NS.scan | ns.scan}. - * + * * @param host - Optional. Hostname/IP of the server to scan, default to current server. * @returns Returns an array of IP addresses */ @@ -7182,12 +7182,12 @@ export interface NS { /** * Returns a string with the IP address of the server that the script is running on. - * + * * @remarks * RAM cost: 0.05 GB * @returns IP address of the server that the script runs on. */ - getIP(): string + getIP(): string; /** * Returns the player’s current hacking level. @@ -7368,11 +7368,11 @@ export interface NS { /** * Given a hostname, returns an IP address, * Given an IP address, returns a hostname - * + * * @remarks RAM cost: 0 GB * @param host - Hostname/IP of target server. */ - dnsLookup(host: string): string + dnsLookup(host: string): string; /** * Returns a boolean denoting whether or not the specified server exists. @@ -7595,7 +7595,7 @@ export interface NS { * @remarks 1.05 GB * @returns Returns an array with the IP addresses of all of the servers you have purchased. */ - getPurchasedServersByIP(): string[] + getPurchasedServersByIP(): string[]; /** * Returns the maximum number of servers you can purchase. diff --git a/src/Server/ServerPurchases.ts b/src/Server/ServerPurchases.ts index a8904ebe4..6781bebf2 100644 --- a/src/Server/ServerPurchases.ts +++ b/src/Server/ServerPurchases.ts @@ -44,7 +44,8 @@ export function getPurchaseServerCost(ram: number): number { export const getPurchasedServerUpgradeCost = (hostname: string, ram: number): number => { const server = GetServer(hostname); if (!server) throw new Error(`Server '${hostname}' not found.`); - if (!Player.purchasedServers.includes(server.hostname)) throw new Error(`Server '${hostname}' not a purchased server.`); + if (!Player.purchasedServers.includes(server.hostname)) + throw new Error(`Server '${hostname}' not a purchased server.`); if (isNaN(ram) || !isPowerOfTwo(ram) || !(Math.sign(ram) === 1)) throw new Error(`${ram} is not a positive power of 2`); if (server.maxRam >= ram) @@ -62,10 +63,10 @@ export const upgradePurchasedServer = (hostname: string, ram: number): void => { }; export const renamePurchasedServer = (hostname: string, newName: string): void => { - if (isIPAddress(hostname)) throw new Error(`${hostname} is an IP address, not a hostname.`) + if (isIPAddress(hostname)) throw new Error(`${hostname} is an IP address, not a hostname.`); const server = GetServer(hostname); if (!server) throw new Error(`Server '${hostname}' doesn't exists.`); - if (newName == "" || isIPAddress(newName)) throw new Error(`${newName} is an invalid hostname.`) + if (newName == "" || isIPAddress(newName)) throw new Error(`${newName} is an invalid hostname.`); if (GetServer(newName)) throw new Error(`Server '${newName}' already exists.`); if (!Player.purchasedServers.includes(hostname)) throw new Error(`Server '${hostname}' is not a player server.`); if (newName.startsWith("hacknet-node-") || newName.startsWith("hacknet-server-")) { diff --git a/src/Terminal/Terminal.ts b/src/Terminal/Terminal.ts index 8be2cd779..5b2897e6e 100644 --- a/src/Terminal/Terminal.ts +++ b/src/Terminal/Terminal.ts @@ -53,7 +53,7 @@ import { help } from "./commands/help"; import { history } from "./commands/history"; import { home } from "./commands/home"; import { hostname } from "./commands/hostname"; -import { ipaddr } from "./commands/ipaddr" +import { ipaddr } from "./commands/ipaddr"; import { kill } from "./commands/kill"; import { killall } from "./commands/killall"; import { ls } from "./commands/ls"; From e4f1b3b14b0dc830a1fa7f4ae25347153c028890 Mon Sep 17 00:00:00 2001 From: Naga Ouroboros Date: Sun, 2 Mar 2025 06:10:54 -0500 Subject: [PATCH 08/11] FIX: Minor documentation clarification --- markdown/bitburner.ns.dnslookup.md | 2 +- markdown/bitburner.ns.md | 6 +++--- markdown/bitburner.ns.scan.md | 2 +- markdown/bitburner.ns.scanbyip.md | 2 +- src/ScriptEditor/NetscriptDefinitions.d.ts | 7 +++---- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/markdown/bitburner.ns.dnslookup.md b/markdown/bitburner.ns.dnslookup.md index 4a43b7f87..bb192af31 100644 --- a/markdown/bitburner.ns.dnslookup.md +++ b/markdown/bitburner.ns.dnslookup.md @@ -4,7 +4,7 @@ ## NS.dnsLookup() method -Given a hostname, returns an IP address, Given an IP address, returns a hostname +Given a hostname, returns its IP address; or given an IP address, returns its hostname. **Signature:** diff --git a/markdown/bitburner.ns.md b/markdown/bitburner.ns.md index 086c06d98..675aef97e 100644 --- a/markdown/bitburner.ns.md +++ b/markdown/bitburner.ns.md @@ -64,7 +64,7 @@ export async function main(ns) { | [closeTail(pid)](./bitburner.ns.closetail.md) | Close the tail window of a script. This function is deprecated and will be removed in a later version. | | [deleteServer(host)](./bitburner.ns.deleteserver.md) | Delete a purchased server. | | [disableLog(fn)](./bitburner.ns.disablelog.md) | Disables logging for the given NS function. | -| [dnsLookup(host)](./bitburner.ns.dnslookup.md) | Given a hostname, returns an IP address, Given an IP address, returns a hostname | +| [dnsLookup(host)](./bitburner.ns.dnslookup.md) | Given a hostname, returns its IP address; or given an IP address, returns its hostname. | | [enableLog(fn)](./bitburner.ns.enablelog.md) | Enables logging for the given NS function. | | [exec(script, host, threadOrOptions, args)](./bitburner.ns.exec.md) | Start another script on any server. | | [exit()](./bitburner.ns.exit.md) | Terminates the current script immediately. | @@ -154,8 +154,8 @@ export async function main(ns) { | [resizeTail(width, height, pid)](./bitburner.ns.resizetail.md) | Resize a tail window. This function is deprecated and will be removed in a later version. | | [rm(name, host)](./bitburner.ns.rm.md) | Delete a file. | | [run(script, threadOrOptions, args)](./bitburner.ns.run.md) | Start another script on the current server. | -| [scan(host)](./bitburner.ns.scan.md) | Get the list of servers connected to a server. | -| [scanByIP(host)](./bitburner.ns.scanbyip.md) | Get the list of servers connected to a server. | +| [scan(host)](./bitburner.ns.scan.md) | Get the list of hostnames connected to a server. | +| [scanByIP(host)](./bitburner.ns.scanbyip.md) | Get the list of IPs connected to a server. | | [scp(files, destination, source)](./bitburner.ns.scp.md) | Copy file between servers. | | [scriptKill(script, host)](./bitburner.ns.scriptkill.md) | Kill all scripts with a filename. | | [scriptRunning(script, host)](./bitburner.ns.scriptrunning.md) | Check if any script with a filename is running. | diff --git a/markdown/bitburner.ns.scan.md b/markdown/bitburner.ns.scan.md index 9bfa1dd4c..ac7beb826 100644 --- a/markdown/bitburner.ns.scan.md +++ b/markdown/bitburner.ns.scan.md @@ -4,7 +4,7 @@ ## NS.scan() method -Get the list of servers connected to a server. +Get the list of hostnames connected to a server. **Signature:** diff --git a/markdown/bitburner.ns.scanbyip.md b/markdown/bitburner.ns.scanbyip.md index 8942cff8e..cb9f932eb 100644 --- a/markdown/bitburner.ns.scanbyip.md +++ b/markdown/bitburner.ns.scanbyip.md @@ -4,7 +4,7 @@ ## NS.scanByIP() method -Get the list of servers connected to a server. +Get the list of IPs connected to a server. **Signature:** diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 3f1a8fa8b..d854567b3 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -6718,7 +6718,7 @@ export interface NS { setTitle(title: string | ReactNode, pid?: number): void; /** - * Get the list of servers connected to a server. + * Get the list of hostnames connected to a server. * @remarks * RAM cost: 0.2 GB * @@ -6776,7 +6776,7 @@ export interface NS { scan(host?: string): string[]; /** - * Get the list of servers connected to a server. + * Get the list of IPs connected to a server. * @remarks * RAM cost: 0.2 GB * @@ -7366,8 +7366,7 @@ export interface NS { getServerNumPortsRequired(host: string): number; /** - * Given a hostname, returns an IP address, - * Given an IP address, returns a hostname + * Given a hostname, returns its IP address; or given an IP address, returns its hostname. * * @remarks RAM cost: 0 GB * @param host - Hostname/IP of target server. From 52e7d11bc8dd4c801cb2cc4550f87d5f80bf73aa Mon Sep 17 00:00:00 2001 From: Naga Ouroboros Date: Fri, 7 Mar 2025 19:07:25 -0500 Subject: [PATCH 09/11] REFACTOR: Employ optional struct to control which server identifier (hostname or IP address) gets returned from applicable methods --- markdown/bitburner.hostreturnoptions.md | 20 ++++++ .../bitburner.hostreturnoptions.returnbyip.md | 13 ++++ markdown/bitburner.md | 1 + markdown/bitburner.ns.getpurchasedservers.md | 13 +++- .../bitburner.ns.getpurchasedserversbyip.md | 23 ------- markdown/bitburner.ns.md | 6 +- markdown/bitburner.ns.scan.md | 13 +++- markdown/bitburner.ns.scanbyip.md | 34 ---------- .../bitburner.singularity.getcurrentserver.md | 13 +++- markdown/bitburner.singularity.md | 2 +- src/Netscript/NetscriptHelpers.tsx | 21 ++++++ src/Netscript/RamCostGenerator.ts | 2 - src/NetscriptFunctions.ts | 58 +++++++---------- src/NetscriptFunctions/Singularity.ts | 10 +-- src/ScriptEditor/NetscriptDefinitions.d.ts | 65 +++++++++---------- 15 files changed, 148 insertions(+), 146 deletions(-) create mode 100644 markdown/bitburner.hostreturnoptions.md create mode 100644 markdown/bitburner.hostreturnoptions.returnbyip.md delete mode 100644 markdown/bitburner.ns.getpurchasedserversbyip.md delete mode 100644 markdown/bitburner.ns.scanbyip.md diff --git a/markdown/bitburner.hostreturnoptions.md b/markdown/bitburner.hostreturnoptions.md new file mode 100644 index 000000000..6e2ad08d2 --- /dev/null +++ b/markdown/bitburner.hostreturnoptions.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [HostReturnOptions](./bitburner.hostreturnoptions.md) + +## HostReturnOptions interface + +Options to control how a server identifier (hostname or IP address) is returned. Affects the behavior of [scan](./bitburner.ns.scan.md), [getPurchasedServers](./bitburner.ns.getpurchasedservers.md), and [getCurrentServer](./bitburner.singularity.getcurrentserver.md) + +**Signature:** + +```typescript +interface HostReturnOptions +``` + +## Properties + +| Property | Modifiers | Type | Description | +| --- | --- | --- | --- | +| [returnByIP?](./bitburner.hostreturnoptions.returnbyip.md) | | boolean | _(Optional)_ If set to true, returns IP addresses instead of hostnames. Defaults to false. | + diff --git a/markdown/bitburner.hostreturnoptions.returnbyip.md b/markdown/bitburner.hostreturnoptions.returnbyip.md new file mode 100644 index 000000000..c435104ff --- /dev/null +++ b/markdown/bitburner.hostreturnoptions.returnbyip.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [HostReturnOptions](./bitburner.hostreturnoptions.md) > [returnByIP](./bitburner.hostreturnoptions.returnbyip.md) + +## HostReturnOptions.returnByIP property + +If set to `true`, returns IP addresses instead of hostnames. Defaults to `false`. + +**Signature:** + +```typescript +returnByIP?: boolean; +``` diff --git a/markdown/bitburner.md b/markdown/bitburner.md index f5e91d9dc..7709c1eb9 100644 --- a/markdown/bitburner.md +++ b/markdown/bitburner.md @@ -101,6 +101,7 @@ | [HacknetRAMRequirement](./bitburner.hacknetramrequirement.md) | Player's Hacknet devices must have at least this much total RAM. | | [HacknetServerConstants](./bitburner.hacknetserverconstants.md) | Hacknet server related constants | | [HacknetServersFormulas](./bitburner.hacknetserversformulas.md) | Hacknet Server formulas | +| [HostReturnOptions](./bitburner.hostreturnoptions.md) | Options to control how a server identifier (hostname or IP address) is returned. Affects the behavior of [scan](./bitburner.ns.scan.md), [getPurchasedServers](./bitburner.ns.getpurchasedservers.md), and [getCurrentServer](./bitburner.singularity.getcurrentserver.md) | | [HP](./bitburner.hp.md) | | | [ILocation](./bitburner.ilocation.md) | | | [IndustryData](./bitburner.industrydata.md) | Corporation industry information | diff --git a/markdown/bitburner.ns.getpurchasedservers.md b/markdown/bitburner.ns.getpurchasedservers.md index 9cfebbedd..c144645d5 100644 --- a/markdown/bitburner.ns.getpurchasedservers.md +++ b/markdown/bitburner.ns.getpurchasedservers.md @@ -4,18 +4,25 @@ ## NS.getPurchasedServers() method -Returns an array with the hostnames of all of the servers you have purchased. +Returns an array with the hostnames or IP addresses of all of the servers you have purchased. Returns hostnames by default. **Signature:** ```typescript -getPurchasedServers(): string[]; +getPurchasedServers(returnOpts?: HostReturnOptions): string[]; ``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| returnOpts | [HostReturnOptions](./bitburner.hostreturnoptions.md) | _(Optional)_ Optional. Controls whether the function returns IPs | + **Returns:** string\[\] -Returns an array with the hostnames of all of the servers you have purchased. +Returns an array with the hostnames or IP addresses of all of the servers you have purchased. ## Remarks diff --git a/markdown/bitburner.ns.getpurchasedserversbyip.md b/markdown/bitburner.ns.getpurchasedserversbyip.md deleted file mode 100644 index 060c04aac..000000000 --- a/markdown/bitburner.ns.getpurchasedserversbyip.md +++ /dev/null @@ -1,23 +0,0 @@ - - -[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [getPurchasedServersByIP](./bitburner.ns.getpurchasedserversbyip.md) - -## NS.getPurchasedServersByIP() method - -Returns an array with the IP addresses of all of the servers you have purchased. - -**Signature:** - -```typescript -getPurchasedServersByIP(): string[]; -``` -**Returns:** - -string\[\] - -Returns an array with the IP addresses of all of the servers you have purchased. - -## Remarks - -1.05 GB - diff --git a/markdown/bitburner.ns.md b/markdown/bitburner.ns.md index 675aef97e..ab570ec45 100644 --- a/markdown/bitburner.ns.md +++ b/markdown/bitburner.ns.md @@ -90,8 +90,7 @@ export async function main(ns) { | [getPurchasedServerCost(ram)](./bitburner.ns.getpurchasedservercost.md) | Get cost of purchasing a server. | | [getPurchasedServerLimit()](./bitburner.ns.getpurchasedserverlimit.md) | Returns the maximum number of servers you can purchase. | | [getPurchasedServerMaxRam()](./bitburner.ns.getpurchasedservermaxram.md) | Returns the maximum RAM that a purchased server can have. | -| [getPurchasedServers()](./bitburner.ns.getpurchasedservers.md) | Returns an array with the hostnames of all of the servers you have purchased. | -| [getPurchasedServersByIP()](./bitburner.ns.getpurchasedserversbyip.md) | Returns an array with the IP addresses of all of the servers you have purchased. | +| [getPurchasedServers(returnOpts)](./bitburner.ns.getpurchasedservers.md) | Returns an array with the hostnames or IP addresses of all of the servers you have purchased. Returns hostnames by default. | | [getPurchasedServerUpgradeCost(host, ram)](./bitburner.ns.getpurchasedserverupgradecost.md) | Get cost of upgrading a purchased server to the given ram. | | [getRecentScripts()](./bitburner.ns.getrecentscripts.md) | Get an array of recently killed scripts across all servers. | | [getResetInfo()](./bitburner.ns.getresetinfo.md) | Get information about resets. | @@ -154,8 +153,7 @@ export async function main(ns) { | [resizeTail(width, height, pid)](./bitburner.ns.resizetail.md) | Resize a tail window. This function is deprecated and will be removed in a later version. | | [rm(name, host)](./bitburner.ns.rm.md) | Delete a file. | | [run(script, threadOrOptions, args)](./bitburner.ns.run.md) | Start another script on the current server. | -| [scan(host)](./bitburner.ns.scan.md) | Get the list of hostnames connected to a server. | -| [scanByIP(host)](./bitburner.ns.scanbyip.md) | Get the list of IPs connected to a server. | +| [scan(host, returnOpts)](./bitburner.ns.scan.md) | Get the list of hostnames or IP addresses connected to a server. | | [scp(files, destination, source)](./bitburner.ns.scp.md) | Copy file between servers. | | [scriptKill(script, host)](./bitburner.ns.scriptkill.md) | Kill all scripts with a filename. | | [scriptRunning(script, host)](./bitburner.ns.scriptrunning.md) | Check if any script with a filename is running. | diff --git a/markdown/bitburner.ns.scan.md b/markdown/bitburner.ns.scan.md index ac7beb826..2eba03ffc 100644 --- a/markdown/bitburner.ns.scan.md +++ b/markdown/bitburner.ns.scan.md @@ -4,12 +4,12 @@ ## NS.scan() method -Get the list of hostnames connected to a server. +Get the list of hostnames or IP addresses connected to a server. **Signature:** ```typescript -scan(host?: string): string[]; +scan(host?: string, returnOpts?: HostReturnOptions): string[]; ``` ## Parameters @@ -17,6 +17,7 @@ scan(host?: string): string[]; | Parameter | Type | Description | | --- | --- | --- | | host | string | _(Optional)_ Optional. Hostname/IP of the server to scan, default to current server. | +| returnOpts | [HostReturnOptions](./bitburner.hostreturnoptions.md) | _(Optional)_ Optional. Controls whether the function returns IPs. | **Returns:** @@ -28,7 +29,7 @@ Returns an array of hostnames. RAM cost: 0.2 GB -Returns an array containing the hostnames of all servers that are one node way from the specified target server. The hostnames in the returned array are strings. +Returns an array containing the hostnames or IP addresses of all servers that are one node way from the specified target server. The hostnames/IPs in the returned array are strings. Returns hostnames by default. The server network is a tree graph with the home server at the root. The parent node is always the first item of the returned array. @@ -63,6 +64,12 @@ let neighbor = ns.scan(); for (let i = 0; i < neighbor.length; i++) { ns.tprint(neighbor[i]); } +// All servers that are one hop from the current server, but by IP address. +ns.tprint("IPs of current server's neighbors."); +let neighbor = ns.scan(null, { returnByIP: true }); +for (let i = 0; i < neighbor.length; i++) { + ns.tprint(neighbor[i]); +} // All neighbors of n00dles. const target = "n00dles"; neighbor = ns.scan(target); diff --git a/markdown/bitburner.ns.scanbyip.md b/markdown/bitburner.ns.scanbyip.md deleted file mode 100644 index cb9f932eb..000000000 --- a/markdown/bitburner.ns.scanbyip.md +++ /dev/null @@ -1,34 +0,0 @@ - - -[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [scanByIP](./bitburner.ns.scanbyip.md) - -## NS.scanByIP() method - -Get the list of IPs connected to a server. - -**Signature:** - -```typescript -scanByIP(host?: string): string[]; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| host | string | _(Optional)_ Optional. Hostname/IP of the server to scan, default to current server. | - -**Returns:** - -string\[\] - -Returns an array of IP addresses - -## Remarks - -RAM cost: 0.2 GB - -Returns an array containing the IP addresses of all servers that are one node way from the specified target server. The IP addresses in the returned array are strings. - -Works identically to [ns.scan](./bitburner.ns.scan.md). - diff --git a/markdown/bitburner.singularity.getcurrentserver.md b/markdown/bitburner.singularity.getcurrentserver.md index b9d5b0b9e..1dbbfac4c 100644 --- a/markdown/bitburner.singularity.getcurrentserver.md +++ b/markdown/bitburner.singularity.getcurrentserver.md @@ -4,18 +4,25 @@ ## Singularity.getCurrentServer() method -Get the current server. +Get the current server. Returns the hostname by default. **Signature:** ```typescript -getCurrentServer(): string; +getCurrentServer(returnOpts?: HostReturnOptions): string; ``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| returnOpts | [HostReturnOptions](./bitburner.hostreturnoptions.md) | _(Optional)_ Optional. Controls whether the function returns an IP. | + **Returns:** string -Name of the current server. +Hostname or IP address of the current server. ## Remarks diff --git a/markdown/bitburner.singularity.md b/markdown/bitburner.singularity.md index 4b35f26b7..1a29f1a4b 100644 --- a/markdown/bitburner.singularity.md +++ b/markdown/bitburner.singularity.md @@ -44,7 +44,7 @@ This API requires Source-File 4 to use. The RAM cost of all these functions is m | [getCompanyRep(companyName)](./bitburner.singularity.getcompanyrep.md) | Get company reputation. | | [getCrimeChance(crime)](./bitburner.singularity.getcrimechance.md) | Get chance to successfully commit a crime. | | [getCrimeStats(crime)](./bitburner.singularity.getcrimestats.md) | Get stats related to a crime. | -| [getCurrentServer()](./bitburner.singularity.getcurrentserver.md) | Get the current server. | +| [getCurrentServer(returnOpts)](./bitburner.singularity.getcurrentserver.md) | Get the current server. Returns the hostname by default. | | [getCurrentWork()](./bitburner.singularity.getcurrentwork.md) | Get the current work the player is doing. | | [getDarkwebProgramCost(programName)](./bitburner.singularity.getdarkwebprogramcost.md) | Check the price of an exploit on the dark web | | [getDarkwebPrograms()](./bitburner.singularity.getdarkwebprograms.md) | Get a list of programs offered on the dark web. | diff --git a/src/Netscript/NetscriptHelpers.tsx b/src/Netscript/NetscriptHelpers.tsx index 1d7b6f098..84bf78c22 100644 --- a/src/Netscript/NetscriptHelpers.tsx +++ b/src/Netscript/NetscriptHelpers.tsx @@ -75,6 +75,8 @@ export const helpers = { scriptArgs, runOptions, spawnOptions, + hostReturnOptions, + returnServerID, argsToString, basicErrorMessage, errorMessage, @@ -120,6 +122,10 @@ export interface CompleteHGWOptions { stock: boolean; additionalMsec: number; } +/** HostReturnOptions with non-optional, type-validated members, for passing between internal functions */ +export interface CompleteHostReturnOptions { + returnByIP: boolean; +} /** Convert a provided value v for argument argName to string. If it wasn't originally a string or number, throw. */ function string(ctx: NetscriptContext, argName: string, v: unknown): string { @@ -230,6 +236,21 @@ function spawnOptions(ctx: NetscriptContext, threadOrOption: unknown): CompleteS return result; } +function hostReturnOptions(returnOpts: unknown): CompleteHostReturnOptions { + const result: CompleteHostReturnOptions = { returnByIP: false }; + if (typeof returnOpts !== "object" || !returnOpts) return result; + // Safe assertion since threadOrOption type has been narrowed to a non-null object + const { returnByIP } = returnOpts as Unknownify; + result.returnByIP = !!returnByIP; + return result; +} + +/** Returns a servers hostname or IP based on the `returnByIP` field of HostReturnOptions */ +function returnServerID(server: BaseServer, returnOpts: CompleteHostReturnOptions): string { + const { returnByIP } = hostReturnOptions(returnOpts); + return returnByIP ? server.ip : server.hostname; +} + function mapToString(map: Map): string { const formattedMap = [...map] .map((m) => { diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index 3a25682bc..c8b0dd7aa 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -498,7 +498,6 @@ export const RamCosts: RamCostTree = { sprintf: 0, vsprintf: 0, scan: RamCostConstants.Scan, - scanByIP: RamCostConstants.Scan, hack: RamCostConstants.Hack, hackAnalyzeThreads: RamCostConstants.HackAnalyze, hackAnalyze: RamCostConstants.HackAnalyze, @@ -568,7 +567,6 @@ export const RamCosts: RamCostTree = { getPurchasedServerCost: RamCostConstants.GetPurchaseServer, getPurchasedServerUpgradeCost: 0.1, getPurchasedServers: 1.05, - getPurchasedServersByIP: 1.05, upgradePurchasedServer: 0.25, renamePurchasedServer: 0, purchaseServer: RamCostConstants.PurchaseServer, diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 60502cd48..9e7bd76b9 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -161,32 +161,23 @@ export const ns: InternalAPI = { } return vsprintf(format, _args); }, - scan: (ctx) => (_host) => { + scan: (ctx) => (_host, _returnOpts) => { const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname; + const returnOpts = helpers.hostReturnOptions(_returnOpts); const server = helpers.getServer(ctx, host); const out: string[] = []; for (let i = 0; i < server.serversOnNetwork.length; i++) { const s = getServerOnNetwork(server, i); if (s === null) continue; - const entry = s.hostname; + const entry = helpers.returnServerID(s, returnOpts); if (entry === null) continue; out.push(entry); } - helpers.log(ctx, () => `returned ${server.serversOnNetwork.length} connections for ${server.hostname}`); - return out; - }, - scanByIP: (ctx) => (_host) => { - const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname; - const server = helpers.getServer(ctx, host); - const out: string[] = []; - for (let i = 0; i < server.serversOnNetwork.length; i++) { - const s = getServerOnNetwork(server, i); - if (s === null) continue; - const entry = s.ip; - if (entry === null) continue; - out.push(entry); - } - helpers.log(ctx, () => `returned ${server.serversOnNetwork.length} connections for ${server.ip}`); + helpers.log( + ctx, + () => + `returned ${server.serversOnNetwork.length} connections for ${isIPAddress(host) ? server.ip : server.hostname}`, + ); return out; }, hasTorRouter: () => () => Player.hasTorRouter(), @@ -1157,9 +1148,9 @@ export const ns: InternalAPI = { return server.ramUsed; }, dnsLookup: (ctx) => (_host) => { - const identifier = helpers.string(ctx, "host", _host); - const server = helpers.getServer(ctx, identifier); - return isIPAddress(identifier) ? server.hostname : server.ip; + const host = helpers.string(ctx, "host", _host); + const server = helpers.getServer(ctx, host); + return isIPAddress(host) ? server.hostname : server.ip; }, serverExists: (ctx) => (_host) => { const host = helpers.string(ctx, "host", _host); @@ -1370,21 +1361,18 @@ export const ns: InternalAPI = { helpers.log(ctx, () => `Could not find server ${hostname} as a purchased server. This is a bug. Report to dev.`); return false; }, - getPurchasedServers: () => (): string[] => { - const res: string[] = []; - Player.purchasedServers.forEach(function (hostname) { - res.push(hostname); - }); - return res; - }, - getPurchasedServersByIP: (ctx) => (): string[] => { - const res: string[] = []; - Player.purchasedServers.forEach(function (hostname) { - const server = helpers.getServer(ctx, hostname); - res.push(server.ip); - }); - return res; - }, + getPurchasedServers: + (ctx) => + (_returnOpts): string[] => { + const returnOpts = helpers.hostReturnOptions(_returnOpts); + const res: string[] = []; + Player.purchasedServers.forEach(function (hostname) { + const server = helpers.getServer(ctx, hostname); + const id = helpers.returnServerID(server, returnOpts); + res.push(id); + }); + return res; + }, writePort: (ctx) => (_portNumber, data) => { const portNumber = helpers.portNumber(ctx, _portNumber); return writePort(portNumber, data); diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index bf950b80f..32f1b3419 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -463,20 +463,22 @@ export function NetscriptSingularity(): InternalAPI { Player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain / 5000); return true; }, - getCurrentServer: (ctx) => () => { + getCurrentServer: (ctx) => (_returnOpts) => { helpers.checkSingularityAccess(ctx); - return Player.getCurrentServer().hostname; + const returnOpts = helpers.hostReturnOptions(_returnOpts); + const server = Player.getCurrentServer(); + return helpers.returnServerID(server, returnOpts); }, connect: (ctx) => (_host) => { helpers.checkSingularityAccess(ctx); const host = helpers.string(ctx, "host", _host); if (!host) { - throw helpers.errorMessage(ctx, `Invalid hostname: '${host}'`); + throw helpers.errorMessage(ctx, `Invalid server: '${host}'`); } const target = GetServer(host); if (target == null) { - throw helpers.errorMessage(ctx, `Invalid hostname: '${host}'`); + throw helpers.errorMessage(ctx, `Invalid server: '${host}'`); } // Adjacent servers diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index d854567b3..3eaa4aebc 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -383,6 +383,16 @@ interface BasicHGWOptions { additionalMsec?: number; } +/** + * Options to control how a server identifier (hostname or IP address) is returned. + * Affects the behavior of {@link NS.scan | scan}, {@link NS.getPurchasedServers | getPurchasedServers}, and {@link Singularity.getCurrentServer | getCurrentServer} + * @public + */ +interface HostReturnOptions { + /** If set to `true`, returns IP addresses instead of hostnames. Defaults to `false`. */ + returnByIP?: boolean; +} + /** * Return value of {@link Sleeve.getSleevePurchasableAugs | getSleevePurchasableAugs} * @public @@ -2648,13 +2658,14 @@ export interface Singularity { /** * Get the current server. + * Returns the hostname by default. * @remarks * RAM cost: 2 GB * 16/4/1 * - * - * @returns Name of the current server. + * @param returnOpts - Optional. Controls whether the function returns an IP. + * @returns Hostname or IP address of the current server. */ - getCurrentServer(): string; + getCurrentServer(returnOpts?: HostReturnOptions): string; /** * Connect to a server. @@ -6718,13 +6729,13 @@ export interface NS { setTitle(title: string | ReactNode, pid?: number): void; /** - * Get the list of hostnames connected to a server. + * Get the list of hostnames or IP addresses connected to a server. * @remarks * RAM cost: 0.2 GB * - * Returns an array containing the hostnames of all servers that are one - * node way from the specified target server. The hostnames in the returned - * array are strings. + * Returns an array containing the hostnames or IP addresses of all servers that are one + * node way from the specified target server. The hostnames/IPs in the returned + * array are strings. Returns hostnames by default. * * The server network is a tree graph with the home server at the root. The parent node is always the first item of * the returned array. @@ -6761,6 +6772,12 @@ export interface NS { * for (let i = 0; i < neighbor.length; i++) { * ns.tprint(neighbor[i]); * } + * // All servers that are one hop from the current server, but by IP address. + * ns.tprint("IPs of current server's neighbors."); + * let neighbor = ns.scan(null, { returnByIP: true }); + * for (let i = 0; i < neighbor.length; i++) { + * ns.tprint(neighbor[i]); + * } * // All neighbors of n00dles. * const target = "n00dles"; * neighbor = ns.scan(target); @@ -6771,25 +6788,10 @@ export interface NS { * ``` * * @param host - Optional. Hostname/IP of the server to scan, default to current server. + * @param returnOpts - Optional. Controls whether the function returns IPs. * @returns Returns an array of hostnames. */ - scan(host?: string): string[]; - - /** - * Get the list of IPs connected to a server. - * @remarks - * RAM cost: 0.2 GB - * - * Returns an array containing the IP addresses of all servers that are one - * node way from the specified target server. The IP addresses in the returned - * array are strings. - * - * Works identically to {@link NS.scan | ns.scan}. - * - * @param host - Optional. Hostname/IP of the server to scan, default to current server. - * @returns Returns an array of IP addresses - */ - scanByIP(host?: string): string[]; + scan(host?: string, returnOpts?: HostReturnOptions): string[]; /** Returns whether the player has access to the darkweb. * @remarks @@ -7581,20 +7583,15 @@ export interface NS { deleteServer(host: string): boolean; /** - * Returns an array with the hostnames of all of the servers you have purchased. + * Returns an array with the hostnames or IP addresses of all of the servers you have purchased. + * Returns hostnames by default. * * @remarks 1.05 GB - * @returns Returns an array with the hostnames of all of the servers you have purchased. - */ - getPurchasedServers(): string[]; - - /** - * Returns an array with the IP addresses of all of the servers you have purchased. * - * @remarks 1.05 GB - * @returns Returns an array with the IP addresses of all of the servers you have purchased. + * @param returnOpts - Optional. Controls whether the function returns IPs + * @returns Returns an array with the hostnames or IP addresses of all of the servers you have purchased. */ - getPurchasedServersByIP(): string[]; + getPurchasedServers(returnOpts?: HostReturnOptions): string[]; /** * Returns the maximum number of servers you can purchase. From a7541694628fac0ff51ba0bb49e82c4b05c3a696 Mon Sep 17 00:00:00 2001 From: Naga Ouroboros Date: Fri, 7 Mar 2025 19:24:44 -0500 Subject: [PATCH 10/11] FIX: Minor documentation error --- markdown/bitburner.ns.scan.md | 2 +- src/ScriptEditor/NetscriptDefinitions.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/markdown/bitburner.ns.scan.md b/markdown/bitburner.ns.scan.md index 2eba03ffc..d5a4e6937 100644 --- a/markdown/bitburner.ns.scan.md +++ b/markdown/bitburner.ns.scan.md @@ -66,7 +66,7 @@ for (let i = 0; i < neighbor.length; i++) { } // All servers that are one hop from the current server, but by IP address. ns.tprint("IPs of current server's neighbors."); -let neighbor = ns.scan(null, { returnByIP: true }); +let neighbor = ns.scan(undefined, { returnByIP: true }); for (let i = 0; i < neighbor.length; i++) { ns.tprint(neighbor[i]); } diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 3eaa4aebc..3d189b63b 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -6774,7 +6774,7 @@ export interface NS { * } * // All servers that are one hop from the current server, but by IP address. * ns.tprint("IPs of current server's neighbors."); - * let neighbor = ns.scan(null, { returnByIP: true }); + * let neighbor = ns.scan(undefined, { returnByIP: true }); * for (let i = 0; i < neighbor.length; i++) { * ns.tprint(neighbor[i]); * } From c1c23f5039e89a1f034fd5f45587ebae881336f6 Mon Sep 17 00:00:00 2001 From: Naga Ouroboros Date: Fri, 7 Mar 2025 19:48:02 -0500 Subject: [PATCH 11/11] FIX: Got the documentation this time, I swear --- markdown/bitburner.ns.scan.md | 6 +++--- src/ScriptEditor/NetscriptDefinitions.d.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/markdown/bitburner.ns.scan.md b/markdown/bitburner.ns.scan.md index d5a4e6937..b494a5324 100644 --- a/markdown/bitburner.ns.scan.md +++ b/markdown/bitburner.ns.scan.md @@ -9,14 +9,14 @@ Get the list of hostnames or IP addresses connected to a server. **Signature:** ```typescript -scan(host?: string, returnOpts?: HostReturnOptions): string[]; +scan(host?: string | null, returnOpts?: HostReturnOptions): string[]; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| host | string | _(Optional)_ Optional. Hostname/IP of the server to scan, default to current server. | +| host | string \| null | _(Optional)_ Optional. Hostname/IP of the server to scan, default to current server. | | returnOpts | [HostReturnOptions](./bitburner.hostreturnoptions.md) | _(Optional)_ Optional. Controls whether the function returns IPs. | **Returns:** @@ -66,7 +66,7 @@ for (let i = 0; i < neighbor.length; i++) { } // All servers that are one hop from the current server, but by IP address. ns.tprint("IPs of current server's neighbors."); -let neighbor = ns.scan(undefined, { returnByIP: true }); +let neighbor = ns.scan(null, { returnByIP: true }); for (let i = 0; i < neighbor.length; i++) { ns.tprint(neighbor[i]); } diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 3d189b63b..7f8612afc 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -6774,7 +6774,7 @@ export interface NS { * } * // All servers that are one hop from the current server, but by IP address. * ns.tprint("IPs of current server's neighbors."); - * let neighbor = ns.scan(undefined, { returnByIP: true }); + * let neighbor = ns.scan(null, { returnByIP: true }); * for (let i = 0; i < neighbor.length; i++) { * ns.tprint(neighbor[i]); * } @@ -6791,7 +6791,7 @@ export interface NS { * @param returnOpts - Optional. Controls whether the function returns IPs. * @returns Returns an array of hostnames. */ - scan(host?: string, returnOpts?: HostReturnOptions): string[]; + scan(host?: string | null, returnOpts?: HostReturnOptions): string[]; /** Returns whether the player has access to the darkweb. * @remarks