From b8f748598f76cb5ebf9cb1b5ef3a455046c920ca Mon Sep 17 00:00:00 2001 From: David Skoland Date: Sat, 18 Nov 2023 20:00:11 +0100 Subject: Change client to use connection string --- webAO/client.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 3170ec8..3190bab 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -17,7 +17,7 @@ import { loadResources } from './client/loadResources' import { AO_HOST } from './client/aoHost' import { fetchBackgroundList, fetchEvidenceList, fetchCharacterList } from './client/fetchLists' -const { ip: serverIP, mode, theme, serverName } = queryParser(); +const { connect, mode, theme, serverName } = queryParser(); document.title = serverName; @@ -70,12 +70,12 @@ fpPromise .then((result) => { hdid = result.visitorId; - if (!serverIP) { - alert("No server IP specified!"); + if (!connect) { + alert("No connection string specified!"); return; } - client = new Client(serverIP); + client = new Client(connect); client.connect() isLowMemory(); loadResources(); @@ -117,7 +117,7 @@ class Client extends EventEmitter { connect: () => void; loadResources: () => void isLowMemory: () => void - constructor(address: string) { + constructor(connectionString: string) { super(); this.connect = () => { @@ -126,7 +126,7 @@ class Client extends EventEmitter { this.on("message", this.onMessage.bind(this)); this.on("error", this.onError.bind(this)); if (mode !== "replay") { - this.serv = new WebSocket(`ws://${address}`); + this.serv = new WebSocket(connectionString); // Assign the websocket events this.serv.addEventListener("open", this.emit.bind(this, "open")); this.serv.addEventListener("close", this.emit.bind(this, "close")); -- cgit From 576d1d2e6b593a89ab5339b94e57ab1b1044db28 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Sat, 18 Nov 2023 20:05:27 +0100 Subject: somewhat backward compatible --- webAO/client.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 3190bab..820b7f2 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -17,7 +17,7 @@ import { loadResources } from './client/loadResources' import { AO_HOST } from './client/aoHost' import { fetchBackgroundList, fetchEvidenceList, fetchCharacterList } from './client/fetchLists' -const { connect, mode, theme, serverName } = queryParser(); +const { ip: serverIP, connect, mode, theme, serverName } = queryParser(); document.title = serverName; @@ -70,12 +70,20 @@ fpPromise .then((result) => { hdid = result.visitorId; - if (!connect) { - alert("No connection string specified!"); - return; + let connectionString = connect; + + if (!connectionString) { + if (serverIP) { + // if connectionString is not set, try IP + // and just guess ws, though it could be wss + connectionString = `ws://${serverIP}`; + } else { + alert("No connection string specified!"); + return; + } } - client = new Client(connect); + client = new Client(connectionString); client.connect() isLowMemory(); loadResources(); -- cgit From f848f34b9979740e85b9648eb42ecafd20dd3926 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Wed, 22 Nov 2023 18:48:59 +0100 Subject: Add clause for checking ws in https --- webAO/client.ts | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'webAO/client.ts') diff --git a/webAO/client.ts b/webAO/client.ts index 820b7f2..c49a104 100644 --- a/webAO/client.ts +++ b/webAO/client.ts @@ -83,6 +83,13 @@ fpPromise } } + if (window.location.protocol === "https:" && connectionString.startsWith("ws://")) { + // If protocol is https: and connectionString is ws:// + // We have a problem, since it's impossible to connect to ws:// from https:// + // Connection will fail, but at least warn the user + alert('Attempted to connect using insecure websockets on https page. Please try removing s from https:// in the URL bar.') + } + client = new Client(connectionString); client.connect() isLowMemory(); -- cgit