diff --git a/frontend/public/js/app.js b/frontend/public/js/app.js index e3ba487..60615c2 100644 --- a/frontend/public/js/app.js +++ b/frontend/public/js/app.js @@ -543,8 +543,18 @@ async function searchLogs(query) { function getPlayersHTML() { return `
-

👥 Joueurs Connectés

-

Liste des joueurs qui se sont connectés

+

👥 Joueurs en Ligne

+
+ +
+
+

Chargement...

+
+
+
+
+

📋 Tous les Joueurs

+

Liste des joueurs qui se sont connectés au serveur

@@ -562,6 +572,10 @@ function getPlayersHTML() { } async function loadPlayersData() { + // Charger les joueurs en ligne + await window.loadOnlinePlayers(); + + // Charger tous les joueurs try { const response = await fetch(`${API_URL}/players`, { credentials: 'include' @@ -591,6 +605,112 @@ async function loadPlayersData() { } } +window.loadOnlinePlayers = async function() { + console.log('Chargement des joueurs en ligne...'); + + const infoDiv = document.getElementById('onlinePlayersInfo'); + const listDiv = document.getElementById('onlinePlayersList'); + + if (!infoDiv || !listDiv) { + console.error('Éléments DOM non trouvés'); + return; + } + + try { + infoDiv.innerHTML = '

⏳ Chargement...

'; + + const response = await fetch(`${API_URL}/rcon/command`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + credentials: 'include', + body: JSON.stringify({ command: 'list' }) + }); + + console.log('Réponse RCON reçue:', response.status); + + if (!response.ok) { + throw new Error(`HTTP ${response.status}`); + } + + const data = await response.json(); + const output = data.response || data.output || ''; + + console.log('Données reçues:', data); + console.log('Output RCON:', output); + + // Supprimer les codes de couleur Minecraft (§X) + const cleanOutput = output.replace(/§[0-9a-fk-or]/gi, ''); + console.log('Output nettoyé:', cleanOutput); + + // Parser différents formats possibles: + // Format moderne: "There are 1/20 players online: player1, player2" + // Format 1.6.4: "There are 1 out of maximum 20 players online. Connected players: player1" + let match = cleanOutput.match(/There are (\d+)\/(\d+) players online:?\s*(.*)/i); + + if (!match) { + // Essayer le format 1.6.4 + match = cleanOutput.match(/There are (\d+) out of maximum (\d+) players online/i); + if (match) { + const onlineCount = parseInt(match[1]); + const maxPlayers = parseInt(match[2]); + + // Chercher les noms de joueurs après "Connected players:" + const playersMatch = cleanOutput.match(/Connected players[:\s]+(.+)/i); + const playerNames = playersMatch ? + playersMatch[1].split(',').map(n => n.trim().replace(/\[AFK\]/gi, '').trim()).filter(n => n) : + []; + + match = [cleanOutput, onlineCount.toString(), maxPlayers.toString(), playerNames.join(', ')]; + } + } + + if (match) { + const onlineCount = parseInt(match[1]); + const maxPlayers = parseInt(match[2]); + const playerNames = match[3] ? match[3].split(',').map(n => n.trim()).filter(n => n) : []; + + console.log(`Joueurs: ${onlineCount}/${maxPlayers}`, playerNames); + + infoDiv.innerHTML = ` +
+

+ + ${onlineCount} joueur${onlineCount !== 1 ? 's' : ''} + + en ligne sur ${maxPlayers} +

+ ${onlineCount > 0 ? '🟢' : '⚪'} +
+ `; + + if (onlineCount > 0 && playerNames.length > 0) { + listDiv.innerHTML = ` +
+ ${playerNames.map(name => ` +
+ 🎮 ${name} +
+ `).join('')} +
+ `; + } else { + listDiv.innerHTML = ''; + } + } else { + infoDiv.innerHTML = `

Aucun joueur en ligne

`; + listDiv.innerHTML = ''; + } + } catch (e) { + console.error('Erreur chargement joueurs en ligne:', e); + infoDiv.innerHTML = ` +

Erreur: ${e.message}

+ `; + listDiv.innerHTML = ''; + } +} + // ========== WHITELIST ========== function getWhitelistHTML() { return `