mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-19 06:03:50 +01:00
Merge pull request #4073 from Hoekstraa/unlimited-ports
API: More ports (previously max 20, now practically unlimited)
This commit is contained in:
commit
0044761fd3
@ -124,7 +124,7 @@ export const CONSTANTS: {
|
||||
// NeuroFlux Governor Augmentation cost multiplier
|
||||
NeuroFluxGovernorLevelMult: 1.14,
|
||||
|
||||
NumNetscriptPorts: 20,
|
||||
NumNetscriptPorts: Number.MAX_SAFE_INTEGER,
|
||||
|
||||
// Server-related constants
|
||||
HomeComputerMaxRam: 1073741824, // 2 ^ 30
|
||||
|
@ -20,7 +20,7 @@ import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions
|
||||
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
||||
import { CONSTANTS } from "../Constants";
|
||||
import { influenceStockThroughServerHack } from "../StockMarket/PlayerInfluencing";
|
||||
import { IPort } from "../NetscriptPort";
|
||||
import { IPort, NetscriptPort } from "../NetscriptPort";
|
||||
import { NetscriptPorts } from "../NetscriptWorker";
|
||||
import { IPlayer } from "../PersonObjects/IPlayer";
|
||||
import { FormulaGang } from "../Gang/formulas/formulas";
|
||||
@ -492,10 +492,16 @@ function getValidPort(ctx: NetscriptContext, port: number): IPort {
|
||||
`Trying to use an invalid port: ${port}. Only ports 1-${CONSTANTS.NumNetscriptPorts} are valid.`,
|
||||
);
|
||||
}
|
||||
const iport = NetscriptPorts[port - 1];
|
||||
let iport = NetscriptPorts.get(port);
|
||||
if (iport == null || !(iport instanceof Object)) {
|
||||
throw makeRuntimeErrorMsg(ctx, `Could not find port: ${port}. This is a bug. Report to dev.`);
|
||||
NetscriptPorts.set(port, NetscriptPort());
|
||||
}
|
||||
// Try again.
|
||||
iport = NetscriptPorts.get(port);
|
||||
if (iport == null || !(iport instanceof Object)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Could not find port: ${port}. This is a bug. Report to dev.`);
|
||||
}
|
||||
|
||||
return iport;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ import { Server } from "./Server/Server";
|
||||
import { influenceStockThroughServerGrow } from "./StockMarket/PlayerInfluencing";
|
||||
import { isValidFilePath, removeLeadingSlash } from "./Terminal/DirectoryHelpers";
|
||||
import { TextFile, getTextFile, createTextFile } from "./TextFile";
|
||||
import { NetscriptPorts, runScriptFromScript } from "./NetscriptWorker";
|
||||
import { runScriptFromScript } from "./NetscriptWorker";
|
||||
import { killWorkerScript } from "./Netscript/killWorkerScript";
|
||||
import { workerScripts } from "./Netscript/WorkerScripts";
|
||||
import { WorkerScript } from "./Netscript/WorkerScript";
|
||||
@ -1518,29 +1518,15 @@ const base: InternalAPI<NS> = {
|
||||
tryWritePort:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_port: unknown, data: unknown = ""): Promise<any> => {
|
||||
let port = helpers.number(ctx, "port", _port);
|
||||
const port = helpers.number(ctx, "port", _port);
|
||||
if (typeof data !== "string" && typeof data !== "number") {
|
||||
throw helpers.makeRuntimeErrorMsg(
|
||||
ctx,
|
||||
`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) {
|
||||
throw helpers.makeRuntimeErrorMsg(
|
||||
ctx,
|
||||
`Invalid port: ${port}. Only ports 1-${CONSTANTS.NumNetscriptPorts} are valid.`,
|
||||
);
|
||||
}
|
||||
const iport = NetscriptPorts[port - 1];
|
||||
if (iport == null || !(iport instanceof Object)) {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Could not find port: ${port}. This is a bug. Report to dev.`);
|
||||
}
|
||||
const iport = helpers.getValidPort(ctx, port);
|
||||
return Promise.resolve(iport.tryWrite(data));
|
||||
} else {
|
||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid argument: ${port}`);
|
||||
}
|
||||
},
|
||||
readPort:
|
||||
(ctx: NetscriptContext) =>
|
||||
|
@ -13,7 +13,7 @@ import { CONSTANTS } from "./Constants";
|
||||
import { Interpreter } from "./ThirdParty/JSInterpreter";
|
||||
import { NetscriptFunctions } from "./NetscriptFunctions";
|
||||
import { executeJSScript, Node } from "./NetscriptJSEvaluator";
|
||||
import { NetscriptPort, IPort } from "./NetscriptPort";
|
||||
import { IPort } from "./NetscriptPort";
|
||||
import { RunningScript } from "./Script/RunningScript";
|
||||
import { getRamUsageFromRunningScript } from "./Script/RunningScriptHelpers";
|
||||
import { scriptCalculateOfflineProduction } from "./Script/ScriptHelpers";
|
||||
@ -37,18 +37,15 @@ import { Terminal } from "./Terminal";
|
||||
import { ScriptArg } from "./Netscript/ScriptArg";
|
||||
import { helpers } from "./Netscript/NetscriptHelpers";
|
||||
|
||||
// Netscript Ports are instantiated here
|
||||
export const NetscriptPorts: IPort[] = [];
|
||||
for (let i = 0; i < CONSTANTS.NumNetscriptPorts; ++i) {
|
||||
NetscriptPorts.push(NetscriptPort());
|
||||
}
|
||||
export const NetscriptPorts: Map<number, IPort> = new Map();
|
||||
|
||||
export function prestigeWorkerScripts(): void {
|
||||
for (const ws of workerScripts.values()) {
|
||||
ws.env.stopFlag = true;
|
||||
killWorkerScript(ws);
|
||||
}
|
||||
for (const port of NetscriptPorts) {
|
||||
|
||||
for (const [__, port] of NetscriptPorts.entries()) {
|
||||
port.clear();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user