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
|
// NeuroFlux Governor Augmentation cost multiplier
|
||||||
NeuroFluxGovernorLevelMult: 1.14,
|
NeuroFluxGovernorLevelMult: 1.14,
|
||||||
|
|
||||||
NumNetscriptPorts: 20,
|
NumNetscriptPorts: Number.MAX_SAFE_INTEGER,
|
||||||
|
|
||||||
// Server-related constants
|
// Server-related constants
|
||||||
HomeComputerMaxRam: 1073741824, // 2 ^ 30
|
HomeComputerMaxRam: 1073741824, // 2 ^ 30
|
||||||
|
@ -20,7 +20,7 @@ import { convertTimeMsToTimeElapsedString } from "../utils/StringHelperFunctions
|
|||||||
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
|
||||||
import { CONSTANTS } from "../Constants";
|
import { CONSTANTS } from "../Constants";
|
||||||
import { influenceStockThroughServerHack } from "../StockMarket/PlayerInfluencing";
|
import { influenceStockThroughServerHack } from "../StockMarket/PlayerInfluencing";
|
||||||
import { IPort } from "../NetscriptPort";
|
import { IPort, NetscriptPort } from "../NetscriptPort";
|
||||||
import { NetscriptPorts } from "../NetscriptWorker";
|
import { NetscriptPorts } from "../NetscriptWorker";
|
||||||
import { IPlayer } from "../PersonObjects/IPlayer";
|
import { IPlayer } from "../PersonObjects/IPlayer";
|
||||||
import { FormulaGang } from "../Gang/formulas/formulas";
|
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.`,
|
`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)) {
|
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;
|
return iport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ import { Server } from "./Server/Server";
|
|||||||
import { influenceStockThroughServerGrow } from "./StockMarket/PlayerInfluencing";
|
import { influenceStockThroughServerGrow } from "./StockMarket/PlayerInfluencing";
|
||||||
import { isValidFilePath, removeLeadingSlash } from "./Terminal/DirectoryHelpers";
|
import { isValidFilePath, removeLeadingSlash } from "./Terminal/DirectoryHelpers";
|
||||||
import { TextFile, getTextFile, createTextFile } from "./TextFile";
|
import { TextFile, getTextFile, createTextFile } from "./TextFile";
|
||||||
import { NetscriptPorts, runScriptFromScript } from "./NetscriptWorker";
|
import { runScriptFromScript } from "./NetscriptWorker";
|
||||||
import { killWorkerScript } from "./Netscript/killWorkerScript";
|
import { killWorkerScript } from "./Netscript/killWorkerScript";
|
||||||
import { workerScripts } from "./Netscript/WorkerScripts";
|
import { workerScripts } from "./Netscript/WorkerScripts";
|
||||||
import { WorkerScript } from "./Netscript/WorkerScript";
|
import { WorkerScript } from "./Netscript/WorkerScript";
|
||||||
@ -1518,29 +1518,15 @@ const base: InternalAPI<NS> = {
|
|||||||
tryWritePort:
|
tryWritePort:
|
||||||
(ctx: NetscriptContext) =>
|
(ctx: NetscriptContext) =>
|
||||||
(_port: unknown, data: unknown = ""): Promise<any> => {
|
(_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") {
|
if (typeof data !== "string" && typeof data !== "number") {
|
||||||
throw helpers.makeRuntimeErrorMsg(
|
throw helpers.makeRuntimeErrorMsg(
|
||||||
ctx,
|
ctx,
|
||||||
`Trying to write invalid data to a port: only strings and numbers are valid.`,
|
`Trying to write invalid data to a port: only strings and numbers are valid.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!isNaN(port)) {
|
const iport = helpers.getValidPort(ctx, 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.`);
|
|
||||||
}
|
|
||||||
return Promise.resolve(iport.tryWrite(data));
|
return Promise.resolve(iport.tryWrite(data));
|
||||||
} else {
|
|
||||||
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid argument: ${port}`);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
readPort:
|
readPort:
|
||||||
(ctx: NetscriptContext) =>
|
(ctx: NetscriptContext) =>
|
||||||
|
@ -13,7 +13,7 @@ import { CONSTANTS } from "./Constants";
|
|||||||
import { Interpreter } from "./ThirdParty/JSInterpreter";
|
import { Interpreter } from "./ThirdParty/JSInterpreter";
|
||||||
import { NetscriptFunctions } from "./NetscriptFunctions";
|
import { NetscriptFunctions } from "./NetscriptFunctions";
|
||||||
import { executeJSScript, Node } from "./NetscriptJSEvaluator";
|
import { executeJSScript, Node } from "./NetscriptJSEvaluator";
|
||||||
import { NetscriptPort, IPort } from "./NetscriptPort";
|
import { IPort } from "./NetscriptPort";
|
||||||
import { RunningScript } from "./Script/RunningScript";
|
import { RunningScript } from "./Script/RunningScript";
|
||||||
import { getRamUsageFromRunningScript } from "./Script/RunningScriptHelpers";
|
import { getRamUsageFromRunningScript } from "./Script/RunningScriptHelpers";
|
||||||
import { scriptCalculateOfflineProduction } from "./Script/ScriptHelpers";
|
import { scriptCalculateOfflineProduction } from "./Script/ScriptHelpers";
|
||||||
@ -37,18 +37,15 @@ import { Terminal } from "./Terminal";
|
|||||||
import { ScriptArg } from "./Netscript/ScriptArg";
|
import { ScriptArg } from "./Netscript/ScriptArg";
|
||||||
import { helpers } from "./Netscript/NetscriptHelpers";
|
import { helpers } from "./Netscript/NetscriptHelpers";
|
||||||
|
|
||||||
// Netscript Ports are instantiated here
|
export const NetscriptPorts: Map<number, IPort> = new Map();
|
||||||
export const NetscriptPorts: IPort[] = [];
|
|
||||||
for (let i = 0; i < CONSTANTS.NumNetscriptPorts; ++i) {
|
|
||||||
NetscriptPorts.push(NetscriptPort());
|
|
||||||
}
|
|
||||||
|
|
||||||
export function prestigeWorkerScripts(): void {
|
export function prestigeWorkerScripts(): void {
|
||||||
for (const ws of workerScripts.values()) {
|
for (const ws of workerScripts.values()) {
|
||||||
ws.env.stopFlag = true;
|
ws.env.stopFlag = true;
|
||||||
killWorkerScript(ws);
|
killWorkerScript(ws);
|
||||||
}
|
}
|
||||||
for (const port of NetscriptPorts) {
|
|
||||||
|
for (const [__, port] of NetscriptPorts.entries()) {
|
||||||
port.clear();
|
port.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user