From eae8a41221a35bb435095f9c4d7419dddb87eee0 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Sat, 18 Nov 2023 19:58:15 +0100 Subject: Change ip to connect and include protocol --- webAO/master.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index 336fc5f..a09d111 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -215,26 +215,29 @@ function processServerlist(serverlist: AOServer[]) { for (let i = 0; i < serverlist.length - 1; i++) { const server = serverlist[i]; let port = 0; + let protocol = ''; if (server.ws_port) { port = server.ws_port; + protocol = 'ws'; } if (server.wss_port) { port = server.wss_port; + protocol = 'wss'; } - if (port === 0) { + if (port === 0 || protocol === '') { continue; } - const ipport = `${server.ip}:${port}`; + const connect = `${protocol}://${server.ip}:${port}`; const serverName = server.name; server.online = 'Offline'; servers.push(server); document.getElementById('masterlist').innerHTML += `
  • ${safeTags(server.name)} (${server.players})

    ` - + `Watch` - + `Join
  • `; + + `Watch` + + `Join`; } } -- cgit From a98967301e83e3301e5fd04b6c31ff76da2e96b4 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Sat, 18 Nov 2023 21:14:02 +0100 Subject: Use current host in https redirect instead of hardcoding --- webAO/master.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index a09d111..4c2175c 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -25,6 +25,7 @@ const clientVersion = process.env.npm_package_version; // const MASTERSERVER_IP = 'master.aceattorneyonline.com:27014'; const serverlist_domain = 'servers.aceattorneyonline.com'; const protocol = window.location.protocol; +const host = window.location.host; const serverlist_cache_key = 'masterlist'; @@ -77,7 +78,7 @@ fpPromise export function check_https() { if (protocol === 'https:') { document.getElementById('https_error').style.display = ''; - setTimeout(() => window.location.replace("http://web.aceattorneyonline.com/"), 5000); + setTimeout(() => window.location.replace(`http://${host}/`), 5000); } } @@ -210,7 +211,6 @@ function getCachedServerlist(): AOServer[] { } function processServerlist(serverlist: AOServer[]) { - const host = window.location.host; const clientURL: string = `${protocol}//${host}/client.html`; for (let i = 0; i < serverlist.length - 1; i++) { const server = serverlist[i]; -- cgit From a4a2c61a828aa60c0d1a47269f5b3cafe4a0cfff Mon Sep 17 00:00:00 2001 From: David Skoland Date: Sun, 19 Nov 2023 23:01:14 +0100 Subject: Yeet check_https --- webAO/master.ts | 9 --------- 1 file changed, 9 deletions(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index 4c2175c..d7f0e21 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -59,8 +59,6 @@ fpPromise .then(async (result) => { hdid = result.visitorId; - check_https(); - getServerlist().then((serverlist) => { processServerlist(serverlist); }); @@ -75,13 +73,6 @@ fpPromise setTimeout(() => checkOnline(-1, '127.0.0.1:50001'), 0); }); -export function check_https() { - if (protocol === 'https:') { - document.getElementById('https_error').style.display = ''; - setTimeout(() => window.location.replace(`http://${host}/`), 5000); - } -} - export function setServ(ID: number) { selectedServer = ID; -- cgit From ca00f00f8414304ac11e08c30c79b5059ae3c0bb Mon Sep 17 00:00:00 2001 From: David Skoland Date: Sun, 19 Nov 2023 23:02:36 +0100 Subject: Do not connect to server on mouseover --- webAO/master.ts | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index d7f0e21..61691df 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -2,12 +2,6 @@ import FingerprintJS from '@fingerprintjs/fingerprintjs'; import { safeTags } from './encoding'; -declare global { - interface Window { - setServ: (ID: number) => void; - } -} - interface AOServer { name: string, description: string, @@ -73,15 +67,6 @@ fpPromise setTimeout(() => checkOnline(-1, '127.0.0.1:50001'), 0); }); -export function setServ(ID: number) { - selectedServer = ID; - - if (document.getElementById(`server${ID}`).className === '') { checkOnline(ID, `${servers[ID].ip}:${servers[ID].ws_port}`); } - - document.getElementById('serverdescription_content').innerHTML = `${servers[ID].online}
    ${safeTags(servers[ID].description)}`; -} -window.setServ = setServ; - function checkOnline(serverID: number, coIP: string) { let serverConnection: WebSocket; if (serverID !== -2) { @@ -226,7 +211,7 @@ function processServerlist(serverlist: AOServer[]) { servers.push(server); document.getElementById('masterlist').innerHTML - += `
  • ${safeTags(server.name)} (${server.players})

    ` + += `
  • ${safeTags(server.name)} (${server.players})

    ` + `Watch` + `Join
  • `; } -- cgit From f837eb7df37f5770e3f481782105911b02b32e27 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Sun, 19 Nov 2023 23:08:50 +0100 Subject: Remove everything related to server connections --- webAO/master.ts | 81 +++++++-------------------------------------------------- 1 file changed, 9 insertions(+), 72 deletions(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index 61691df..c5f57c0 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -1,5 +1,3 @@ -import FingerprintJS from '@fingerprintjs/fingerprintjs'; - import { safeTags } from './encoding'; interface AOServer { @@ -23,10 +21,6 @@ const host = window.location.host; const serverlist_cache_key = 'masterlist'; -let hdid: string; - -let selectedServer: number = -1; - const servers: AOServer[] = []; servers[-2] = { name: 'Singleplayer', @@ -47,78 +41,21 @@ servers[-1] = { players: 0, }; -const fpPromise = FingerprintJS.load(); -fpPromise - .then((fp) => fp.get()) - .then(async (result) => { - hdid = result.visitorId; - - getServerlist().then((serverlist) => { - processServerlist(serverlist); - }); - - processClientVersion(clientVersion); - getMasterVersion().then((masterVersion) => { - processMasterVersion(masterVersion); - }); - - // i don't need the ms to play alone - setTimeout(() => checkOnline(-1, '127.0.0.1:50001'), 0); +function main() { + getServerlist().then((serverlist) => { + processServerlist(serverlist); }); -function checkOnline(serverID: number, coIP: string) { - let serverConnection: WebSocket; - if (serverID !== -2) { - try { - serverConnection = new WebSocket(`ws://${coIP}`); - } catch (SecurityError) { - document.getElementById(`server${serverID}`).className = 'unavailable'; - return; - } - } + processClientVersion(clientVersion); - // define what the callbacks do - function onCOOpen() { - document.getElementById(`server${serverID}`).className = 'available'; - serverConnection.send(`HI#${hdid}#%`); - serverConnection.send('ID#webAO#webAO#%'); - } - - function onCOMessage(e: MessageEvent) { - const comsg = e.data; - const coheader = comsg.split('#', 2)[0]; - const coarguments = comsg.split('#').slice(1); - if (coheader === 'PN') { - servers[serverID].online = `Online: ${Number(coarguments[0])}/${Number(coarguments[1])}`; - serverConnection.close(); - return; - } if (coheader === 'BD') { - servers[serverID].online = 'Banned'; - servers[serverID].description = coarguments[0]; - serverConnection.close(); - return; - } - if (serverID === selectedServer) { - document.getElementById('serverdescription_content').innerHTML = `${servers[serverID].online}
    ${safeTags(servers[serverID].description)}`; - } - } - - // assign the callbacks - serverConnection.onopen = function () { - onCOOpen(); - }; + getMasterVersion().then((masterVersion) => { + processMasterVersion(masterVersion); + }); +} - serverConnection.onmessage = function (evt: MessageEvent) { - onCOMessage(evt); - }; +main(); - serverConnection.onerror = function (_evt: Event) { - document.getElementById(`server${serverID}`).className = 'unavailable'; - console.error(`Error connecting to ${coIP}`); - console.error(_evt); - }; -} // Fetches the serverlist from the masterserver // Returns a properly typed list of servers -- cgit From df67ca5b2cded28a933aa43de2b1366c98562d55 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Sun, 19 Nov 2023 23:19:25 +0100 Subject: Add setServ back also known as "whoops, we actually needed that code" This changes "Online" to "Players", and will only show the playercount reported by masterserver. It's a bit disingenuous to show "Online" if we can't confirm that we can actually connect to it. --- webAO/master.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index c5f57c0..c3893c0 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -1,5 +1,11 @@ import { safeTags } from './encoding'; +declare global { + interface Window { + setServ: (ID: number) => void; + } +} + interface AOServer { name: string, description: string, @@ -56,6 +62,15 @@ function main() { main(); +export function setServ(ID: number) { + console.log(`Setting server to ${ID}`); + const server = servers[ID]; + const onlineStr = server.online; + const serverDesc = safeTags(server.description); + document.getElementById('serverdescription_content').innerHTML = `${onlineStr}
    ${serverDesc})`; +} +window.setServ = setServ; + // Fetches the serverlist from the masterserver // Returns a properly typed list of servers @@ -144,11 +159,11 @@ function processServerlist(serverlist: AOServer[]) { const connect = `${protocol}://${server.ip}:${port}`; const serverName = server.name; - server.online = 'Offline'; + server.online = `Players: ${server.players}`; servers.push(server); document.getElementById('masterlist').innerHTML - += `
  • ${safeTags(server.name)} (${server.players})

    ` + += `
  • ${safeTags(server.name)} (${server.players})

    ` + `Watch` + `Join
  • `; } -- cgit From 4377952b7bb867f99bd316859f1484213d5b7b5d Mon Sep 17 00:00:00 2001 From: David Skoland Date: Sun, 19 Nov 2023 23:22:43 +0100 Subject: Remove wayward ) --- webAO/master.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index c3893c0..e07af61 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -67,7 +67,7 @@ export function setServ(ID: number) { const server = servers[ID]; const onlineStr = server.online; const serverDesc = safeTags(server.description); - document.getElementById('serverdescription_content').innerHTML = `${onlineStr}
    ${serverDesc})`; + document.getElementById('serverdescription_content').innerHTML = `${onlineStr}
    ${serverDesc}`; } window.setServ = setServ; -- cgit From ced12928a8ed0cd45bf3f381338fbbbe788f285e Mon Sep 17 00:00:00 2001 From: David Skoland Date: Sun, 19 Nov 2023 23:26:13 +0100 Subject: Make Join button open in new tab --- webAO/master.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index e07af61..51a1f4a 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -164,8 +164,8 @@ function processServerlist(serverlist: AOServer[]) { document.getElementById('masterlist').innerHTML += `
  • ${safeTags(server.name)} (${server.players})

    ` - + `Watch` - + `Join
  • `; + + `Watch` + + `Join`; } } -- cgit From 9589b233b2ff8e9064350e73e28bdc633f0d2a9f Mon Sep 17 00:00:00 2001 From: David Skoland Date: Sun, 19 Nov 2023 23:56:09 +0100 Subject: Remove debug statement --- webAO/master.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index 51a1f4a..b101d3d 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -63,7 +63,6 @@ function main() { main(); export function setServ(ID: number) { - console.log(`Setting server to ${ID}`); const server = servers[ID]; const onlineStr = server.online; const serverDesc = safeTags(server.description); -- cgit From 45dd60334185f97a0798c8ba7adad98261309878 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Sun, 19 Nov 2023 23:59:45 +0100 Subject: Nice off-by-one error bro --- webAO/master.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index b101d3d..dc169e4 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -139,7 +139,7 @@ function getCachedServerlist(): AOServer[] { function processServerlist(serverlist: AOServer[]) { const clientURL: string = `${protocol}//${host}/client.html`; - for (let i = 0; i < serverlist.length - 1; i++) { + for (let i = 0; i < serverlist.length; i++) { const server = serverlist[i]; let port = 0; let protocol = ''; -- cgit From e1620384089976954d80161e1a91b17b1ac75d95 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Mon, 20 Nov 2023 00:00:21 +0100 Subject: Warning about no ws port --- webAO/master.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index dc169e4..000f816 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -153,6 +153,7 @@ function processServerlist(serverlist: AOServer[]) { protocol = 'wss'; } if (port === 0 || protocol === '') { + console.warn(`Server ${server.name} has no websocket port, skipping`) continue; } -- cgit From dc54ca89f2639123a8e66ab38c6b8aeabeaf45c3 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Mon, 20 Nov 2023 00:06:17 +0100 Subject: Need to adjust http/s as well --- webAO/master.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index 000f816..f12674f 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -138,26 +138,29 @@ function getCachedServerlist(): AOServer[] { } function processServerlist(serverlist: AOServer[]) { - const clientURL: string = `${protocol}//${host}/client.html`; for (let i = 0; i < serverlist.length; i++) { const server = serverlist[i]; let port = 0; - let protocol = ''; + let ws_protocol = ''; + let http_protocol = ''; if (server.ws_port) { port = server.ws_port; - protocol = 'ws'; + ws_protocol = 'ws'; + http_protocol = 'http'; } if (server.wss_port) { port = server.wss_port; - protocol = 'wss'; + ws_protocol = 'wss'; + http_protocol = 'https'; } if (port === 0 || protocol === '') { console.warn(`Server ${server.name} has no websocket port, skipping`) continue; } - const connect = `${protocol}://${server.ip}:${port}`; + const clientURL: string = `${http_protocol}//${host}/client.html`; + const connect = `${ws_protocol}://${server.ip}:${port}`; const serverName = server.name; server.online = `Players: ${server.players}`; servers.push(server); -- cgit From 9215c454967540a714b71cfa31d4ad52ad62c5b8 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Mon, 20 Nov 2023 00:07:28 +0100 Subject: Missing colon --- webAO/master.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index f12674f..17e5f54 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -159,7 +159,7 @@ function processServerlist(serverlist: AOServer[]) { continue; } - const clientURL: string = `${http_protocol}//${host}/client.html`; + const clientURL: string = `${http_protocol}://${host}/client.html`; const connect = `${ws_protocol}://${server.ip}:${port}`; const serverName = server.name; server.online = `Players: ${server.players}`; -- cgit 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 From 4664501188f0f4cace7772c0c1b96d0387df7442 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Mon, 20 Nov 2023 00:32:44 +0100 Subject: Fix domain tricks for localhost --- webAO/master.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index bfd5d34..41a1688 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -143,29 +143,34 @@ function processServerlist(serverlist: AOServer[]) { let port = 0; let ws_protocol = ''; let http_protocol = ''; - let domain = ''; + let client_subdomain = ''; if (server.ws_port) { port = server.ws_port; ws_protocol = 'ws'; http_protocol = 'http'; - domain = 'insecure'; + client_subdomain = 'insecure'; } if (server.wss_port) { port = server.wss_port; ws_protocol = 'wss'; http_protocol = 'https'; - domain = 'web'; + client_subdomain = 'web'; } + if (port === 0 || protocol === '') { console.warn(`Server ${server.name} has no websocket port, skipping`) continue; } + let hostname = window.location.hostname; // 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 there is only one element, it's typically localhost or something, so don't replace it + if (domainElements.length >= 2) { + domainElements[0] = client_subdomain; + hostname = domainElements.join('.'); + } if (window.location.port) { hostname += `:${window.location.port}`; -- cgit From 10d553972ac84f3b96455b351e4e9f8cc0a1fccd Mon Sep 17 00:00:00 2001 From: David Skoland Date: Mon, 20 Nov 2023 00:52:30 +0100 Subject: host isn't used --- webAO/master.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index 41a1688..68a0b3e 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -23,7 +23,6 @@ const clientVersion = process.env.npm_package_version; // const MASTERSERVER_IP = 'master.aceattorneyonline.com:27014'; const serverlist_domain = 'servers.aceattorneyonline.com'; const protocol = window.location.protocol; -const host = window.location.host; const serverlist_cache_key = 'masterlist'; -- cgit From 1e56d094361f7fd4a0ad3ae0a3147120158ea6ba Mon Sep 17 00:00:00 2001 From: David Skoland Date: Mon, 20 Nov 2023 20:40:40 +0100 Subject: Remove subdomain terribleness and split clientURL into a function --- webAO/master.ts | 60 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 24 deletions(-) (limited to 'webAO/master.ts') diff --git a/webAO/master.ts b/webAO/master.ts index 68a0b3e..295d326 100644 --- a/webAO/master.ts +++ b/webAO/master.ts @@ -136,55 +136,67 @@ function getCachedServerlist(): AOServer[] { return JSON.parse(cached) as AOServer[]; } +// Constructs the client URL robustly, independent of domain and path +function constructClientURL(protocol: string): string { + const clientURL = new URL(window.location.href); + + // Use the given protocol + clientURL.protocol = protocol; + + // Remove the last part of the pathname (e.g., "index.html") + const pathname = clientURL.pathname; + const parts = pathname.split('/'); + parts.pop(); + + // Reconstruct the pathname + clientURL.pathname = parts.join('/'); + + // If clientURL.pathname does not end with a slash, add one + if (clientURL.pathname[clientURL.pathname.length - 1] !== '/') { + clientURL.pathname += '/' + } + + clientURL.pathname += "client.html"; + + return clientURL.href; +} + function processServerlist(serverlist: AOServer[]) { for (let i = 0; i < serverlist.length; i++) { const server = serverlist[i]; - let port = 0; + let ws_port = 0; let ws_protocol = ''; let http_protocol = ''; - let client_subdomain = ''; if (server.ws_port) { - port = server.ws_port; + ws_port = server.ws_port; ws_protocol = 'ws'; http_protocol = 'http'; - client_subdomain = 'insecure'; } if (server.wss_port) { - port = server.wss_port; + ws_port = server.wss_port; ws_protocol = 'wss'; http_protocol = 'https'; - client_subdomain = 'web'; } - if (port === 0 || protocol === '') { + if (ws_port === 0 || ws_protocol === '' || http_protocol === '') { console.warn(`Server ${server.name} has no websocket port, skipping`) continue; } - let hostname = window.location.hostname; - // Replace the first element of the domain with the correct subdomain - const domainElements = window.location.hostname.split('.'); - // If there is only one element, it's typically localhost or something, so don't replace it - if (domainElements.length >= 2) { - domainElements[0] = client_subdomain; - 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 clientURL = constructClientURL(http_protocol); + const connect = `${ws_protocol}://${server.ip}:${ws_port}`; const serverName = server.name; + const fullClientWatchURL = `${clientURL}?mode=watch&connect=${connect}&serverName=${serverName}`; + const fullClientJoinURL = `${clientURL}?mode=join&connect=${connect}&serverName=${serverName}`; + server.online = `Players: ${server.players}`; servers.push(server); document.getElementById('masterlist').innerHTML += `
  • ${safeTags(server.name)} (${server.players})

    ` - + `Watch` - + `Join
  • `; + + `Watch` + + `Join`; } } -- cgit