aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/app/css/launcher.css29
-rw-r--r--src/app/index.html3
-rw-r--r--src/app/launcher.js47
-rw-r--r--src/lang/en.json5
-rw-r--r--src/lang/es.json5
-rw-r--r--src/lang/fr.json5
6 files changed, 93 insertions, 1 deletions
diff --git a/src/app/css/launcher.css b/src/app/css/launcher.css
index 03812c6..ce54ddf 100644
--- a/src/app/css/launcher.css
+++ b/src/app/css/launcher.css
@@ -297,3 +297,32 @@ code {
margin-top: calc(var(--spacing) / 2);
margin-bottom: calc(var(--spacing) / 2);
}
+
+#serverstatus {
+ --spacing: calc(var(--padding) / 5);
+
+ transition-duration: 0.2s;
+ transition-timing-function: ease-in-out;
+ transition-property: background, opacity;
+
+ opacity: 0.0;
+ display: block;
+ margin: 0 auto;
+ font-weight: 700;
+ width: fit-content;
+ color: transparent;
+ border-radius: 50px;
+ flex-basis: max-content;
+ background: transparent;
+ margin-top: calc(var(--spacing) * 2);
+ padding: var(--spacing) calc(var(--spacing) * 3);
+}
+
+#serverstatus.up,
+#serverstatus.down {
+ color: white;
+ opacity: 1.0;
+}
+
+#serverstatus.up {background: rgb(var(--blue));}
+#serverstatus.down {background: rgb(var(--red));}
diff --git a/src/app/index.html b/src/app/index.html
index f67a7a8..2305e4c 100644
--- a/src/app/index.html
+++ b/src/app/index.html
@@ -197,6 +197,7 @@
<div class="inline">
<div id="nsversion"></div>
<a id="update" href="#" onclick="update()">(%%gui.update.check%%)</a>
+ <div id="serverstatus" class="checking"></div>
</div>
</div>
</div>
@@ -240,4 +241,4 @@
<script src="settings.js"></script>
<script src="launcher.js"></script>
</body>
-</html>
+<
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)
diff --git a/src/lang/en.json b/src/lang/en.json
index 2c068ac..34c4619 100644
--- a/src/lang/en.json
+++ b/src/lang/en.json
@@ -113,6 +113,11 @@
"gui.nsupdate.gaming.title": "Northstar update available!",
"gui.nsupdate.gaming.body": "An update for Northstar is available.\nYou can force its installation after closing the game.",
+ "gui.server.player": "player",
+ "gui.server.players": "players",
+ "gui.server.servers": "servers",
+ "gui.server.offline": "Masterserver is Offline",
+
"gui.launch": "Launch",
"gui.launchvanilla": "Vanilla",
"gui.launchnorthstar": "Northstar",
diff --git a/src/lang/es.json b/src/lang/es.json
index 8128440..4efa765 100644
--- a/src/lang/es.json
+++ b/src/lang/es.json
@@ -130,6 +130,11 @@
"gui.toast.desc.malformed": "tiene una estructura de carpetas incorrecta, si usted es el desarrollador, debe corregir esto.",
"gui.toast.desc.failed": "Se produjo un error desconocido al intentar instalar la modificación. Esto puede ser culpa del autor de la modificación, y también puede ser culpa de Viper.",
+ "gui.server.player": "jugador",
+ "gui.server.players": "jugadores",
+ "gui.server.servers": "servidores",
+ "gui.server.offline": "El servidor Master está desconectado",
+
"viper.menu.main": "Viper",
"viper.menu.release": "Notas de la versión",
"viper.menu.info": "Extras",
diff --git a/src/lang/fr.json b/src/lang/fr.json
index 1f37948..3fba39f 100644
--- a/src/lang/fr.json
+++ b/src/lang/fr.json
@@ -113,6 +113,11 @@
"gui.nsupdate.gaming.title": "Mise à jour Northstar disponible !",
"gui.nsupdate.gaming.body": "Une mise à jour pour Northstar est disponible.\nVous pourrez l'installer après avoir fermé le jeu.",
+ "gui.server.player": "joueur",
+ "gui.server.players": "joueurs",
+ "gui.server.servers": "serveurs",
+ "gui.server.offline": "Le serveur maître est hors-ligne",
+
"gui.launch": "Jouer",
"gui.launchvanilla": "Vanilla",
"gui.launchnorthstar": "Northstar",