mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-05-07 16:17:49 +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:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user