diff --git a/backend/src/routes/players.js b/backend/src/routes/players.js index 44b7e60..0be5868 100644 --- a/backend/src/routes/players.js +++ b/backend/src/routes/players.js @@ -46,6 +46,21 @@ router.get('/', isAuthenticated, async (req, res) => { console.warn('usercache.json non trouvé:', usercacheFile); } + // Récupérer les OP depuis ops.txt + let ops = []; + const opsFile = path.join(SERVER_DIR, 'ops.txt'); + if (await fs.pathExists(opsFile)) { + try { + const opsContent = await fs.readFile(opsFile, 'utf8'); + ops = opsContent + .split('\n') + .map(line => line.trim()) + .filter(line => line.length > 0); + } catch (e) { + console.error('Erreur lecture ops.txt:', e); + } + } + // Récupérer les stats de dernière connexion const statsDir = path.join(SERVER_DIR, 'world', 'stats'); let statsByUuid = {}; @@ -71,9 +86,11 @@ router.get('/', isAuthenticated, async (req, res) => { const players = playerFiles.map(file => { const uuid = file.replace('.dat', ''); + const playerName = usercache[uuid] || 'Inconnu'; return { uuid, - name: usercache[uuid] || 'Inconnu', + name: playerName, + isOp: ops.includes(playerName), lastPlayed: new Date() // TODO: Extraire du fichier .dat si possible }; }); diff --git a/frontend/public/js/app.js b/frontend/public/js/app.js index f282ba6..6e057b2 100644 --- a/frontend/public/js/app.js +++ b/frontend/public/js/app.js @@ -891,12 +891,13 @@ function getPlayersHTML() { Nom + OP UUID Dernière Connexion - Chargement... + Chargement... @@ -924,12 +925,13 @@ async function loadPlayersData() { table.innerHTML = data.players.map(p => ` ${p.name} + ${p.isOp ? '✅ OP' : '❌'} ${p.uuid} ${new Date(p.lastPlayed).toLocaleString()} `).join(''); } else { - table.innerHTML = 'Aucun joueur'; + table.innerHTML = 'Aucun joueur'; } } catch (e) { console.error('Erreur joueurs:', e); @@ -1018,15 +1020,46 @@ window.loadOnlinePlayers = async function() { `; if (onlineCount > 0 && playerNames.length > 0) { - listDiv.innerHTML = ` -
- ${playerNames.map(name => ` -
- 🎮 ${name} -
- `).join('')} -
- `; + // Charger les infos des joueurs pour voir qui est OP + try { + const playersResponse = await fetch(`${API_URL}/players`, { + credentials: 'include' + }); + let playersData = await playersResponse.json(); + let playersByName = {}; + if (playersData.players) { + playersByName = playersData.players.reduce((acc, p) => { + acc[p.name] = p; + return acc; + }, {}); + } + + listDiv.innerHTML = ` +
+ ${playerNames.map(name => { + const playerInfo = playersByName[name]; + const isOp = playerInfo && playerInfo.isOp; + return ` +
+ 🎮 ${name} + ${isOp ? '
👑 OP
' : ''} +
+ `; + }).join('')} +
+ `; + } catch (e) { + console.error('Erreur chargement infos joueurs:', e); + listDiv.innerHTML = ` +
+ ${playerNames.map(name => ` +
+ 🎮 ${name} +
+ `).join('')} +
+ `; + } } else { listDiv.innerHTML = ''; }