From dc703cc897807beda58e442d8af6d729e03aaaf9 Mon Sep 17 00:00:00 2001 From: Revision Date: Sat, 10 May 2025 13:47:22 +0200 Subject: [PATCH] Fixed a typo in filename and renamed table for consistency (#1279) * Fixed a typo in filename and renamed table for consistency * Added update file to rename the tables * Drop old tables if they exist and create new ones if they don't exist already --- ...count_keys.sql => playerbots_account_keys.sql} | 4 ++-- .../playerbots/base/playerbots_account_links.sql | 4 ++-- .../updates/db_playerbots/2025_05_09_00.sql | 15 +++++++++++++++ src/PlayerbotMgr.cpp | 14 +++++++------- 4 files changed, 26 insertions(+), 11 deletions(-) rename data/sql/playerbots/base/{playerbotds_account_keys.sql => playerbots_account_keys.sql} (65%) create mode 100644 data/sql/playerbots/updates/db_playerbots/2025_05_09_00.sql diff --git a/data/sql/playerbots/base/playerbotds_account_keys.sql b/data/sql/playerbots/base/playerbots_account_keys.sql similarity index 65% rename from data/sql/playerbots/base/playerbotds_account_keys.sql rename to data/sql/playerbots/base/playerbots_account_keys.sql index 97c239ed..6639dec3 100644 --- a/data/sql/playerbots/base/playerbotds_account_keys.sql +++ b/data/sql/playerbots/base/playerbots_account_keys.sql @@ -1,6 +1,6 @@ -DROP TABLE IF EXISTS `playerbot_account_keys`; +DROP TABLE IF EXISTS `playerbots_account_keys`; -CREATE TABLE `playerbot_account_keys` ( +CREATE TABLE `playerbots_account_keys` ( `account_id` INT PRIMARY KEY, `security_key` VARCHAR(255) NOT NULL, `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP diff --git a/data/sql/playerbots/base/playerbots_account_links.sql b/data/sql/playerbots/base/playerbots_account_links.sql index 590e4825..4f3dcbe7 100644 --- a/data/sql/playerbots/base/playerbots_account_links.sql +++ b/data/sql/playerbots/base/playerbots_account_links.sql @@ -1,6 +1,6 @@ -DROP TABLE IF EXISTS `playerbot_account_links`; +DROP TABLE IF EXISTS `playerbots_account_links`; -CREATE TABLE `playerbot_account_links` ( +CREATE TABLE `playerbots_account_links` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `account_id` INT NOT NULL, `linked_account_id` INT NOT NULL, diff --git a/data/sql/playerbots/updates/db_playerbots/2025_05_09_00.sql b/data/sql/playerbots/updates/db_playerbots/2025_05_09_00.sql new file mode 100644 index 00000000..96b9fcbf --- /dev/null +++ b/data/sql/playerbots/updates/db_playerbots/2025_05_09_00.sql @@ -0,0 +1,15 @@ +DROP TABLE IF EXISTS `playerbot_account_keys`; +CREATE TABLE IF NOT EXISTS `playerbots_account_keys` ( + `account_id` INT PRIMARY KEY, + `security_key` VARCHAR(255) NOT NULL, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP +) ENGINE=INNODB DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `playerbot_account_links`; +CREATE TABLE IF NOT EXISTS `playerbots_account_links` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `account_id` INT NOT NULL, + `linked_account_id` INT NOT NULL, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + UNIQUE KEY `account_link` (`account_id`, `linked_account_id`) +) ENGINE=INNODB DEFAULT CHARSET=latin1; diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index 21e5aa66..b0de82ab 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -157,7 +157,7 @@ void PlayerbotHolder::AddPlayerBot(ObjectGuid playerGuid, uint32 masterAccountId bool PlayerbotHolder::IsAccountLinked(uint32 accountId, uint32 linkedAccountId) { QueryResult result = PlayerbotsDatabase.Query( - "SELECT 1 FROM playerbot_account_links WHERE account_id = {} AND linked_account_id = {}", accountId, linkedAccountId); + "SELECT 1 FROM playerbots_account_links WHERE account_id = {} AND linked_account_id = {}", accountId, linkedAccountId); return result != nullptr; } @@ -1734,7 +1734,7 @@ void PlayerbotMgr::HandleSetSecurityKeyCommand(Player* player, const std::string // Store the hashed key in the database PlayerbotsDatabase.Execute( - "REPLACE INTO playerbot_account_keys (account_id, security_key) VALUES ({}, '{}')", + "REPLACE INTO playerbots_account_keys (account_id, security_key) VALUES ({}, '{}')", accountId, hashedKey.str()); ChatHandler(player->GetSession()).PSendSysMessage("Security key set successfully."); @@ -1752,7 +1752,7 @@ void PlayerbotMgr::HandleLinkAccountCommand(Player* player, const std::string& a Field* fields = result->Fetch(); uint32 linkedAccountId = fields[0].Get(); - result = PlayerbotsDatabase.Query("SELECT security_key FROM playerbot_account_keys WHERE account_id = {}", linkedAccountId); + result = PlayerbotsDatabase.Query("SELECT security_key FROM playerbots_account_keys WHERE account_id = {}", linkedAccountId); if (!result) { ChatHandler(player->GetSession()).PSendSysMessage("Invalid security key."); @@ -1778,10 +1778,10 @@ void PlayerbotMgr::HandleLinkAccountCommand(Player* player, const std::string& a uint32 accountId = player->GetSession()->GetAccountId(); PlayerbotsDatabase.Execute( - "INSERT IGNORE INTO playerbot_account_links (account_id, linked_account_id) VALUES ({}, {})", + "INSERT IGNORE INTO playerbots_account_links (account_id, linked_account_id) VALUES ({}, {})", accountId, linkedAccountId); PlayerbotsDatabase.Execute( - "INSERT IGNORE INTO playerbot_account_links (account_id, linked_account_id) VALUES ({}, {})", + "INSERT IGNORE INTO playerbots_account_links (account_id, linked_account_id) VALUES ({}, {})", linkedAccountId, accountId); ChatHandler(player->GetSession()).PSendSysMessage("Account linked successfully."); @@ -1790,7 +1790,7 @@ void PlayerbotMgr::HandleLinkAccountCommand(Player* player, const std::string& a void PlayerbotMgr::HandleViewLinkedAccountsCommand(Player* player) { uint32 accountId = player->GetSession()->GetAccountId(); - QueryResult result = PlayerbotsDatabase.Query("SELECT linked_account_id FROM playerbot_account_links WHERE account_id = {}", accountId); + QueryResult result = PlayerbotsDatabase.Query("SELECT linked_account_id FROM playerbots_account_links WHERE account_id = {}", accountId); if (!result) { @@ -1831,7 +1831,7 @@ void PlayerbotMgr::HandleUnlinkAccountCommand(Player* player, const std::string& uint32 linkedAccountId = fields[0].Get(); uint32 accountId = player->GetSession()->GetAccountId(); - PlayerbotsDatabase.Execute("DELETE FROM playerbot_account_links WHERE (account_id = {} AND linked_account_id = {}) OR (account_id = {} AND linked_account_id = {})", + PlayerbotsDatabase.Execute("DELETE FROM playerbots_account_links WHERE (account_id = {} AND linked_account_id = {}) OR (account_id = {} AND linked_account_id = {})", accountId, linkedAccountId, linkedAccountId, accountId); ChatHandler(player->GetSession()).PSendSysMessage("Account unlinked successfully.");