Merge pull request #2934 from phyzical/bugfix/1955

added check for NS interface with user defined guard
This commit is contained in:
hydroflame
2022-03-10 21:44:37 -05:00
committed by GitHub
3 changed files with 13 additions and 8 deletions
+11 -6
View File
@@ -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) {