aboutsummaryrefslogtreecommitdiff
path: root/src/app/launcher.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-06-01 19:24:26 +0200
committerGitHub <noreply@github.com>2022-06-01 19:24:26 +0200
commit461ad2c4183f47c089f307e21acc0c2316874243 (patch)
tree643c051bd2aa9ec5c71c1e25fc86065d9f76429d /src/app/launcher.js
parent1c06ab53f1cf2228e1034a66538f3a31a14e3743 (diff)
parent6794097cb275bed0f208614e15404a46d734ca4a (diff)
downloadViper-461ad2c4183f47c089f307e21acc0c2316874243.tar.gz
Viper-461ad2c4183f47c089f307e21acc0c2316874243.zip
Merge pull request #130 from 0neGal/server-status
feat: Master server status
Diffstat (limited to 'src/app/launcher.js')
-rw-r--r--src/app/launcher.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/app/launcher.js b/src/app/launcher.js
index e0b56db..fbeb703 100644
--- a/src/app/launcher.js
+++ b/src/app/launcher.js
@@ -1,5 +1,9 @@
const markdown = require("marked").parse;
+var servercount;
+var playercount;
+var masterserver;
+
// Changes the main page
// This is the tabs in the sidebar
function page(page) {
@@ -110,3 +114,46 @@ function showNsSection(section) {
break;
}
}
+
+async function loadServers() {
+ serverstatus.classList.add("checking");
+
+ try {
+ let servers = await (await fetch("https://northstar.tf/client/servers")).json();
+ masterserver = true;
+
+ playercount = 0;
+ servercount = servers.length;
+
+ for (let i = 0; i < servers.length; i++) {
+ playercount += servers[i].playerCount
+ }
+ }catch (err) {
+ playercount = 0;
+ servercount = 0;
+ masterserver = false;
+ }
+
+ serverstatus.classList.remove("checking");
+
+ if (servercount == 0 || ! servercount || ! playercount) {masterserver = false}
+
+ let playerstr = lang("gui.server.players");
+ if (playercount == 1) {
+ playerstr = lang("gui.server.player");
+ }
+
+ if (masterserver) {
+ serverstatus.classList.add("up");
+ serverstatus.innerHTML = `${servercount} ${lang("gui.server.servers")} - ${playercount} ${playerstr}`;
+ } else {
+ serverstatus.classList.add("down");
+ serverstatus.innerHTML = lang("gui.server.offline");
+
+ }
+}; loadServers()
+
+// Refreshes every 5 minutes
+setInterval(() => {
+ loadServers();
+}, 300000)