mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 12:15:44 +01:00
Merge pull request #2934 from phyzical/bugfix/1955
added check for NS interface with user defined guard
This commit is contained in:
commit
9d080c9901
2
dist/bitburner.d.ts
vendored
2
dist/bitburner.d.ts
vendored
@ -3915,7 +3915,7 @@ export declare interface NS extends Singularity {
|
|||||||
* @param data - Data to write.
|
* @param data - Data to write.
|
||||||
* @returns True if the data is successfully written to the port, and false otherwise.
|
* @returns True if the data is successfully written to the port, and false otherwise.
|
||||||
*/
|
*/
|
||||||
tryWritePort(port: number, data: string[] | number): Promise<boolean>;
|
tryWritePort(port: number, data: string | number): Promise<boolean>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read content of a file.
|
* Read content of a file.
|
||||||
|
@ -174,7 +174,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
throw makeRuntimeRejectMsg(
|
throw makeRuntimeRejectMsg(
|
||||||
workerScript,
|
workerScript,
|
||||||
`Invalid scriptArgs argument passed into getRunningScript() from ${callingFnName}(). ` +
|
`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(
|
workerScript.log(
|
||||||
"weaken",
|
"weaken",
|
||||||
() =>
|
() =>
|
||||||
`'${server.hostname}' security level weakened to ${
|
`'${server.hostname}' security level weakened to ${server.hackDifficulty
|
||||||
server.hackDifficulty
|
|
||||||
}. Gained ${numeralWrapper.formatExp(expGain)} hacking exp (t=${numeralWrapper.formatThreads(threads)})`,
|
}. Gained ${numeralWrapper.formatExp(expGain)} hacking exp (t=${numeralWrapper.formatThreads(threads)})`,
|
||||||
);
|
);
|
||||||
workerScript.scriptRef.onlineExpGained += expGain;
|
workerScript.scriptRef.onlineExpGained += expGain;
|
||||||
@ -1650,12 +1649,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
|
|
||||||
const cost = getPurchaseServerCost(ram);
|
const cost = getPurchaseServerCost(ram);
|
||||||
if (cost === Infinity) {
|
if (cost === Infinity) {
|
||||||
if(ram > getPurchaseServerMaxRam()){
|
if (ram > getPurchaseServerMaxRam()) {
|
||||||
workerScript.log("purchaseServer", () => `Invalid argument: ram='${ram}' must not be greater than 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`);
|
workerScript.log("purchaseServer", () => `Invalid argument: ram='${ram}' must be a positive power of 2`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1837,6 +1836,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
},
|
},
|
||||||
tryWritePort: function (port: any, data: any = ""): any {
|
tryWritePort: function (port: any, data: any = ""): any {
|
||||||
updateDynamicRam("tryWritePort", getRamCost(Player, "tryWritePort"));
|
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)) {
|
if (!isNaN(port)) {
|
||||||
port = Math.round(port);
|
port = Math.round(port);
|
||||||
if (port < 1 || port > CONSTANTS.NumNetscriptPorts) {
|
if (port < 1 || port > CONSTANTS.NumNetscriptPorts) {
|
||||||
|
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -5652,7 +5652,7 @@ export interface NS extends Singularity {
|
|||||||
* @param data - Data to write.
|
* @param data - Data to write.
|
||||||
* @returns True if the data is successfully written to the port, and false otherwise.
|
* @returns True if the data is successfully written to the port, and false otherwise.
|
||||||
*/
|
*/
|
||||||
tryWritePort(port: number, data: string[] | number): Promise<boolean>;
|
tryWritePort(port: number, data: string | number): Promise<boolean>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read content of a file.
|
* Read content of a file.
|
||||||
|
Loading…
Reference in New Issue
Block a user