feat: afficher statut OP des joueurs (lire ops.txt)

This commit is contained in:
2026-02-05 02:07:17 +01:00
parent c4c9714d41
commit 4891c539da
2 changed files with 62 additions and 12 deletions

View File

@@ -46,6 +46,21 @@ router.get('/', isAuthenticated, async (req, res) => {
console.warn('usercache.json non trouvé:', usercacheFile); 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 // Récupérer les stats de dernière connexion
const statsDir = path.join(SERVER_DIR, 'world', 'stats'); const statsDir = path.join(SERVER_DIR, 'world', 'stats');
let statsByUuid = {}; let statsByUuid = {};
@@ -71,9 +86,11 @@ router.get('/', isAuthenticated, async (req, res) => {
const players = playerFiles.map(file => { const players = playerFiles.map(file => {
const uuid = file.replace('.dat', ''); const uuid = file.replace('.dat', '');
const playerName = usercache[uuid] || 'Inconnu';
return { return {
uuid, uuid,
name: usercache[uuid] || 'Inconnu', name: playerName,
isOp: ops.includes(playerName),
lastPlayed: new Date() // TODO: Extraire du fichier .dat si possible lastPlayed: new Date() // TODO: Extraire du fichier .dat si possible
}; };
}); });

View File

@@ -891,12 +891,13 @@ function getPlayersHTML() {
<thead> <thead>
<tr> <tr>
<th>Nom</th> <th>Nom</th>
<th>OP</th>
<th>UUID</th> <th>UUID</th>
<th>Dernière Connexion</th> <th>Dernière Connexion</th>
</tr> </tr>
</thead> </thead>
<tbody id="playersTable"> <tbody id="playersTable">
<tr><td colspan="3" style="text-align: center;">Chargement...</td></tr> <tr><td colspan="4" style="text-align: center;">Chargement...</td></tr>
</tbody> </tbody>
</table> </table>
</div> </div>
@@ -924,12 +925,13 @@ async function loadPlayersData() {
table.innerHTML = data.players.map(p => ` table.innerHTML = data.players.map(p => `
<tr> <tr>
<td>${p.name}</td> <td>${p.name}</td>
<td style="text-align: center;">${p.isOp ? '✅ OP' : '❌'}</td>
<td><code style="font-size: 11px;">${p.uuid}</code></td> <td><code style="font-size: 11px;">${p.uuid}</code></td>
<td>${new Date(p.lastPlayed).toLocaleString()}</td> <td>${new Date(p.lastPlayed).toLocaleString()}</td>
</tr> </tr>
`).join(''); `).join('');
} else { } else {
table.innerHTML = '<tr><td colspan="3" style="text-align: center;">Aucun joueur</td></tr>'; table.innerHTML = '<tr><td colspan="4" style="text-align: center;">Aucun joueur</td></tr>';
} }
} catch (e) { } catch (e) {
console.error('Erreur joueurs:', e); console.error('Erreur joueurs:', e);
@@ -1018,6 +1020,36 @@ window.loadOnlinePlayers = async function() {
`; `;
if (onlineCount > 0 && playerNames.length > 0) { if (onlineCount > 0 && playerNames.length > 0) {
// 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 = `
<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-top: 15px;">
${playerNames.map(name => {
const playerInfo = playersByName[name];
const isOp = playerInfo && playerInfo.isOp;
return `
<div style="padding: 12px; background: white; border: 2px solid ${isOp ? '#FFD700' : '#4CAF50'}; border-radius: 8px; text-align: center;">
<span style="font-weight: bold; color: #333;">🎮 ${name}</span>
${isOp ? '<div style="margin-top: 5px; font-size: 12px; color: #FFD700; font-weight: bold;">👑 OP</div>' : ''}
</div>
`;
}).join('')}
</div>
`;
} catch (e) {
console.error('Erreur chargement infos joueurs:', e);
listDiv.innerHTML = ` listDiv.innerHTML = `
<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-top: 15px;"> <div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; margin-top: 15px;">
${playerNames.map(name => ` ${playerNames.map(name => `
@@ -1027,6 +1059,7 @@ window.loadOnlinePlayers = async function() {
`).join('')} `).join('')}
</div> </div>
`; `;
}
} else { } else {
listDiv.innerHTML = ''; listDiv.innerHTML = '';
} }