Connect to owned servers from anywhere (#159)

* purchasedByPlayer allows connect-from-anywhere as if the server was backdoored.
* Also added optional backdoorInstalled variable to type for BaseServer. This has no runtime effect, but it allows accessing that variable without TS needing us to verify whether it's instanceof Server first.
This commit is contained in:
Snarling 2022-10-25 17:48:46 -04:00 committed by GitHub
parent 8837c01d21
commit 239834dba6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

@ -93,6 +93,9 @@ export abstract class BaseServer {
// Flag indicating whether this is a purchased server // Flag indicating whether this is a purchased server
purchasedByPlayer = false; purchasedByPlayer = false;
// Variables that exist only on some types of servers can just be optional.
backdoorInstalled?: boolean;
constructor(params: IConstructorParams = { hostname: "", ip: createRandomIp() }) { constructor(params: IConstructorParams = { hostname: "", ip: createRandomIp() }) {
this.ip = params.ip ? params.ip : createRandomIp(); this.ip = params.ip ? params.ip : createRandomIp();

@ -2,7 +2,6 @@ import { Terminal } from "../../Terminal";
import { BaseServer } from "../../Server/BaseServer"; import { BaseServer } from "../../Server/BaseServer";
import { getServerOnNetwork } from "../../Server/ServerHelpers"; import { getServerOnNetwork } from "../../Server/ServerHelpers";
import { GetServer } from "../../Server/AllServers"; import { GetServer } from "../../Server/AllServers";
import { Server } from "../../Server/Server";
export function connect(args: (string | number | boolean)[], server: BaseServer): void { export function connect(args: (string | number | boolean)[], server: BaseServer): void {
// Disconnect from current server in Terminal and connect to new one // Disconnect from current server in Terminal and connect to new one
@ -24,7 +23,7 @@ export function connect(args: (string | number | boolean)[], server: BaseServer)
const other = GetServer(hostname); const other = GetServer(hostname);
if (other !== null) { if (other !== null) {
if (other instanceof Server && other.backdoorInstalled) { if (other.backdoorInstalled || other.purchasedByPlayer) {
Terminal.connectToServer(hostname); Terminal.connectToServer(hostname);
return; return;
} }