diff --git a/dist/bitburner.d.ts b/dist/bitburner.d.ts index 56fc6734c..24335cadd 100644 --- a/dist/bitburner.d.ts +++ b/dist/bitburner.d.ts @@ -3915,7 +3915,7 @@ export declare interface NS extends Singularity { * @param data - Data to write. * @returns True if the data is successfully written to the port, and false otherwise. */ - tryWritePort(port: number, data: string[] | number): Promise; + tryWritePort(port: number, data: string | number): Promise; /** * Read content of a file. diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 2a6efef8e..45549b987 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -174,7 +174,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { throw makeRuntimeRejectMsg( workerScript, `Invalid scriptArgs argument passed into getRunningScript() from ${callingFnName}(). ` + - `This is probably a bug. Please report to game developer`, + `This is probably a bug. Please report to game developer`, ); } @@ -692,8 +692,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { workerScript.log( "weaken", () => - `'${server.hostname}' security level weakened to ${ - server.hackDifficulty + `'${server.hostname}' security level weakened to ${server.hackDifficulty }. Gained ${numeralWrapper.formatExp(expGain)} hacking exp (t=${numeralWrapper.formatThreads(threads)})`, ); workerScript.scriptRef.onlineExpGained += expGain; @@ -1650,12 +1649,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { const cost = getPurchaseServerCost(ram); if (cost === Infinity) { - if(ram > getPurchaseServerMaxRam()){ + if (ram > getPurchaseServerMaxRam()) { workerScript.log("purchaseServer", () => `Invalid argument: ram='${ram}' must not be greater than getPurchaseServerMaxRam`); - }else{ + } else { workerScript.log("purchaseServer", () => `Invalid argument: ram='${ram}' must be a positive power of 2`); } - + return ""; } @@ -1837,6 +1836,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { }, tryWritePort: function (port: any, data: any = ""): any { updateDynamicRam("tryWritePort", getRamCost(Player, "tryWritePort")); + if (typeof data !== "string" && typeof data !== "number") { + throw makeRuntimeErrorMsg( + "tryWritePort", + `Trying to write invalid data to a port: only strings and numbers are valid.`, + ); + } if (!isNaN(port)) { port = Math.round(port); if (port < 1 || port > CONSTANTS.NumNetscriptPorts) { diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index c2e582f53..c5669f5ad 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -5652,7 +5652,7 @@ export interface NS extends Singularity { * @param data - Data to write. * @returns True if the data is successfully written to the port, and false otherwise. */ - tryWritePort(port: number, data: string[] | number): Promise; + tryWritePort(port: number, data: string | number): Promise; /** * Read content of a file.