diff --git a/backend/src/controllers/serverStatusController.ts b/backend/src/controllers/serverStatusController.ts index aa0969e..d062ef5 100644 --- a/backend/src/controllers/serverStatusController.ts +++ b/backend/src/controllers/serverStatusController.ts @@ -1,4 +1,5 @@ import { Request, Response } from 'express'; +import { connectRcon, disconnectRcon } from '../helpers/rconHelper'; const SLEEPING_SERVER_URL = process.env.SLEEPING_SERVER_URL || 'http://localhost:5000'; @@ -72,3 +73,29 @@ export const wakeUpServer = async (req: Request, res: Response) => { } }; +/** + * Get the RCON connection status + */ +export const getRconStatus = async (req: Request, res: Response) => { + try { + // Try to connect to RCON server + await connectRcon(); + + // If connection successful, disconnect and return success + disconnectRcon(); + + res.status(200).json({ + status: 'Running', + connected: true, + message: 'RCON server is connected' + }); + } catch (error) { + console.error('[RCON Status] RCON connection failed:', error instanceof Error ? error.message : error); + res.status(200).json({ + status: 'Offline', + connected: false, + message: 'RCON server is not connected - Entries cannot be approved' + }); + } +}; + diff --git a/backend/src/routes/serverStatusRoutes.ts b/backend/src/routes/serverStatusRoutes.ts index bdbae00..f30dda0 100644 --- a/backend/src/routes/serverStatusRoutes.ts +++ b/backend/src/routes/serverStatusRoutes.ts @@ -1,5 +1,6 @@ import express from 'express'; -import { getServerStatus, wakeUpServer } from '../controllers/serverStatusController'; +import { getServerStatus, wakeUpServer, getRconStatus } from '../controllers/serverStatusController'; +import { authMiddleware } from '../middleware/authMiddleware'; const router = express.Router(); @@ -7,6 +8,9 @@ const router = express.Router(); router.get('/', getServerStatus); router.post('/wakeup', wakeUpServer); +// Protected route - only authenticated admins can check RCON status +router.get('/rcon', authMiddleware, getRconStatus); + export default router; diff --git a/frontend/src/components/Dashboard.tsx b/frontend/src/components/Dashboard.tsx index 8e63f3e..a52a574 100644 --- a/frontend/src/components/Dashboard.tsx +++ b/frontend/src/components/Dashboard.tsx @@ -36,6 +36,7 @@ function Dashboard() { const [invitationCode, setInvitationCode] = useState(null); const [isCopied, setIsCopied] = useState(false); const [error, setError] = useState(null); + const [rconConnected, setRconConnected] = useState(true); const invitationCodeRef = useRef(null); @@ -69,14 +70,53 @@ function Dashboard() { navigate("/admin/login"); } + // Function to fetch RCON status + const fetchRconStatus = async () => { + try { + const response = await apiJwt.get('/api/status/rcon'); + setRconConnected(response.data.connected); + } catch (error) { + console.error('[Dashboard] Error fetching RCON status:', error); + setRconConnected(false); + } + }; + useEffect(() => { const url = window.location.host; document.title = `Admin Dashboard - ${url}`; + + // Fetch RCON status immediately + fetchRconStatus(); + + // Set up polling to fetch status every 5 seconds + const statusInterval = setInterval(() => { + fetchRconStatus(); + }, 5000); // Poll every 5 seconds + + // Cleanup interval on unmount + return () => { + clearInterval(statusInterval); + }; }, []); return (
+ + {/* Server Status Indicator */} +
+
+
+ {rconConnected ? '🟩' : '🟥'} + {rconConnected ? 'Server is running' : 'Server is offline - Entries cannot be approved'} +
+
+
+