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

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

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

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

@ -22,8 +22,7 @@ import {
} from "../HacknetHelpers"; } from "../HacknetHelpers";
import { IPlayer } from "../../PersonObjects/IPlayer"; import { IPlayer } from "../../PersonObjects/IPlayer";
import { getServer } from "../../Server/ServerHelpers"; import { GetServer } from "../../Server/AllServers";
import { Server } from "../../Server/Server";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import Grid from "@mui/material/Grid"; import Grid from "@mui/material/Grid";
@ -51,7 +50,7 @@ export function HacknetRoot(props: IProps): React.ReactElement {
const node = props.player.hacknetNodes[i]; const node = props.player.hacknetNodes[i];
if (hasHacknetServers(props.player)) { if (hasHacknetServers(props.player)) {
if (node instanceof HacknetNode) throw new Error("node was hacknet node"); // should never happen 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 instanceof HacknetServer)) throw new Error("node was not hacknet server"); // should never happen
if (hserver) { if (hserver) {
totalProduction += hserver.hashRate; totalProduction += hserver.hashRate;
@ -89,7 +88,7 @@ export function HacknetRoot(props: IProps): React.ReactElement {
const nodes = props.player.hacknetNodes.map((node: string | HacknetNode) => { const nodes = props.player.hacknetNodes.map((node: string | HacknetNode) => {
if (hasHacknetServers(props.player)) { if (hasHacknetServers(props.player)) {
if (node instanceof HacknetNode) throw new Error("node was hacknet node"); // should never happen 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) { if (hserver == null) {
throw new Error(`Could not find Hacknet Server object in AllServers map for IP: ${node}`); 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 { Settings } from "../../Settings/Settings";
import { SpecialServerIps } from "../../Server/SpecialServerIps"; import { isBackdoorInstalled } from "../../Server/ServerHelpers";
import { getServer, isBackdoorInstalled } from "../../Server/ServerHelpers"; import { GetServer } from "../../Server/AllServers";
import { CorruptableText } from "../../ui/React/CorruptableText"; import { CorruptableText } from "../../ui/React/CorruptableText";
import { use } from "../../ui/Context"; import { use } from "../../ui/Context";
@ -83,8 +83,7 @@ export function GenericLocation({ loc }: IProps): React.ReactElement {
} }
const locContent: React.ReactNode[] = getLocationSpecificContent(); const locContent: React.ReactNode[] = getLocationSpecificContent();
const ip = SpecialServerIps.getIp(loc.name); const server = GetServer(loc.name);
const server = getServer(ip);
const backdoorInstalled = server !== null && isBackdoorInstalled(server); const backdoorInstalled = server !== null && isBackdoorInstalled(server);
return ( return (

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

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

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

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

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

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

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

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

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

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

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

@ -9,8 +9,7 @@ import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
import { Server } from "../../Server/Server"; import { Server } from "../../Server/Server";
import { BaseServer } from "../../Server/BaseServer"; import { BaseServer } from "../../Server/BaseServer";
import { HacknetServer } from "../../Hacknet/HacknetServer"; import { HacknetServer } from "../../Hacknet/HacknetServer";
import { AddToAllServers, createUniqueRandomIp } from "../../Server/AllServers"; import { GetServer, AddToAllServers, createUniqueRandomIp } from "../../Server/AllServers";
import { getServer } from "../../Server/ServerHelpers";
import { SpecialServerIps } from "../../Server/SpecialServerIps"; import { SpecialServerIps } from "../../Server/SpecialServerIps";
export function hasTorRouter(this: IPlayer): boolean { export function hasTorRouter(this: IPlayer): boolean {
@ -18,13 +17,13 @@ export function hasTorRouter(this: IPlayer): boolean {
} }
export function getCurrentServer(this: IPlayer): BaseServer { 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."); if (server === null) throw new Error("somehow connected to a server that does not exist.");
return server; return server;
} }
export function getHomeComputer(this: IPlayer): Server { export function getHomeComputer(this: IPlayer): Server {
const home = getServer(this.homeComputer); const home = GetServer("home");
if (home instanceof Server) return home; if (home instanceof Server) return home;
throw new Error("home computer was not a normal server"); 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 { resetPidCounter } from "./Netscript/Pid";
import { LiteratureNames } from "./Literature/data/LiteratureNames"; import { LiteratureNames } from "./Literature/data/LiteratureNames";
import { AddToAllServers, initForeignServers, prestigeAllServers } from "./Server/AllServers"; import { GetServer, AddToAllServers, initForeignServers, prestigeAllServers } from "./Server/AllServers";
import { prestigeHomeComputer, getServer } from "./Server/ServerHelpers"; import { prestigeHomeComputer } from "./Server/ServerHelpers";
import { SourceFileFlags, updateSourceFileFlags } from "./SourceFile/SourceFileFlags"; 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 { deleteStockMarket, initStockMarket, initSymbolToStockMap } from "./StockMarket/StockMarket";
import { Terminal } from "./Terminal"; import { Terminal } from "./Terminal";
@ -87,6 +87,7 @@ function prestigeAugmentation(): void {
if (Terminal.action !== null) { if (Terminal.action !== null) {
Terminal.finishAction(Router, Player, true); Terminal.finishAction(Router, Player, true);
} }
Terminal.clear();
// Re-initialize things - This will update any changes // Re-initialize things - This will update any changes
initFactions(); // Factions must be initialized before augmentations initFactions(); // Factions must be initialized before augmentations
@ -131,12 +132,8 @@ function prestigeAugmentation(): void {
// Red Pill // Red Pill
if (augmentationExists(AugmentationNames.TheRedPill) && Augmentations[AugmentationNames.TheRedPill].owned) { if (augmentationExists(AugmentationNames.TheRedPill) && Augmentations[AugmentationNames.TheRedPill].owned) {
const WorldDaemonIP = SpecialServerIps[SpecialServerNames.WorldDaemon]; const WorldDaemon = GetServer(SpecialServerNames.WorldDaemon);
if (typeof WorldDaemonIP !== "string") throw new Error("WorldDaemonIP should be string"); const DaedalusServer = GetServer(SpecialServerNames.DaedalusServer);
const WorldDaemon = getServer(WorldDaemonIP);
const DaedalusServerIP = SpecialServerIps[SpecialServerNames.DaedalusServer];
if (typeof DaedalusServerIP !== "string") throw new Error("DaedalusServerIP should be string");
const DaedalusServer = getServer(DaedalusServerIP);
if (WorldDaemon && DaedalusServer) { if (WorldDaemon && DaedalusServer) {
WorldDaemon.serversOnNetwork.push(DaedalusServer.ip); WorldDaemon.serversOnNetwork.push(DaedalusServer.ip);
DaedalusServer.serversOnNetwork.push(WorldDaemon.ip); DaedalusServer.serversOnNetwork.push(WorldDaemon.ip);

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

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

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

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

@ -9,6 +9,7 @@ import { IMap } from "../types";
import { createRandomIp } from "../utils/IPAddress"; import { createRandomIp } from "../utils/IPAddress";
import { getRandomInt } from "../utils/helpers/getRandomInt"; import { getRandomInt } from "../utils/helpers/getRandomInt";
import { Reviver } from "../utils/JSONReviver"; import { Reviver } from "../utils/JSONReviver";
import { isValidIPAddress } from "../utils/helpers/isValidIPAddress";
/** /**
* Map of all Servers that exist in the game * Map of all Servers that exist in the game
@ -17,8 +18,41 @@ import { Reviver } from "../utils/JSONReviver";
*/ */
let AllServers: IMap<Server | HacknetServer> = {}; let AllServers: IMap<Server | HacknetServer> = {};
export function GetServerByIP(ip: string): Server | HacknetServer | undefined { function GetServerByIP(ip: string): BaseServer | undefined {
return AllServers[ip]; 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[] { 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 { Server, IConstructorParams } from "./Server";
import { BaseServer } from "./BaseServer"; import { BaseServer } from "./BaseServer";
import { calculateServerGrowth } from "./formulas/grow"; import { calculateServerGrowth } from "./formulas/grow";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers"; import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { CONSTANTS } from "../Constants"; import { CONSTANTS } from "../Constants";
import { HacknetServer } from "../Hacknet/HacknetServer";
import { IPlayer } from "../PersonObjects/IPlayer"; import { IPlayer } from "../PersonObjects/IPlayer";
import { Programs } from "../Programs/Programs"; import { Programs } from "../Programs/Programs";
import { LiteratureNames } from "../Literature/data/LiteratureNames"; import { LiteratureNames } from "../Literature/data/LiteratureNames";
import { isValidNumber } from "../utils/helpers/isValidNumber"; import { isValidNumber } from "../utils/helpers/isValidNumber";
import { isValidIPAddress } from "../utils/helpers/isValidIPAddress";
/** /**
* Constructs a new server, while also ensuring that the new server * Constructs a new server, while also ensuring that the new server
@ -22,12 +20,12 @@ export function safetlyCreateUniqueServer(params: IConstructorParams): Server {
params.ip = createUniqueRandomIp(); 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 // Use a for loop to ensure that we don't get suck in an infinite loop somehow
let hostname: string = params.hostname; let hostname: string = params.hostname;
for (let i = 0; i < 200; ++i) { for (let i = 0; i < 200; ++i) {
hostname = `${params.hostname}-${i}`; hostname = `${params.hostname}-${i}`;
if (GetServerByHostname(hostname) == null) { if (GetServer(hostname) == null) {
break; break;
} }
} }
@ -119,31 +117,6 @@ export function prestigeHomeComputer(homeComp: Server): void {
homeComp.messages.push(LiteratureNames.HackersStartingHandbook); 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 // Returns the i-th server on the specified server's network
// A Server's serverOnNetwork property holds only the IPs. This function returns // A Server's serverOnNetwork property holds only the IPs. This function returns
// the actual Server object // the actual Server object
@ -153,7 +126,7 @@ export function getServerOnNetwork(server: BaseServer, i: number): BaseServer |
return null; return null;
} }
return getServer(server.serversOnNetwork[i]); return GetServer(server.serversOnNetwork[i]);
} }
export function isBackdoorInstalled(server: BaseServer): boolean { export function isBackdoorInstalled(server: BaseServer): boolean {

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

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

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

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