Skip to content

Commit

Permalink
BUGFIX: Hashserver UI shows wrong server list when purchasing upgrades (
Browse files Browse the repository at this point in the history
  • Loading branch information
catloversg authored Nov 20, 2024
1 parent fe2c98e commit 70a231e
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions src/ui/React/ServerDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ import Select, { SelectChangeEvent } from "@mui/material/Select";
import MenuItem from "@mui/material/MenuItem";
import Button from "@mui/material/Button";
import { AugmentationName } from "@enums";
import { SpecialServers } from "../../Server/data/SpecialServers";
import { throwIfReachable } from "../../utils/helpers/throwIfReachable";

// TODO make this an enum when this gets converted to TypeScript
export const ServerType = {
All: 0,
Foreign: 1, // Hackable, non-owned servers
Owned: 2, // Home Computer, Purchased Servers, and Hacknet Servers
Purchased: 3, // Everything from Owned except home computer
};
export enum ServerType {
All = 0,
Foreign = 1, // Non-owned servers
Owned = 2, // Home Computer, Purchased Servers, and Hacknet Servers
Purchased = 3, // Everything from Owned except home computer
}

interface IProps {
purchase: () => void;
canPurchase: boolean;
serverType: number;
serverType: ServerType;
onChange: (event: SelectChangeEvent) => void;
value: string;
}
Expand All @@ -35,24 +36,35 @@ 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: BaseServer): boolean {
const purchased = (s instanceof Server && s.purchasedByPlayer) || s instanceof HacknetServer;
function isValidServer(baseServer: BaseServer): boolean {
/**
* isOwnedServer is true if baseServer is home, private servers, or hacknet servers. Note that, with home computer,
* baseServer.purchasedByPlayer is true.
*/
const isOwnedServer =
(baseServer instanceof Server && baseServer.purchasedByPlayer) || baseServer instanceof HacknetServer;
const type = props.serverType;
switch (type) {
case ServerType.All:
return true;
case ServerType.Foreign:
return s.hostname !== "home" && !purchased && !Player.hasAugmentation(AugmentationName.TheRedPill, true)
? s.hostname !== "w0r1d_d43m0n"
: true;
// Exclude home, private servers, hacknet servers.
if (isOwnedServer) {
return false;
}
// If the player has not installed TRP, exclude WD server.
return (
Player.hasAugmentation(AugmentationName.TheRedPill, true) ||
baseServer.hostname !== SpecialServers.WorldDaemon
);
case ServerType.Owned:
return purchased || s.hostname === "home";
return isOwnedServer;
case ServerType.Purchased:
return purchased;
return isOwnedServer && baseServer.hostname !== SpecialServers.Home;
default:
console.warn(`Invalid ServerType specified for ServerDropdown component: ${type}`);
return false;
throwIfReachable(type);
}
return false;
}

const servers = [];
Expand Down

0 comments on commit 70a231e

Please sign in to comment.