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;
const parseLogMessage = (log) => {
// Exemple de format de log Palworld:
// [2024.01.15-12:34:56] PlayerName (76561198012345678): !link ABC123
// Format réel de log Palworld:
// [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);
console.log('Parsing log:', log);
console.log('Regex match:', 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 {
playerName: match[1].trim(),
steamId: match[2],
code: match[3].toUpperCase()
playerName: playerName,
code: code,
needsSteamId: true
};
}
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) => {
try {
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 {
const message = JSON.parse(data.toString());
@ -125,13 +157,17 @@ const connectWebSocket = async (pterodactylToken, serverId) => {
if (message.event === 'console output') {
const log = message.args[0];
// Afficher le log pour debug
console.log('📝 Log:', log);
// Détecter les commandes !link
const linkData = parseLogMessage(log);
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`);
}
}
}