more convertion from ip to hostname

This commit is contained in:
Olivier Gagnon 2021-10-07 16:56:01 -04:00
parent be29481689
commit a7dfb1a537
30 changed files with 161 additions and 189 deletions

@ -6,8 +6,7 @@ import {
} from "./CodingContracts";
import { Factions } from "./Faction/Factions";
import { Player } from "./Player";
import { GetAllServers } from "./Server/AllServers";
import { getServer } from "./Server/ServerHelpers";
import { GetServer, GetAllServers } from "./Server/AllServers";
import { SpecialServerNames } from "./Server/SpecialServerIps";
import { Server } from "./Server/Server";
import { BaseServer } from "./Server/BaseServer";
@ -68,7 +67,7 @@ export function generateContract(params: IGenerateContractParams): void {
// Server
let server;
if (params.server != null) {
server = getServer(params.server);
server = GetServer(params.server);
if (server == null) {
server = getRandomServer();
}

@ -8,9 +8,8 @@ import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import Select, { SelectChangeEvent } from "@mui/material/Select";
import { GetAllServers } from "../../Server/AllServers";
import { GetServer, GetAllServers } from "../../Server/AllServers";
import { Server } from "../../Server/Server";
import { GetServerByHostname } from "../../Server/ServerHelpers";
import MenuItem from "@mui/material/MenuItem";
export function Servers(): React.ReactElement {
@ -19,7 +18,7 @@ export function Servers(): React.ReactElement {
setServer(event.target.value as string);
}
function rootServer(): void {
const s = GetServerByHostname(server);
const s = GetServer(server);
if (s === null) return;
if (!(s instanceof Server)) return;
s.hasAdminRights = true;
@ -45,7 +44,7 @@ export function Servers(): React.ReactElement {
}
function minSecurity(): void {
const s = GetServerByHostname(server);
const s = GetServer(server);
if (s === null) return;
if (!(s instanceof Server)) return;
s.hackDifficulty = s.minDifficulty;
@ -59,7 +58,7 @@ export function Servers(): React.ReactElement {
}
function maxMoney(): void {
const s = GetServerByHostname(server);
const s = GetServer(server);
if (s === null) return;
if (!(s instanceof Server)) return;
s.moneyAvailable = s.moneyMax;

@ -1,6 +1,5 @@
import React from "react";
import { GetAllServers } from "../Server/AllServers";
import { getServer } from "../Server/ServerHelpers";
import { GetServer, GetAllServers } from "../Server/AllServers";
import { Modal } from "../ui/React/Modal";
import { numeralWrapper } from "../ui/numeralFormat";
@ -22,7 +21,7 @@ interface IServerProps {
}
function ServerAccordion(props: IServerProps): React.ReactElement {
const server = getServer(props.ip);
const server = GetServer(props.ip);
if (server === null) throw new Error("server should not be null");
let totalSize = 0;
for (const f of server.scripts) {

@ -19,7 +19,7 @@ import { HashUpgrades } from "./HashUpgrades";
import { generateRandomContract } from "../CodingContractGenerator";
import { iTutorialSteps, iTutorialNextStep, ITutorial } from "../InteractiveTutorial";
import { IPlayer } from "../PersonObjects/IPlayer";
import { GetServerByHostname, getServer } from "../Server/ServerHelpers";
import { GetServer } from "../Server/AllServers";
import { Server } from "../Server/Server";
import { SourceFileFlags } from "../SourceFile/SourceFileFlags";
@ -415,7 +415,7 @@ function processAllHacknetServerEarnings(player: IPlayer, numCycles: number): nu
// Also, update the hash rate before processing
const ip = player.hacknetNodes[i];
if (ip instanceof HacknetNode) throw new Error(`player nodes should not be HacketNode`);
const hserver = getServer(ip);
const hserver = GetServer(ip);
if (!(hserver instanceof HacknetServer)) throw new Error(`player nodes shoud not be Server`);
hserver.updateHashRate(player.hacknet_node_money_mult);
const h = hserver.process(numCycles);
@ -447,7 +447,7 @@ export function updateHashManagerCapacity(player: IPlayer): void {
}
const ip = nodes[i];
if (ip instanceof HacknetNode) throw new Error(`player nodes should be string but isn't`);
const h = getServer(ip);
const h = GetServer(ip);
if (!(h instanceof HacknetServer)) {
player.hashManager.updateCapacity(0);
return;
@ -487,7 +487,7 @@ export function purchaseHashUpgrade(player: IPlayer, upgName: string, upgTarget:
}
case "Reduce Minimum Security": {
try {
const target = GetServerByHostname(upgTarget);
const target = GetServer(upgTarget);
if (target == null) {
console.error(`Invalid target specified in purchaseHashUpgrade(): ${upgTarget}`);
return false;
@ -503,7 +503,7 @@ export function purchaseHashUpgrade(player: IPlayer, upgName: string, upgTarget:
}
case "Increase Maximum Money": {
try {
const target = GetServerByHostname(upgTarget);
const target = GetServer(upgTarget);
if (target == null) {
console.error(`Invalid target specified in purchaseHashUpgrade(): ${upgTarget}`);
return false;

@ -22,8 +22,7 @@ import {
} from "../HacknetHelpers";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { getServer } from "../../Server/ServerHelpers";
import { Server } from "../../Server/Server";
import { GetServer } from "../../Server/AllServers";
import Typography from "@mui/material/Typography";
import Grid from "@mui/material/Grid";
@ -51,7 +50,7 @@ export function HacknetRoot(props: IProps): React.ReactElement {
const node = props.player.hacknetNodes[i];
if (hasHacknetServers(props.player)) {
if (node instanceof HacknetNode) throw new Error("node was hacknet node"); // should never happen
const hserver = getServer(node);
const hserver = GetServer(node);
if (!(hserver instanceof HacknetServer)) throw new Error("node was not hacknet server"); // should never happen
if (hserver) {
totalProduction += hserver.hashRate;
@ -89,7 +88,7 @@ export function HacknetRoot(props: IProps): React.ReactElement {
const nodes = props.player.hacknetNodes.map((node: string | HacknetNode) => {
if (hasHacknetServers(props.player)) {
if (node instanceof HacknetNode) throw new Error("node was hacknet node"); // should never happen
const hserver = getServer(node);
const hserver = GetServer(node);
if (hserver == null) {
throw new Error(`Could not find Hacknet Server object in AllServers map for IP: ${node}`);
}

@ -23,8 +23,8 @@ import { LocationType } from "../LocationTypeEnum";
import { Settings } from "../../Settings/Settings";
import { SpecialServerIps } from "../../Server/SpecialServerIps";
import { getServer, isBackdoorInstalled } from "../../Server/ServerHelpers";
import { isBackdoorInstalled } from "../../Server/ServerHelpers";
import { GetServer } from "../../Server/AllServers";
import { CorruptableText } from "../../ui/React/CorruptableText";
import { use } from "../../ui/Context";
@ -83,8 +83,7 @@ export function GenericLocation({ loc }: IProps): React.ReactElement {
}
const locContent: React.ReactNode[] = getLocationSpecificContent();
const ip = SpecialServerIps.getIp(loc.name);
const server = getServer(ip);
const server = GetServer(loc.name);
const backdoorInstalled = server !== null && isBackdoorInstalled(server);
return (

@ -10,9 +10,8 @@ import { Location } from "../Location";
import { CONSTANTS } from "../../Constants";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { getServer } from "../../Server/ServerHelpers";
import { GetServer } from "../../Server/AllServers";
import { Server } from "../../Server/Server";
import { SpecialServerIps } from "../../Server/SpecialServerIps";
import { Money } from "../../ui/React/Money";
import { IRouter } from "../../ui/Router";
@ -25,8 +24,7 @@ type IProps = {
export function GymLocation(props: IProps): React.ReactElement {
function calculateCost(): number {
const ip = SpecialServerIps.getIp(props.loc.name);
const server = getServer(ip);
const server = GetServer(props.loc.name);
if (server == null || !server.hasOwnProperty("backdoorInstalled")) return props.loc.costMult;
const discount = (server as Server).backdoorInstalled ? 0.9 : 1;
return props.loc.costMult * discount;

@ -10,9 +10,8 @@ import Button from "@mui/material/Button";
import { Location } from "../Location";
import { CONSTANTS } from "../../Constants";
import { getServer } from "../../Server/ServerHelpers";
import { GetServer } from "../../Server/AllServers";
import { Server } from "../../Server/Server";
import { SpecialServerIps } from "../../Server/SpecialServerIps";
import { Money } from "../../ui/React/Money";
import { use } from "../../ui/Context";
@ -26,8 +25,7 @@ export function UniversityLocation(props: IProps): React.ReactElement {
const router = use.Router();
function calculateCost(): number {
const ip = SpecialServerIps.getIp(props.loc.name);
const server = getServer(ip);
const server = GetServer(props.loc.name);
if (server == null || !server.hasOwnProperty("backdoorInstalled")) return props.loc.costMult;
const discount = (server as Server).backdoorInstalled ? 0.9 : 1;
return props.loc.costMult * discount;

@ -4,7 +4,7 @@ import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
import { Programs } from "../Programs/Programs";
import { Player } from "../Player";
import { redPillFlag } from "../RedPill";
import { GetServerByHostname } from "../Server/ServerHelpers";
import { GetServer } from "../Server/AllServers";
import { Settings } from "../Settings/Settings";
import { dialogBoxCreate } from "../ui/React/DialogBox";
import { Reviver } from "../utils/JSONReviver";
@ -32,7 +32,7 @@ function showMessage(msg: Message): void {
//Adds a message to a server
function addMessageToServer(msg: Message, serverHostname: string): void {
const server = GetServerByHostname(serverHostname);
const server = GetServer(serverHostname);
if (server == null) {
console.warn(`Could not find server ${serverHostname}`);
return;

@ -2,7 +2,7 @@ import { Milestone } from "./Milestone";
import { IPlayer } from "../PersonObjects/IPlayer";
import { Factions } from "../Faction/Factions";
import { Faction } from "../Faction/Faction";
import { GetServerByHostname } from "../Server/ServerHelpers";
import { GetServer } from "../Server/AllServers";
function allFactionAugs(p: IPlayer, f: Faction): boolean {
const factionAugs = f.augmentations.slice().filter((aug) => aug !== "NeuroFlux Governor");
@ -21,7 +21,7 @@ export const Milestones: Milestone[] = [
{
title: "Gain root access on CSEC",
fulfilled: (): boolean => {
const server = GetServerByHostname("CSEC");
const server = GetServer("CSEC");
if (!server || !server.hasOwnProperty("hasAdminRights")) return false;
return (server as any).hasAdminRights;
},
@ -29,7 +29,7 @@ export const Milestones: Milestone[] = [
{
title: "Install the backdoor on CSEC",
fulfilled: (): boolean => {
const server = GetServerByHostname("CSEC");
const server = GetServer("CSEC");
if (!server || !server.hasOwnProperty("backdoorInstalled")) return false;
return (server as any).backdoorInstalled;
},

@ -11,7 +11,7 @@ import { RamCostConstants } from "./RamCostGenerator";
import { RunningScript } from "../Script/RunningScript";
import { Script } from "../Script/Script";
import { getServer } from "../Server/ServerHelpers";
import { GetServer } from "../Server/AllServers";
import { BaseServer } from "../Server/BaseServer";
import { IMap } from "../types";
@ -118,7 +118,7 @@ export class WorkerScript {
runningScriptObj.pid = sanitizedPid;
// Get the underlying script's code
const server = getServer(this.serverIp);
const server = GetServer(this.serverIp);
if (server == null) {
throw new Error(`WorkerScript constructed with invalid server ip: ${this.serverIp}`);
}
@ -147,7 +147,7 @@ export class WorkerScript {
* Returns the Server on which this script is running
*/
getServer(): BaseServer {
const server = getServer(this.serverIp);
const server = GetServer(this.serverIp);
if (server == null) throw new Error(`Script ${this.name} pid ${this.pid} is running on non-existent server?`);
return server;
}

@ -7,7 +7,7 @@ import { workerScripts } from "./WorkerScripts";
import { WorkerScriptStartStopEventEmitter } from "./WorkerScriptStartStopEventEmitter";
import { RunningScript } from "../Script/RunningScript";
import { getServer } from "../Server/ServerHelpers";
import { GetServer } from "../Server/AllServers";
import { compareArrays } from "../utils/helpers/compareArrays";
import { roundToTwo } from "../utils/helpers/roundToTwo";
@ -84,7 +84,7 @@ function removeWorkerScript(workerScript: WorkerScript, rerenderUi = true): void
const name = workerScript.name;
// Get the server on which the script runs
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
console.error(`Could not find server on which this script is running: ${ip}`);
return;

@ -1,5 +1,5 @@
import { isString } from "./utils/helpers/isString";
import { getServer } from "./Server/ServerHelpers";
import { GetServer } from "./Server/AllServers";
import { WorkerScript } from "./Netscript/WorkerScript";
export function netscriptDelay(time: number, workerScript: WorkerScript): Promise<void> {
@ -14,7 +14,7 @@ export function netscriptDelay(time: number, workerScript: WorkerScript): Promis
export function makeRuntimeRejectMsg(workerScript: WorkerScript, msg: string): string {
const lineNum = "";
const server = getServer(workerScript.serverIp);
const server = GetServer(workerScript.serverIp);
if (server == null) {
throw new Error(`WorkerScript constructed with invalid server ip: ${workerScript.serverIp}`);
}

@ -59,18 +59,6 @@ import { Factions, factionExists } from "./Faction/Factions";
import { joinFaction, purchaseAugmentation } from "./Faction/FactionHelpers";
import { netscriptCanGrow, netscriptCanHack, netscriptCanWeaken } from "./Hacking/netscriptCanHack";
import {
getCostOfNextHacknetNode,
getCostOfNextHacknetServer,
hasHacknetServers,
purchaseHacknet,
purchaseLevelUpgrade,
purchaseRamUpgrade,
purchaseCoreUpgrade,
purchaseCacheUpgrade,
purchaseHashUpgrade,
updateHashManagerCapacity,
} from "./Hacknet/HacknetHelpers";
import {
calculateMoneyGainRate,
calculateLevelUpgradeCost,
@ -101,11 +89,9 @@ import { findRunningScript, findRunningScriptByPid } from "./Script/ScriptHelper
import { isScriptFilename } from "./Script/isScriptFilename";
import { PromptEvent } from "./ui/React/PromptManager";
import { GetAllServers, DeleteServer, AddToAllServers, createUniqueRandomIp } from "./Server/AllServers";
import { GetServer, GetAllServers, DeleteServer, AddToAllServers, createUniqueRandomIp } from "./Server/AllServers";
import { RunningScript } from "./Script/RunningScript";
import {
GetServerByHostname,
getServer,
getServerOnNetwork,
numCycleForGrowth,
processSingleServerGrowth,
@ -251,7 +237,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
* @returns {Server} The specified Server
*/
const safeGetServer = function (ip: any, callingFnName: any = ""): BaseServer {
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg(callingFnName, `Invalid IP/hostname: ${ip}`);
}
@ -599,7 +585,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
throw makeRuntimeErrorMsg("hack", "Takes 1 argument.");
}
const threads = resolveNetscriptRequestedThreads(workerScript, "hack", requestedThreads);
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
throw makeRuntimeErrorMsg("hack", `Invalid IP/hostname: ${ip}.`);
}
@ -738,7 +724,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
vsprintf: vsprintf,
scan: function (ip: any = workerScript.serverIp, hostnames: any = true): any {
updateDynamicRam("scan", getRamCost("scan"));
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("scan", `Invalid IP/hostname: ${ip}.`);
}
@ -825,7 +811,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("grow", "Takes 1 argument.");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("grow", "Cannot be executed on this server.");
return false;
@ -834,7 +820,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
throw makeRuntimeErrorMsg("grow", `Invalid IP/hostname: ${ip}.`);
}
const host = getServer(workerScript.serverIp);
const host = GetServer(workerScript.serverIp);
if (host === null) {
throw new Error("Workerscript host is null");
}
@ -899,7 +885,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("weaken", "Takes 1 argument.");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("weaken", "Cannot be executed on this server.");
return false;
@ -924,7 +910,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
);
return netscriptDelay(weakenTime * 1000, workerScript).then(function () {
if (workerScript.env.stopFlag) return Promise.reject(workerScript);
const host = getServer(workerScript.serverIp);
const host = GetServer(workerScript.serverIp);
if (host === null) {
workerScript.log("weaken", "Server is null, did it die?");
return Promise.resolve(0);
@ -1018,7 +1004,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("nuke", "Takes 1 argument.");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("nuke", "Cannot be executed on this server.");
return false;
@ -1045,7 +1031,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("brutessh", "Takes 1 argument.");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("brutessh", "Cannot be executed on this server.");
return false;
@ -1070,7 +1056,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("ftpcrack", "Takes 1 argument.");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("ftpcrack", "Cannot be executed on this server.");
return false;
@ -1095,7 +1081,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("relaysmtp", "Takes 1 argument.");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("relaysmtp", "Cannot be executed on this server.");
return false;
@ -1120,7 +1106,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("httpworm", "Takes 1 argument");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("httpworm", "Cannot be executed on this server.");
return false;
@ -1145,7 +1131,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("sqlinject", "Takes 1 argument.");
}
const server = getServer(ip);
const server = GetServer(ip);
if (!(server instanceof Server)) {
workerScript.log("sqlinject", "Cannot be executed on this server.");
return false;
@ -1173,7 +1159,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (isNaN(threads) || threads <= 0) {
throw makeRuntimeErrorMsg("run", `Invalid thread count. Must be numeric and > 0, is ${threads}`);
}
const scriptServer = getServer(workerScript.serverIp);
const scriptServer = GetServer(workerScript.serverIp);
if (scriptServer == null) {
throw makeRuntimeErrorMsg("run", "Could not find server. This is a bug. Report to dev.");
}
@ -1188,7 +1174,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (isNaN(threads) || threads <= 0) {
throw makeRuntimeErrorMsg("exec", `Invalid thread count. Must be numeric and > 0, is ${threads}`);
}
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("exec", `Invalid IP/hostname: ${ip}`);
}
@ -1205,7 +1191,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (isNaN(threads) || threads <= 0) {
throw makeRuntimeErrorMsg("spawn", `Invalid thread count. Must be numeric and > 0, is ${threads}`);
}
const scriptServer = getServer(workerScript.serverIp);
const scriptServer = GetServer(workerScript.serverIp);
if (scriptServer == null) {
throw makeRuntimeErrorMsg("spawn", "Could not find server. This is a bug. Report to dev");
}
@ -1265,7 +1251,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("killall", "Takes 1 argument");
}
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("killall", `Invalid IP/hostname: ${ip}`);
}
@ -1322,12 +1308,12 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (scriptname === undefined || ip1 === undefined || ip2 === undefined) {
throw makeRuntimeErrorMsg("scp", "Takes 2 or 3 arguments");
}
destServer = getServer(ip2);
destServer = GetServer(ip2);
if (destServer == null) {
throw makeRuntimeErrorMsg("scp", `Invalid IP/hostname: ${ip2}`);
}
currServ = getServer(ip1);
currServ = GetServer(ip1);
if (currServ == null) {
throw makeRuntimeErrorMsg("scp", `Invalid IP/hostname: ${ip1}`);
}
@ -1336,12 +1322,12 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (scriptname === undefined || ip1 === undefined) {
throw makeRuntimeErrorMsg("scp", "Takes 2 or 3 arguments");
}
destServer = getServer(ip1);
destServer = GetServer(ip1);
if (destServer == null) {
throw makeRuntimeErrorMsg("scp", `Invalid IP/hostname: ${ip1}`);
}
currServ = getServer(workerScript.serverIp);
currServ = GetServer(workerScript.serverIp);
if (currServ == null) {
throw makeRuntimeErrorMsg("scp", "Could not find server ip for this script. This is a bug. Report to dev.");
}
@ -1446,7 +1432,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("ls", "Usage: ls(ip/hostname, [grep filter])");
}
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("ls", `Invalid IP/hostname: ${ip}`);
}
@ -1522,7 +1508,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
},
ps: function (ip: any = workerScript.serverIp): any {
updateDynamicRam("ps", getRamCost("ps"));
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("ps", `Invalid IP/hostname: ${ip}`);
}
@ -1543,7 +1529,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
if (ip === undefined) {
throw makeRuntimeErrorMsg("hasRootAccess", "Takes 1 argument");
}
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("hasRootAccess", `Invalid IP/hostname: ${ip}`);
}
@ -1551,7 +1537,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
},
getIp: function (): any {
updateDynamicRam("getIp", getRamCost("getIp"));
const scriptServer = getServer(workerScript.serverIp);
const scriptServer = GetServer(workerScript.serverIp);
if (scriptServer == null) {
throw makeRuntimeErrorMsg("getIp", "Could not find server. This is a bug. Report to dev.");
}
@ -1559,7 +1545,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
},
getHostname: function (): any {
updateDynamicRam("getHostname", getRamCost("getHostname"));
const scriptServer = getServer(workerScript.serverIp);
const scriptServer = GetServer(workerScript.serverIp);
if (scriptServer == null) {
throw makeRuntimeErrorMsg("getHostname", "Could not find server. This is a bug. Report to dev.");
}
@ -1768,14 +1754,14 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
},
serverExists: function (ip: any): any {
updateDynamicRam("serverExists", getRamCost("serverExists"));
return getServer(ip) !== null;
return GetServer(ip) !== null;
},
fileExists: function (filename: any, ip: any = workerScript.serverIp): any {
updateDynamicRam("fileExists", getRamCost("fileExists"));
if (filename === undefined) {
throw makeRuntimeErrorMsg("fileExists", "Usage: fileExists(scriptname, [server])");
}
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("fileExists", `Invalid IP/hostname: ${ip}`);
}
@ -2199,7 +2185,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
updateDynamicRam("deleteServer", getRamCost("deleteServer"));
let hostnameStr = String(hostname);
hostnameStr = hostnameStr.replace(/\s\s+/g, "");
const server = GetServerByHostname(hostnameStr);
const server = GetServer(hostnameStr);
if (!(server instanceof Server)) {
workerScript.log("deleteServer", `Invalid argument: hostname='${hostnameStr}'`);
return false;
@ -2280,7 +2266,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
const res: string[] = [];
Player.purchasedServers.forEach(function (ip) {
if (hostname) {
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("getPurchasedServers", "Could not find server. This is a bug. Report to dev.");
}
@ -2401,7 +2387,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
} else if (isString(port)) {
// Read from script or text file
const fn = port;
const server = getServer(workerScript.serverIp);
const server = GetServer(workerScript.serverIp);
if (server == null) {
throw makeRuntimeErrorMsg("read", "Error getting Server. This is a bug. Report to dev.");
}
@ -2467,7 +2453,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
} else if (isString(port)) {
// Clear text file
const fn = port;
const server = getServer(workerScript.serverIp);
const server = GetServer(workerScript.serverIp);
if (server == null) {
throw makeRuntimeErrorMsg("clear", "Error getting Server. This is a bug. Report to dev.");
}
@ -2518,7 +2504,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
},
scriptRunning: function (scriptname: any, ip: any): any {
updateDynamicRam("scriptRunning", getRamCost("scriptRunning"));
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("scriptRunning", `Invalid IP/hostname: ${ip}`);
}
@ -2531,7 +2517,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
},
scriptKill: function (scriptname: any, ip: any): any {
updateDynamicRam("scriptKill", getRamCost("scriptKill"));
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("scriptKill", `Invalid IP/hostname: ${ip}`);
}
@ -2549,7 +2535,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
},
getScriptRam: function (scriptname: any, ip: any = workerScript.serverIp): any {
updateDynamicRam("getScriptRam", getRamCost("getScriptRam"));
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("getScriptRam", `Invalid IP/hostname: ${ip}`);
}
@ -2648,7 +2634,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
return res;
} else {
// Get income for a particular script
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("getScriptIncome", `Invalid IP/hostnamed: ${ip}`);
}
@ -2673,7 +2659,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
return total;
} else {
// Get income for a particular script
const server = getServer(ip);
const server = GetServer(ip);
if (server == null) {
throw makeRuntimeErrorMsg("getScriptExpGain", `Invalid IP/hostnamed: ${ip}`);
}
@ -3038,7 +3024,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
throw makeRuntimeErrorMsg("connect", `Invalid hostname: '${hostname}'`);
}
const target = getServer(hostname);
const target = GetServer(hostname);
if (target == null) {
throw makeRuntimeErrorMsg("connect", `Invalid hostname: '${hostname}'`);
return;

@ -16,7 +16,7 @@ import {
} from "../Hacknet/HacknetHelpers";
import { HacknetServer } from "../Hacknet/HacknetServer";
import { HacknetNode } from "../Hacknet/HacknetNode";
import { getServer } from "../Server/ServerHelpers";
import { GetServer } from "../Server/AllServers";
export interface INetscriptHacknet {
numNodes(): number;
@ -58,7 +58,7 @@ export function NetscriptHacknet(
if (hasHacknetServers(player)) {
const hi = player.hacknetNodes[i];
if (typeof hi !== "string") throw new Error("hacknet node was not a string");
const hserver = getServer(hi);
const hserver = GetServer(hi);
if (!(hserver instanceof HacknetServer)) throw new Error("hacknet server was not actually hacknet server");
if (hserver == null) {
throw helper.makeRuntimeErrorMsg(

@ -48,7 +48,6 @@ export interface IPlayer {
hashManager: HashManager;
hasTixApiAccess: boolean;
hasWseAccount: boolean;
homeComputer: string;
hp: number;
jobs: IMap<string>;
init: () => void;

@ -55,7 +55,6 @@ export class PlayerObject implements IPlayer {
hashManager: HashManager;
hasTixApiAccess: boolean;
hasWseAccount: boolean;
homeComputer: string;
hp: number;
jobs: IMap<string>;
init: () => void;
@ -336,9 +335,6 @@ export class PlayerObject implements IPlayer {
//Money
this.money = new Decimal(1000);
//IP Address of Starting (home) computer
this.homeComputer = "";
//Location information
this.city = CityName.Sector12;
this.location = LocationName.TravelAgency;

@ -32,9 +32,9 @@ import {
getFactionSecurityWorkRepGain,
getFactionFieldWorkRepGain,
} from "../formulas/reputation";
import { AddToAllServers, createUniqueRandomIp } from "../../Server/AllServers";
import { GetServer, AddToAllServers, createUniqueRandomIp } from "../../Server/AllServers";
import { Server } from "../../Server/Server";
import { safetlyCreateUniqueServer, getServer } from "../../Server/ServerHelpers";
import { safetlyCreateUniqueServer } from "../../Server/ServerHelpers";
import { Settings } from "../../Settings/Settings";
import { SpecialServerIps, SpecialServerNames } from "../../Server/SpecialServerIps";
import { applySourceFile } from "../../SourceFile/applySourceFile";
@ -70,7 +70,6 @@ export function init(this: IPlayer): void {
organizationName: "Home PC",
purchasedByPlayer: true,
});
this.homeComputer = t_homeComp.ip;
this.currentServer = t_homeComp.ip;
AddToAllServers(t_homeComp);
@ -80,7 +79,6 @@ export function init(this: IPlayer): void {
export function prestigeAugmentation(this: IPlayer): void {
const homeComp = this.getHomeComputer();
this.currentServer = homeComp.ip;
this.homeComputer = homeComp.ip;
this.numPeopleKilled = 0;
this.karma = 0;
@ -579,7 +577,7 @@ export function startWork(this: IPlayer, router: IRouter, companyName: string):
export function cancelationPenalty(this: IPlayer): number {
const specialIp = SpecialServerIps[this.companyName];
if (typeof specialIp === "string" && specialIp !== "") {
const server = getServer(specialIp);
const server = GetServer(specialIp);
if (server instanceof Server) {
if (server && server.backdoorInstalled) return 0.75;
}
@ -2194,7 +2192,7 @@ export function checkForFactionInvitations(this: IPlayer): Faction[] {
const fulcrumsecrettechonologiesFac = Factions["Fulcrum Secret Technologies"];
const fulcrumIP = SpecialServerIps[SpecialServerNames.BitRunnersServer];
if (typeof fulcrumIP !== "string") throw new Error("Fulcrum Secret Technologies should be string");
const fulcrumSecretServer = getServer(fulcrumIP);
const fulcrumSecretServer = GetServer(fulcrumIP);
if (!(fulcrumSecretServer instanceof Server)) throw new Error("Fulcrum Secret Technologies should be normal server");
if (fulcrumSecretServer == null) {
console.error("Could not find Fulcrum Secret Technologies Server");
@ -2214,7 +2212,7 @@ export function checkForFactionInvitations(this: IPlayer): Faction[] {
const bitrunnersFac = Factions["BitRunners"];
const bitrunnerIP = SpecialServerIps[SpecialServerNames.BitRunnersServer];
if (typeof bitrunnerIP !== "string") throw new Error("BitRunners should be string");
const bitrunnersServer = getServer(bitrunnerIP);
const bitrunnersServer = GetServer(bitrunnerIP);
if (!(bitrunnersServer instanceof Server)) throw new Error("BitRunners should be normal server");
if (bitrunnersServer == null) {
console.error("Could not find BitRunners Server");
@ -2232,7 +2230,7 @@ export function checkForFactionInvitations(this: IPlayer): Faction[] {
const theblackhandFac = Factions["The Black Hand"];
const tbhIP = SpecialServerIps[SpecialServerNames.TheBlackHandServer];
if (typeof tbhIP !== "string") throw new Error("TheBlackHand should be string");
const blackhandServer = getServer(tbhIP);
const blackhandServer = GetServer(tbhIP);
if (!(blackhandServer instanceof Server)) throw new Error("TheBlackHand should be normal server");
if (blackhandServer == null) {
console.error("Could not find The Black Hand Server");
@ -2249,7 +2247,7 @@ export function checkForFactionInvitations(this: IPlayer): Faction[] {
const nitesecFac = Factions["NiteSec"];
const nitesecIP = SpecialServerIps[SpecialServerNames.NiteSecServer];
if (typeof nitesecIP !== "string") throw new Error("NiteSec should be string");
const nitesecServer = getServer(nitesecIP);
const nitesecServer = GetServer(nitesecIP);
if (!(nitesecServer instanceof Server)) throw new Error("NiteSec should be normal server");
if (nitesecServer == null) {
console.error("Could not find NiteSec Server");
@ -2448,7 +2446,7 @@ export function checkForFactionInvitations(this: IPlayer): Faction[] {
for (let i = 0; i < this.hacknetNodes.length; ++i) {
const v = this.hacknetNodes[i];
if (typeof v === "string") {
const hserver = getServer(v);
const hserver = GetServer(v);
if (hserver === null || !(hserver instanceof HacknetServer))
throw new Error("player hacknet server was not HacknetServer");
totalHacknetLevels += hserver.level;
@ -2489,7 +2487,7 @@ export function checkForFactionInvitations(this: IPlayer): Faction[] {
const cybersecFac = Factions["CyberSec"];
const cyberSecIP = SpecialServerIps[SpecialServerNames.CyberSecServer];
if (typeof cyberSecIP !== "string") throw new Error("cybersec should be string");
const cybersecServer = getServer(cyberSecIP);
const cybersecServer = GetServer(cyberSecIP);
if (!(cybersecServer instanceof Server)) throw new Error("cybersec should be normal server");
if (cybersecServer == null) {
console.error("Could not find CyberSec Server");

@ -9,8 +9,7 @@ import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
import { Server } from "../../Server/Server";
import { BaseServer } from "../../Server/BaseServer";
import { HacknetServer } from "../../Hacknet/HacknetServer";
import { AddToAllServers, createUniqueRandomIp } from "../../Server/AllServers";
import { getServer } from "../../Server/ServerHelpers";
import { GetServer, AddToAllServers, createUniqueRandomIp } from "../../Server/AllServers";
import { SpecialServerIps } from "../../Server/SpecialServerIps";
export function hasTorRouter(this: IPlayer): boolean {
@ -18,13 +17,13 @@ export function hasTorRouter(this: IPlayer): boolean {
}
export function getCurrentServer(this: IPlayer): BaseServer {
const server = getServer(this.currentServer);
const server = GetServer(this.currentServer);
if (server === null) throw new Error("somehow connected to a server that does not exist.");
return server;
}
export function getHomeComputer(this: IPlayer): Server {
const home = getServer(this.homeComputer);
const home = GetServer("home");
if (home instanceof Server) return home;
throw new Error("home computer was not a normal server");
}

@ -17,10 +17,10 @@ import { Router } from "./ui/GameRoot";
import { resetPidCounter } from "./Netscript/Pid";
import { LiteratureNames } from "./Literature/data/LiteratureNames";
import { AddToAllServers, initForeignServers, prestigeAllServers } from "./Server/AllServers";
import { prestigeHomeComputer, getServer } from "./Server/ServerHelpers";
import { GetServer, AddToAllServers, initForeignServers, prestigeAllServers } from "./Server/AllServers";
import { prestigeHomeComputer } from "./Server/ServerHelpers";
import { SourceFileFlags, updateSourceFileFlags } from "./SourceFile/SourceFileFlags";
import { SpecialServerIps, prestigeSpecialServerIps, SpecialServerNames } from "./Server/SpecialServerIps";
import { prestigeSpecialServerIps, SpecialServerNames } from "./Server/SpecialServerIps";
import { deleteStockMarket, initStockMarket, initSymbolToStockMap } from "./StockMarket/StockMarket";
import { Terminal } from "./Terminal";
@ -87,6 +87,7 @@ function prestigeAugmentation(): void {
if (Terminal.action !== null) {
Terminal.finishAction(Router, Player, true);
}
Terminal.clear();
// Re-initialize things - This will update any changes
initFactions(); // Factions must be initialized before augmentations
@ -131,12 +132,8 @@ function prestigeAugmentation(): void {
// Red Pill
if (augmentationExists(AugmentationNames.TheRedPill) && Augmentations[AugmentationNames.TheRedPill].owned) {
const WorldDaemonIP = SpecialServerIps[SpecialServerNames.WorldDaemon];
if (typeof WorldDaemonIP !== "string") throw new Error("WorldDaemonIP should be string");
const WorldDaemon = getServer(WorldDaemonIP);
const DaedalusServerIP = SpecialServerIps[SpecialServerNames.DaedalusServer];
if (typeof DaedalusServerIP !== "string") throw new Error("DaedalusServerIP should be string");
const DaedalusServer = getServer(DaedalusServerIP);
const WorldDaemon = GetServer(SpecialServerNames.WorldDaemon);
const DaedalusServer = GetServer(SpecialServerNames.DaedalusServer);
if (WorldDaemon && DaedalusServer) {
WorldDaemon.serversOnNetwork.push(DaedalusServer.ip);
DaedalusServer.serversOnNetwork.push(WorldDaemon.ip);

@ -5,9 +5,8 @@ import { Server } from "../../Server/Server";
import { ITerminal } from "../../Terminal/ITerminal";
import { IRouter } from "../../ui/Router";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { HacknetServer } from "../../Hacknet/HacknetServer";
import { convertTimeMsToTimeElapsedString } from "../../utils/StringHelperFunctions";
import { getServer } from "../../Server/ServerHelpers";
import { GetServer } from "../../Server/AllServers";
import { numeralWrapper } from "../../ui/numeralFormat";
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
import { BitFlumeEvent } from "../../BitNode/ui/BitFlumeModal";
@ -224,7 +223,7 @@ export const programsMetadata: IProgramCreationParams[] = [
return;
}
const targetServer = getServer(args[0]);
const targetServer = GetServer(args[0]);
if (targetServer == null) {
terminal.print("Invalid server IP/hostname");
return;

@ -218,6 +218,13 @@ function loadGame(saveString: string): boolean {
console.error("ERROR: Failed to parse last export bonus Settings " + err);
}
}
if (Player.inGang() && saveObj.hasOwnProperty("AllGangsSave")) {
try {
loadAllGangs(saveObj.AllGangsSave);
} catch (e) {
console.error("ERROR: Failed to parse AllGangsSave: " + e);
}
}
if (saveObj.hasOwnProperty("VersionSave")) {
try {
const ver = JSON.parse(saveObj.VersionSave, Reviver);
@ -235,13 +242,6 @@ function loadGame(saveString: string): boolean {
} else {
createNewUpdateText();
}
if (Player.inGang() && saveObj.hasOwnProperty("AllGangsSave")) {
try {
loadAllGangs(saveObj.AllGangsSave);
} catch (e) {
console.error("ERROR: Failed to parse AllGangsSave: " + e);
}
}
return true;
}

@ -1,4 +1,4 @@
import { getServer } from "../Server/ServerHelpers";
import { GetServer } from "../Server/AllServers";
import { RunningScript } from "./RunningScript";
export function getRamUsageFromRunningScript(script: RunningScript): number {
@ -6,7 +6,7 @@ export function getRamUsageFromRunningScript(script: RunningScript): number {
return script.ramUsage; // Use cached value
}
const server = getServer(script.server);
const server = GetServer(script.server);
if (server == null) {
return 0;
}

@ -3,7 +3,8 @@ import { Player } from "../Player";
import { BaseServer } from "../Server/BaseServer";
import { Server } from "../Server/Server";
import { RunningScript } from "../Script/RunningScript";
import { processSingleServerGrowth, getServer } from "../Server/ServerHelpers";
import { processSingleServerGrowth } from "../Server/ServerHelpers";
import { GetServer } from "../Server/AllServers";
import { numeralWrapper } from "../ui/numeralFormat";
@ -31,7 +32,7 @@ export function scriptCalculateOfflineProduction(runningScript: RunningScript):
if (runningScript.dataMap[ip][2] == 0 || runningScript.dataMap[ip][2] == null) {
continue;
}
const serv = getServer(ip);
const serv = GetServer(ip);
if (serv == null) {
continue;
}
@ -39,7 +40,7 @@ export function scriptCalculateOfflineProduction(runningScript: RunningScript):
((0.5 * runningScript.dataMap[ip][2]) / runningScript.onlineRunningTime) * timePassed,
);
runningScript.log(`Called on ${serv.hostname} ${timesGrown} times while offline`);
const host = getServer(runningScript.server);
const host = GetServer(runningScript.server);
if (host === null) throw new Error("getServer of null key?");
if (!(serv instanceof Server)) throw new Error("trying to grow a non-normal server");
const growth = processSingleServerGrowth(serv, timesGrown, Player, host.cpuCores);
@ -64,13 +65,13 @@ export function scriptCalculateOfflineProduction(runningScript: RunningScript):
if (runningScript.dataMap[ip][3] == 0 || runningScript.dataMap[ip][3] == null) {
continue;
}
const serv = getServer(ip);
const serv = GetServer(ip);
if (serv == null) {
continue;
}
if (!(serv instanceof Server)) throw new Error("trying to weaken a non-normal server");
const host = getServer(runningScript.server);
const host = GetServer(runningScript.server);
if (host === null) throw new Error("getServer of null key?");
const timesWeakened = Math.round(
((0.5 * runningScript.dataMap[ip][3]) / runningScript.onlineRunningTime) * timePassed,

@ -9,6 +9,7 @@ import { IMap } from "../types";
import { createRandomIp } from "../utils/IPAddress";
import { getRandomInt } from "../utils/helpers/getRandomInt";
import { Reviver } from "../utils/JSONReviver";
import { isValidIPAddress } from "../utils/helpers/isValidIPAddress";
/**
* Map of all Servers that exist in the game
@ -17,8 +18,41 @@ import { Reviver } from "../utils/JSONReviver";
*/
let AllServers: IMap<Server | HacknetServer> = {};
export function GetServerByIP(ip: string): Server | HacknetServer | undefined {
return AllServers[ip];
function GetServerByIP(ip: string): BaseServer | undefined {
for (const key in AllServers) {
const server = AllServers[key];
if (server.ip !== ip) continue;
return server;
}
}
//Returns server object with corresponding hostname
// Relatively slow, would rather not use this a lot
function GetServerByHostname(hostname: string): BaseServer | null {
for (const key in AllServers) {
const server = AllServers[key];
if (server.hostname == hostname) {
return server;
}
}
return null;
}
//Get server by IP or hostname. Returns null if invalid
export function GetServer(s: string): BaseServer | null {
const server = AllServers[s];
if (server) return server;
if (!isValidIPAddress(s)) {
return GetServerByHostname(s);
}
const ipserver = GetServerByIP(s);
if (ipserver !== undefined) {
return ipserver;
}
return null;
}
export function GetAllServers(): BaseServer[] {

@ -1,17 +1,15 @@
import { GetAllServers, GetServerByIP, createUniqueRandomIp, ipExists } from "./AllServers";
import { GetServer, createUniqueRandomIp, ipExists } from "./AllServers";
import { Server, IConstructorParams } from "./Server";
import { BaseServer } from "./BaseServer";
import { calculateServerGrowth } from "./formulas/grow";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { CONSTANTS } from "../Constants";
import { HacknetServer } from "../Hacknet/HacknetServer";
import { IPlayer } from "../PersonObjects/IPlayer";
import { Programs } from "../Programs/Programs";
import { LiteratureNames } from "../Literature/data/LiteratureNames";
import { isValidNumber } from "../utils/helpers/isValidNumber";
import { isValidIPAddress } from "../utils/helpers/isValidIPAddress";
/**
* Constructs a new server, while also ensuring that the new server
@ -22,12 +20,12 @@ export function safetlyCreateUniqueServer(params: IConstructorParams): Server {
params.ip = createUniqueRandomIp();
}
if (GetServerByHostname(params.hostname) != null) {
if (GetServer(params.hostname) != null) {
// Use a for loop to ensure that we don't get suck in an infinite loop somehow
let hostname: string = params.hostname;
for (let i = 0; i < 200; ++i) {
hostname = `${params.hostname}-${i}`;
if (GetServerByHostname(hostname) == null) {
if (GetServer(hostname) == null) {
break;
}
}
@ -119,31 +117,6 @@ export function prestigeHomeComputer(homeComp: Server): void {
homeComp.messages.push(LiteratureNames.HackersStartingHandbook);
}
//Returns server object with corresponding hostname
// Relatively slow, would rather not use this a lot
export function GetServerByHostname(hostname: string): BaseServer | null {
for (const server of GetAllServers()) {
if (server.hostname == hostname) {
return server;
}
}
return null;
}
//Get server by IP or hostname. Returns null if invalid
export function getServer(s: string): BaseServer | null {
if (!isValidIPAddress(s)) {
return GetServerByHostname(s);
}
const server = GetServerByIP(s);
if (server !== undefined) {
return server;
}
return null;
}
// Returns the i-th server on the specified server's network
// A Server's serverOnNetwork property holds only the IPs. This function returns
// the actual Server object
@ -153,7 +126,7 @@ export function getServerOnNetwork(server: BaseServer, i: number): BaseServer |
return null;
}
return getServer(server.serversOnNetwork[i]);
return GetServer(server.serversOnNetwork[i]);
}
export function isBackdoorInstalled(server: BaseServer): boolean {

@ -12,12 +12,12 @@ import { TextFile } from "../TextFile";
import { Script } from "../Script/Script";
import { isScriptFilename } from "../Script/isScriptFilename";
import { CONSTANTS } from "../Constants";
import { GetAllServers } from "../Server/AllServers";
import { GetServer, GetAllServers } from "../Server/AllServers";
import { removeLeadingSlash, isInRootDirectory, evaluateFilePath } from "./DirectoryHelpers";
import { checkIfConnectedToDarkweb } from "../DarkWeb/DarkWeb";
import { iTutorialNextStep, iTutorialSteps, ITutorial } from "../InteractiveTutorial";
import { GetServerByHostname, getServer, getServerOnNetwork, processSingleServerGrowth } from "../Server/ServerHelpers";
import { getServerOnNetwork, processSingleServerGrowth } from "../Server/ServerHelpers";
import { ParseCommand, ParseCommands } from "./Parser";
import { SpecialServerIps, SpecialServerNames } from "../Server/SpecialServerIps";
import { Settings } from "../Settings/Settings";
@ -513,7 +513,7 @@ export class Terminal implements ITerminal {
}
connectToServer(player: IPlayer, server: string): void {
const serv = getServer(server);
const serv = GetServer(server);
if (serv == null) {
this.error("Invalid server. Connection failed.");
return;
@ -577,7 +577,7 @@ export class Terminal implements ITerminal {
const s = player.getCurrentServer();
/****************** Interactive Tutorial Terminal Commands ******************/
if (ITutorial.isRunning) {
const n00dlesServ = GetServerByHostname("n00dles");
const n00dlesServ = GetServer("n00dles");
if (n00dlesServ == null) {
throw new Error("Could not get n00dles server");
return;

@ -3,7 +3,7 @@ import { IRouter } from "../../ui/Router";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { BaseServer } from "../../Server/BaseServer";
import { Message } from "../../Message/Message";
import { getServer } from "../../Server/ServerHelpers";
import { GetServer } from "../../Server/AllServers";
import { isScriptFilename } from "../../Script/isScriptFilename";
export function scp(
@ -24,7 +24,7 @@ export function scp(
return;
}
const destServer = getServer(args[1] + "");
const destServer = GetServer(args[1] + "");
if (destServer == null) {
terminal.error(`Invalid destination. ${args[1]} not found`);
return;

@ -5,8 +5,7 @@ import { Aliases, GlobalAliases } from "../Alias";
import { DarkWebItems } from "../DarkWeb/DarkWebItems";
import { Message } from "../Message/Message";
import { IPlayer } from "../PersonObjects/IPlayer";
import { GetAllServers } from "../Server/AllServers";
import { getServer } from "../Server/ServerHelpers";
import { GetServer, GetAllServers } from "../Server/AllServers";
// An array of all Terminal commands
const commands = [
@ -244,7 +243,7 @@ export function determineAllPossibilitiesForTabCompletion(
if (isCommand("connect")) {
// All network connections
for (let i = 0; i < currServ.serversOnNetwork.length; ++i) {
const serv = getServer(currServ.serversOnNetwork[i]);
const serv = GetServer(currServ.serversOnNetwork[i]);
if (serv == null) {
continue;
}

@ -11,7 +11,7 @@ import List from "@mui/material/List";
import TablePagination from "@mui/material/TablePagination";
import { WorkerScript } from "../../Netscript/WorkerScript";
import { WorkerScriptStartStopEventEmitter } from "../../Netscript/WorkerScriptStartStopEventEmitter";
import { getServer } from "../../Server/ServerHelpers";
import { GetServer } from "../../Server/AllServers";
import { BaseServer } from "../../Server/BaseServer";
import { Settings } from "../../Settings/Settings";
import { TablePaginationActionsAll } from "../React/TablePaginationActionsAll";
@ -54,7 +54,7 @@ export function ServerAccordions(props: IProps): React.ReactElement {
const serverToScriptMap: IServerToScriptsMap = {};
for (const ws of props.workerScripts.values()) {
const server = getServer(ws.serverIp);
const server = GetServer(ws.serverIp);
if (server == null) {
console.warn(`WorkerScript has invalid IP address: ${ws.serverIp}`);
continue;