added basic type check to tryWritePort

This commit is contained in:
phyzical
2022-02-07 22:14:48 +08:00
parent 6ed5a445a8
commit e8954bc1ee
3 changed files with 8 additions and 2 deletions
+6
View File
@@ -1841,6 +1841,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") || isNS(data)) {
throw makeRuntimeErrorMsg(
"writePort",
`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) {