From f9c0f142474cf5afdeca58285c9a4ea11ca2817d Mon Sep 17 00:00:00 2001 From: cialloo Date: Sun, 5 Oct 2025 09:12:00 +0800 Subject: [PATCH] Add server statistics display in App component with online count and active players --- src/App.tsx | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 2ac8252..5a0cc44 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,6 +2,7 @@ import { useTranslation } from 'react-i18next' import { Link } from 'react-router-dom' import Layout from './components/Layout' import { useStats } from './contexts/StatsContext' +import { useServers } from './contexts/ServerContext' import './App.css' // Loading Skeleton Component @@ -37,6 +38,21 @@ const LoadingSkeleton = ({ width = '60px', height = '40px', className = '' }: { function App() { const { t } = useTranslation() const { stats, recentChats, topPlayers, loading } = useStats() + const { servers } = useServers() + + // Calculate server statistics + const onlineServers = servers.filter(s => s.status === 'online') + const totalPlayers = onlineServers.reduce((sum, s) => sum + (s.a2sData ? (s.a2sData.playerCount - s.a2sData.botCount) : 0), 0) + const totalSlots = onlineServers.reduce((sum, s) => sum + (s.a2sData?.maxPlayers || 0), 0) + + // Get most popular server (highest player count) + const mostPopularServer = onlineServers.length > 0 + ? onlineServers.reduce((prev, current) => { + const prevPlayers = (prev.a2sData?.playerCount || 0) - (prev.a2sData?.botCount || 0) + const currentPlayers = (current.a2sData?.playerCount || 0) - (current.a2sData?.botCount || 0) + return currentPlayers > prevPlayers ? current : prev + }) + : null // Format playtime from seconds to hours and minutes const formatPlayTime = (seconds: number) => { @@ -217,9 +233,56 @@ function App() {

{t('activity.serverInfo')}

-
{t('activity.serverStatus')}
-
{t('activity.currentMap')}
-
{t('activity.nextRestart')}
+
+ {t('activity.serverStatus')} + 0 ? '#10b981' : '#ef4444', + fontWeight: 'bold' + }}> + {onlineServers.length}/{servers.length} Online + +
+
+ Active Players + + {totalPlayers}/{totalSlots} + +
+
+ Most Popular + + {mostPopularServer ? mostPopularServer.name : 'N/A'} + +