This commit is contained in:
Louis Mazin 2025-12-08 21:49:45 +01:00
parent 7c12981f43
commit f6a8bb6143

View File

@ -8,25 +8,57 @@ let client = null;
let heartbeatInterval = null; let heartbeatInterval = null;
const parseLogMessage = (log) => { const parseLogMessage = (log) => {
// Exemple de format de log Palworld: // Format réel de log Palworld:
// [2024.01.15-12:34:56] PlayerName (76561198012345678): !link ABC123 // [2025-12-08 21:47:17] [CHAT] <LouisMazin> !link ABC123
const linkRegex = /\[.*?\]\s*(.+?)\s*\((\d{17})\).*?!link\s+([A-Z0-9]{6})/i; const linkRegex = /\[.*?\]\s*\[CHAT\]\s*<(.+?)>\s*!link\s+([A-Z0-9]{6})/i;
const match = log.match(linkRegex); const match = log.match(linkRegex);
console.log('Parsing log:', log);
console.log('Regex match:', match);
if (match) { if (match) {
const playerName = match[1].trim();
const code = match[2].toUpperCase();
console.log(`✅ Commande !link détectée: ${playerName} avec le code ${code}`);
// Le Steam ID n'est pas dans les logs de chat
// On va devoir le récupérer via l'API des joueurs connectés
return { return {
playerName: match[1].trim(), playerName: playerName,
steamId: match[2], code: code,
code: match[3].toUpperCase() needsSteamId: true
}; };
} }
return null; return null;
}; };
const getSteamIdFromPlayerName = async (playerName) => {
try {
const response = await axios({
method: 'get',
url: 'http://play.louismazin.ovh:8212/v1/api/players',
headers: {
'Accept': 'application/json',
'Authorization': `Basic ${process.env.PALWORLD_API_TOKEN}`
}
});
const players = response.data.players || {};
// Chercher le joueur par nom
for (const [steamId, player] of Object.entries(players)) {
if (player.name === playerName) {
return steamId;
}
}
return null;
} catch (error) {
console.error('Erreur lors de la récupération du Steam ID:', error.message);
return null;
}
};
const handleLinkCommand = async (playerName, steamId, code) => { const handleLinkCommand = async (playerName, steamId, code) => {
try { try {
console.log(`🔗 Tentative de liaison détectée: ${playerName} (${steamId}) avec le code ${code}`); console.log(`🔗 Tentative de liaison détectée: ${playerName} (${steamId}) avec le code ${code}`);
@ -95,7 +127,7 @@ const connectWebSocket = async (pterodactylToken, serverId) => {
})); }));
}); });
ws.on('message', (data) => { ws.on('message', async (data) => {
try { try {
const message = JSON.parse(data.toString()); const message = JSON.parse(data.toString());
@ -125,13 +157,17 @@ const connectWebSocket = async (pterodactylToken, serverId) => {
if (message.event === 'console output') { if (message.event === 'console output') {
const log = message.args[0]; const log = message.args[0];
// Afficher le log pour debug
console.log('📝 Log:', log);
// Détecter les commandes !link
const linkData = parseLogMessage(log); const linkData = parseLogMessage(log);
if (linkData) { if (linkData) {
handleLinkCommand(linkData.playerName, linkData.steamId, linkData.code); // Récupérer le Steam ID depuis l'API
const steamId = await getSteamIdFromPlayerName(linkData.playerName);
if (steamId) {
await handleLinkCommand(linkData.playerName, steamId, linkData.code);
} else {
console.log(`❌ Impossible de trouver le Steam ID pour ${linkData.playerName}`);
console.log(`💡 Le joueur doit être connecté sur le serveur`);
}
} }
} }