From c9b2130ad8efce9b0e933f670b63d479e7fab632 Mon Sep 17 00:00:00 2001 From: Louis Mazin Date: Tue, 9 Dec 2025 19:39:07 +0100 Subject: [PATCH] test --- consoleMonitor.js | 10 ++++++---- database.js | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/consoleMonitor.js b/consoleMonitor.js index 1db7ba7..b2e8c26 100644 --- a/consoleMonitor.js +++ b/consoleMonitor.js @@ -234,14 +234,16 @@ const connectWebSocket = async (pterodactylToken, serverId) => { console.log(`❌ Impossible de trouver le Steam ID pour ${linkData.playerName}`); } } else if (linkData.type === 'disconnect') { - // Extraire le Steam ID du userId (format: gdk_STEAMID) try { - await updateLastConnection(linkData.userId); - console.log(`✅ Dernière connexion mise à jour pour ${linkData.playerName} (${linkData.userId})`); + const result = await updateLastConnection(linkData.userId); + if (result.changes > 0) { + console.log(`✅ Dernière connexion mise à jour pour ${linkData.playerName} (${linkData.userId})`); + } else { + console.log(`ℹ️ Aucun compte lié trouvé pour ${linkData.playerName} (${linkData.userId})`); + } } catch (error) { console.error('Erreur lors de la mise à jour de la dernière connexion:', error); } - } } } diff --git a/database.js b/database.js index 561f1cf..bd02044 100644 --- a/database.js +++ b/database.js @@ -16,7 +16,41 @@ const initDatabase = async () => { }); console.log('✅ Base de données connectée'); - return pool; + + const connection = getConnection(); + + // Table pour les codes de liaison temporaires + await connection.execute(` + CREATE TABLE IF NOT EXISTS link_codes ( + id INT AUTO_INCREMENT PRIMARY KEY, + discord_id VARCHAR(20) NOT NULL, + code VARCHAR(6) NOT NULL UNIQUE, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + expires_at TIMESTAMP NOT NULL, + used BOOLEAN DEFAULT FALSE, + INDEX idx_code (code), + INDEX idx_discord_id (discord_id) + ) + `); + + // Table pour les liaisons confirmées + await connection.execute(` + CREATE TABLE IF NOT EXISTS user_links ( + id INT AUTO_INCREMENT PRIMARY KEY, + discord_id VARCHAR(20) NOT NULL UNIQUE, + discord_username VARCHAR(100) NOT NULL, + steam_id VARCHAR(50) NOT NULL, + player_id VARCHAR(50), + palworld_username VARCHAR(100) NOT NULL, + linked_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + lastConnection TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + INDEX idx_discord_id (discord_id), + INDEX idx_steam_id (steam_id), + INDEX idx_player_id (player_id) + ) + `); + + console.log('✅ Tables créées/vérifiées'); } catch (error) { console.error('❌ Erreur de connexion à la base de données:', error); throw error;