This commit is contained in:
Louis Mazin 2025-12-09 13:53:28 +01:00
parent b801d4b6f1
commit 93f5e64df7

View File

@ -9,6 +9,7 @@ let heartbeatInterval = null;
let checkInterval = null;
let isMonitoring = false;
let isConnecting = false;
let connectionTimestamp = null;
const parseLogMessage = (log) => {
// Format réel de log Palworld:
@ -149,6 +150,8 @@ const connectWebSocket = async (pterodactylToken, serverId) => {
}
isConnecting = true;
connectionTimestamp = Date.now();
console.log(`📅 Timestamp de connexion: ${new Date(connectionTimestamp).toISOString()}`);
try {
const credentials = await getWebSocketCredentials(pterodactylToken, serverId);
@ -193,6 +196,18 @@ const connectWebSocket = async (pterodactylToken, serverId) => {
if (message.event === 'console output') {
const log = message.args[0];
// Extraire le timestamp du log
const timestampMatch = log.match(/\[(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})\]/);
if (timestampMatch) {
const logTimestamp = new Date(timestampMatch[1]).getTime();
// Ignorer les messages antérieurs à la connexion
if (logTimestamp < connectionTimestamp) {
return;
}
}
const linkData = parseLogMessage(log);
if (linkData) {
@ -200,7 +215,6 @@ const connectWebSocket = async (pterodactylToken, serverId) => {
if (playerData) {
await handleLinkCommand(linkData.playerName, playerData, linkData.code);
// Vérifier immédiatement après la liaison
setTimeout(() => checkAndManageWebSocket(), 2000);
} else {
console.log(`❌ Impossible de trouver le Steam ID pour ${linkData.playerName}`);
@ -226,6 +240,7 @@ const connectWebSocket = async (pterodactylToken, serverId) => {
console.log(`⚠️ WebSocket Pterodactyl déconnecté (Code: ${code})`);
ws = null;
isConnecting = false;
connectionTimestamp = null;
if (heartbeatInterval) {
clearInterval(heartbeatInterval);
@ -236,6 +251,7 @@ const connectWebSocket = async (pterodactylToken, serverId) => {
} catch (error) {
console.error('Erreur lors de la connexion WebSocket:', error);
isConnecting = false;
connectionTimestamp = null;
}
};