mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
NETSCRIPT: Add functionality and support to fully allow Players to use IP addresses in place of hostnames (#1990)
This commit is contained in:
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
20
markdown/bitburner.hostreturnoptions.md
Normal file
20
markdown/bitburner.hostreturnoptions.md
Normal file
@@ -0,0 +1,20 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[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 <code>true</code>, returns IP addresses instead of hostnames. Defaults to <code>false</code>. |
|
||||
|
||||
13
markdown/bitburner.hostreturnoptions.returnbyip.md
Normal file
13
markdown/bitburner.hostreturnoptions.returnbyip.md
Normal file
@@ -0,0 +1,13 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[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;
|
||||
```
|
||||
@@ -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 |
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
28
markdown/bitburner.ns.dnslookup.md
Normal file
28
markdown/bitburner.ns.dnslookup.md
Normal file
@@ -0,0 +1,28 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [dnsLookup](./bitburner.ns.dnslookup.md)
|
||||
|
||||
## NS.dnsLookup() method
|
||||
|
||||
Given a hostname, returns its IP address; or given an IP address, returns its hostname.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
dnsLookup(host: string): string;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| host | string | Hostname/IP of target server. |
|
||||
|
||||
**Returns:**
|
||||
|
||||
string
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 0.05 GB
|
||||
|
||||
@@ -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 <code>target server</code> on which to execute the script. |
|
||||
| host | string | Hostname/IP of the <code>target server</code> 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. |
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
23
markdown/bitburner.ns.getip.md
Normal file
23
markdown/bitburner.ns.getip.md
Normal file
@@ -0,0 +1,23 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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.)
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
@@ -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:**
|
||||
|
||||
@@ -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:**
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ grow(host: string, opts?: BasicHGWOptions): Promise<number>;
|
||||
|
||||
| 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:**
|
||||
|
||||
@@ -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. |
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
@@ -16,7 +16,7 @@ hack(host: string, opts?: BasicHGWOptions): Promise<number>;
|
||||
|
||||
| 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:**
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
@@ -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:**
|
||||
|
||||
@@ -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:**
|
||||
|
||||
@@ -64,9 +64,10 @@ 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 its IP address; or given an IP address, returns its hostname. |
|
||||
| [dynamicImport(path)](./bitburner.ns.dynamicimport.md) | Dynamically import a script. Only scripts located on the same server can be imported. A dynamic import will not adjust RAM usage. This must be done manually with [ramOverride](./bitburner.ns.ramoverride.md)<!-- -->. |
|
||||
| [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. |
|
||||
@@ -83,17 +84,18 @@ 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. |
|
||||
| [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. |
|
||||
| [getPurchasedServerUpgradeCost(hostname, ram)](./bitburner.ns.getpurchasedserverupgradecost.md) | Get cost of upgrading a purchased server to the given ram. |
|
||||
| [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. |
|
||||
| [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. |
|
||||
@@ -117,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. |
|
||||
@@ -129,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,7 +154,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 servers 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. |
|
||||
@@ -171,7 +173,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. |
|
||||
|
||||
@@ -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. |
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ RAM cost: 2.25 GB
|
||||
|
||||
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.
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -4,19 +4,20 @@
|
||||
|
||||
## NS.scan() method
|
||||
|
||||
Get the list of servers 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 | null, returnOpts?: HostReturnOptions): string[];
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| host | string | _(Optional)_ Optional. Hostname 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:**
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 <code>/</code>. |
|
||||
| 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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
|
||||
@@ -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:**
|
||||
|
||||
@@ -16,7 +16,7 @@ weaken(host: string, opts?: BasicHGWOptions): Promise<number>;
|
||||
|
||||
| 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:**
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ This API requires Source-File 4 to use. The RAM cost of all these functions is m
|
||||
| [cat(filename)](./bitburner.singularity.cat.md) | Displays the content of a file on the currently connected server. |
|
||||
| [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. |
|
||||
@@ -45,7 +45,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. |
|
||||
|
||||
@@ -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:**
|
||||
|
||||
@@ -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:**
|
||||
|
||||
@@ -76,6 +76,8 @@ export const helpers = {
|
||||
boolean,
|
||||
runOptions,
|
||||
spawnOptions,
|
||||
hostReturnOptions,
|
||||
returnServerID,
|
||||
argsToString,
|
||||
basicErrorMessage,
|
||||
errorMessage,
|
||||
@@ -121,6 +123,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 {
|
||||
@@ -239,6 +245,20 @@ 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 returnOpts type has been narrowed to a non-null object
|
||||
const { returnByIP } = returnOpts as Unknownify<CompleteHostReturnOptions>;
|
||||
result.returnByIP = !!returnByIP;
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Returns a server's hostname or IP based on the `returnByIP` field of HostReturnOptions */
|
||||
function returnServerID(server: BaseServer, returnOpts: CompleteHostReturnOptions): string {
|
||||
return returnOpts.returnByIP ? server.ip : server.hostname;
|
||||
}
|
||||
|
||||
function mapToString(map: Map<unknown, unknown>): string {
|
||||
const formattedMap = [...map]
|
||||
.map((m) => {
|
||||
|
||||
@@ -547,6 +547,7 @@ export const RamCosts: RamCostTree<NSFull> = {
|
||||
getRecentScripts: RamCostConstants.RecentScripts,
|
||||
hasRootAccess: RamCostConstants.HasRootAccess,
|
||||
getHostname: RamCostConstants.GetHostname,
|
||||
getIP: RamCostConstants.GetHostname,
|
||||
getHackingLevel: RamCostConstants.GetHackingLevel,
|
||||
getHackingMultipliers: 0.25,
|
||||
getHacknetMultipliers: 0.25,
|
||||
@@ -562,6 +563,7 @@ export const RamCosts: RamCostTree<NSFull> = {
|
||||
getServerNumPortsRequired: RamCostConstants.GetServer,
|
||||
getServerMaxRam: RamCostConstants.GetServerMaxRam,
|
||||
getServerUsedRam: RamCostConstants.GetServerUsedRam,
|
||||
dnsLookup: 0.05,
|
||||
serverExists: RamCostConstants.GetServer,
|
||||
fileExists: RamCostConstants.FileExists,
|
||||
isRunning: RamCostConstants.IsRunning,
|
||||
|
||||
@@ -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";
|
||||
import { compile } from "./NetscriptJSEvaluator";
|
||||
import { Script } from "./Script/Script";
|
||||
|
||||
@@ -162,31 +163,36 @@ export const ns: InternalAPI<NSFull> = {
|
||||
}
|
||||
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, _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}`);
|
||||
helpers.log(
|
||||
ctx,
|
||||
() =>
|
||||
`returned ${server.serversOnNetwork.length} connections for ${isIPAddress(host) ? server.ip : server.hostname}`,
|
||||
);
|
||||
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;
|
||||
@@ -212,10 +218,10 @@ export const ns: InternalAPI<NSFull> = {
|
||||
|
||||
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;
|
||||
@@ -223,11 +229,11 @@ export const ns: InternalAPI<NSFull> = {
|
||||
|
||||
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;
|
||||
@@ -243,10 +249,10 @@ export const ns: InternalAPI<NSFull> = {
|
||||
|
||||
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;
|
||||
@@ -270,11 +276,11 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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.");
|
||||
}
|
||||
@@ -295,12 +301,12 @@ export const ns: InternalAPI<NSFull> = {
|
||||
)} (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;
|
||||
@@ -345,12 +351,12 @@ export const ns: InternalAPI<NSFull> = {
|
||||
},
|
||||
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.");
|
||||
@@ -366,11 +372,11 @@ export const ns: InternalAPI<NSFull> = {
|
||||
|
||||
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.");
|
||||
}
|
||||
@@ -391,11 +397,11 @@ export const ns: InternalAPI<NSFull> = {
|
||||
)} (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;
|
||||
@@ -549,8 +555,8 @@ export const ns: InternalAPI<NSFull> = {
|
||||
},
|
||||
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));
|
||||
@@ -589,10 +595,10 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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;
|
||||
@@ -611,9 +617,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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;
|
||||
@@ -630,9 +636,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
}
|
||||
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;
|
||||
@@ -649,9 +655,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
}
|
||||
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;
|
||||
@@ -668,9 +674,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
}
|
||||
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;
|
||||
@@ -687,9 +693,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
}
|
||||
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;
|
||||
@@ -718,12 +724,12 @@ export const ns: InternalAPI<NSFull> = {
|
||||
},
|
||||
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:
|
||||
@@ -771,8 +777,8 @@ export const ns: InternalAPI<NSFull> = {
|
||||
},
|
||||
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) {
|
||||
@@ -800,7 +806,7 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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 {
|
||||
@@ -809,7 +815,7 @@ export const ns: InternalAPI<NSFull> = {
|
||||
} 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;
|
||||
@@ -817,10 +823,10 @@ export const ns: InternalAPI<NSFull> = {
|
||||
},
|
||||
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;
|
||||
|
||||
@@ -900,10 +906,10 @@ export const ns: InternalAPI<NSFull> = {
|
||||
}
|
||||
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),
|
||||
@@ -924,9 +930,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
},
|
||||
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()) {
|
||||
@@ -941,12 +947,17 @@ export const ns: InternalAPI<NSFull> = {
|
||||
}
|
||||
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,
|
||||
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}`);
|
||||
@@ -987,9 +998,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
|
||||
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,
|
||||
@@ -1017,9 +1028,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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;
|
||||
@@ -1035,9 +1046,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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;
|
||||
@@ -1048,9 +1059,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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;
|
||||
@@ -1061,9 +1072,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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;
|
||||
@@ -1074,9 +1085,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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;
|
||||
@@ -1087,9 +1098,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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;
|
||||
@@ -1100,9 +1111,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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;
|
||||
@@ -1113,9 +1124,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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;
|
||||
@@ -1126,27 +1137,32 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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;
|
||||
},
|
||||
serverExists: (ctx) => (_hostname) => {
|
||||
const hostname = helpers.string(ctx, "hostname", _hostname);
|
||||
const server = GetServer(hostname);
|
||||
dnsLookup: (ctx) => (_host) => {
|
||||
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);
|
||||
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);
|
||||
@@ -1159,8 +1175,8 @@ export const ns: InternalAPI<NSFull> = {
|
||||
},
|
||||
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: () => () => {
|
||||
@@ -1189,7 +1205,7 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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 "";
|
||||
}
|
||||
@@ -1242,22 +1258,22 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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));
|
||||
@@ -1347,13 +1363,18 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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;
|
||||
},
|
||||
getPurchasedServers:
|
||||
(ctx) =>
|
||||
(_returnOpts): string[] => {
|
||||
const returnOpts = helpers.hostReturnOptions(_returnOpts);
|
||||
const res: string[] = [];
|
||||
for (const hostname of Player.purchasedServers) {
|
||||
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);
|
||||
@@ -1427,10 +1448,10 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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;
|
||||
@@ -1443,16 +1464,16 @@ export const ns: InternalAPI<NSFull> = {
|
||||
|
||||
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));
|
||||
@@ -1466,23 +1487,23 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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
|
||||
@@ -1516,9 +1537,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
},
|
||||
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;
|
||||
@@ -1531,9 +1552,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
},
|
||||
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;
|
||||
@@ -1546,9 +1567,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
},
|
||||
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;
|
||||
@@ -1574,8 +1595,8 @@ export const ns: InternalAPI<NSFull> = {
|
||||
},
|
||||
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));
|
||||
@@ -1592,8 +1613,8 @@ export const ns: InternalAPI<NSFull> = {
|
||||
},
|
||||
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));
|
||||
@@ -1698,11 +1719,11 @@ export const ns: InternalAPI<NSFull> = {
|
||||
});
|
||||
});
|
||||
},
|
||||
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;
|
||||
@@ -1729,9 +1750,9 @@ export const ns: InternalAPI<NSFull> = {
|
||||
}
|
||||
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;
|
||||
},
|
||||
@@ -1785,8 +1806,8 @@ export const ns: InternalAPI<NSFull> = {
|
||||
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);
|
||||
|
||||
@@ -1802,13 +1823,13 @@ export const ns: InternalAPI<NSFull> = {
|
||||
}
|
||||
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.`);
|
||||
|
||||
@@ -49,10 +49,10 @@ export function NetscriptCodingContract(): InternalAPI<ICodingContract> {
|
||||
}
|
||||
|
||||
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<ICodingContract> {
|
||||
`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<ICodingContract> {
|
||||
},
|
||||
} 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) => {
|
||||
|
||||
@@ -464,9 +464,11 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
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);
|
||||
},
|
||||
cat: (ctx) => (_filename) => {
|
||||
helpers.checkSingularityAccess(ctx);
|
||||
@@ -474,16 +476,16 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
const server = Player.getCurrentServer();
|
||||
cat([filename], server);
|
||||
},
|
||||
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 server: '${host}'`);
|
||||
}
|
||||
|
||||
const target = GetServer(hostname);
|
||||
const target = GetServer(host);
|
||||
if (target == null) {
|
||||
throw helpers.errorMessage(ctx, `Invalid hostname: '${hostname}'`);
|
||||
throw helpers.errorMessage(ctx, `Invalid server: '${host}'`);
|
||||
}
|
||||
|
||||
// Adjacent servers
|
||||
@@ -498,8 +500,8 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if (other.hostname === hostname) {
|
||||
Terminal.connectToServer(hostname, true);
|
||||
if (other.hostname === target.hostname) {
|
||||
Terminal.connectToServer(host, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -509,7 +511,7 @@ export function NetscriptSingularity(): InternalAPI<ISingularity> {
|
||||
* is true.
|
||||
*/
|
||||
if (target.backdoorInstalled || target.purchasedByPlayer) {
|
||||
Terminal.connectToServer(hostname, true);
|
||||
Terminal.connectToServer(host, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ export function NetscriptUserInterface(): InternalAPI<IUserInterface> {
|
||||
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<IUserInterface> {
|
||||
|
||||
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));
|
||||
|
||||
224
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
224
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@@ -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;
|
||||
|
||||
/**
|
||||
* Displays the content of a file on the currently connected server.
|
||||
@@ -2671,11 +2682,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.
|
||||
@@ -3088,7 +3099,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
|
||||
@@ -3912,7 +3923,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.
|
||||
*/
|
||||
@@ -3927,7 +3938,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}`;
|
||||
@@ -3940,7 +3951,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;
|
||||
@@ -3955,7 +3966,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;
|
||||
@@ -3979,7 +3990,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;
|
||||
@@ -3992,7 +4003,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;
|
||||
@@ -5835,7 +5846,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;
|
||||
@@ -5935,7 +5946,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;
|
||||
@@ -6176,7 +6187,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).
|
||||
*/
|
||||
@@ -6222,7 +6233,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).
|
||||
*/
|
||||
@@ -6249,7 +6260,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.
|
||||
*/
|
||||
@@ -6311,7 +6322,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;
|
||||
@@ -6324,10 +6335,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.
|
||||
@@ -6341,7 +6352,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;
|
||||
@@ -6371,7 +6382,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).
|
||||
@@ -6386,11 +6397,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: {
|
||||
/**
|
||||
@@ -6642,7 +6653,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.
|
||||
*/
|
||||
@@ -6782,13 +6793,13 @@ export interface NS {
|
||||
setTitle(title: string | ReactNode, pid?: number): void;
|
||||
|
||||
/**
|
||||
* Get the list of servers 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.
|
||||
@@ -6825,6 +6836,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);
|
||||
@@ -6834,10 +6851,11 @@ 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.
|
||||
* @param returnOpts - Optional. Controls whether the function returns IPs.
|
||||
* @returns Returns an array of hostnames.
|
||||
*/
|
||||
scan(host?: string): string[];
|
||||
scan(host?: string | null, returnOpts?: HostReturnOptions): string[];
|
||||
|
||||
/** Returns whether the player has access to the darkweb.
|
||||
* @remarks
|
||||
@@ -6871,7 +6889,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;
|
||||
@@ -6887,7 +6905,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;
|
||||
@@ -6903,7 +6921,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;
|
||||
@@ -6919,7 +6937,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;
|
||||
@@ -6935,7 +6953,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;
|
||||
@@ -6951,7 +6969,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;
|
||||
@@ -7027,12 +7045,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.
|
||||
@@ -7075,7 +7093,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
|
||||
@@ -7089,7 +7107,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
|
||||
*
|
||||
@@ -7108,11 +7126,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.
|
||||
@@ -7124,7 +7142,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.
|
||||
*/
|
||||
@@ -7161,8 +7179,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;
|
||||
@@ -7175,7 +7193,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.
|
||||
*/
|
||||
@@ -7196,7 +7214,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[];
|
||||
@@ -7214,7 +7232,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;
|
||||
@@ -7228,6 +7246,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.
|
||||
*
|
||||
@@ -7280,7 +7307,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;
|
||||
@@ -7298,7 +7325,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;
|
||||
@@ -7310,7 +7337,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;
|
||||
@@ -7327,7 +7354,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;
|
||||
@@ -7341,7 +7368,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;
|
||||
@@ -7350,7 +7377,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;
|
||||
@@ -7362,7 +7389,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;
|
||||
@@ -7372,7 +7399,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;
|
||||
@@ -7381,7 +7408,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;
|
||||
@@ -7390,7 +7417,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;
|
||||
@@ -7399,16 +7426,24 @@ 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;
|
||||
|
||||
/**
|
||||
* Given a hostname, returns its IP address; or given an IP address, returns its hostname.
|
||||
*
|
||||
* @remarks RAM cost: 0.05 GB
|
||||
* @param host - Hostname/IP of target server.
|
||||
*/
|
||||
dnsLookup(host: string): string;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
@@ -7432,7 +7467,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;
|
||||
@@ -7443,8 +7478,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.)
|
||||
@@ -7461,7 +7496,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.
|
||||
*/
|
||||
@@ -7473,18 +7508,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.
|
||||
@@ -7531,9 +7566,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
|
||||
@@ -7567,22 +7602,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.
|
||||
@@ -7600,24 +7635,27 @@ 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;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
getPurchasedServers(): string[];
|
||||
getPurchasedServers(returnOpts?: HostReturnOptions): string[];
|
||||
|
||||
/**
|
||||
* Returns the maximum number of servers you can purchase.
|
||||
@@ -7785,7 +7823,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;
|
||||
@@ -7810,7 +7848,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;
|
||||
@@ -7824,7 +7862,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;
|
||||
@@ -7846,7 +7884,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;
|
||||
@@ -7860,7 +7898,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;
|
||||
@@ -7873,7 +7911,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;
|
||||
@@ -7886,7 +7924,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;
|
||||
@@ -7917,7 +7955,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.
|
||||
*/
|
||||
@@ -7945,7 +7983,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.
|
||||
*/
|
||||
@@ -8278,7 +8316,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.
|
||||
*/
|
||||
|
||||
@@ -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 "../Types/strings";
|
||||
|
||||
// Returns the cost of purchasing a server with the given RAM
|
||||
// Returns Infinity for invalid 'ram' arguments
|
||||
@@ -43,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(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 +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.`);
|
||||
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-")) {
|
||||
|
||||
@@ -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<string, string[]> = {
|
||||
" ",
|
||||
],
|
||||
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]",
|
||||
" ",
|
||||
|
||||
@@ -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";
|
||||
@@ -84,6 +85,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<string, (args: (string | number | boolean)[], server: BaseServer) => void> = {
|
||||
"scan-analyze": scananalyze,
|
||||
@@ -109,6 +111,7 @@ export const TerminalCommands: Record<string, (args: (string | number | boolean)
|
||||
history: history,
|
||||
home: home,
|
||||
hostname: hostname,
|
||||
ipaddr: ipaddr,
|
||||
kill: kill,
|
||||
killall: killall,
|
||||
ls: ls,
|
||||
@@ -593,11 +596,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
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
10
src/Terminal/commands/ipaddr.ts
Normal file
10
src/Terminal/commands/ipaddr.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Terminal } from "../../Terminal";
|
||||
import { BaseServer } from "../../Server/BaseServer";
|
||||
|
||||
export function ipaddr(args: (string | number | boolean)[], server: BaseServer): void {
|
||||
if (args.length !== 0) {
|
||||
Terminal.error("Incorrect usage of hostname command. Usage: ipaddr");
|
||||
return;
|
||||
}
|
||||
Terminal.print(server.ip);
|
||||
}
|
||||
Reference in New Issue
Block a user