nice
This commit is contained in:
parent
b801d4b6f1
commit
93f5e64df7
@ -9,6 +9,7 @@ let heartbeatInterval = null;
|
|||||||
let checkInterval = null;
|
let checkInterval = null;
|
||||||
let isMonitoring = false;
|
let isMonitoring = false;
|
||||||
let isConnecting = false;
|
let isConnecting = false;
|
||||||
|
let connectionTimestamp = null;
|
||||||
|
|
||||||
const parseLogMessage = (log) => {
|
const parseLogMessage = (log) => {
|
||||||
// Format réel de log Palworld:
|
// Format réel de log Palworld:
|
||||||
@ -44,7 +45,7 @@ const getSteamIdFromPlayerName = async (playerName) => {
|
|||||||
'Authorization': `Basic ${process.env.PALWORLD_API_TOKEN}`
|
'Authorization': `Basic ${process.env.PALWORLD_API_TOKEN}`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const players = response.data.players || {};
|
const players = response.data.players || {};
|
||||||
console.log(`🔍 Recherche du Steam ID pour le joueur: ${playerName}`);
|
console.log(`🔍 Recherche du Steam ID pour le joueur: ${playerName}`);
|
||||||
// Chercher le joueur par nom
|
// Chercher le joueur par nom
|
||||||
@ -149,6 +150,8 @@ const connectWebSocket = async (pterodactylToken, serverId) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isConnecting = true;
|
isConnecting = true;
|
||||||
|
connectionTimestamp = Date.now();
|
||||||
|
console.log(`📅 Timestamp de connexion: ${new Date(connectionTimestamp).toISOString()}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const credentials = await getWebSocketCredentials(pterodactylToken, serverId);
|
const credentials = await getWebSocketCredentials(pterodactylToken, serverId);
|
||||||
@ -193,6 +196,18 @@ 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];
|
||||||
|
|
||||||
|
// 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);
|
const linkData = parseLogMessage(log);
|
||||||
|
|
||||||
if (linkData) {
|
if (linkData) {
|
||||||
@ -200,7 +215,6 @@ const connectWebSocket = async (pterodactylToken, serverId) => {
|
|||||||
|
|
||||||
if (playerData) {
|
if (playerData) {
|
||||||
await handleLinkCommand(linkData.playerName, playerData, linkData.code);
|
await handleLinkCommand(linkData.playerName, playerData, linkData.code);
|
||||||
// Vérifier immédiatement après la liaison
|
|
||||||
setTimeout(() => checkAndManageWebSocket(), 2000);
|
setTimeout(() => checkAndManageWebSocket(), 2000);
|
||||||
} else {
|
} else {
|
||||||
console.log(`❌ Impossible de trouver le Steam ID pour ${linkData.playerName}`);
|
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})`);
|
console.log(`⚠️ WebSocket Pterodactyl déconnecté (Code: ${code})`);
|
||||||
ws = null;
|
ws = null;
|
||||||
isConnecting = false;
|
isConnecting = false;
|
||||||
|
connectionTimestamp = null;
|
||||||
|
|
||||||
if (heartbeatInterval) {
|
if (heartbeatInterval) {
|
||||||
clearInterval(heartbeatInterval);
|
clearInterval(heartbeatInterval);
|
||||||
@ -236,6 +251,7 @@ const connectWebSocket = async (pterodactylToken, serverId) => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Erreur lors de la connexion WebSocket:', error);
|
console.error('Erreur lors de la connexion WebSocket:', error);
|
||||||
isConnecting = false;
|
isConnecting = false;
|
||||||
|
connectionTimestamp = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user