From be29481689d33c2d5129eac7ee1f68c422e31f61 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Thu, 7 Oct 2021 16:04:04 -0400 Subject: [PATCH] unexport AllServers --- src/CodingContractGenerator.ts | 21 +++++----- src/DevMenu/ui/Servers.tsx | 31 +++++++-------- src/Diagnostic/FileDiagnosticModal.tsx | 14 ++++--- src/Hacknet/HacknetHelpers.tsx | 9 ++--- src/Hacknet/ui/HacknetRoot.tsx | 11 +++--- src/Netscript/WorkerScript.ts | 6 +-- src/Netscript/killWorkerScript.ts | 4 +- src/NetscriptEvaluator.ts | 4 +- src/NetscriptFunctions.ts | 7 ++-- src/NetscriptFunctions/Hacknet.ts | 4 +- src/NetscriptWorker.ts | 36 ++++++++--------- src/PersonObjects/IPlayer.ts | 3 +- src/PersonObjects/Player/PlayerObject.ts | 3 +- .../Player/PlayerObjectGeneralMethods.tsx | 22 ++++++----- .../Player/PlayerObjectServerMethods.ts | 10 +++-- src/Prestige.ts | 8 ++-- src/Programs/data/ProgramsMetadata.ts | 4 +- src/SaveObject.tsx | 18 +-------- src/Script/RunningScriptHelpers.ts | 4 +- src/Script/ScriptHelpers.ts | 13 ++++--- src/Server/AllServers.ts | 39 ++++++++++++++++++- src/Server/ServerHelpers.ts | 27 +++++++------ src/Terminal/Terminal.ts | 20 +++++++--- ...termineAllPossibilitiesForTabCompletion.ts | 11 +++--- src/ui/GameRoot.tsx | 6 +-- src/ui/React/LogBoxManager.tsx | 1 - src/ui/React/ServerDropdown.tsx | 8 ++-- 27 files changed, 185 insertions(+), 159 deletions(-) diff --git a/src/CodingContractGenerator.ts b/src/CodingContractGenerator.ts index 93d499781..610619409 100644 --- a/src/CodingContractGenerator.ts +++ b/src/CodingContractGenerator.ts @@ -6,11 +6,11 @@ import { } from "./CodingContracts"; import { Factions } from "./Faction/Factions"; import { Player } from "./Player"; -import { AllServers } from "./Server/AllServers"; -import { GetServerByHostname } from "./Server/ServerHelpers"; +import { GetAllServers } from "./Server/AllServers"; +import { getServer } from "./Server/ServerHelpers"; import { SpecialServerNames } from "./Server/SpecialServerIps"; import { Server } from "./Server/Server"; -import { HacknetServer } from "./Hacknet/HacknetServer"; +import { BaseServer } from "./Server/BaseServer"; import { getRandomInt } from "./utils/helpers/getRandomInt"; @@ -68,10 +68,7 @@ export function generateContract(params: IGenerateContractParams): void { // Server let server; if (params.server != null) { - server = GetServerByHostname(params.server); - if (server == null) { - server = AllServers[params.server]; - } + server = getServer(params.server); if (server == null) { server = getRandomServer(); } @@ -165,10 +162,10 @@ function getRandomReward(): ICodingContractReward { return reward; } -function getRandomServer(): Server | HacknetServer { - const servers = Object.keys(AllServers); +function getRandomServer(): BaseServer { + const servers = GetAllServers(); let randIndex = getRandomInt(0, servers.length - 1); - let randServer = AllServers[servers[randIndex]]; + let randServer = servers[randIndex]; // An infinite loop shouldn't ever happen, but to be safe we'll use // a for loop with a limited number of tries @@ -181,13 +178,13 @@ function getRandomServer(): Server | HacknetServer { break; } randIndex = getRandomInt(0, servers.length - 1); - randServer = AllServers[servers[randIndex]]; + randServer = servers[randIndex]; } return randServer; } -function getRandomFilename(server: Server | HacknetServer, reward: ICodingContractReward): string { +function getRandomFilename(server: BaseServer, reward: ICodingContractReward): string { let contractFn = `contract-${getRandomInt(0, 1e6)}`; for (let i = 0; i < 1000; ++i) { diff --git a/src/DevMenu/ui/Servers.tsx b/src/DevMenu/ui/Servers.tsx index 9b1b66e35..13d8ce41c 100644 --- a/src/DevMenu/ui/Servers.tsx +++ b/src/DevMenu/ui/Servers.tsx @@ -8,8 +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 { AllServers } from "../../Server/AllServers"; -import { HacknetServer } from "../../Hacknet/HacknetServer"; +import { GetAllServers } from "../../Server/AllServers"; +import { Server } from "../../Server/Server"; import { GetServerByHostname } from "../../Server/ServerHelpers"; import MenuItem from "@mui/material/MenuItem"; @@ -21,7 +21,7 @@ export function Servers(): React.ReactElement { function rootServer(): void { const s = GetServerByHostname(server); if (s === null) return; - if (s instanceof HacknetServer) return; + if (!(s instanceof Server)) return; s.hasAdminRights = true; s.sshPortOpen = true; s.ftpPortOpen = true; @@ -32,9 +32,8 @@ export function Servers(): React.ReactElement { } function rootAllServers(): void { - for (const i in AllServers) { - const s = AllServers[i]; - if (s instanceof HacknetServer) return; + for (const s of GetAllServers()) { + if (!(s instanceof Server)) return; s.hasAdminRights = true; s.sshPortOpen = true; s.ftpPortOpen = true; @@ -48,30 +47,28 @@ export function Servers(): React.ReactElement { function minSecurity(): void { const s = GetServerByHostname(server); if (s === null) return; - if (s instanceof HacknetServer) return; + if (!(s instanceof Server)) return; s.hackDifficulty = s.minDifficulty; } function minAllSecurity(): void { - for (const i in AllServers) { - const server = AllServers[i]; - if (server instanceof HacknetServer) continue; - server.hackDifficulty = server.minDifficulty; + for (const s of GetAllServers()) { + if (!(s instanceof Server)) return; + s.hackDifficulty = s.minDifficulty; } } function maxMoney(): void { const s = GetServerByHostname(server); if (s === null) return; - if (s instanceof HacknetServer) return; + if (!(s instanceof Server)) return; s.moneyAvailable = s.moneyMax; } function maxAllMoney(): void { - for (const i in AllServers) { - const server = AllServers[i]; - if (server instanceof HacknetServer) continue; - server.moneyAvailable = server.moneyMax; + for (const s of GetAllServers()) { + if (!(s instanceof Server)) return; + s.moneyAvailable = s.moneyMax; } } @@ -89,7 +86,7 @@ export function Servers(): React.ReactElement {