aboutsummaryrefslogtreecommitdiff
path: root/webAO
diff options
context:
space:
mode:
authorstonedDiscord <Tukz@gmx.de>2025-01-30 10:50:43 +0000
committerstonedDiscord <Tukz@gmx.de>2025-01-30 10:50:43 +0000
commit9be77db6e8def89cf26c5be4db22731b6d3a69f2 (patch)
treeb50dbfef2ad0429065910d34f4734e7aab185055 /webAO
parenta3a8e7d2e35d3606d979fea3b6d2c489feac4049 (diff)
change serverlist to use detail tag
prep for onhover description
Diffstat (limited to 'webAO')
-rw-r--r--webAO/master.ts99
-rw-r--r--webAO/styles/master.css8
2 files changed, 45 insertions, 62 deletions
diff --git a/webAO/master.ts b/webAO/master.ts
index 87c7525..fbddaa3 100644
--- a/webAO/master.ts
+++ b/webAO/master.ts
@@ -1,11 +1,5 @@
import { safeTags } from "./encoding";
-declare global {
- interface Window {
- setServ: (ID: number) => void;
- }
-}
-
interface AOServer {
name: string;
description: string;
@@ -27,22 +21,13 @@ const protocol = window.location.protocol;
const serverlist_cache_key = "masterlist";
const servers: AOServer[] = [];
-servers[-2] = {
- name: "Singleplayer",
- description: "Build cases, try out new things",
- ip: "127.0.0.1",
- players: 0,
- online: "Singleplayer",
- port: 50001,
-} as AOServer;
-
servers[-1] = {
name: "Localhost",
description: "This is your computer on port 50001",
ip: "127.0.0.1",
players: 0,
online: "Localhost",
- port: 50001,
+ ws_port: 50001,
} as AOServer;
function main() {
@@ -50,6 +35,8 @@ function main() {
processServerlist(serverlist);
});
+ addServer(servers[-1]);
+
processClientVersion(clientVersion);
getMasterVersion().then((masterVersion) => {
@@ -59,17 +46,6 @@ function main() {
main();
-export function setServ(ID: number) {
- const server = servers[ID];
- const onlineStr = server.online;
- document.getElementById("serverdescription_content").innerHTML =
- `<b>${onlineStr}</b><br>`;
- document
- .getElementById("serverdescription_content")
- .appendChild(document.createTextNode(server.description));
-}
-window.setServ = setServ;
-
// Fetches the serverlist from the masterserver
// Returns a properly typed list of servers
async function getServerlist(): Promise<AOServer[]> {
@@ -164,41 +140,48 @@ function constructClientURL(protocol: string): string {
return clientURL.href;
}
-function processServerlist(serverlist: AOServer[]) {
- for (let i = 0; i < serverlist.length; i++) {
- const server = serverlist[i];
- let ws_port = 0;
- let ws_protocol = "";
- let http_protocol = "";
-
- if (server.ws_port) {
- ws_port = server.ws_port;
- ws_protocol = "ws";
- http_protocol = "http";
- }
- if (server.wss_port && !window.navigator.userAgent.includes("Nintendo")) {
- ws_port = server.wss_port;
- ws_protocol = "wss";
- http_protocol = "https";
- }
+function addServer(server: AOServer) {
+ let ws_port = 0;
+ let ws_protocol = "";
+ let http_protocol = "";
- if (ws_port === 0 || ws_protocol === "" || http_protocol === "") {
- console.warn(`Server ${server.name} has no websocket port, skipping`);
- continue;
- }
+ if (server.ws_port) {
+ ws_port = server.ws_port;
+ ws_protocol = "ws";
+ http_protocol = "http";
+ }
+ if (server.wss_port && !window.navigator.userAgent.includes("Nintendo")) {
+ ws_port = server.wss_port;
+ ws_protocol = "wss";
+ http_protocol = "https";
+ }
+
+ if (ws_port === 0 || ws_protocol === "" || http_protocol === "") {
+ console.warn(`Server ${server.name} has no websocket port, skipping`);
+ return;
+ }
+
+ 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}`;
+
+ servers.push(server);
- 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}`;
+ document.getElementById("masterlist").innerHTML +=
+ `<details name="servers">` +
+ `<summary><p>${safeTags(server.name)} (${server.players})</p>` +
+ `<a class="button" href="${fullClientJoinURL}" target="_blank">Join</a>` +
+ `<a class="button" href="${fullClientWatchURL}" target="_blank">Watch</a></summary>` +
+ `<p>${safeTags(server.description)}</p>` +
+ `</details>`
- servers.push(server);
+}
- document.getElementById("masterlist").innerHTML +=
- `<li id="server${i}" onmouseover="setServ(${i})"><p>${safeTags(server.name)} (${server.players})</p>` +
- `<a class="button" href="${fullClientWatchURL}" target="_blank">Watch</a>` +
- `<a class="button" href="${fullClientJoinURL}" target="_blank">Join</a></li>`;
+function processServerlist(serverlist: AOServer[]) {
+ for (let i = 0; i < serverlist.length; i++) {
+ addServer(serverlist[i]);
}
}
diff --git a/webAO/styles/master.css b/webAO/styles/master.css
index 3f73294..a893f6e 100644
--- a/webAO/styles/master.css
+++ b/webAO/styles/master.css
@@ -92,7 +92,7 @@
margin: auto;
}
-.serverlist li {
+.serverlist details {
position: relative;
right: 0;
background-color: #fff;
@@ -110,16 +110,16 @@
cursor: default;
}
-.serverlist li:hover {
+.serverlist details:hover {
background-color: #ffff6b;
border-color: #efad21;
}
-.serverlist li p {
+.serverlist details p {
display: inline-block !important;
}
-.serverlist li a {
+.serverlist details a {
float: right;
}