From 239834dba61f71078cd5b345f40ddb3193663e74 Mon Sep 17 00:00:00 2001 From: Snarling <84951833+Snarling@users.noreply.github.com> Date: Tue, 25 Oct 2022 17:48:46 -0400 Subject: [PATCH] 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. --- src/Server/BaseServer.ts | 3 +++ src/Terminal/commands/connect.ts | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Server/BaseServer.ts b/src/Server/BaseServer.ts index 22dd7d0e5..7cdbc6250 100644 --- a/src/Server/BaseServer.ts +++ b/src/Server/BaseServer.ts @@ -93,6 +93,9 @@ export abstract class BaseServer { // Flag indicating whether this is a purchased server purchasedByPlayer = false; + // Variables that exist only on some types of servers can just be optional. + backdoorInstalled?: boolean; + constructor(params: IConstructorParams = { hostname: "", ip: createRandomIp() }) { this.ip = params.ip ? params.ip : createRandomIp(); diff --git a/src/Terminal/commands/connect.ts b/src/Terminal/commands/connect.ts index a5583010f..791d9a3aa 100644 --- a/src/Terminal/commands/connect.ts +++ b/src/Terminal/commands/connect.ts @@ -2,7 +2,6 @@ import { Terminal } from "../../Terminal"; import { BaseServer } from "../../Server/BaseServer"; import { getServerOnNetwork } from "../../Server/ServerHelpers"; import { GetServer } from "../../Server/AllServers"; -import { Server } from "../../Server/Server"; export function connect(args: (string | number | boolean)[], server: BaseServer): void { // 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); if (other !== null) { - if (other instanceof Server && other.backdoorInstalled) { + if (other.backdoorInstalled || other.purchasedByPlayer) { Terminal.connectToServer(hostname); return; }