aboutsummaryrefslogtreecommitdiff
path: root/webAO/master.ts
diff options
context:
space:
mode:
authorDavid Skoland <davidskoland@gmail.com>2023-11-20 00:27:12 +0100
committerDavid Skoland <davidskoland@gmail.com>2023-11-20 21:10:04 +0100
commit4035a59b4da2c6bd899f4e0bb91d4fbd5a94a7ac (patch)
tree3c5cdbe4ed897b9cad38fb8c726dbcb2c60e288f /webAO/master.ts
parent9215c454967540a714b71cfa31d4ad52ad62c5b8 (diff)
More protocol magic
Diffstat (limited to 'webAO/master.ts')
-rw-r--r--webAO/master.ts14
1 files changed, 13 insertions, 1 deletions
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}`;