Merge pull request #1866 from danielyxie/dev

getServer of hacknet doesn't return undefined
This commit is contained in:
hydroflame
2021-12-12 13:48:39 -05:00
committed by GitHub
4 changed files with 23 additions and 15 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1334,15 +1334,24 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
getServer: function (hostname: any = workerScript.hostname): any {
updateDynamicRam("getServer", getRamCost("getServer"));
const server = safeGetServer(hostname, "getServer");
const copy = Object.assign({}, server);
const copy = Object.assign({}, server) as any;
// These fields should be hidden.
copy.contracts = [];
copy.messages = [];
copy.runningScripts = [];
copy.scripts = [];
copy.textFiles = [];
copy.programs = [];
copy.serversOnNetwork = [];
copy.contracts = undefined;
copy.messages = undefined;
copy.runningScripts = undefined;
copy.scripts = undefined;
copy.textFiles = undefined;
copy.programs = undefined;
copy.serversOnNetwork = undefined;
if (!copy.baseDifficulty) copy.baseDifficulty = 0;
if (!copy.hackDifficulty) copy.hackDifficulty = 0;
if (!copy.minDifficulty) copy.minDifficulty = 0;
if (!copy.moneyAvailable) copy.moneyAvailable = 0;
if (!copy.moneyMax) copy.moneyMax = 0;
if (!copy.numOpenPortsRequired) copy.numOpenPortsRequired = 0;
if (!copy.openPortCount) copy.openPortCount = 0;
if (!copy.requiredHackingSkill) copy.requiredHackingSkill = 0;
if (!copy.serverGrowth) copy.serverGrowth = 0;
return copy;
},
getServerMoneyAvailable: function (hostname: any): any {

View File

@@ -4842,13 +4842,12 @@ export interface NS extends Singularity {
deleteServer(host: string): boolean;
/**
* Returns an array with either the hostnames or IPs of all of the servers you have purchased.
* Returns an array with the hostnames of all of the servers you have purchased.
*
* @remarks 2.25 GB
* @param hostnameMode - Optional. Defaults to true. Returns hostnames if true, and IPs if false.
* @returns Returns an array with either the hostnames or IPs of all of the servers you have purchased.
* @returns Returns an array with the hostnames of all of the servers you have purchased.
*/
getPurchasedServers(hostnameMode?: boolean): string[];
getPurchasedServers(): string[];
/**
* Returns the maximum number of servers you can purchase.