test
This commit is contained in:
parent
b49fdb56cf
commit
fc7542db6b
@ -8,6 +8,7 @@ let reconnectTimeout = null;
|
||||
let client = null;
|
||||
let heartbeatInterval = null;
|
||||
let checkInterval = null;
|
||||
let refreshCredentialsInterval = null; // Interval pour rafraîchir les credentials périodiquement
|
||||
let isMonitoring = false;
|
||||
let isConnecting = false;
|
||||
let connectionTimestamp = null;
|
||||
@ -16,6 +17,7 @@ let monitoringStartTimestamp = null; // Timestamp du démarrage du monitoring (n
|
||||
// Backoff de reconnexion
|
||||
let reconnectDelayMs = 5000;
|
||||
const RECONNECT_DELAY_MAX_MS = 5 * 60 * 1000; // 5 min
|
||||
const CREDENTIALS_REFRESH_INTERVAL = 55 * 60 * 1000; // Rafraîchir toutes les 55 minutes (avant l'expiration)
|
||||
|
||||
// Suivi des joueurs connectés (fallback si la console n’affiche pas les déconnexions)
|
||||
const connectedPlayers = new Map(); // steamId -> { name, playerId, lastSeen }
|
||||
@ -432,6 +434,11 @@ const stopWebSocketOnly = () => {
|
||||
heartbeatInterval = null;
|
||||
}
|
||||
|
||||
if (refreshCredentialsInterval) {
|
||||
clearInterval(refreshCredentialsInterval);
|
||||
refreshCredentialsInterval = null;
|
||||
}
|
||||
|
||||
if (ws) {
|
||||
ws.close();
|
||||
ws = null;
|
||||
@ -440,6 +447,25 @@ const stopWebSocketOnly = () => {
|
||||
isConnecting = false;
|
||||
};
|
||||
|
||||
const forceReconnectToRefreshCredentials = async () => {
|
||||
if (!isMonitoring) return;
|
||||
|
||||
console.log('🔄 Rafraîchissement des credentials WebSocket (reconnexion préventive)...');
|
||||
|
||||
// Fermer la connexion actuelle proprement
|
||||
if (ws) {
|
||||
ws.close();
|
||||
ws = null;
|
||||
}
|
||||
|
||||
// Attendre un peu avant de reconnecter
|
||||
setTimeout(async () => {
|
||||
if (isMonitoring) {
|
||||
await checkAndManageWebSocket();
|
||||
}
|
||||
}, 2000);
|
||||
};
|
||||
|
||||
const startConsoleMonitoring = (discordClient, pterodactylToken) => {
|
||||
if (isMonitoring) {
|
||||
console.log('⚠️ Surveillance déjà active');
|
||||
@ -466,6 +492,11 @@ const startConsoleMonitoring = (discordClient, pterodactylToken) => {
|
||||
// Vérifier toutes les 20 secondes (nettoyage codes et reconnect si besoin)
|
||||
if (checkInterval) clearInterval(checkInterval);
|
||||
checkInterval = setInterval(checkAndManageWebSocket, 20000); // 20s pour détecter vite les départs silencieux
|
||||
|
||||
// Rafraîchir les credentials toutes les 55 minutes pour éviter l'expiration
|
||||
if (refreshCredentialsInterval) clearInterval(refreshCredentialsInterval);
|
||||
refreshCredentialsInterval = setInterval(forceReconnectToRefreshCredentials, CREDENTIALS_REFRESH_INTERVAL);
|
||||
console.log(`⏱️ Rafraîchissement automatique des credentials programmé toutes les ${CREDENTIALS_REFRESH_INTERVAL / 60000} minutes`);
|
||||
};
|
||||
|
||||
const stopConsoleMonitoring = () => {
|
||||
@ -476,6 +507,11 @@ const stopConsoleMonitoring = () => {
|
||||
checkInterval = null;
|
||||
}
|
||||
|
||||
if (refreshCredentialsInterval) {
|
||||
clearInterval(refreshCredentialsInterval);
|
||||
refreshCredentialsInterval = null;
|
||||
}
|
||||
|
||||
if (reconnectTimeout) {
|
||||
clearTimeout(reconnectTimeout);
|
||||
reconnectTimeout = null;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user