diff options
Diffstat (limited to 'webAO/master.js')
| -rw-r--r-- | webAO/master.js | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/webAO/master.js b/webAO/master.js index 3c2c01b..608cc29 100644 --- a/webAO/master.js +++ b/webAO/master.js @@ -25,7 +25,7 @@ masterserver.onopen = (evt) => onOpen(evt); masterserver.onmessage = (evt) => onMessage(evt); const server_description = []; -server_description[99] = "This is your computer on port 27016"; +server_description[-1] = "This is your computer on port 50001"; const online_counter = []; export function setServ(ID) { @@ -50,7 +50,7 @@ function onOpen(_e) { masterserver.send("VC#%"); } -function checkOnline(serverID, coIP) { +async function checkOnline(serverID, coIP) { function onCOOpen(_e) { document.getElementById(`server${serverID}`).className = "available"; oserv.send(`HI#${hdid}#%`); @@ -72,6 +72,10 @@ function checkOnline(serverID, coIP) { } } + function onCOError(_e) { + console.warn(serverID + " threw an error."); + } + var oserv = new WebSocket("ws://" + coIP); oserv.onopen = function (evt) { @@ -82,6 +86,10 @@ function checkOnline(serverID, coIP) { onCOMessage(evt); }; + oserv.onerror = function(evt) { + onCOError(evt) + }; + } function onMessage(e) { @@ -91,7 +99,7 @@ function onMessage(e) { if (header === "ALL") { const servers = msg.split("#").slice(1); - for (let i = 0; i < servers.length; i++) { + for (let i = 0; i < servers.length-1; i++) { const serverEntry = servers[i]; const args = serverEntry.split("&"); const asset = args[4] ? `&asset=${args[4]}` : ""; @@ -101,8 +109,9 @@ function onMessage(e) { + `<a class="button" href="client.html?mode=watch&ip=${args[2]}:${args[3]}${asset}">Watch</a>` + `<a class="button" href="client.html?mode=join&ip=${args[2]}:${args[3]}${asset}">Join</a></li>`; server_description[i] = args[1]; - setTimeout(checkOnline(i, args[2] + ":" + args[3]), 100); + checkOnline(i, `${args[2]}:${args[3]}`); } + checkOnline(-1, "127.0.0.1:50001"); } else if (header === "SN") { const args = msg.split("#"); @@ -113,7 +122,7 @@ function onMessage(e) { + `<a class="button" href="client.html?mode=join&ip=${args[2]}:${args[4]}">Join</a></li>`; server_description[i] = args[6]; masterserver.send("SR#" + i + "#%"); - setTimeout(checkOnline(i, args[2] + ":" + args[4]), i*1000); + checkOnline(i, `${args[2]}:${args[3]}`); } else if (header === "servercheok") { const args = msg.split("#").slice(1); |
