From 156690a4f0b2a970c7343c7dead3f9e637e5b71a Mon Sep 17 00:00:00 2001 From: Louis Mazin Date: Mon, 8 Dec 2025 21:57:35 +0100 Subject: [PATCH] noice --- commands/utility/check-linked.js | 2 +- commands/utility/link.js | 20 +++++++++++++------- consoleMonitor.js | 29 +++++++++++++++-------------- database.js | 14 ++++++++------ 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/commands/utility/check-linked.js b/commands/utility/check-linked.js index 2a02d73..8548d49 100644 --- a/commands/utility/check-linked.js +++ b/commands/utility/check-linked.js @@ -39,7 +39,7 @@ module.exports = { embed.addFields({ name: `👤 ${discordName}`, - value: `🎮 Palworld: **${link.palworld_username}**\n🆔 Steam ID: \`${link.steam_id}\`\n📅 Lié le: ${new Date(link.linked_at).toLocaleDateString('fr-FR')}`, + value: `🎮 Palworld: **${link.palworld_username}**\n🆔 Steam ID: \`${link.steam_id}\`\n🎯 Player ID: \`${link.player_id || 'N/A'}\`\n📅 Lié le: ${new Date(link.linked_at).toLocaleDateString('fr-FR')}`, inline: false }); } diff --git a/commands/utility/link.js b/commands/utility/link.js index 53f66a5..a484c46 100644 --- a/commands/utility/link.js +++ b/commands/utility/link.js @@ -34,17 +34,21 @@ module.exports = { }); const players = response.data.players || {}; - let steamId = null; + let playerData = null; // Chercher le joueur par nom for (const [id, player] of Object.entries(players)) { if (player.name === palworldName) { - steamId = id; + playerData = { + steamId: player.userId.replace('steam_', ''), + playerId: player.playerId, + name: player.name + }; break; } } - if (!steamId) { + if (!playerData) { return interaction.editReply({ content: `❌ Impossible de trouver le joueur **${palworldName}** sur le serveur.\n\n` + `💡 Le joueur doit être connecté sur le serveur Palworld.`, @@ -57,7 +61,7 @@ module.exports = { const code = await generateLinkCode(discordUser.id); // Effectuer la liaison immédiatement - const result = await verifyLinkCode(code, steamId, palworldName); + const result = await verifyLinkCode(code, playerData.steamId, playerData.name, playerData.playerId); if (result.success) { await updateUserLinkWithUsername(discordUser.id, discordUser.tag); @@ -68,7 +72,8 @@ module.exports = { .addFields( { name: '👤 Discord', value: `${discordUser.tag} (<@${discordUser.id}>)`, inline: false }, { name: '🎮 Palworld', value: palworldName, inline: true }, - { name: '🆔 Steam ID', value: `\`${steamId}\``, inline: true } + { name: '🆔 Steam ID', value: `\`${playerData.steamId}\``, inline: true }, + { name: '🎯 Player ID', value: `\`${playerData.playerId}\``, inline: false } ) .setTimestamp(); @@ -76,8 +81,9 @@ module.exports = { await discordUser.send( `✅ **Liaison effectuée par un administrateur**\n\n` + `Votre compte Discord a été lié à votre compte Palworld:\n` + - `🎮 Nom Palworld: **${palworldName}**\n` + - `🆔 Steam ID: \`${steamId}\`` + `🎮 Nom Palworld: **${playerData.name}**\n` + + `🆔 Steam ID: \`${playerData.steamId}\`\n` + + `🎯 Player ID: \`${playerData.playerId}\`` ).catch(() => {}); await interaction.editReply({ embeds: [embed], ephemeral: true }); diff --git a/consoleMonitor.js b/consoleMonitor.js index 7c0bed2..b5af8ef 100644 --- a/consoleMonitor.js +++ b/consoleMonitor.js @@ -46,11 +46,15 @@ const getSteamIdFromPlayerName = async (playerName) => { }); const players = response.data.players || {}; - console.log(players); + // Chercher le joueur par nom for (const [steamId, player] of Object.entries(players)) { if (player.name === playerName) { - return steamId; + return { + steamId: player.userId.replace('steam_', ''), + playerId: player.playerId, + name: player.name + }; } } @@ -61,16 +65,15 @@ const getSteamIdFromPlayerName = async (playerName) => { } }; -const handleLinkCommand = async (playerName, steamId, code) => { +const handleLinkCommand = async (playerName, playerData, code) => { try { - console.log(`🔗 Tentative de liaison détectée: ${playerName} (${steamId}) avec le code ${code}`); + console.log(`🔗 Tentative de liaison détectée: ${playerName} (${playerData.steamId}) avec le code ${code}`); - const result = await verifyLinkCode(code, steamId, playerName); + const result = await verifyLinkCode(code, playerData.steamId, playerData.name, playerData.playerId); if (result.success) { console.log(`✅ Liaison réussie pour ${playerName}`); - // Envoyer un message de confirmation à l'utilisateur Discord if (client) { const user = await client.users.fetch(result.discordId).catch(() => null); if (user) { @@ -78,8 +81,9 @@ const handleLinkCommand = async (playerName, steamId, code) => { await user.send( `✅ **Liaison réussie !**\n\n` + `Votre compte Discord a été lié avec succès à votre compte Palworld:\n` + - `🎮 Nom Palworld: **${playerName}**\n` + - `🆔 Steam ID: \`${steamId}\`` + `🎮 Nom Palworld: **${playerData.name}**\n` + + `🆔 Steam ID: \`${playerData.steamId}\`\n` + + `🎯 Player ID: \`${playerData.playerId}\`` ).catch(() => {}); } } @@ -192,16 +196,13 @@ const connectWebSocket = async (pterodactylToken, serverId) => { const linkData = parseLogMessage(log); if (linkData) { - // Récupérer le Steam ID depuis l'API - const steamId = await getSteamIdFromPlayerName(linkData.playerName); + const playerData = await getSteamIdFromPlayerName(linkData.playerName); - if (steamId) { - await handleLinkCommand(linkData.playerName, steamId, linkData.code); - // Vérifier immédiatement s'il faut fermer la connexion + if (playerData) { + await handleLinkCommand(linkData.playerName, playerData, linkData.code); await checkAndManageWebSocket(); } else { console.log(`❌ Impossible de trouver le Steam ID pour ${linkData.playerName}`); - console.log(`💡 Le joueur doit être connecté sur le serveur`); } } } diff --git a/database.js b/database.js index 77d54a0..9bbcb18 100644 --- a/database.js +++ b/database.js @@ -53,11 +53,13 @@ const createTables = async () => { id INT AUTO_INCREMENT PRIMARY KEY, discord_id VARCHAR(20) NOT NULL UNIQUE, discord_username VARCHAR(100) NOT NULL, - steam_id VARCHAR(20) NOT NULL, + steam_id VARCHAR(50) NOT NULL, + player_id VARCHAR(50), palworld_username VARCHAR(100) NOT NULL, linked_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, INDEX idx_discord_id (discord_id), - INDEX idx_steam_id (steam_id) + INDEX idx_steam_id (steam_id), + INDEX idx_player_id (player_id) ) `); @@ -77,7 +79,7 @@ const generateLinkCode = async (discordId) => { return code; }; -const verifyLinkCode = async (code, steamId, palworldUsername) => { +const verifyLinkCode = async (code, steamId, palworldUsername, playerId = null) => { const connection = getConnection(); const [rows] = await connection.execute( @@ -91,10 +93,10 @@ const verifyLinkCode = async (code, steamId, palworldUsername) => { const linkData = rows[0]; - // Créer la liaison + // Créer la liaison avec player_id await connection.execute( - 'INSERT INTO user_links (discord_id, discord_username, steam_id, palworld_username) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE steam_id = ?, palworld_username = ?', - [linkData.discord_id, 'temp', steamId, palworldUsername, steamId, palworldUsername] + 'INSERT INTO user_links (discord_id, discord_username, steam_id, player_id, palworld_username) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE steam_id = ?, player_id = ?, palworld_username = ?', + [linkData.discord_id, 'temp', steamId, playerId, palworldUsername, steamId, playerId, palworldUsername] ); // Marquer le code comme utilisé