MISC: Refactor implementation of ports (#2396)

This moves the implementation entirely into the PortHandle class, which
makes the code a bit more streamlined and will allow for other port
implementations in the future.
This commit is contained in:
David Walker
2025-11-22 17:52:25 -08:00
committed by GitHub
parent 67119e6c9c
commit 50b0cc2808
3 changed files with 74 additions and 80 deletions
+4 -4
View File
@@ -26,7 +26,7 @@ import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
import { CONSTANTS } from "../Constants";
import { influenceStockThroughServerHack } from "../StockMarket/PlayerInfluencing";
import { PortNumber } from "../NetscriptPort";
import { type PortNumber, PortHandle } from "../NetscriptPort";
import { FormulaGang } from "../Gang/formulas/formulas";
import { GangMember } from "../Gang/GangMember";
import { GangMemberTask } from "../Gang/GangMemberTask";
@@ -88,7 +88,7 @@ export const helpers = {
getServer,
scriptIdentifier,
hack,
portNumber,
portHandle,
person,
server,
gang,
@@ -611,7 +611,7 @@ function hack(ctx: NetscriptContext, hostname: string, manual: boolean, opts: un
});
}
function portNumber(ctx: NetscriptContext, _n: unknown): PortNumber {
function portHandle(ctx: NetscriptContext, _n: unknown): PortHandle {
const n = positiveInteger(ctx, "portNumber", _n);
if (n > CONSTANTS.NumNetscriptPorts) {
throw errorMessage(
@@ -619,7 +619,7 @@ function portNumber(ctx: NetscriptContext, _n: unknown): PortNumber {
`Trying to use an invalid port: ${n}. Must be less or equal to ${CONSTANTS.NumNetscriptPorts}.`,
);
}
return n as PortNumber;
return new PortHandle(n as PortNumber);
}
function person(ctx: NetscriptContext, p: unknown): IPerson {