mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-28 08:57:32 +01:00
Merge pull request #1433 from danielyxie/dev
Convert everything to hostname as primary
This commit is contained in:
commit
06b706beca
36
dist/vendor.bundle.js
vendored
36
dist/vendor.bundle.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -6,11 +6,10 @@ import {
|
||||
} from "./CodingContracts";
|
||||
import { Factions } from "./Faction/Factions";
|
||||
import { Player } from "./Player";
|
||||
import { AllServers } from "./Server/AllServers";
|
||||
import { GetServerByHostname } from "./Server/ServerHelpers";
|
||||
import { SpecialServerNames } from "./Server/SpecialServerIps";
|
||||
import { GetServer, GetAllServers } from "./Server/AllServers";
|
||||
import { SpecialServers } from "./Server/data/SpecialServers";
|
||||
import { Server } from "./Server/Server";
|
||||
import { HacknetServer } from "./Hacknet/HacknetServer";
|
||||
import { BaseServer } from "./Server/BaseServer";
|
||||
|
||||
import { getRandomInt } from "./utils/helpers/getRandomInt";
|
||||
|
||||
@ -68,10 +67,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 +161,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
|
||||
@ -176,18 +172,18 @@ function getRandomServer(): Server | HacknetServer {
|
||||
if (
|
||||
randServer instanceof Server &&
|
||||
!randServer.purchasedByPlayer &&
|
||||
randServer.hostname !== SpecialServerNames.WorldDaemon
|
||||
randServer.hostname !== SpecialServers.WorldDaemon
|
||||
) {
|
||||
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) {
|
||||
|
@ -2,26 +2,18 @@ import { DarkWebItems } from "./DarkWebItems";
|
||||
|
||||
import { Player } from "../Player";
|
||||
import { Terminal } from "../Terminal";
|
||||
import { SpecialServerIps } from "../Server/SpecialServerIps";
|
||||
import { SpecialServers } from "../Server/data/SpecialServers";
|
||||
import { numeralWrapper } from "../ui/numeralFormat";
|
||||
|
||||
import { isValidIPAddress } from "../utils/helpers/isValidIPAddress";
|
||||
|
||||
//Posts a "help" message if connected to DarkWeb
|
||||
export function checkIfConnectedToDarkweb(): void {
|
||||
if (SpecialServerIps.hasOwnProperty("Darkweb Server")) {
|
||||
const darkwebIp = SpecialServerIps.getIp("Darkweb Server");
|
||||
if (!isValidIPAddress(darkwebIp)) {
|
||||
return;
|
||||
}
|
||||
const server = Player.getCurrentServer();
|
||||
if (server !== null && darkwebIp == server.ip) {
|
||||
Terminal.print(
|
||||
"You are now connected to the dark web. From the dark web you can purchase illegal items. " +
|
||||
"Use the 'buy -l' command to display a list of all the items you can buy. Use 'buy [item-name] " +
|
||||
"to purchase an item.",
|
||||
);
|
||||
}
|
||||
const server = Player.getCurrentServer();
|
||||
if (server !== null && SpecialServers.DarkWeb == server.hostname) {
|
||||
Terminal.print(
|
||||
"You are now connected to the dark web. From the dark web you can purchase illegal items. " +
|
||||
"Use the 'buy -l' command to display a list of all the items you can buy. Use 'buy [item-name] " +
|
||||
"to purchase an item.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 { AllServers } from "../../Server/AllServers";
|
||||
import { HacknetServer } from "../../Hacknet/HacknetServer";
|
||||
import { GetServerByHostname } from "../../Server/ServerHelpers";
|
||||
import { GetServer, GetAllServers } from "../../Server/AllServers";
|
||||
import { Server } from "../../Server/Server";
|
||||
import MenuItem from "@mui/material/MenuItem";
|
||||
|
||||
export function Servers(): React.ReactElement {
|
||||
@ -19,9 +18,9 @@ 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 HacknetServer) return;
|
||||
if (!(s instanceof Server)) return;
|
||||
s.hasAdminRights = true;
|
||||
s.sshPortOpen = true;
|
||||
s.ftpPortOpen = true;
|
||||
@ -32,9 +31,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;
|
||||
@ -46,32 +44,30 @@ export function Servers(): React.ReactElement {
|
||||
}
|
||||
|
||||
function minSecurity(): void {
|
||||
const s = GetServerByHostname(server);
|
||||
const s = GetServer(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);
|
||||
const s = GetServer(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 +85,7 @@ export function Servers(): React.ReactElement {
|
||||
</td>
|
||||
<td colSpan={2}>
|
||||
<Select id="dev-servers-dropdown" onChange={setServerDropdown} value={server}>
|
||||
{Object.values(AllServers).map((server) => (
|
||||
{GetAllServers().map((server) => (
|
||||
<MenuItem key={server.hostname} value={server.hostname}>
|
||||
{server.hostname}
|
||||
</MenuItem>
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React from "react";
|
||||
import { AllServers } from "../Server/AllServers";
|
||||
import { GetServer, GetAllServers } from "../Server/AllServers";
|
||||
import { Modal } from "../ui/React/Modal";
|
||||
import { numeralWrapper } from "../ui/numeralFormat";
|
||||
|
||||
@ -17,11 +17,12 @@ import AccordionDetails from "@mui/material/AccordionDetails";
|
||||
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
||||
|
||||
interface IServerProps {
|
||||
ip: string;
|
||||
hostname: string;
|
||||
}
|
||||
|
||||
function ServerAccordion(props: IServerProps): React.ReactElement {
|
||||
const server = AllServers[props.ip];
|
||||
const server = GetServer(props.hostname);
|
||||
if (server === null) throw new Error("server should not be null");
|
||||
let totalSize = 0;
|
||||
for (const f of server.scripts) {
|
||||
totalSize += f.code.length;
|
||||
@ -98,9 +99,9 @@ interface IProps {
|
||||
}
|
||||
|
||||
export function FileDiagnosticModal(props: IProps): React.ReactElement {
|
||||
const ips: string[] = [];
|
||||
for (const ip of Object.keys(AllServers)) {
|
||||
ips.push(ip);
|
||||
const keys: string[] = [];
|
||||
for (const key in GetAllServers()) {
|
||||
keys.push(key);
|
||||
}
|
||||
|
||||
return (
|
||||
@ -110,8 +111,8 @@ export function FileDiagnosticModal(props: IProps): React.ReactElement {
|
||||
Welcome to the file diagnostic! If your save file is really big it's likely because you have too many
|
||||
text/scripts. This tool can help you narrow down where they are.
|
||||
</Typography>
|
||||
{ips.map((ip: string) => (
|
||||
<ServerAccordion key={ip} ip={ip} />
|
||||
{keys.map((hostname: string) => (
|
||||
<ServerAccordion key={hostname} hostname={hostname} />
|
||||
))}
|
||||
</>
|
||||
</Modal>
|
||||
|
@ -19,8 +19,7 @@ import { HashUpgrades } from "./HashUpgrades";
|
||||
import { generateRandomContract } from "../CodingContractGenerator";
|
||||
import { iTutorialSteps, iTutorialNextStep, ITutorial } from "../InteractiveTutorial";
|
||||
import { IPlayer } from "../PersonObjects/IPlayer";
|
||||
import { AllServers } from "../Server/AllServers";
|
||||
import { GetServerByHostname } from "../Server/ServerHelpers";
|
||||
import { GetServer } from "../Server/AllServers";
|
||||
import { Server } from "../Server/Server";
|
||||
import { SourceFileFlags } from "../SourceFile/SourceFileFlags";
|
||||
|
||||
@ -416,8 +415,8 @@ 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 = AllServers[ip];
|
||||
if (hserver instanceof Server) throw new Error(`player nodes shoud not be Server`);
|
||||
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);
|
||||
hashes += h;
|
||||
@ -448,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 = AllServers[ip];
|
||||
const h = GetServer(ip);
|
||||
if (!(h instanceof HacknetServer)) {
|
||||
player.hashManager.updateCapacity(0);
|
||||
return;
|
||||
@ -488,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;
|
||||
@ -504,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;
|
||||
|
@ -7,6 +7,7 @@ import { GeneralInfo } from "./GeneralInfo";
|
||||
import { HacknetNodeElem } from "./HacknetNodeElem";
|
||||
import { HacknetServerElem } from "./HacknetServerElem";
|
||||
import { HacknetNode } from "../HacknetNode";
|
||||
import { HacknetServer } from "../HacknetServer";
|
||||
import { HashUpgradeModal } from "./HashUpgradeModal";
|
||||
import { MultiplierButtons } from "./MultiplierButtons";
|
||||
import { PlayerInfo } from "./PlayerInfo";
|
||||
@ -21,8 +22,7 @@ import {
|
||||
} from "../HacknetHelpers";
|
||||
|
||||
import { IPlayer } from "../../PersonObjects/IPlayer";
|
||||
import { AllServers } from "../../Server/AllServers";
|
||||
import { Server } from "../../Server/Server";
|
||||
import { GetServer } from "../../Server/AllServers";
|
||||
|
||||
import Typography from "@mui/material/Typography";
|
||||
import Grid from "@mui/material/Grid";
|
||||
@ -50,8 +50,8 @@ 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 = AllServers[node];
|
||||
if (hserver instanceof Server) throw new Error("node was a normal server"); // should never happen
|
||||
const hserver = GetServer(node);
|
||||
if (!(hserver instanceof HacknetServer)) throw new Error("node was not hacknet server"); // should never happen
|
||||
if (hserver) {
|
||||
totalProduction += hserver.hashRate;
|
||||
} else {
|
||||
@ -88,11 +88,11 @@ 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 = AllServers[node];
|
||||
const hserver = GetServer(node);
|
||||
if (hserver == null) {
|
||||
throw new Error(`Could not find Hacknet Server object in AllServers map for IP: ${node}`);
|
||||
}
|
||||
if (hserver instanceof Server) throw new Error("node was normal server"); // should never happen
|
||||
if (!(hserver instanceof HacknetServer)) throw new Error("node was not hacknet server"); // should never happen
|
||||
return (
|
||||
<HacknetServerElem
|
||||
player={props.player}
|
||||
|
@ -7,7 +7,6 @@ import { CONSTANTS } from "../Constants";
|
||||
import { IPlayer } from "../PersonObjects/IPlayer";
|
||||
import { AddToAllServers, createUniqueRandomIp } from "../Server/AllServers";
|
||||
import { safetlyCreateUniqueServer } from "../Server/ServerHelpers";
|
||||
import { SpecialServerIps } from "../Server/SpecialServerIps";
|
||||
|
||||
import { dialogBoxCreate } from "../ui/React/DialogBox";
|
||||
|
||||
@ -36,10 +35,9 @@ export function purchaseTorRouter(p: IPlayer): void {
|
||||
maxRam: 1,
|
||||
});
|
||||
AddToAllServers(darkweb);
|
||||
SpecialServerIps.addIp("Darkweb Server", darkweb.ip);
|
||||
|
||||
p.getHomeComputer().serversOnNetwork.push(darkweb.ip);
|
||||
darkweb.serversOnNetwork.push(p.getHomeComputer().ip);
|
||||
p.getHomeComputer().serversOnNetwork.push(darkweb.hostname);
|
||||
darkweb.serversOnNetwork.push(p.getHomeComputer().hostname);
|
||||
dialogBoxCreate(
|
||||
"You have purchased a TOR router!<br>" +
|
||||
"You now have access to the dark web from your home computer.<br>" +
|
||||
|
@ -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 { AllServers } from "../Server/AllServers";
|
||||
import { GetServer } from "../Server/AllServers";
|
||||
import { BaseServer } from "../Server/BaseServer";
|
||||
import { IMap } from "../types";
|
||||
|
||||
@ -104,11 +104,11 @@ export class WorkerScript {
|
||||
/**
|
||||
* IP Address on which this script is running
|
||||
*/
|
||||
serverIp: string;
|
||||
hostname: string;
|
||||
|
||||
constructor(runningScriptObj: RunningScript, pid: number, nsFuncsGenerator?: (ws: WorkerScript) => any) {
|
||||
this.name = runningScriptObj.filename;
|
||||
this.serverIp = runningScriptObj.server;
|
||||
this.hostname = runningScriptObj.server;
|
||||
|
||||
const sanitizedPid = Math.round(pid);
|
||||
if (typeof sanitizedPid !== "number" || isNaN(sanitizedPid)) {
|
||||
@ -118,9 +118,9 @@ export class WorkerScript {
|
||||
runningScriptObj.pid = sanitizedPid;
|
||||
|
||||
// Get the underlying script's code
|
||||
const server = AllServers[this.serverIp];
|
||||
const server = GetServer(this.hostname);
|
||||
if (server == null) {
|
||||
throw new Error(`WorkerScript constructed with invalid server ip: ${this.serverIp}`);
|
||||
throw new Error(`WorkerScript constructed with invalid server ip: ${this.hostname}`);
|
||||
}
|
||||
let found = false;
|
||||
for (let i = 0; i < server.scripts.length; ++i) {
|
||||
@ -147,7 +147,7 @@ export class WorkerScript {
|
||||
* Returns the Server on which this script is running
|
||||
*/
|
||||
getServer(): BaseServer {
|
||||
const server = AllServers[this.serverIp];
|
||||
const server = GetServer(this.hostname);
|
||||
if (server == null) throw new Error(`Script ${this.name} pid ${this.pid} is running on non-existent server?`);
|
||||
return server;
|
||||
}
|
||||
|
@ -7,17 +7,17 @@ import { workerScripts } from "./WorkerScripts";
|
||||
import { WorkerScriptStartStopEventEmitter } from "./WorkerScriptStartStopEventEmitter";
|
||||
|
||||
import { RunningScript } from "../Script/RunningScript";
|
||||
import { AllServers } from "../Server/AllServers";
|
||||
import { GetServer } from "../Server/AllServers";
|
||||
|
||||
import { compareArrays } from "../utils/helpers/compareArrays";
|
||||
import { roundToTwo } from "../utils/helpers/roundToTwo";
|
||||
|
||||
export function killWorkerScript(runningScriptObj: RunningScript, serverIp: string, rerenderUi?: boolean): boolean;
|
||||
export function killWorkerScript(runningScriptObj: RunningScript, hostname: string, rerenderUi?: boolean): boolean;
|
||||
export function killWorkerScript(workerScript: WorkerScript): boolean;
|
||||
export function killWorkerScript(pid: number): boolean;
|
||||
export function killWorkerScript(
|
||||
script: RunningScript | WorkerScript | number,
|
||||
serverIp?: string,
|
||||
hostname?: string,
|
||||
rerenderUi?: boolean,
|
||||
): boolean {
|
||||
if (rerenderUi == null || typeof rerenderUi !== "boolean") {
|
||||
@ -28,7 +28,7 @@ export function killWorkerScript(
|
||||
stopAndCleanUpWorkerScript(script);
|
||||
|
||||
return true;
|
||||
} else if (script instanceof RunningScript && typeof serverIp === "string") {
|
||||
} else if (script instanceof RunningScript && typeof hostname === "string") {
|
||||
// Try to kill by PID
|
||||
const res = killWorkerScriptByPid(script.pid, rerenderUi);
|
||||
if (res) {
|
||||
@ -37,7 +37,7 @@ export function killWorkerScript(
|
||||
|
||||
// If for some reason that doesn't work, we'll try the old way
|
||||
for (const ws of workerScripts.values()) {
|
||||
if (ws.name == script.filename && ws.serverIp == serverIp && compareArrays(ws.args, script.args)) {
|
||||
if (ws.name == script.filename && ws.hostname == hostname && compareArrays(ws.args, script.args)) {
|
||||
stopAndCleanUpWorkerScript(ws, rerenderUi);
|
||||
|
||||
return true;
|
||||
@ -80,11 +80,11 @@ function stopAndCleanUpWorkerScript(workerScript: WorkerScript, rerenderUi = tru
|
||||
*/
|
||||
function removeWorkerScript(workerScript: WorkerScript, rerenderUi = true): void {
|
||||
if (workerScript instanceof WorkerScript) {
|
||||
const ip = workerScript.serverIp;
|
||||
const ip = workerScript.hostname;
|
||||
const name = workerScript.name;
|
||||
|
||||
// Get the server on which the script runs
|
||||
const server = AllServers[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 { AllServers } from "./Server/AllServers";
|
||||
import { GetServer } from "./Server/AllServers";
|
||||
import { WorkerScript } from "./Netscript/WorkerScript";
|
||||
|
||||
export function netscriptDelay(time: number, workerScript: WorkerScript): Promise<void> {
|
||||
@ -14,9 +14,9 @@ export function netscriptDelay(time: number, workerScript: WorkerScript): Promis
|
||||
|
||||
export function makeRuntimeRejectMsg(workerScript: WorkerScript, msg: string): string {
|
||||
const lineNum = "";
|
||||
const server = AllServers[workerScript.serverIp];
|
||||
const server = GetServer(workerScript.hostname);
|
||||
if (server == null) {
|
||||
throw new Error(`WorkerScript constructed with invalid server ip: ${workerScript.serverIp}`);
|
||||
throw new Error(`WorkerScript constructed with invalid server ip: ${workerScript.hostname}`);
|
||||
}
|
||||
|
||||
return "|" + server.hostname + "|" + workerScript.name + "|" + msg + lineNum;
|
||||
|
@ -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 { AllServers, 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,
|
||||
@ -113,7 +99,6 @@ import {
|
||||
} from "./Server/ServerHelpers";
|
||||
import { getPurchaseServerCost, getPurchaseServerLimit, getPurchaseServerMaxRam } from "./Server/ServerPurchases";
|
||||
import { Server } from "./Server/Server";
|
||||
import { SpecialServerIps } from "./Server/SpecialServerIps";
|
||||
import { SourceFileFlags } from "./SourceFile/SourceFileFlags";
|
||||
import { buyStock, sellStock, shortStock, sellShort } from "./StockMarket/BuyingAndSelling";
|
||||
import { influenceStockThroughServerHack, influenceStockThroughServerGrow } from "./StockMarket/PlayerInfluencing";
|
||||
@ -151,7 +136,6 @@ import { IIndustry } from "./Corporation/IIndustry";
|
||||
|
||||
import { Faction } from "./Faction/Faction";
|
||||
import { Augmentation } from "./Augmentation/Augmentation";
|
||||
import { HacknetNode } from "./Hacknet/HacknetNode";
|
||||
|
||||
import { CodingContract } from "./CodingContracts";
|
||||
import { Stock } from "./StockMarket/Stock";
|
||||
@ -212,7 +196,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
|
||||
let threads = workerScript.scriptRef.threads;
|
||||
if (typeof threads !== "number") {
|
||||
console.warn(`WorkerScript detected NaN for threadcount for ${workerScript.name} on ${workerScript.serverIp}`);
|
||||
console.warn(`WorkerScript detected NaN for threadcount for ${workerScript.name} on ${workerScript.hostname}`);
|
||||
threads = 1;
|
||||
}
|
||||
|
||||
@ -251,7 +235,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}`);
|
||||
}
|
||||
@ -285,7 +269,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
if (fn != null && typeof fn === "string") {
|
||||
// Get Logs of another script
|
||||
if (ip == null) {
|
||||
ip = workerScript.serverIp;
|
||||
ip = workerScript.hostname;
|
||||
}
|
||||
const server = safeGetServer(ip, callingFnName);
|
||||
|
||||
@ -301,8 +285,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
callingFnName = "getRunningScriptgetRunningScriptByPid";
|
||||
}
|
||||
|
||||
for (const name of Object.keys(AllServers)) {
|
||||
const server = AllServers[name];
|
||||
for (const server of GetAllServers()) {
|
||||
const runningScript = findRunningScriptByPid(pid, server);
|
||||
if (runningScript) return runningScript;
|
||||
}
|
||||
@ -600,7 +583,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}.`);
|
||||
}
|
||||
@ -664,7 +647,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
workerScript.scriptRef.onlineMoneyMade += moneyGained;
|
||||
Player.scriptProdSinceLastAug += moneyGained;
|
||||
Player.recordMoneySource(moneyGained, "hacking");
|
||||
workerScript.scriptRef.recordHack(server.ip, moneyGained, threads);
|
||||
workerScript.scriptRef.recordHack(server.hostname, moneyGained, threads);
|
||||
Player.gainHackingExp(expGainedOnSuccess);
|
||||
workerScript.scriptRef.onlineExpGained += expGainedOnSuccess;
|
||||
workerScript.log(
|
||||
@ -737,9 +720,9 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
hacknet: hacknet,
|
||||
sprintf: sprintf,
|
||||
vsprintf: vsprintf,
|
||||
scan: function (ip: any = workerScript.serverIp, hostnames: any = true): any {
|
||||
scan: function (ip: any = workerScript.hostname, 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}.`);
|
||||
}
|
||||
@ -751,7 +734,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
if (hostnames) {
|
||||
entry = s.hostname;
|
||||
} else {
|
||||
entry = s.ip;
|
||||
entry = s.hostname;
|
||||
}
|
||||
if (entry == null) {
|
||||
continue;
|
||||
@ -826,7 +809,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;
|
||||
@ -835,7 +818,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
throw makeRuntimeErrorMsg("grow", `Invalid IP/hostname: ${ip}.`);
|
||||
}
|
||||
|
||||
const host = getServer(workerScript.serverIp);
|
||||
const host = GetServer(workerScript.hostname);
|
||||
if (host === null) {
|
||||
throw new Error("Workerscript host is null");
|
||||
}
|
||||
@ -861,7 +844,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const moneyBefore = server.moneyAvailable <= 0 ? 1 : server.moneyAvailable;
|
||||
processSingleServerGrowth(server, threads, Player, host.cpuCores);
|
||||
const moneyAfter = server.moneyAvailable;
|
||||
workerScript.scriptRef.recordGrow(server.ip, threads);
|
||||
workerScript.scriptRef.recordGrow(server.hostname, threads);
|
||||
const expGain = calculateHackingExpGain(server, Player) * threads;
|
||||
const logGrowPercent = moneyAfter / moneyBefore - 1;
|
||||
workerScript.log(
|
||||
@ -900,7 +883,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;
|
||||
@ -925,14 +908,14 @@ 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.hostname);
|
||||
if (host === null) {
|
||||
workerScript.log("weaken", "Server is null, did it die?");
|
||||
return Promise.resolve(0);
|
||||
}
|
||||
const coreBonus = 1 + (host.cpuCores - 1) / 16;
|
||||
server.weaken(CONSTANTS.ServerWeakenAmount * threads * coreBonus);
|
||||
workerScript.scriptRef.recordWeaken(server.ip, threads);
|
||||
workerScript.scriptRef.recordWeaken(server.hostname, threads);
|
||||
const expGain = calculateHackingExpGain(server, Player) * threads;
|
||||
workerScript.log(
|
||||
"weaken",
|
||||
@ -998,7 +981,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
|
||||
return runningScriptObj.logs.slice();
|
||||
},
|
||||
tail: function (fn: any, ip: any = workerScript.serverIp, ...scriptArgs: any): any {
|
||||
tail: function (fn: any, ip: any = workerScript.hostname, ...scriptArgs: any): any {
|
||||
let runningScriptObj;
|
||||
if (arguments.length === 0) {
|
||||
runningScriptObj = workerScript.scriptRef;
|
||||
@ -1019,7 +1002,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;
|
||||
@ -1046,7 +1029,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;
|
||||
@ -1071,7 +1054,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;
|
||||
@ -1096,7 +1079,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;
|
||||
@ -1121,7 +1104,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;
|
||||
@ -1146,7 +1129,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;
|
||||
@ -1174,7 +1157,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.hostname);
|
||||
if (scriptServer == null) {
|
||||
throw makeRuntimeErrorMsg("run", "Could not find server. This is a bug. Report to dev.");
|
||||
}
|
||||
@ -1189,7 +1172,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}`);
|
||||
}
|
||||
@ -1206,7 +1189,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.hostname);
|
||||
if (scriptServer == null) {
|
||||
throw makeRuntimeErrorMsg("spawn", "Could not find server. This is a bug. Report to dev");
|
||||
}
|
||||
@ -1242,7 +1225,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return false;
|
||||
}
|
||||
|
||||
res = killWorkerScript(runningScriptObj, server.ip);
|
||||
res = killWorkerScript(runningScriptObj, server.hostname);
|
||||
}
|
||||
|
||||
if (res) {
|
||||
@ -1261,18 +1244,18 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
killall: function (ip: any = workerScript.serverIp): any {
|
||||
killall: function (ip: any = workerScript.hostname): any {
|
||||
updateDynamicRam("killall", getRamCost("killall"));
|
||||
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}`);
|
||||
}
|
||||
const scriptsRunning = server.runningScripts.length > 0;
|
||||
for (let i = server.runningScripts.length - 1; i >= 0; --i) {
|
||||
killWorkerScript(server.runningScripts[i], server.ip, false);
|
||||
killWorkerScript(server.runningScripts[i], server.hostname, false);
|
||||
}
|
||||
WorkerScriptStartStopEventEmitter.emit();
|
||||
workerScript.log(
|
||||
@ -1323,12 +1306,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}`);
|
||||
}
|
||||
@ -1337,12 +1320,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.hostname);
|
||||
if (currServ == null) {
|
||||
throw makeRuntimeErrorMsg("scp", "Could not find server ip for this script. This is a bug. Report to dev.");
|
||||
}
|
||||
@ -1437,7 +1420,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
const newScript = new Script(scriptname);
|
||||
newScript.code = sourceScript.code;
|
||||
newScript.ramUsage = sourceScript.ramUsage;
|
||||
newScript.server = destServer.ip;
|
||||
newScript.server = destServer.hostname;
|
||||
destServer.scripts.push(newScript);
|
||||
workerScript.log("scp", `File '${scriptname}' copied over to '${destServer.hostname}'.`);
|
||||
return true;
|
||||
@ -1447,7 +1430,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}`);
|
||||
}
|
||||
@ -1521,9 +1504,9 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
allFiles.sort();
|
||||
return allFiles;
|
||||
},
|
||||
ps: function (ip: any = workerScript.serverIp): any {
|
||||
ps: function (ip: any = workerScript.hostname): any {
|
||||
updateDynamicRam("ps", getRamCost("ps"));
|
||||
const server = getServer(ip);
|
||||
const server = GetServer(ip);
|
||||
if (server == null) {
|
||||
throw makeRuntimeErrorMsg("ps", `Invalid IP/hostname: ${ip}`);
|
||||
}
|
||||
@ -1544,7 +1527,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}`);
|
||||
}
|
||||
@ -1552,15 +1535,15 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
},
|
||||
getIp: function (): any {
|
||||
updateDynamicRam("getIp", getRamCost("getIp"));
|
||||
const scriptServer = getServer(workerScript.serverIp);
|
||||
const scriptServer = GetServer(workerScript.hostname);
|
||||
if (scriptServer == null) {
|
||||
throw makeRuntimeErrorMsg("getIp", "Could not find server. This is a bug. Report to dev.");
|
||||
}
|
||||
return scriptServer.ip;
|
||||
return scriptServer.hostname;
|
||||
},
|
||||
getHostname: function (): any {
|
||||
updateDynamicRam("getHostname", getRamCost("getHostname"));
|
||||
const scriptServer = getServer(workerScript.serverIp);
|
||||
const scriptServer = GetServer(workerScript.hostname);
|
||||
if (scriptServer == null) {
|
||||
throw makeRuntimeErrorMsg("getHostname", "Could not find server. This is a bug. Report to dev.");
|
||||
}
|
||||
@ -1769,14 +1752,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 {
|
||||
fileExists: function (filename: any, ip: any = workerScript.hostname): 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}`);
|
||||
}
|
||||
@ -1801,7 +1784,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
return false;
|
||||
},
|
||||
isRunning: function (fn: any, ip: any = workerScript.serverIp, ...scriptArgs: any): any {
|
||||
isRunning: function (fn: any, ip: any = workerScript.hostname, ...scriptArgs: any): any {
|
||||
updateDynamicRam("isRunning", getRamCost("isRunning"));
|
||||
if (fn === undefined || ip === undefined) {
|
||||
throw makeRuntimeErrorMsg("isRunning", "Usage: isRunning(scriptname, server, [arg1], [arg2]...)");
|
||||
@ -2185,10 +2168,10 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
});
|
||||
AddToAllServers(newServ);
|
||||
|
||||
Player.purchasedServers.push(newServ.ip);
|
||||
Player.purchasedServers.push(newServ.hostname);
|
||||
const homeComputer = Player.getHomeComputer();
|
||||
homeComputer.serversOnNetwork.push(newServ.ip);
|
||||
newServ.serversOnNetwork.push(homeComputer.ip);
|
||||
homeComputer.serversOnNetwork.push(newServ.hostname);
|
||||
newServ.serversOnNetwork.push(homeComputer.hostname);
|
||||
Player.loseMoney(cost);
|
||||
workerScript.log(
|
||||
"purchaseServer",
|
||||
@ -2200,7 +2183,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;
|
||||
@ -2215,7 +2198,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return false;
|
||||
}
|
||||
|
||||
const ip = server.ip;
|
||||
const ip = server.hostname;
|
||||
|
||||
// Can't delete server you're currently connected to
|
||||
if (server.isConnectedTo) {
|
||||
@ -2224,7 +2207,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
|
||||
// A server cannot delete itself
|
||||
if (ip === workerScript.serverIp) {
|
||||
if (ip === workerScript.hostname) {
|
||||
workerScript.log("deleteServer", "Cannot delete the server this script is running on.");
|
||||
return false;
|
||||
}
|
||||
@ -2257,7 +2240,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
|
||||
// Delete from all servers
|
||||
delete AllServers[ip];
|
||||
DeleteServer(ip);
|
||||
|
||||
// Delete from home computer
|
||||
found = false;
|
||||
@ -2281,7 +2264,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.");
|
||||
}
|
||||
@ -2336,7 +2319,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
let script = workerScript.getScriptOnServer(fn, server);
|
||||
if (script == null) {
|
||||
// Create a new script
|
||||
script = new Script(fn, data, server.ip, server.scripts);
|
||||
script = new Script(fn, data, server.hostname, server.scripts);
|
||||
server.scripts.push(script);
|
||||
return true;
|
||||
}
|
||||
@ -2402,7 +2385,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.hostname);
|
||||
if (server == null) {
|
||||
throw makeRuntimeErrorMsg("read", "Error getting Server. This is a bug. Report to dev.");
|
||||
}
|
||||
@ -2468,7 +2451,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.hostname);
|
||||
if (server == null) {
|
||||
throw makeRuntimeErrorMsg("clear", "Error getting Server. This is a bug. Report to dev.");
|
||||
}
|
||||
@ -2506,7 +2489,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
updateDynamicRam("rm", getRamCost("rm"));
|
||||
|
||||
if (ip == null || ip === "") {
|
||||
ip = workerScript.serverIp;
|
||||
ip = workerScript.hostname;
|
||||
}
|
||||
const s = safeGetServer(ip, "rm");
|
||||
|
||||
@ -2519,7 +2502,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}`);
|
||||
}
|
||||
@ -2532,14 +2515,14 @@ 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}`);
|
||||
}
|
||||
let suc = false;
|
||||
for (let i = 0; i < server.runningScripts.length; ++i) {
|
||||
if (server.runningScripts[i].filename == scriptname) {
|
||||
killWorkerScript(server.runningScripts[i], server.ip);
|
||||
killWorkerScript(server.runningScripts[i], server.hostname);
|
||||
suc = true;
|
||||
}
|
||||
}
|
||||
@ -2548,9 +2531,9 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
getScriptName: function (): any {
|
||||
return workerScript.name;
|
||||
},
|
||||
getScriptRam: function (scriptname: any, ip: any = workerScript.serverIp): any {
|
||||
getScriptRam: function (scriptname: any, ip: any = workerScript.hostname): any {
|
||||
updateDynamicRam("getScriptRam", getRamCost("getScriptRam"));
|
||||
const server = getServer(ip);
|
||||
const server = GetServer(ip);
|
||||
if (server == null) {
|
||||
throw makeRuntimeErrorMsg("getScriptRam", `Invalid IP/hostname: ${ip}`);
|
||||
}
|
||||
@ -2649,7 +2632,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}`);
|
||||
}
|
||||
@ -2674,7 +2657,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}`);
|
||||
}
|
||||
@ -2715,7 +2698,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
});
|
||||
});
|
||||
},
|
||||
wget: async function (url: any, target: any, ip: any = workerScript.serverIp): Promise<boolean> {
|
||||
wget: async function (url: any, target: any, ip: any = workerScript.hostname): Promise<boolean> {
|
||||
if (!isScriptFilename(target) && !target.endsWith(".txt")) {
|
||||
workerScript.log("wget", `Invalid target file: '${target}'. Must be a script or text file.`);
|
||||
return Promise.resolve(false);
|
||||
@ -2953,7 +2936,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
updateDynamicRam("purchaseTor", getRamCost("purchaseTor"));
|
||||
checkSingularityAccess("purchaseTor", 1);
|
||||
|
||||
if (SpecialServerIps["Darkweb Server"] != null) {
|
||||
if (Player.hasTorRouter()) {
|
||||
workerScript.log("purchaseTor", "You already have a TOR router!");
|
||||
return false;
|
||||
}
|
||||
@ -2974,10 +2957,9 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
maxRam: 1,
|
||||
});
|
||||
AddToAllServers(darkweb);
|
||||
SpecialServerIps.addIp("Darkweb Server", darkweb.ip);
|
||||
|
||||
Player.getHomeComputer().serversOnNetwork.push(darkweb.ip);
|
||||
darkweb.serversOnNetwork.push(Player.getHomeComputer().ip);
|
||||
Player.getHomeComputer().serversOnNetwork.push(darkweb.hostname);
|
||||
darkweb.serversOnNetwork.push(Player.getHomeComputer().hostname);
|
||||
Player.gainIntelligenceExp(CONSTANTS.IntelligenceSingFnBaseExpGain);
|
||||
workerScript.log("purchaseTor", "You have purchased a Tor router!");
|
||||
return true;
|
||||
@ -2986,7 +2968,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
updateDynamicRam("purchaseProgram", getRamCost("purchaseProgram"));
|
||||
checkSingularityAccess("purchaseProgram", 1);
|
||||
|
||||
if (SpecialServerIps["Darkweb Server"] == null) {
|
||||
if (!Player.hasTorRouter()) {
|
||||
workerScript.log("purchaseProgram", "You do not have the TOR router.");
|
||||
return false;
|
||||
}
|
||||
@ -3039,7 +3021,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;
|
||||
@ -3047,7 +3029,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
|
||||
if (hostname === "home") {
|
||||
Player.getCurrentServer().isConnectedTo = false;
|
||||
Player.currentServer = Player.getHomeComputer().ip;
|
||||
Player.currentServer = Player.getHomeComputer().hostname;
|
||||
Player.getCurrentServer().isConnectedTo = true;
|
||||
Terminal.setcwd("/");
|
||||
return true;
|
||||
@ -3057,9 +3039,9 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
for (let i = 0; i < server.serversOnNetwork.length; i++) {
|
||||
const other = getServerOnNetwork(server, i);
|
||||
if (other === null) continue;
|
||||
if (other.ip == hostname || other.hostname == hostname) {
|
||||
if (other.hostname == hostname) {
|
||||
Player.getCurrentServer().isConnectedTo = false;
|
||||
Player.currentServer = target.ip;
|
||||
Player.currentServer = target.hostname;
|
||||
Player.getCurrentServer().isConnectedTo = true;
|
||||
Terminal.setcwd("/");
|
||||
return true;
|
||||
@ -3152,7 +3134,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
workMoney: Player.work_money_mult,
|
||||
},
|
||||
timeWorked: Player.timeWorked,
|
||||
tor: SpecialServerIps.hasOwnProperty("Darkweb Server"),
|
||||
tor: Player.hasTorRouter(),
|
||||
workHackExpGain: Player.workHackExpGained,
|
||||
workStrExpGain: Player.workStrExpGained,
|
||||
workDefExpGain: Player.workDefExpGained,
|
||||
@ -3258,7 +3240,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
playtimeSinceLastBitnode: Player.playtimeSinceLastBitnode,
|
||||
jobs: {},
|
||||
factions: Player.factions.slice(),
|
||||
tor: SpecialServerIps.hasOwnProperty("Darkweb Server"),
|
||||
tor: Player.hasTorRouter(),
|
||||
};
|
||||
Object.assign(data.jobs, Player.jobs);
|
||||
return data;
|
||||
@ -4413,7 +4395,7 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
|
||||
// Coding Contract API
|
||||
codingcontract: {
|
||||
attempt: function (answer: any, fn: any, ip: any = workerScript.serverIp, { returnReward }: any = {}): any {
|
||||
attempt: function (answer: any, fn: any, ip: any = workerScript.hostname, { returnReward }: any = {}): any {
|
||||
updateDynamicRam("attempt", getRamCost("codingcontract", "attempt"));
|
||||
const contract = getCodingContract("attempt", ip, fn);
|
||||
|
||||
@ -4456,12 +4438,12 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return returnReward ? "" : false;
|
||||
}
|
||||
},
|
||||
getContractType: function (fn: any, ip: any = workerScript.serverIp): any {
|
||||
getContractType: function (fn: any, ip: any = workerScript.hostname): any {
|
||||
updateDynamicRam("getContractType", getRamCost("codingcontract", "getContractType"));
|
||||
const contract = getCodingContract("getContractType", ip, fn);
|
||||
return contract.getType();
|
||||
},
|
||||
getData: function (fn: any, ip: any = workerScript.serverIp): any {
|
||||
getData: function (fn: any, ip: any = workerScript.hostname): any {
|
||||
updateDynamicRam("getData", getRamCost("codingcontract", "getData"));
|
||||
const contract = getCodingContract("getData", ip, fn);
|
||||
const data = contract.getData();
|
||||
@ -4481,12 +4463,12 @@ function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return data;
|
||||
}
|
||||
},
|
||||
getDescription: function (fn: any, ip: any = workerScript.serverIp): any {
|
||||
getDescription: function (fn: any, ip: any = workerScript.hostname): any {
|
||||
updateDynamicRam("getDescription", getRamCost("codingcontract", "getDescription"));
|
||||
const contract = getCodingContract("getDescription", ip, fn);
|
||||
return contract.getDescription();
|
||||
},
|
||||
getNumTriesRemaining: function (fn: any, ip: any = workerScript.serverIp): any {
|
||||
getNumTriesRemaining: function (fn: any, ip: any = workerScript.hostname): any {
|
||||
updateDynamicRam("getNumTriesRemaining", getRamCost("codingcontract", "getNumTriesRemaining"));
|
||||
const contract = getCodingContract("getNumTriesRemaining", ip, fn);
|
||||
return contract.getMaxNumTries() - contract.tries;
|
||||
|
@ -16,7 +16,7 @@ import {
|
||||
} from "../Hacknet/HacknetHelpers";
|
||||
import { HacknetServer } from "../Hacknet/HacknetServer";
|
||||
import { HacknetNode } from "../Hacknet/HacknetNode";
|
||||
import { AllServers } from "../Server/AllServers";
|
||||
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 = AllServers[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(
|
||||
|
@ -4,7 +4,6 @@ import { getRamCost } from "../Netscript/RamCostGenerator";
|
||||
import { FactionWorkType } from "../Faction/FactionWorkTypeEnum";
|
||||
import { SourceFileFlags } from "../SourceFile/SourceFileFlags";
|
||||
import { SleeveTaskType } from "../PersonObjects/Sleeve/SleeveTaskTypesEnum";
|
||||
import { SpecialServerIps } from "../Server/SpecialServerIps";
|
||||
import { WorkerScript } from "../Netscript/WorkerScript";
|
||||
import { findSleevePurchasableAugs } from "../PersonObjects/Sleeve/SleeveHelpers";
|
||||
import { Augmentations } from "../Augmentation/Augmentations";
|
||||
@ -231,7 +230,6 @@ export function NetscriptSleeve(
|
||||
jobs: Object.keys(player.jobs), // technically sleeves have the same jobs as the player.
|
||||
jobTitle: Object.values(player.jobs),
|
||||
maxHp: sl.max_hp,
|
||||
tor: SpecialServerIps.hasOwnProperty("Darkweb Server"), // There's no reason not to give that infomation here as well. Worst case scenario it isn't used.
|
||||
|
||||
mult: {
|
||||
agility: sl.agility_mult,
|
||||
|
@ -18,7 +18,7 @@ import { RunningScript } from "./Script/RunningScript";
|
||||
import { getRamUsageFromRunningScript } from "./Script/RunningScriptHelpers";
|
||||
import { scriptCalculateOfflineProduction } from "./Script/ScriptHelpers";
|
||||
import { Script } from "./Script/Script";
|
||||
import { AllServers } from "./Server/AllServers";
|
||||
import { GetAllServers } from "./Server/AllServers";
|
||||
import { BaseServer } from "./Server/BaseServer";
|
||||
import { Settings } from "./Settings/Settings";
|
||||
|
||||
@ -544,11 +544,11 @@ export function createAndAddWorkerScript(
|
||||
console.error("Error text: " + w.errorMessage);
|
||||
return;
|
||||
}
|
||||
const serverIp = errorTextArray[1];
|
||||
const hostname = errorTextArray[1];
|
||||
const scriptName = errorTextArray[2];
|
||||
const errorMsg = errorTextArray[3];
|
||||
|
||||
let msg = `RUNTIME ERROR<br>${scriptName}@${serverIp}<br>`;
|
||||
let msg = `RUNTIME ERROR<br>${scriptName}@${hostname}<br>`;
|
||||
if (w.args.length > 0) {
|
||||
msg += `Args: ${arrayToString(w.args)}<br>`;
|
||||
}
|
||||
@ -600,28 +600,24 @@ export function loadAllRunningScripts(): void {
|
||||
if (skipScriptLoad) {
|
||||
console.info("Skipping the load of any scripts during startup");
|
||||
}
|
||||
for (const property in AllServers) {
|
||||
if (AllServers.hasOwnProperty(property)) {
|
||||
const server = AllServers[property];
|
||||
for (const server of GetAllServers()) {
|
||||
// Reset each server's RAM usage to 0
|
||||
server.ramUsed = 0;
|
||||
|
||||
// Reset each server's RAM usage to 0
|
||||
server.ramUsed = 0;
|
||||
// Reset modules on all scripts
|
||||
for (let i = 0; i < server.scripts.length; ++i) {
|
||||
server.scripts[i].markUpdated();
|
||||
}
|
||||
|
||||
// Reset modules on all scripts
|
||||
for (let i = 0; i < server.scripts.length; ++i) {
|
||||
server.scripts[i].markUpdated();
|
||||
}
|
||||
if (skipScriptLoad) {
|
||||
// Start game with no scripts
|
||||
server.runningScripts.length = 0;
|
||||
} else {
|
||||
for (let j = 0; j < server.runningScripts.length; ++j) {
|
||||
createAndAddWorkerScript(server.runningScripts[j], server);
|
||||
|
||||
if (skipScriptLoad) {
|
||||
// Start game with no scripts
|
||||
server.runningScripts.length = 0;
|
||||
} else {
|
||||
for (let j = 0; j < server.runningScripts.length; ++j) {
|
||||
createAndAddWorkerScript(server.runningScripts[j], server);
|
||||
|
||||
// Offline production
|
||||
scriptCalculateOfflineProduction(server.runningScripts[j]);
|
||||
}
|
||||
// Offline production
|
||||
scriptCalculateOfflineProduction(server.runningScripts[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import { HashManager } from "../Hacknet/HashManager";
|
||||
import { HacknetNode } from "../Hacknet/HacknetNode";
|
||||
import { LocationName } from "../Locations/data/LocationNames";
|
||||
import { Server } from "../Server/Server";
|
||||
import { BaseServer } from "../Server/BaseServer";
|
||||
import { IPlayerOwnedSourceFile } from "../SourceFile/PlayerOwnedSourceFile";
|
||||
import { MoneySourceTracker } from "../utils/MoneySourceTracker";
|
||||
import { Exploit } from "../Exploits/Exploit";
|
||||
@ -47,7 +48,6 @@ export interface IPlayer {
|
||||
hashManager: HashManager;
|
||||
hasTixApiAccess: boolean;
|
||||
hasWseAccount: boolean;
|
||||
homeComputer: string;
|
||||
hp: number;
|
||||
jobs: IMap<string>;
|
||||
init: () => void;
|
||||
@ -185,7 +185,7 @@ export interface IPlayer {
|
||||
gainCharismaExp(exp: number): void;
|
||||
gainIntelligenceExp(exp: number): void;
|
||||
gainMoney(money: number): void;
|
||||
getCurrentServer(): Server | HacknetServer;
|
||||
getCurrentServer(): BaseServer;
|
||||
getGangFaction(): Faction;
|
||||
getGangName(): string;
|
||||
getHomeComputer(): Server;
|
||||
|
@ -13,6 +13,7 @@ import { Exploit } from "../../Exploits/Exploit";
|
||||
import { WorkerScript } from "../../Netscript/WorkerScript";
|
||||
import { CompanyPosition } from "../../Company/CompanyPosition";
|
||||
import { Server } from "../../Server/Server";
|
||||
import { BaseServer } from "../../Server/BaseServer";
|
||||
import { HacknetServer } from "../../Hacknet/HacknetServer";
|
||||
import { Faction } from "../../Faction/Faction";
|
||||
import { Company } from "../../Company/Company";
|
||||
@ -54,7 +55,6 @@ export class PlayerObject implements IPlayer {
|
||||
hashManager: HashManager;
|
||||
hasTixApiAccess: boolean;
|
||||
hasWseAccount: boolean;
|
||||
homeComputer: string;
|
||||
hp: number;
|
||||
jobs: IMap<string>;
|
||||
init: () => void;
|
||||
@ -192,7 +192,7 @@ export class PlayerObject implements IPlayer {
|
||||
gainCharismaExp: (exp: number) => void;
|
||||
gainIntelligenceExp: (exp: number) => void;
|
||||
gainMoney: (money: number) => void;
|
||||
getCurrentServer: () => Server | HacknetServer;
|
||||
getCurrentServer: () => BaseServer;
|
||||
getGangFaction: () => Faction;
|
||||
getGangName: () => string;
|
||||
getHomeComputer: () => Server;
|
||||
@ -335,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,11 +32,11 @@ import {
|
||||
getFactionSecurityWorkRepGain,
|
||||
getFactionFieldWorkRepGain,
|
||||
} from "../formulas/reputation";
|
||||
import { AllServers, AddToAllServers, createUniqueRandomIp } from "../../Server/AllServers";
|
||||
import { GetServer, AddToAllServers, createUniqueRandomIp } from "../../Server/AllServers";
|
||||
import { Server } from "../../Server/Server";
|
||||
import { safetlyCreateUniqueServer } from "../../Server/ServerHelpers";
|
||||
import { Settings } from "../../Settings/Settings";
|
||||
import { SpecialServerIps, SpecialServerNames } from "../../Server/SpecialServerIps";
|
||||
import { SpecialServers } from "../../Server/data/SpecialServers";
|
||||
import { applySourceFile } from "../../SourceFile/applySourceFile";
|
||||
import { applyExploit } from "../../Exploits/applyExploits";
|
||||
import { SourceFiles } from "../../SourceFile/SourceFiles";
|
||||
@ -44,6 +44,7 @@ import { SourceFileFlags } from "../../SourceFile/SourceFileFlags";
|
||||
import { influenceStockThroughCompanyWork } from "../../StockMarket/PlayerInfluencing";
|
||||
import { getHospitalizationCost } from "../../Hospital/Hospital";
|
||||
import { WorkerScript } from "../../Netscript/WorkerScript";
|
||||
import { HacknetServer } from "../../Hacknet/HacknetServer";
|
||||
|
||||
import Decimal from "decimal.js";
|
||||
|
||||
@ -69,8 +70,7 @@ export function init(this: IPlayer): void {
|
||||
organizationName: "Home PC",
|
||||
purchasedByPlayer: true,
|
||||
});
|
||||
this.homeComputer = t_homeComp.ip;
|
||||
this.currentServer = t_homeComp.ip;
|
||||
this.currentServer = SpecialServers.Home;
|
||||
AddToAllServers(t_homeComp);
|
||||
|
||||
this.getHomeComputer().programs.push(Programs.NukeProgram.name);
|
||||
@ -78,8 +78,7 @@ 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.currentServer = SpecialServers.Home;
|
||||
|
||||
this.numPeopleKilled = 0;
|
||||
this.karma = 0;
|
||||
@ -576,13 +575,11 @@ 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 = AllServers[specialIp];
|
||||
if (server instanceof Server) {
|
||||
if (server && server.backdoorInstalled) return 0.75;
|
||||
}
|
||||
const server = GetServer(this.companyName);
|
||||
if (server instanceof Server) {
|
||||
if (server && server.backdoorInstalled) return 0.75;
|
||||
}
|
||||
|
||||
return 0.5;
|
||||
}
|
||||
|
||||
@ -2191,9 +2188,7 @@ export function checkForFactionInvitations(this: IPlayer): Faction[] {
|
||||
|
||||
//Fulcrum Secret Technologies - If u've unlocked fulcrum secret technolgoies server and have a high rep with the company
|
||||
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 = AllServers[fulcrumIP];
|
||||
const fulcrumSecretServer = GetServer(SpecialServers.FulcrumSecretTechnologies);
|
||||
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");
|
||||
@ -2211,9 +2206,7 @@ export function checkForFactionInvitations(this: IPlayer): Faction[] {
|
||||
|
||||
//BitRunners
|
||||
const bitrunnersFac = Factions["BitRunners"];
|
||||
const bitrunnerIP = SpecialServerIps[SpecialServerNames.BitRunnersServer];
|
||||
if (typeof bitrunnerIP !== "string") throw new Error("BitRunners should be string");
|
||||
const bitrunnersServer = AllServers[bitrunnerIP];
|
||||
const bitrunnersServer = GetServer(SpecialServers.BitRunnersServer);
|
||||
if (!(bitrunnersServer instanceof Server)) throw new Error("BitRunners should be normal server");
|
||||
if (bitrunnersServer == null) {
|
||||
console.error("Could not find BitRunners Server");
|
||||
@ -2229,9 +2222,7 @@ export function checkForFactionInvitations(this: IPlayer): Faction[] {
|
||||
//The Black Hand
|
||||
|
||||
const theblackhandFac = Factions["The Black Hand"];
|
||||
const tbhIP = SpecialServerIps[SpecialServerNames.TheBlackHandServer];
|
||||
if (typeof tbhIP !== "string") throw new Error("TheBlackHand should be string");
|
||||
const blackhandServer = AllServers[tbhIP];
|
||||
const blackhandServer = GetServer(SpecialServers.TheBlackHandServer);
|
||||
if (!(blackhandServer instanceof Server)) throw new Error("TheBlackHand should be normal server");
|
||||
if (blackhandServer == null) {
|
||||
console.error("Could not find The Black Hand Server");
|
||||
@ -2246,9 +2237,7 @@ export function checkForFactionInvitations(this: IPlayer): Faction[] {
|
||||
|
||||
//NiteSec
|
||||
const nitesecFac = Factions["NiteSec"];
|
||||
const nitesecIP = SpecialServerIps[SpecialServerNames.NiteSecServer];
|
||||
if (typeof nitesecIP !== "string") throw new Error("NiteSec should be string");
|
||||
const nitesecServer = AllServers[nitesecIP];
|
||||
const nitesecServer = GetServer(SpecialServers.NiteSecServer);
|
||||
if (!(nitesecServer instanceof Server)) throw new Error("NiteSec should be normal server");
|
||||
if (nitesecServer == null) {
|
||||
console.error("Could not find NiteSec Server");
|
||||
@ -2447,8 +2436,9 @@ 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 = AllServers[v];
|
||||
if (hserver instanceof Server) throw new Error("player hacknet server was not HacknetServer");
|
||||
const hserver = GetServer(v);
|
||||
if (hserver === null || !(hserver instanceof HacknetServer))
|
||||
throw new Error("player hacknet server was not HacknetServer");
|
||||
totalHacknetLevels += hserver.level;
|
||||
totalHacknetRam += hserver.maxRam;
|
||||
totalHacknetCores += hserver.cores;
|
||||
@ -2485,9 +2475,7 @@ export function checkForFactionInvitations(this: IPlayer): Faction[] {
|
||||
|
||||
//CyberSec
|
||||
const cybersecFac = Factions["CyberSec"];
|
||||
const cyberSecIP = SpecialServerIps[SpecialServerNames.CyberSecServer];
|
||||
if (typeof cyberSecIP !== "string") throw new Error("cybersec should be string");
|
||||
const cybersecServer = AllServers[cyberSecIP];
|
||||
const cybersecServer = GetServer(SpecialServers.CyberSecServer);
|
||||
if (!(cybersecServer instanceof Server)) throw new Error("cybersec should be normal server");
|
||||
if (cybersecServer == null) {
|
||||
console.error("Could not find CyberSec Server");
|
||||
|
@ -7,22 +7,23 @@ import { CONSTANTS } from "../../Constants";
|
||||
|
||||
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
|
||||
import { Server } from "../../Server/Server";
|
||||
import { BaseServer } from "../../Server/BaseServer";
|
||||
import { HacknetServer } from "../../Hacknet/HacknetServer";
|
||||
import { AddToAllServers, AllServers, createUniqueRandomIp } from "../../Server/AllServers";
|
||||
import { SpecialServerIps } from "../../Server/SpecialServerIps";
|
||||
import { GetServer, AddToAllServers, createUniqueRandomIp } from "../../Server/AllServers";
|
||||
import { SpecialServers } from "../../Server/data/SpecialServers";
|
||||
|
||||
export function hasTorRouter(this: IPlayer): boolean {
|
||||
return SpecialServerIps.hasOwnProperty("Darkweb Server");
|
||||
return !!GetServer(SpecialServers.DarkWeb);
|
||||
}
|
||||
|
||||
export function getCurrentServer(this: IPlayer): Server | HacknetServer {
|
||||
const server = AllServers[this.currentServer];
|
||||
export function getCurrentServer(this: IPlayer): BaseServer {
|
||||
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 = AllServers[this.homeComputer];
|
||||
const home = GetServer("home");
|
||||
if (home instanceof Server) return home;
|
||||
throw new Error("home computer was not a normal server");
|
||||
}
|
||||
@ -48,13 +49,13 @@ export function createHacknetServer(this: IPlayer): HacknetServer {
|
||||
ip: createUniqueRandomIp(),
|
||||
// player: this,
|
||||
});
|
||||
this.hacknetNodes.push(server.ip);
|
||||
this.hacknetNodes.push(server.hostname);
|
||||
|
||||
// Configure the HacknetServer to actually act as a Server
|
||||
AddToAllServers(server);
|
||||
const homeComputer = this.getHomeComputer();
|
||||
homeComputer.serversOnNetwork.push(server.ip);
|
||||
server.serversOnNetwork.push(homeComputer.ip);
|
||||
homeComputer.serversOnNetwork.push(server.hostname);
|
||||
server.serversOnNetwork.push(SpecialServers.Home);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
@ -17,10 +17,10 @@ import { Router } from "./ui/GameRoot";
|
||||
import { resetPidCounter } from "./Netscript/Pid";
|
||||
import { LiteratureNames } from "./Literature/data/LiteratureNames";
|
||||
|
||||
import { AllServers, AddToAllServers, initForeignServers, prestigeAllServers } from "./Server/AllServers";
|
||||
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 { SpecialServers } from "./Server/data/SpecialServers";
|
||||
import { deleteStockMarket, initStockMarket, initSymbolToStockMap } from "./StockMarket/StockMarket";
|
||||
import { Terminal } from "./Terminal";
|
||||
|
||||
@ -46,9 +46,6 @@ function prestigeAugmentation(): void {
|
||||
// Delete all servers except home computer
|
||||
prestigeAllServers();
|
||||
|
||||
// Delete Special Server IPs
|
||||
prestigeSpecialServerIps(); // Must be done before initForeignServers()
|
||||
|
||||
// Reset home computer (only the programs) and add to AllServers
|
||||
AddToAllServers(homeComp);
|
||||
prestigeHomeComputer(homeComp);
|
||||
@ -87,6 +84,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,15 +129,11 @@ 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 = AllServers[WorldDaemonIP];
|
||||
const DaedalusServerIP = SpecialServerIps[SpecialServerNames.DaedalusServer];
|
||||
if (typeof DaedalusServerIP !== "string") throw new Error("DaedalusServerIP should be string");
|
||||
const DaedalusServer = AllServers[DaedalusServerIP];
|
||||
const WorldDaemon = GetServer(SpecialServers.WorldDaemon);
|
||||
const DaedalusServer = GetServer(SpecialServers.DaedalusServer);
|
||||
if (WorldDaemon && DaedalusServer) {
|
||||
WorldDaemon.serversOnNetwork.push(DaedalusServer.ip);
|
||||
DaedalusServer.serversOnNetwork.push(WorldDaemon.ip);
|
||||
WorldDaemon.serversOnNetwork.push(DaedalusServer.hostname);
|
||||
DaedalusServer.serversOnNetwork.push(WorldDaemon.hostname);
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,9 +153,6 @@ function prestigeSourceFile(flume: boolean): void {
|
||||
// Delete all servers except home computer
|
||||
prestigeAllServers(); // Must be done before initForeignServers()
|
||||
|
||||
// Delete Special Server IPs
|
||||
prestigeSpecialServerIps();
|
||||
|
||||
// Reset home computer (only the programs) and add to AllServers
|
||||
AddToAllServers(homeComp);
|
||||
prestigeHomeComputer(homeComp);
|
||||
|
@ -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,14 +223,14 @@ 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;
|
||||
}
|
||||
|
||||
if (targetServer instanceof HacknetServer) {
|
||||
terminal.print(`ServerProfiler.exe cannot be run on a Hacknet Server.`);
|
||||
if (!(targetServer instanceof Server)) {
|
||||
terminal.print(`ServerProfiler.exe can only be run on normal servers.`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,8 @@ import { Factions, loadFactions } from "./Faction/Factions";
|
||||
import { loadAllGangs, AllGangs } from "./Gang/AllGangs";
|
||||
import { loadMessages, initMessages, Messages } from "./Message/MessageHelpers";
|
||||
import { Player, loadPlayer } from "./Player";
|
||||
import { AllServers, loadAllServers } from "./Server/AllServers";
|
||||
import { saveAllServers, loadAllServers } from "./Server/AllServers";
|
||||
import { Settings } from "./Settings/Settings";
|
||||
import { loadSpecialServerIps, SpecialServerIps } from "./Server/SpecialServerIps";
|
||||
import { SourceFileFlags } from "./SourceFile/SourceFileFlags";
|
||||
import { loadStockMarket, StockMarket } from "./StockMarket/StockMarket";
|
||||
|
||||
@ -28,7 +27,6 @@ class BitburnerSaveObject {
|
||||
AllServersSave = "";
|
||||
CompaniesSave = "";
|
||||
FactionsSave = "";
|
||||
SpecialServerIpsSave = "";
|
||||
AliasesSave = "";
|
||||
GlobalAliasesSave = "";
|
||||
MessagesSave = "";
|
||||
@ -41,24 +39,9 @@ class BitburnerSaveObject {
|
||||
getSaveString(): string {
|
||||
this.PlayerSave = JSON.stringify(Player);
|
||||
|
||||
// Delete all logs from all running scripts
|
||||
const TempAllServers = JSON.parse(JSON.stringify(AllServers), Reviver);
|
||||
for (const ip in TempAllServers) {
|
||||
const server = TempAllServers[ip];
|
||||
if (server == null) {
|
||||
continue;
|
||||
}
|
||||
for (let i = 0; i < server.runningScripts.length; ++i) {
|
||||
const runningScriptObj = server.runningScripts[i];
|
||||
runningScriptObj.logs.length = 0;
|
||||
runningScriptObj.logs = [];
|
||||
}
|
||||
}
|
||||
|
||||
this.AllServersSave = JSON.stringify(TempAllServers);
|
||||
this.AllServersSave = saveAllServers();
|
||||
this.CompaniesSave = JSON.stringify(Companies);
|
||||
this.FactionsSave = JSON.stringify(Factions);
|
||||
this.SpecialServerIpsSave = JSON.stringify(SpecialServerIps);
|
||||
this.AliasesSave = JSON.stringify(Aliases);
|
||||
this.GlobalAliasesSave = JSON.stringify(GlobalAliases);
|
||||
this.MessagesSave = JSON.stringify(Messages);
|
||||
@ -170,7 +153,6 @@ function loadGame(saveString: string): boolean {
|
||||
loadAllServers(saveObj.AllServersSave);
|
||||
loadCompanies(saveObj.CompaniesSave);
|
||||
loadFactions(saveObj.FactionsSave);
|
||||
loadSpecialServerIps(saveObj.SpecialServerIpsSave);
|
||||
|
||||
if (saveObj.hasOwnProperty("AliasesSave")) {
|
||||
try {
|
||||
@ -232,6 +214,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);
|
||||
@ -249,13 +238,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;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ export class RunningScript {
|
||||
// Script arguments
|
||||
args: any[] = [];
|
||||
|
||||
// Map of [key: server ip] -> Hacking data. Used for offline progress calculations.
|
||||
// Map of [key: hostname] -> Hacking data. Used for offline progress calculations.
|
||||
// Hacking data format: [MoneyStolen, NumTimesHacked, NumTimesGrown, NumTimesWeaken]
|
||||
dataMap: IMap<number[]> = {};
|
||||
|
||||
@ -52,7 +52,7 @@ export class RunningScript {
|
||||
// How much RAM this script uses for ONE thread
|
||||
ramUsage = 0;
|
||||
|
||||
// IP of the server on which this script is running
|
||||
// hostname of the server on which this script is running
|
||||
server = "";
|
||||
|
||||
// Number of threads that this script is running with
|
||||
@ -93,28 +93,28 @@ export class RunningScript {
|
||||
}
|
||||
|
||||
// Update the moneyStolen and numTimesHack maps when hacking
|
||||
recordHack(serverIp: string, moneyGained: number, n = 1): void {
|
||||
if (this.dataMap[serverIp] == null || this.dataMap[serverIp].constructor !== Array) {
|
||||
this.dataMap[serverIp] = [0, 0, 0, 0];
|
||||
recordHack(hostname: string, moneyGained: number, n = 1): void {
|
||||
if (this.dataMap[hostname] == null || this.dataMap[hostname].constructor !== Array) {
|
||||
this.dataMap[hostname] = [0, 0, 0, 0];
|
||||
}
|
||||
this.dataMap[serverIp][0] += moneyGained;
|
||||
this.dataMap[serverIp][1] += n;
|
||||
this.dataMap[hostname][0] += moneyGained;
|
||||
this.dataMap[hostname][1] += n;
|
||||
}
|
||||
|
||||
// Update the grow map when calling grow()
|
||||
recordGrow(serverIp: string, n = 1): void {
|
||||
if (this.dataMap[serverIp] == null || this.dataMap[serverIp].constructor !== Array) {
|
||||
this.dataMap[serverIp] = [0, 0, 0, 0];
|
||||
recordGrow(hostname: string, n = 1): void {
|
||||
if (this.dataMap[hostname] == null || this.dataMap[hostname].constructor !== Array) {
|
||||
this.dataMap[hostname] = [0, 0, 0, 0];
|
||||
}
|
||||
this.dataMap[serverIp][2] += n;
|
||||
this.dataMap[hostname][2] += n;
|
||||
}
|
||||
|
||||
// Update the weaken map when calling weaken() {
|
||||
recordWeaken(serverIp: string, n = 1): void {
|
||||
if (this.dataMap[serverIp] == null || this.dataMap[serverIp].constructor !== Array) {
|
||||
this.dataMap[serverIp] = [0, 0, 0, 0];
|
||||
recordWeaken(hostname: string, n = 1): void {
|
||||
if (this.dataMap[hostname] == null || this.dataMap[hostname].constructor !== Array) {
|
||||
this.dataMap[hostname] = [0, 0, 0, 0];
|
||||
}
|
||||
this.dataMap[serverIp][3] += n;
|
||||
this.dataMap[hostname][3] += n;
|
||||
}
|
||||
|
||||
// Serialize the current object to a JSON save state
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { AllServers } from "../Server/AllServers";
|
||||
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 = AllServers[script.server];
|
||||
const server = GetServer(script.server);
|
||||
if (server == null) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -37,14 +37,14 @@ export class Script {
|
||||
// Amount of RAM this Script requres to run
|
||||
ramUsage = 0;
|
||||
|
||||
// IP of server that this script is on.
|
||||
// hostname of server that this script is on.
|
||||
server = "";
|
||||
|
||||
constructor(fn = "", code = "", server = "", otherScripts: Script[] = []) {
|
||||
this.filename = fn;
|
||||
this.code = code;
|
||||
this.ramUsage = 0;
|
||||
this.server = server; // IP of server this script is on
|
||||
this.server = server; // hostname of server this script is on
|
||||
this.module = "";
|
||||
this.moduleSequenceNumber = ++globalModuleSequenceNumber;
|
||||
if (this.code !== "") {
|
||||
@ -90,12 +90,12 @@ export class Script {
|
||||
* @param {string} code - The new contents of the script
|
||||
* @param {Script[]} otherScripts - Other scripts on the server. Used to process imports
|
||||
*/
|
||||
saveScript(filename: string, code: string, serverIp: string, otherScripts: Script[]): void {
|
||||
saveScript(filename: string, code: string, hostname: string, otherScripts: Script[]): void {
|
||||
// Update code and filename
|
||||
this.code = code.replace(/^\s+|\s+$/g, "");
|
||||
|
||||
this.filename = filename;
|
||||
this.server = serverIp;
|
||||
this.server = hostname;
|
||||
this.updateRamUsage(otherScripts);
|
||||
this.markUpdated();
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { CONSTANTS } from "../Constants";
|
||||
import { Player } from "../Player";
|
||||
import { AllServers } from "../Server/AllServers";
|
||||
import { BaseServer } from "../Server/BaseServer";
|
||||
import { Server } from "../Server/Server";
|
||||
import { RunningScript } from "../Script/RunningScript";
|
||||
import { processSingleServerGrowth } from "../Server/ServerHelpers";
|
||||
import { GetServer } from "../Server/AllServers";
|
||||
|
||||
import { numeralWrapper } from "../ui/numeralFormat";
|
||||
|
||||
@ -27,20 +27,21 @@ export function scriptCalculateOfflineProduction(runningScript: RunningScript):
|
||||
//Data map: [MoneyStolen, NumTimesHacked, NumTimesGrown, NumTimesWeaken]
|
||||
|
||||
// Grow
|
||||
for (const ip in runningScript.dataMap) {
|
||||
if (runningScript.dataMap.hasOwnProperty(ip)) {
|
||||
if (runningScript.dataMap[ip][2] == 0 || runningScript.dataMap[ip][2] == null) {
|
||||
for (const hostname in runningScript.dataMap) {
|
||||
if (runningScript.dataMap.hasOwnProperty(hostname)) {
|
||||
if (runningScript.dataMap[hostname][2] == 0 || runningScript.dataMap[hostname][2] == null) {
|
||||
continue;
|
||||
}
|
||||
const serv = AllServers[ip];
|
||||
const serv = GetServer(hostname);
|
||||
if (serv == null) {
|
||||
continue;
|
||||
}
|
||||
const timesGrown = Math.round(
|
||||
((0.5 * runningScript.dataMap[ip][2]) / runningScript.onlineRunningTime) * timePassed,
|
||||
((0.5 * runningScript.dataMap[hostname][2]) / runningScript.onlineRunningTime) * timePassed,
|
||||
);
|
||||
runningScript.log(`Called on ${serv.hostname} ${timesGrown} times while offline`);
|
||||
const host = AllServers[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);
|
||||
runningScript.log(
|
||||
@ -59,20 +60,21 @@ export function scriptCalculateOfflineProduction(runningScript: RunningScript):
|
||||
runningScript.offlineExpGained += expGain;
|
||||
|
||||
// Weaken
|
||||
for (const ip in runningScript.dataMap) {
|
||||
if (runningScript.dataMap.hasOwnProperty(ip)) {
|
||||
if (runningScript.dataMap[ip][3] == 0 || runningScript.dataMap[ip][3] == null) {
|
||||
for (const hostname in runningScript.dataMap) {
|
||||
if (runningScript.dataMap.hasOwnProperty(hostname)) {
|
||||
if (runningScript.dataMap[hostname][3] == 0 || runningScript.dataMap[hostname][3] == null) {
|
||||
continue;
|
||||
}
|
||||
const serv = AllServers[ip];
|
||||
const serv = GetServer(hostname);
|
||||
if (serv == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!(serv instanceof Server)) throw new Error("trying to weaken a non-normal server");
|
||||
const host = AllServers[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,
|
||||
((0.5 * runningScript.dataMap[hostname][3]) / runningScript.onlineRunningTime) * timePassed,
|
||||
);
|
||||
runningScript.log(`Called weaken() on ${serv.hostname} ${timesWeakened} times while offline`);
|
||||
const coreBonus = 1 + (host.cpuCores - 1) / 16;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Server } from "./Server";
|
||||
import { SpecialServerIps } from "./SpecialServerIps";
|
||||
import { BaseServer } from "./BaseServer";
|
||||
import { serverMetadata } from "./data/servers";
|
||||
|
||||
import { HacknetServer } from "../Hacknet/HacknetServer";
|
||||
@ -8,13 +8,68 @@ 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
|
||||
* Key (string) = IP
|
||||
* Value = Server object
|
||||
*/
|
||||
export let AllServers: IMap<Server | HacknetServer> = {};
|
||||
let AllServers: IMap<Server | HacknetServer> = {};
|
||||
|
||||
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[] {
|
||||
const servers: BaseServer[] = [];
|
||||
for (const key in AllServers) {
|
||||
servers.push(AllServers[key]);
|
||||
}
|
||||
return servers;
|
||||
}
|
||||
|
||||
export function DeleteServer(serverkey: string): void {
|
||||
for (const key in AllServers) {
|
||||
const server = AllServers[key];
|
||||
if (server.ip !== serverkey && server.hostname !== serverkey) continue;
|
||||
delete AllServers[key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
export function ipExists(ip: string): boolean {
|
||||
return AllServers[ip] != null;
|
||||
@ -33,15 +88,13 @@ export function createUniqueRandomIp(): string {
|
||||
|
||||
// Saftely add a Server to the AllServers map
|
||||
export function AddToAllServers(server: Server | HacknetServer): void {
|
||||
const serverIp = server.ip;
|
||||
if (ipExists(serverIp)) {
|
||||
console.warn(`IP of server that's being added: ${serverIp}`);
|
||||
if (GetServer(server.hostname)) {
|
||||
console.warn(`Hostname of the server thats being added: ${server.hostname}`);
|
||||
console.warn(`The server that already has this IP is: ${AllServers[serverIp].hostname}`);
|
||||
console.warn(`The server that already has this IP is: ${AllServers[server.hostname].hostname}`);
|
||||
throw new Error("Error: Trying to add a server with an existing IP");
|
||||
}
|
||||
|
||||
AllServers[serverIp] = server;
|
||||
AllServers[server.hostname] = server;
|
||||
}
|
||||
|
||||
interface IServerParams {
|
||||
@ -108,10 +161,6 @@ export function initForeignServers(homeComputer: Server): void {
|
||||
server.messages.push(filename);
|
||||
}
|
||||
|
||||
if (metadata.specialName !== undefined) {
|
||||
SpecialServerIps.addIp(metadata.specialName, server.ip);
|
||||
}
|
||||
|
||||
AddToAllServers(server);
|
||||
if (metadata.networkLayer !== undefined) {
|
||||
networkLayers[toNumber(metadata.networkLayer) - 1].push(server);
|
||||
@ -120,8 +169,8 @@ export function initForeignServers(homeComputer: Server): void {
|
||||
|
||||
/* Create a randomized network for all the foreign servers */
|
||||
const linkComputers = (server1: Server, server2: Server): void => {
|
||||
server1.serversOnNetwork.push(server2.ip);
|
||||
server2.serversOnNetwork.push(server1.ip);
|
||||
server1.serversOnNetwork.push(server2.hostname);
|
||||
server2.serversOnNetwork.push(server1.hostname);
|
||||
};
|
||||
|
||||
const getRandomArrayItem = (arr: any[]): any => arr[Math.floor(Math.random() * arr.length)];
|
||||
@ -148,5 +197,18 @@ export function prestigeAllServers(): void {
|
||||
|
||||
export function loadAllServers(saveString: string): void {
|
||||
AllServers = JSON.parse(saveString, Reviver);
|
||||
console.log(AllServers);
|
||||
}
|
||||
|
||||
export function saveAllServers(): string {
|
||||
const TempAllServers = JSON.parse(JSON.stringify(AllServers), Reviver);
|
||||
for (const key in TempAllServers) {
|
||||
const server = TempAllServers[key];
|
||||
for (let i = 0; i < server.runningScripts.length; ++i) {
|
||||
const runningScriptObj = server.runningScripts[i];
|
||||
runningScriptObj.logs.length = 0;
|
||||
runningScriptObj.logs = [];
|
||||
}
|
||||
}
|
||||
|
||||
return JSON.stringify(TempAllServers);
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ export class BaseServer {
|
||||
}
|
||||
|
||||
// Otherwise, create a new script
|
||||
const newScript = new Script(fn, code, this.ip, this.scripts);
|
||||
const newScript = new Script(fn, code, this.hostname, this.scripts);
|
||||
this.scripts.push(newScript);
|
||||
ret.success = true;
|
||||
return ret;
|
||||
|
@ -1,17 +1,15 @@
|
||||
import { AllServers, 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,46 +117,20 @@ 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): Server | HacknetServer | null {
|
||||
for (const ip in AllServers) {
|
||||
if (AllServers.hasOwnProperty(ip)) {
|
||||
if (AllServers[ip].hostname == hostname) {
|
||||
return AllServers[ip];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//Get server by IP or hostname. Returns null if invalid
|
||||
export function getServer(s: string): Server | HacknetServer | null {
|
||||
if (!isValidIPAddress(s)) {
|
||||
return GetServerByHostname(s);
|
||||
}
|
||||
if (AllServers[s] !== undefined) {
|
||||
return AllServers[s];
|
||||
}
|
||||
|
||||
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
|
||||
export function getServerOnNetwork(server: BaseServer, i: number): Server | HacknetServer | null {
|
||||
export function getServerOnNetwork(server: BaseServer, i: number): BaseServer | null {
|
||||
if (i > server.serversOnNetwork.length) {
|
||||
console.error("Tried to get server on network that was out of range");
|
||||
return null;
|
||||
}
|
||||
|
||||
return AllServers[server.serversOnNetwork[i]];
|
||||
return GetServer(server.serversOnNetwork[i]);
|
||||
}
|
||||
|
||||
export function isBackdoorInstalled(server: Server | HacknetServer): boolean {
|
||||
if ("backdoorInstalled" in server) {
|
||||
export function isBackdoorInstalled(server: BaseServer): boolean {
|
||||
if (server instanceof Server) {
|
||||
return server.backdoorInstalled;
|
||||
}
|
||||
return false;
|
||||
|
@ -80,12 +80,12 @@ export function purchaseServer(hostname: string, ram: number, cost: number, p: I
|
||||
AddToAllServers(newServ);
|
||||
|
||||
// Add to Player's purchasedServers array
|
||||
p.purchasedServers.push(newServ.ip);
|
||||
p.purchasedServers.push(newServ.hostname);
|
||||
|
||||
// Connect new server to home computer
|
||||
const homeComputer = p.getHomeComputer();
|
||||
homeComputer.serversOnNetwork.push(newServ.ip);
|
||||
newServ.serversOnNetwork.push(homeComputer.ip);
|
||||
homeComputer.serversOnNetwork.push(newServ.hostname);
|
||||
newServ.serversOnNetwork.push(homeComputer.hostname);
|
||||
|
||||
p.loseMoney(cost);
|
||||
|
||||
|
@ -1,58 +0,0 @@
|
||||
import { IMap } from "../types";
|
||||
import { Reviver, Generic_toJSON, Generic_fromJSON } from "../utils/JSONReviver";
|
||||
|
||||
/* Holds IP of Special Servers */
|
||||
export const SpecialServerNames: IMap<string> = {
|
||||
FulcrumSecretTechnologies: "Fulcrum Secret Technologies Server",
|
||||
CyberSecServer: "CyberSec Server",
|
||||
NiteSecServer: "NiteSec Server",
|
||||
TheBlackHandServer: "The Black Hand Server",
|
||||
BitRunnersServer: "BitRunners Server",
|
||||
TheDarkArmyServer: "The Dark Army Server",
|
||||
DaedalusServer: "Daedalus Server",
|
||||
WorldDaemon: "w0r1d_d43m0n",
|
||||
};
|
||||
|
||||
export class SpecialServerIpsMap {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
[key: string]: Function | string;
|
||||
|
||||
addIp(name: string, ip: string): void {
|
||||
this[name] = ip;
|
||||
}
|
||||
|
||||
getIp(name: string): string {
|
||||
return this[name] as string;
|
||||
}
|
||||
|
||||
// Serialize the current object to a JSON save state
|
||||
toJSON(): any {
|
||||
return Generic_toJSON("SpecialServerIpsMap", this);
|
||||
}
|
||||
|
||||
// Initializes a SpecialServerIpsMap Object from a JSON save state
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
static fromJSON(value: any): SpecialServerIpsMap {
|
||||
return Generic_fromJSON(SpecialServerIpsMap, value.data);
|
||||
}
|
||||
}
|
||||
|
||||
Reviver.constructors.SpecialServerIpsMap = SpecialServerIpsMap;
|
||||
|
||||
export let SpecialServerIps: SpecialServerIpsMap = new SpecialServerIpsMap();
|
||||
|
||||
export function prestigeSpecialServerIps(): void {
|
||||
for (const member in SpecialServerIps) {
|
||||
delete SpecialServerIps[member];
|
||||
}
|
||||
|
||||
SpecialServerIps = new SpecialServerIpsMap();
|
||||
}
|
||||
|
||||
export function loadSpecialServerIps(saveString: string): void {
|
||||
SpecialServerIps = JSON.parse(saveString, Reviver);
|
||||
}
|
||||
|
||||
export function initSpecialServerIps(): void {
|
||||
SpecialServerIps = new SpecialServerIpsMap();
|
||||
}
|
26
src/Server/data/SpecialServers.ts
Normal file
26
src/Server/data/SpecialServers.ts
Normal file
@ -0,0 +1,26 @@
|
||||
/* Holds IP of Special Servers */
|
||||
export const SpecialServers: {
|
||||
[key: string]: string | undefined;
|
||||
|
||||
Home: string;
|
||||
FulcrumSecretTechnologies: string;
|
||||
CyberSecServer: string;
|
||||
NiteSecServer: string;
|
||||
TheBlackHandServer: string;
|
||||
BitRunnersServer: string;
|
||||
TheDarkArmyServer: string;
|
||||
DaedalusServer: string;
|
||||
WorldDaemon: string;
|
||||
DarkWeb: string;
|
||||
} = {
|
||||
Home: "home",
|
||||
FulcrumSecretTechnologies: "fulcrumassets",
|
||||
CyberSecServer: "CSEC",
|
||||
NiteSecServer: "avmnite-02h",
|
||||
TheBlackHandServer: "I.I.I.I",
|
||||
BitRunnersServer: "run4theh111z",
|
||||
TheDarkArmyServer: ".",
|
||||
DaedalusServer: "The-Cave",
|
||||
WorldDaemon: "w0r1d_d43m0n",
|
||||
DarkWeb: "darkweb",
|
||||
};
|
@ -4,6 +4,7 @@
|
||||
import { IMinMaxRange } from "../../types";
|
||||
import { LocationName } from "../../Locations/data/LocationNames";
|
||||
import { LiteratureNames } from "../../Literature/data/LiteratureNames";
|
||||
import { SpecialServers } from "./SpecialServers";
|
||||
|
||||
/**
|
||||
* The metadata describing the base state of servers on the network.
|
||||
@ -319,7 +320,7 @@ export const serverMetadata: IServerMetadata[] = [
|
||||
min: 1100,
|
||||
},
|
||||
serverGrowth: 1,
|
||||
specialName: "Fulcrum Secret Technologies Server",
|
||||
specialName: SpecialServers.FulcrumSecretTechnologies,
|
||||
},
|
||||
{
|
||||
hackDifficulty: {
|
||||
@ -1470,7 +1471,7 @@ export const serverMetadata: IServerMetadata[] = [
|
||||
min: 505,
|
||||
},
|
||||
serverGrowth: 0,
|
||||
specialName: "BitRunners Server",
|
||||
specialName: SpecialServers.BitRunnersServer,
|
||||
},
|
||||
{
|
||||
hackDifficulty: 0,
|
||||
@ -1489,7 +1490,7 @@ export const serverMetadata: IServerMetadata[] = [
|
||||
min: 340,
|
||||
},
|
||||
serverGrowth: 0,
|
||||
specialName: "The Black Hand Server",
|
||||
specialName: SpecialServers.TheBlackHandServer,
|
||||
},
|
||||
{
|
||||
hackDifficulty: 0,
|
||||
@ -1508,7 +1509,7 @@ export const serverMetadata: IServerMetadata[] = [
|
||||
min: 202,
|
||||
},
|
||||
serverGrowth: 0,
|
||||
specialName: "NiteSec Server",
|
||||
specialName: SpecialServers.NiteSecServer,
|
||||
},
|
||||
{
|
||||
hackDifficulty: 0,
|
||||
@ -1523,7 +1524,7 @@ export const serverMetadata: IServerMetadata[] = [
|
||||
min: 505,
|
||||
},
|
||||
serverGrowth: 0,
|
||||
specialName: "The Dark Army Server",
|
||||
specialName: SpecialServers.TheDarkArmyServer,
|
||||
},
|
||||
{
|
||||
hackDifficulty: 0,
|
||||
@ -1539,7 +1540,7 @@ export const serverMetadata: IServerMetadata[] = [
|
||||
min: 51,
|
||||
},
|
||||
serverGrowth: 0,
|
||||
specialName: "CyberSec Server",
|
||||
specialName: SpecialServers.CyberSecServer,
|
||||
},
|
||||
{
|
||||
hackDifficulty: 0,
|
||||
@ -1551,7 +1552,7 @@ export const serverMetadata: IServerMetadata[] = [
|
||||
organizationName: "Helios",
|
||||
requiredHackingSkill: 925,
|
||||
serverGrowth: 0,
|
||||
specialName: "Daedalus Server",
|
||||
specialName: SpecialServers.DaedalusServer,
|
||||
},
|
||||
{
|
||||
hackDifficulty: 0,
|
||||
@ -1561,6 +1562,6 @@ export const serverMetadata: IServerMetadata[] = [
|
||||
organizationName: "w0r1d_d43m0n",
|
||||
requiredHackingSkill: 3000,
|
||||
serverGrowth: 0,
|
||||
specialName: "w0r1d_d43m0n",
|
||||
specialName: SpecialServers.WorldDaemon,
|
||||
},
|
||||
];
|
||||
|
@ -22,7 +22,6 @@ export const TerminalHelpText: string[] = [
|
||||
"help [command] Display this help text, or the help text for a command",
|
||||
"home Connect to home computer",
|
||||
"hostname Displays the hostname of the machine",
|
||||
"ifconfig Displays the IP address of the machine",
|
||||
"kill [script/pid] [args...] Stops the specified script on the current server ",
|
||||
"killall Stops all running scripts on the current machine",
|
||||
"ls [dir] [| grep pattern] Displays all files on the machine",
|
||||
@ -219,7 +218,6 @@ export const HelpTexts: IMap<string[]> = {
|
||||
"home" + "Connect to your home computer. This will work no matter what server you are currently connected to.",
|
||||
],
|
||||
hostname: ["hostname", " ", "Prints the hostname of the current server"],
|
||||
ifconfig: ["ipconfig", " ", "Prints the IP address of the current server"],
|
||||
kill: [
|
||||
"kill [script name] [args...]",
|
||||
" ",
|
||||
|
@ -12,14 +12,14 @@ import { TextFile } from "../TextFile";
|
||||
import { Script } from "../Script/Script";
|
||||
import { isScriptFilename } from "../Script/isScriptFilename";
|
||||
import { CONSTANTS } from "../Constants";
|
||||
import { AllServers } 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 { SpecialServers } from "../Server/data/SpecialServers";
|
||||
import { Settings } from "../Settings/Settings";
|
||||
import { createProgressBarText } from "../utils/helpers/createProgressBarText";
|
||||
import {
|
||||
@ -49,7 +49,6 @@ import { hack } from "./commands/hack";
|
||||
import { help } from "./commands/help";
|
||||
import { home } from "./commands/home";
|
||||
import { hostname } from "./commands/hostname";
|
||||
import { ifconfig } from "./commands/ifconfig";
|
||||
import { kill } from "./commands/kill";
|
||||
import { killall } from "./commands/killall";
|
||||
import { ls } from "./commands/ls";
|
||||
@ -116,6 +115,7 @@ export class Terminal implements ITerminal {
|
||||
this.error("Cannot hack this kind of server");
|
||||
return;
|
||||
}
|
||||
if (!(server instanceof Server)) throw new Error("server should be normal server");
|
||||
this.startAction(calculateHackingTime(server, player) / 4, "h");
|
||||
}
|
||||
|
||||
@ -125,6 +125,7 @@ export class Terminal implements ITerminal {
|
||||
this.error("Cannot hack this kind of server");
|
||||
return;
|
||||
}
|
||||
if (!(server instanceof Server)) throw new Error("server should be normal server");
|
||||
this.startAction(calculateGrowTime(server, player) / 16, "g");
|
||||
}
|
||||
startWeaken(player: IPlayer): void {
|
||||
@ -133,6 +134,7 @@ export class Terminal implements ITerminal {
|
||||
this.error("Cannot hack this kind of server");
|
||||
return;
|
||||
}
|
||||
if (!(server instanceof Server)) throw new Error("server should be normal server");
|
||||
this.startAction(calculateWeakenTime(server, player) / 16, "w");
|
||||
}
|
||||
|
||||
@ -143,6 +145,7 @@ export class Terminal implements ITerminal {
|
||||
this.error("Cannot backdoor this kind of server");
|
||||
return;
|
||||
}
|
||||
if (!(server instanceof Server)) throw new Error("server should be normal server");
|
||||
this.startAction(calculateHackingTime(server, player) / 4, "b");
|
||||
}
|
||||
|
||||
@ -163,6 +166,7 @@ export class Terminal implements ITerminal {
|
||||
this.error("Cannot hack this kind of server");
|
||||
return;
|
||||
}
|
||||
if (!(server instanceof Server)) throw new Error("server should be normal server");
|
||||
|
||||
// Calculate whether hack was successful
|
||||
const hackChance = calculateHackingChance(server, player);
|
||||
@ -171,10 +175,7 @@ export class Terminal implements ITerminal {
|
||||
const expGainedOnFailure = expGainedOnSuccess / 4;
|
||||
if (rand < hackChance) {
|
||||
// Success!
|
||||
if (
|
||||
SpecialServerIps[SpecialServerNames.WorldDaemon] &&
|
||||
SpecialServerIps[SpecialServerNames.WorldDaemon] == server.ip
|
||||
) {
|
||||
if (SpecialServers.WorldDaemon === server.hostname) {
|
||||
if (player.bitNodeN == null) {
|
||||
player.bitNodeN = 1;
|
||||
}
|
||||
@ -218,6 +219,7 @@ export class Terminal implements ITerminal {
|
||||
this.error("Cannot hack this kind of server");
|
||||
return;
|
||||
}
|
||||
if (!(server instanceof Server)) throw new Error("server should be normal server");
|
||||
const expGain = calculateHackingExpGain(server, player);
|
||||
const growth = processSingleServerGrowth(server, 1, player, server.cpuCores) - 1;
|
||||
this.print(
|
||||
@ -235,6 +237,7 @@ export class Terminal implements ITerminal {
|
||||
this.error("Cannot hack this kind of server");
|
||||
return;
|
||||
}
|
||||
if (!(server instanceof Server)) throw new Error("server should be normal server");
|
||||
const expGain = calculateHackingExpGain(server, player);
|
||||
server.weaken(CONSTANTS.ServerWeakenAmount);
|
||||
this.print(
|
||||
@ -251,10 +254,8 @@ export class Terminal implements ITerminal {
|
||||
this.error("Cannot hack this kind of server");
|
||||
return;
|
||||
}
|
||||
if (
|
||||
SpecialServerIps[SpecialServerNames.WorldDaemon] &&
|
||||
SpecialServerIps[SpecialServerNames.WorldDaemon] == server.ip
|
||||
) {
|
||||
if (!(server instanceof Server)) throw new Error("server should be normal server");
|
||||
if (SpecialServers.WorldDaemon === server.hostname) {
|
||||
if (player.bitNodeN == null) {
|
||||
player.bitNodeN = 1;
|
||||
}
|
||||
@ -287,7 +288,7 @@ export class Terminal implements ITerminal {
|
||||
}
|
||||
this.print(
|
||||
`Total money available on server: ${
|
||||
!(currServ instanceof HacknetServer) ? numeralWrapper.formatMoney(currServ.moneyAvailable) : "N/A"
|
||||
currServ instanceof Server ? numeralWrapper.formatMoney(currServ.moneyAvailable) : "N/A"
|
||||
}`,
|
||||
);
|
||||
if (currServ instanceof Server) {
|
||||
@ -449,8 +450,8 @@ export class Terminal implements ITerminal {
|
||||
const visited: {
|
||||
[key: string]: number | undefined;
|
||||
} = {};
|
||||
for (const ip in AllServers) {
|
||||
visited[ip] = 0;
|
||||
for (const server of GetAllServers()) {
|
||||
visited[server.hostname] = 0;
|
||||
}
|
||||
|
||||
const stack: BaseServer[] = [];
|
||||
@ -465,12 +466,12 @@ export class Terminal implements ITerminal {
|
||||
const isHacknet = s instanceof HacknetServer;
|
||||
if (!all && (s as any).purchasedByPlayer && s.hostname != "home") {
|
||||
continue; // Purchased server
|
||||
} else if (visited[s.ip] || d > depth) {
|
||||
} else if (visited[s.hostname] || d > depth) {
|
||||
continue; // Already visited or out-of-depth
|
||||
} else if (!all && isHacknet) {
|
||||
continue; // Hacknet Server
|
||||
} else {
|
||||
visited[s.ip] = 1;
|
||||
visited[s.hostname] = 1;
|
||||
}
|
||||
for (let i = s.serversOnNetwork.length - 1; i >= 0; --i) {
|
||||
const newS = getServerOnNetwork(s, i);
|
||||
@ -505,13 +506,13 @@ 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;
|
||||
}
|
||||
player.getCurrentServer().isConnectedTo = false;
|
||||
player.currentServer = serv.ip;
|
||||
player.currentServer = serv.hostname;
|
||||
player.getCurrentServer().isConnectedTo = true;
|
||||
this.print("Connected to " + serv.hostname);
|
||||
this.setcwd("/");
|
||||
@ -569,7 +570,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;
|
||||
@ -617,7 +618,10 @@ export class Terminal implements ITerminal {
|
||||
break;
|
||||
case iTutorialSteps.TerminalConnect:
|
||||
if (commandArray.length == 2) {
|
||||
if (commandArray[0] == "connect" && (commandArray[1] == "n00dles" || commandArray[1] == n00dlesServ.ip)) {
|
||||
if (
|
||||
commandArray[0] == "connect" &&
|
||||
(commandArray[1] == "n00dles" || commandArray[1] == n00dlesServ.hostname)
|
||||
) {
|
||||
iTutorialNextStep();
|
||||
} else {
|
||||
this.print("Wrong command! Try again!");
|
||||
@ -733,7 +737,6 @@ export class Terminal implements ITerminal {
|
||||
help: help,
|
||||
home: home,
|
||||
hostname: hostname,
|
||||
ifconfig: ifconfig,
|
||||
kill: kill,
|
||||
killall: killall,
|
||||
ls: ls,
|
||||
|
@ -3,7 +3,8 @@ import { IRouter } from "../../ui/Router";
|
||||
import { IPlayer } from "../../PersonObjects/IPlayer";
|
||||
import { BaseServer } from "../../Server/BaseServer";
|
||||
import { listAllDarkwebItems, buyDarkwebItem } from "../../DarkWeb/DarkWeb";
|
||||
import { SpecialServerIps } from "../../Server/SpecialServerIps";
|
||||
import { SpecialServers } from "../../Server/data/SpecialServers";
|
||||
import { GetServer } from "../../Server/AllServers";
|
||||
|
||||
export function buy(
|
||||
terminal: ITerminal,
|
||||
@ -12,7 +13,7 @@ export function buy(
|
||||
server: BaseServer,
|
||||
args: (string | number)[],
|
||||
): void {
|
||||
if (!SpecialServerIps.hasOwnProperty("Darkweb Server")) {
|
||||
if (!GetServer(SpecialServers.DarkWeb)) {
|
||||
terminal.error(
|
||||
"You need to be able to connect to the Dark Web to use the buy command. (Maybe there's a TOR router you can buy somewhere)",
|
||||
);
|
||||
|
@ -17,13 +17,13 @@ export function connect(
|
||||
return;
|
||||
}
|
||||
|
||||
const ip = args[0] + "";
|
||||
const hostname = args[0] + "";
|
||||
|
||||
for (let i = 0; i < server.serversOnNetwork.length; i++) {
|
||||
const other = getServerOnNetwork(server, i);
|
||||
if (other === null) throw new Error(`Server on network should not be null`);
|
||||
if (other.ip == ip || other.hostname == ip) {
|
||||
terminal.connectToServer(player, ip);
|
||||
if (other.hostname == hostname) {
|
||||
terminal.connectToServer(player, hostname);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ export function home(
|
||||
return;
|
||||
}
|
||||
player.getCurrentServer().isConnectedTo = false;
|
||||
player.currentServer = player.getHomeComputer().ip;
|
||||
player.currentServer = player.getHomeComputer().hostname;
|
||||
player.getCurrentServer().isConnectedTo = true;
|
||||
terminal.print("Connected to home");
|
||||
terminal.setcwd("/");
|
||||
|
@ -1,18 +0,0 @@
|
||||
import { ITerminal } from "../ITerminal";
|
||||
import { IRouter } from "../../ui/Router";
|
||||
import { IPlayer } from "../../PersonObjects/IPlayer";
|
||||
import { BaseServer } from "../../Server/BaseServer";
|
||||
|
||||
export function ifconfig(
|
||||
terminal: ITerminal,
|
||||
router: IRouter,
|
||||
player: IPlayer,
|
||||
server: BaseServer,
|
||||
args: (string | number)[],
|
||||
): void {
|
||||
if (args.length !== 0) {
|
||||
terminal.error("Incorrect usage of ifconfig command. Usage: ifconfig");
|
||||
return;
|
||||
}
|
||||
terminal.print(player.getCurrentServer().ip);
|
||||
}
|
@ -36,7 +36,7 @@ export function kill(
|
||||
terminal.error("No such script is running. Nothing to kill");
|
||||
return;
|
||||
}
|
||||
killWorkerScript(runningScript, server.ip, false);
|
||||
killWorkerScript(runningScript, server.hostname, false);
|
||||
terminal.print(`Killing ${scriptName}`);
|
||||
} catch (e) {
|
||||
terminal.error(e + "");
|
||||
|
@ -7,7 +7,7 @@ import { WorkerScriptStartStopEventEmitter } from "../../Netscript/WorkerScriptS
|
||||
|
||||
export function killall(terminal: ITerminal, router: IRouter, player: IPlayer, server: BaseServer): void {
|
||||
for (let i = server.runningScripts.length - 1; i >= 0; --i) {
|
||||
killWorkerScript(server.runningScripts[i], server.ip, false);
|
||||
killWorkerScript(server.runningScripts[i], server.hostname, false);
|
||||
}
|
||||
WorkerScriptStartStopEventEmitter.emit();
|
||||
terminal.print("Killing all running scripts");
|
||||
|
@ -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,7 +5,7 @@ import { Aliases, GlobalAliases } from "../Alias";
|
||||
import { DarkWebItems } from "../DarkWeb/DarkWebItems";
|
||||
import { Message } from "../Message/Message";
|
||||
import { IPlayer } from "../PersonObjects/IPlayer";
|
||||
import { AllServers } from "../Server/AllServers";
|
||||
import { GetServer, GetAllServers } from "../Server/AllServers";
|
||||
|
||||
// An array of all Terminal commands
|
||||
const commands = [
|
||||
@ -223,9 +223,8 @@ export function determineAllPossibilitiesForTabCompletion(
|
||||
}
|
||||
|
||||
if (isCommand("scp") && index === 1) {
|
||||
for (const iphostname in AllServers) {
|
||||
allPos.push(AllServers[iphostname].ip);
|
||||
allPos.push(AllServers[iphostname].hostname);
|
||||
for (const server of GetAllServers()) {
|
||||
allPos.push(server.hostname);
|
||||
}
|
||||
|
||||
return allPos;
|
||||
@ -243,11 +242,10 @@ export function determineAllPossibilitiesForTabCompletion(
|
||||
if (isCommand("connect")) {
|
||||
// All network connections
|
||||
for (let i = 0; i < currServ.serversOnNetwork.length; ++i) {
|
||||
const serv = AllServers[currServ.serversOnNetwork[i]];
|
||||
const serv = GetServer(currServ.serversOnNetwork[i]);
|
||||
if (serv == null) {
|
||||
continue;
|
||||
}
|
||||
allPos.push(serv.ip);
|
||||
allPos.push(serv.hostname);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,6 @@ import { initForeignServers } from "./Server/AllServers";
|
||||
import { Settings } from "./Settings/Settings";
|
||||
import { ThemeEvents } from "./ui/React/Theme";
|
||||
import { updateSourceFileFlags } from "./SourceFile/SourceFileFlags";
|
||||
import { initSpecialServerIps } from "./Server/SpecialServerIps";
|
||||
import { initSymbolToStockMap, processStockPrices } from "./StockMarket/StockMarket";
|
||||
import { Terminal } from "./Terminal";
|
||||
import { Sleeve } from "./PersonObjects/Sleeve/Sleeve";
|
||||
@ -409,7 +408,6 @@ const Engine: {
|
||||
} else {
|
||||
// No save found, start new game
|
||||
initBitNodeMultipliers(Player);
|
||||
initSpecialServerIps();
|
||||
Engine.start(); // Run main game loop and Scripts loop
|
||||
Player.init();
|
||||
initForeignServers(Player.getHomeComputer());
|
||||
|
@ -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,9 +54,9 @@ 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.hostname);
|
||||
if (server == null) {
|
||||
console.warn(`WorkerScript has invalid IP address: ${ws.serverIp}`);
|
||||
console.warn(`WorkerScript has invalid IP address: ${ws.hostname}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ import { ITutorialEvents } from "./InteractiveTutorial/ITutorialEvents";
|
||||
import { Faction } from "../Faction/Faction";
|
||||
import { prestigeAugmentation } from "../Prestige";
|
||||
import { dialogBoxCreate } from "./React/DialogBox";
|
||||
import { AllServers } from "../Server/AllServers";
|
||||
import { GetAllServers } from "../Server/AllServers";
|
||||
import { Factions } from "../Faction/Factions";
|
||||
import { buyStock, sellStock, shortStock, sellShort } from "../StockMarket/BuyingAndSelling";
|
||||
import {
|
||||
@ -356,8 +356,8 @@ export function GameRoot({ player, engine, terminal }: IProps): React.ReactEleme
|
||||
save={() => saveObject.saveGame()}
|
||||
export={() => saveObject.exportGame()}
|
||||
forceKill={() => {
|
||||
for (const hostname of Object.keys(AllServers)) {
|
||||
AllServers[hostname].runningScripts = [];
|
||||
for (const server of GetAllServers()) {
|
||||
server.runningScripts = [];
|
||||
}
|
||||
dialogBoxCreate("Forcefully deleted all running scripts. Please save and refresh page.");
|
||||
}}
|
||||
|
@ -8,7 +8,6 @@ import Button from "@mui/material/Button";
|
||||
import Paper from "@mui/material/Paper";
|
||||
import Draggable from "react-draggable";
|
||||
import { ResizableBox } from "react-resizable";
|
||||
import { Theme } from "@mui/material";
|
||||
import makeStyles from "@mui/styles/makeStyles";
|
||||
import createStyles from "@mui/styles/createStyles";
|
||||
import ArrowForwardIosIcon from "@mui/icons-material/ArrowForwardIos";
|
||||
|
@ -4,8 +4,9 @@
|
||||
* Configurable to only contain certain types of servers
|
||||
*/
|
||||
import React from "react";
|
||||
import { AllServers } from "../../Server/AllServers";
|
||||
import { GetAllServers } from "../../Server/AllServers";
|
||||
import { Server } from "../../Server/Server";
|
||||
import { BaseServer } from "../../Server/BaseServer";
|
||||
|
||||
import { HacknetServer } from "../../Hacknet/HacknetServer";
|
||||
import Select, { SelectChangeEvent } from "@mui/material/Select";
|
||||
@ -30,7 +31,7 @@ export function ServerDropdown(props: IProps): React.ReactElement {
|
||||
* Checks if the server should be shown in the dropdown menu, based on the
|
||||
* 'serverType' property
|
||||
*/
|
||||
function isValidServer(s: Server | HacknetServer): boolean {
|
||||
function isValidServer(s: BaseServer): boolean {
|
||||
const purchased = s instanceof Server && s.purchasedByPlayer;
|
||||
const type = props.serverType;
|
||||
switch (type) {
|
||||
@ -49,8 +50,7 @@ export function ServerDropdown(props: IProps): React.ReactElement {
|
||||
}
|
||||
|
||||
const servers = [];
|
||||
for (const serverName in AllServers) {
|
||||
const server = AllServers[serverName];
|
||||
for (const server of GetAllServers()) {
|
||||
if (isValidServer(server)) {
|
||||
servers.push(
|
||||
<MenuItem key={server.hostname} value={server.hostname}>
|
||||
|
Loading…
Reference in New Issue
Block a user