1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<title>StarKingdoms.TK</title>
<link rel="stylesheet" href="./static/index.css"/>
</head>
<body>
<h1>StarKingdoms</h1>
<fieldset class="joingamebox">
<legend>Join Game</legend>
<form action="/play.html" method="GET">
<label for="server">Choose server</label>
<select class="joingamecontent" name="server" id="server">
<!-- Dynamically filled by the JS later in this file -->
</select>
<br>
<label for="textures">Texture quality</label>
<select class="joingamecontent" name="textures" id="textures">
<option value="full">Full quality (May impact loading times)</option>
<option selected value="375">Medium quality (Recommended)</option>
<option value="125">Low quality</option>
</select>
<br>
<label for="username">Username</label>
<br>
<input class="m-5px" type="text" name="username" id="username" required />
<br>
<button class="m-5px w-full">Launch!</button>
</form>
</fieldset>
<script>
let servers = ["localhost:3000"];
function server_url_to_ping_url(server) { return "http://" + server + "/ping" }
function server_url_to_gateway_url(server) { return "ws://" + server + "/ws" }
function load_server(server) {
// ping the server to get server information
fetch(server_url_to_ping_url(server)).then(response => {
response.json().then(response => {
let elem = document.createElement("option");
elem.value = server_url_to_gateway_url(server);
elem.text = `${response.description} - ${response.version.name} - ${response.players} online`;
document.getElementById("server").appendChild(elem);
})
})
}
for (let i = 0; i < servers.length; i++) {
load_server(servers[i]);
}
</script>
</body>
</html>