From 4035a59b4da2c6bd899f4e0bb91d4fbd5a94a7ac Mon Sep 17 00:00:00 2001 From: David Skoland Date: Mon, 20 Nov 2023 00:27:12 +0100 Subject: More protocol magic --- webAO/master.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index 17e5f54..bfd5d34 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -143,23 +143,35 @@ function processServerlist(serverlist: AOServer[]) { let port = 0; let ws_protocol = ''; let http_protocol = ''; + let domain = ''; if (server.ws_port) { port = server.ws_port; ws_protocol = 'ws'; http_protocol = 'http'; + domain = 'insecure'; } if (server.wss_port) { port = server.wss_port; ws_protocol = 'wss'; http_protocol = 'https'; + domain = 'web'; } if (port === 0 || protocol === '') { console.warn(`Server ${server.name} has no websocket port, skipping`) continue; } - const clientURL: string = `${http_protocol}://${host}/client.html`; + // Replace the first element of the domain with the correct subdomain + const domainElements = window.location.hostname.split('.'); + domainElements[0] = domain; + let hostname = domainElements.join('.'); + + if (window.location.port) { + hostname += `:${window.location.port}`; + } + + const clientURL: string = `${http_protocol}://${hostname}/client.html`; const connect = `${ws_protocol}://${server.ip}:${port}`; const serverName = server.name; server.online = `Players: ${server.players}`; -- cgit