aboutsummaryrefslogtreecommitdiff
path: root/src/app/launcher.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-06-29 23:29:02 +0200
committerGitHub <noreply@github.com>2022-06-29 23:29:02 +0200
commitcbca61d836ee573a469f6339c22c2891cef9428c (patch)
tree6175a5f57a32a2f3bc90b4d4247444f3dd94ed5f /src/app/launcher.js
parent99209092b6ad1079202208833e542201f1197e2d (diff)
parent0c7f6f438ca530a192577907d3af9a7d95949ef3 (diff)
downloadViper-cbca61d836ee573a469f6339c22c2891cef9428c.tar.gz
Viper-cbca61d836ee573a469f6339c22c2891cef9428c.zip
Merge branch 'main' into add-badges
Diffstat (limited to 'src/app/launcher.js')
-rw-r--r--src/app/launcher.js56
1 files changed, 53 insertions, 3 deletions
diff --git a/src/app/launcher.js b/src/app/launcher.js
index 51d3a63..fbeb703 100644
--- a/src/app/launcher.js
+++ b/src/app/launcher.js
@@ -1,10 +1,14 @@
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) {
- let pages = document.querySelectorAll(".mainContainer .contentContainer")
- let btns = document.querySelectorAll(".gamesContainer button")
+ let btns = document.querySelectorAll(".gamesContainer button");
+ let pages = document.querySelectorAll(".mainContainer .contentContainer");
for (let i = 0; i < pages.length; i++) {
pages[i].classList.add("hidden");
@@ -82,7 +86,10 @@ function showVpSection(section) {
}
function showNsSection(section) {
- if (!["main", "release", "mods"].includes(section)) throw new Error("unknown ns section");
+ if (!["main", "release", "mods"].includes(section)) {
+ throw new Error("unknown ns section");
+ }
+
nsMainBtn.removeAttribute("active");
nsModsBtn.removeAttribute("active");
nsReleaseBtn.removeAttribute("active");
@@ -107,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)