add online user count + servertime
authorxangelo <git@xangelo.ca>
Wed, 25 May 2022 20:14:22 +0000 (16:14 -0400)
committerxangelo <git@xangelo.ca>
Wed, 25 May 2022 20:14:22 +0000 (16:14 -0400)
public/game.html
public/scifi.css
src/api.ts

index 39295a1a0d461c174184b7ef3b68e42624ad7884..2ac499877f5ec10e449b96f134d4e6313a0d6e9a 100644 (file)
             </div>
         </div>
     </div>
+    <div class="row">
+      <div id="stats" class="col text-right" hx-get="/server-stats" hx-trigger="load delay:1s, every 60s">
+      </div>
+    </div>
     <footer>
         A project by <a href="https://xangelo.ca">xangelo</a>
     </footer>
index 4dc0085d4cdd56aa6f0de71c2e1b05449db8dc8a..7fc5c335c86e5f5e8c7e593c55d8370df44fbdb0 100644 (file)
@@ -373,3 +373,7 @@ form > div {
 #chat-form button {
   max-width: 150px;
 }
+
+#stats {
+  margin-top: 1rem;
+}
index b086ff3534e1d36a77c4b3157ed30e11510c4ff6..0c37379dcb91d42cf8c0dbc1700cacfab07080dd 100644 (file)
@@ -373,6 +373,17 @@ server.post<{body: {message: string}}, void>('/chat', async req => {
   return;
 });
 
+server.get<void, string>('/server-stats', async req => {
+  const date = new Date();
+  return `
+  <div class="text-right">
+    <span class="success-text">${(await server.ws.allSockets()).size} Online</span><br>
+    <span>
+    Server Time: ${date.getHours()}:${date.getMinutes()}
+    </span>
+  </div>`;
+});
+
 server.ws.on('connection', async socket => {
   const auth = server.authFromUrl(socket.request.headers['referer']);
   const acct = await accountRepo.validate(auth.authInfo.accountId, auth.authInfo.token);