diff --git a/src/creatures/players/components/player_forge_history.cpp b/src/creatures/players/components/player_forge_history.cpp index c8e681ba9b4..9089731bbf5 100644 --- a/src/creatures/players/components/player_forge_history.cpp +++ b/src/creatures/players/components/player_forge_history.cpp @@ -14,13 +14,14 @@ #include "utils/tools.hpp" #include "game/scheduling/save_manager.hpp" -PlayerForgeHistory::PlayerForgeHistory(Player &player) : m_player(player) {} +PlayerForgeHistory::PlayerForgeHistory(Player &player) : + m_player(player) { } -const std::vector& PlayerForgeHistory::get() const { +const std::vector &PlayerForgeHistory::get() const { return m_history; } -void PlayerForgeHistory::add(const ForgeHistory& history) { +void PlayerForgeHistory::add(const ForgeHistory &history) { m_history.push_back(history); m_modifiedHistory.push_back(history); } @@ -28,17 +29,16 @@ void PlayerForgeHistory::add(const ForgeHistory& history) { void PlayerForgeHistory::remove(int historyId) { m_removedHistoryIds.push_back(historyId); m_history.erase( - std::remove_if(m_history.begin(), m_history.end(), - [historyId](const ForgeHistory& h) { return h.id == historyId; }), + std::remove_if(m_history.begin(), m_history.end(), [historyId](const ForgeHistory &h) { return h.id == historyId; }), m_history.end() ); } bool PlayerForgeHistory::load() { auto playerGUID = m_player.getGUID(); - Database& db = Database::getInstance(); + Database &db = Database::getInstance(); auto query = fmt::format("SELECT * FROM forge_history WHERE player_id = {}", playerGUID); - const DBResult_ptr& result = db.storeQuery(query); + const DBResult_ptr &result = db.storeQuery(query); if (!result) { g_logger().debug("Failed to load forge history for player with ID: {}", playerGUID); return false; @@ -67,7 +67,7 @@ bool PlayerForgeHistory::save() { auto modifiedHistory = m_modifiedHistory; auto forgeHistorySaveTask = [playerGUID, removedHistoryIds, modifiedHistory]() mutable { - Database& db = Database::getInstance(); + Database &db = Database::getInstance(); if (!removedHistoryIds.empty()) { std::string idsToDelete = fmt::format("{}", fmt::join(removedHistoryIds, ", ")); @@ -87,14 +87,8 @@ bool PlayerForgeHistory::save() { DBInsert insertQuery("INSERT INTO `forge_history` (`id`, `player_id`, `action_type`, `description`, `done_at`, `is_success`) VALUES "); insertQuery.upsert({ "action_type", "description", "done_at", "is_success" }); - for (const auto& history : modifiedHistory) { - auto row = fmt::format("{}, {}, {}, {}, {}, {}", - history.id, - playerGUID, - history.actionType, - db.escapeString(history.description), - history.createdAt, - history.success ? 1 : 0); + for (const auto &history : modifiedHistory) { + auto row = fmt::format("{}, {}, {}, {}, {}, {}", history.id, playerGUID, history.actionType, db.escapeString(history.description), history.createdAt, history.success ? 1 : 0); if (!insertQuery.addRow(row)) { g_logger().warn("Failed to add forge history entry for player with ID: {}", playerGUID); diff --git a/src/creatures/players/components/player_forge_history.hpp b/src/creatures/players/components/player_forge_history.hpp index 08425c28c43..9f0086dd41c 100644 --- a/src/creatures/players/components/player_forge_history.hpp +++ b/src/creatures/players/components/player_forge_history.hpp @@ -41,9 +41,9 @@ struct ForgeHistory { class PlayerForgeHistory { public: PlayerForgeHistory(Player &player); - - const std::vector& get() const; - void add(const ForgeHistory& history); + + const std::vector &get() const; + void add(const ForgeHistory &history); void remove(int historyId); bool load(); diff --git a/src/creatures/players/components/player_stash.cpp b/src/creatures/players/components/player_stash.cpp index b255cde5047..72ca8ecd11e 100644 --- a/src/creatures/players/components/player_stash.cpp +++ b/src/creatures/players/components/player_stash.cpp @@ -14,7 +14,8 @@ #include "creatures/players/player.hpp" #include "game/scheduling/save_manager.hpp" -PlayerStash::PlayerStash(Player &player) : m_player(player) { } +PlayerStash::PlayerStash(Player &player) : + m_player(player) { } void PlayerStash::add(uint16_t itemId, uint32_t amount) { const auto it = m_stashItems.find(itemId); @@ -24,8 +25,8 @@ void PlayerStash::add(uint16_t itemId, uint32_t amount) { m_stashItems[itemId] = amount; } - m_modifiedItems[itemId] = m_stashItems[itemId]; // Track added/modified items - m_removedItems.erase(itemId); // Remove from removed if it was there + m_modifiedItems[itemId] = m_stashItems[itemId]; // Track added/modified items + m_removedItems.erase(itemId); // Remove from removed if it was there } uint32_t PlayerStash::getCount(uint16_t itemId) const { @@ -41,11 +42,11 @@ bool PlayerStash::remove(uint16_t itemId, uint32_t amount) { if (it != m_stashItems.end()) { if (it->second > amount) { m_stashItems[itemId] -= amount; - m_modifiedItems[itemId] = m_stashItems[itemId]; // Track modified item + m_modifiedItems[itemId] = m_stashItems[itemId]; // Track modified item } else if (it->second == amount) { m_stashItems.erase(itemId); - m_removedItems.insert(itemId); // Track removed item - m_modifiedItems.erase(itemId); // Ensure it's not in added items + m_removedItems.insert(itemId); // Track removed item + m_modifiedItems.erase(itemId); // Ensure it's not in added items } else { return false; } @@ -58,13 +59,13 @@ bool PlayerStash::find(uint16_t itemId) const { return m_stashItems.find(itemId) != m_stashItems.end(); } -const std::map& PlayerStash::getItems() const { +const std::map &PlayerStash::getItems() const { return m_stashItems; } uint16_t PlayerStash::getSize() const { uint16_t size = 0; - for (const auto& [itemId, itemCount] : m_stashItems) { + for (const auto &[itemId, itemCount] : m_stashItems) { size += ceil(itemCount / static_cast(Item::items[itemId].stackSize)); } return size; @@ -80,7 +81,7 @@ bool PlayerStash::save() { auto modifiedItems = m_modifiedItems; auto stashSaveTask = [playerGUID, removedItems, modifiedItems]() mutable { - Database& db = Database::getInstance(); + Database &db = Database::getInstance(); if (!removedItems.empty()) { std::string removedItemIds = fmt::format("{}", fmt::join(removedItems, ", ")); @@ -100,7 +101,7 @@ bool PlayerStash::save() { DBInsert insertQuery("INSERT INTO `player_stash` (`player_id`, `item_id`, `item_count`) VALUES "); insertQuery.upsert({ "item_count" }); - for (const auto& [itemId, itemCount] : modifiedItems) { + for (const auto &[itemId, itemCount] : modifiedItems) { auto row = fmt::format("{}, {}, {}", playerGUID, itemId, itemCount); if (!insertQuery.addRow(row)) { g_logger().warn("[PlayerStash::save] - Failed to add row for stash item: {}", itemId); @@ -121,9 +122,9 @@ bool PlayerStash::save() { } bool PlayerStash::load() { - Database& db = Database::getInstance(); + Database &db = Database::getInstance(); auto query = fmt::format("SELECT `item_count`, `item_id` FROM `player_stash` WHERE `player_id` = {}", m_player.getGUID()); - const DBResult_ptr& result = db.storeQuery(query); + const DBResult_ptr &result = db.storeQuery(query); if (!result) { g_logger().debug("[PlayerStash::load] - Failed to load stash items for player: {}", m_player.getName()); return false; diff --git a/src/creatures/players/components/player_stash.hpp b/src/creatures/players/components/player_stash.hpp index 1ed4d270cdd..b3c83b248c4 100644 --- a/src/creatures/players/components/player_stash.hpp +++ b/src/creatures/players/components/player_stash.hpp @@ -23,7 +23,7 @@ class PlayerStash { bool find(uint16_t itemId) const; - const std::map& getItems() const; + const std::map &getItems() const; uint16_t getSize() const; @@ -36,5 +36,5 @@ class PlayerStash { std::map m_stashItems; std::map m_modifiedItems; std::set m_removedItems; - Player& m_player; + Player &m_player; }; diff --git a/src/creatures/players/components/player_storage.cpp b/src/creatures/players/components/player_storage.cpp index bfd7e581dd8..2570abd5044 100644 --- a/src/creatures/players/components/player_storage.cpp +++ b/src/creatures/players/components/player_storage.cpp @@ -19,7 +19,8 @@ #include "creatures/players/storages/storages.hpp" #include "game/scheduling/save_manager.hpp" -PlayerStorage::PlayerStorage(Player &player) : m_player(player) {} +PlayerStorage::PlayerStorage(Player &player) : + m_player(player) { } void PlayerStorage::add(const uint32_t key, const int32_t value, const bool shouldStorageUpdate /* = false*/, const bool shouldTrackModification /*= true*/) { if (IS_IN_KEYRANGE(key, RESERVED_RANGE)) { @@ -167,7 +168,7 @@ void PlayerStorage::getReservedRange() { for (const auto &entry : m_player.outfits) { uint32_t key = ++outfits_key; m_storageMap[key] = (entry.lookType << 16) | entry.addons; - m_modifiedKeys.insert(key); // Track the key for saving + m_modifiedKeys.insert(key); // Track the key for saving } // Generate familiars range @@ -175,6 +176,6 @@ void PlayerStorage::getReservedRange() { for (const auto &entry : m_player.familiars) { uint32_t key = ++familiar_key; m_storageMap[key] = (entry.lookType << 16); - m_modifiedKeys.insert(key); // Track the key for saving + m_modifiedKeys.insert(key); // Track the key for saving } } diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index f7a33227d11..726d2f14c40 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -10167,29 +10167,29 @@ const std::unique_ptr &Player::cyclopedia() const { } // Stash interface -std::unique_ptr& Player::stash() { +std::unique_ptr &Player::stash() { return m_stashPlayer; } -const std::unique_ptr& Player::stash() const { +const std::unique_ptr &Player::stash() const { return m_stashPlayer; } // Forge history interface -std::unique_ptr& Player::forgeHistory() { +std::unique_ptr &Player::forgeHistory() { return m_forgeHistoryPlayer; } -const std::unique_ptr& Player::forgeHistory() const { +const std::unique_ptr &Player::forgeHistory() const { return m_forgeHistoryPlayer; } // Storage interface -std::unique_ptr& Player::storage() { +std::unique_ptr &Player::storage() { return m_storagePlayer; } -const std::unique_ptr& Player::storage() const { +const std::unique_ptr &Player::storage() const { return m_storagePlayer; } diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 6119a0d0027..c645925e081 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -1219,16 +1219,16 @@ class Player final : public Creature, public Cylinder, public Bankable { const std::unique_ptr &vip() const; // Player stash methods interface - std::unique_ptr& stash(); - const std::unique_ptr& stash() const; + std::unique_ptr &stash(); + const std::unique_ptr &stash() const; // Player stash methods interface - std::unique_ptr& forgeHistory(); - const std::unique_ptr& forgeHistory() const; + std::unique_ptr &forgeHistory(); + const std::unique_ptr &forgeHistory() const; // Player storage methods interface - std::unique_ptr& storage(); - const std::unique_ptr& storage() const; + std::unique_ptr &storage(); + const std::unique_ptr &storage() const; void sendLootMessage(const std::string &message) const; diff --git a/src/game/scheduling/save_manager.cpp b/src/game/scheduling/save_manager.cpp index 84e3948cebb..d0a88133d6b 100644 --- a/src/game/scheduling/save_manager.cpp +++ b/src/game/scheduling/save_manager.cpp @@ -19,8 +19,7 @@ #include "game/scheduling/task.hpp" SaveManager::SaveManager(ThreadPool &threadPool, KVStore &kvStore, Logger &logger, Game &game) : - threadPool(threadPool), kv(kvStore), logger(logger), game(game) -{ + threadPool(threadPool), kv(kvStore), logger(logger), game(game) { m_threads.reserve(threadPool.get_thread_count() + 1); for (uint_fast16_t i = 0; i < m_threads.capacity(); ++i) { m_threads.emplace_back(std::make_unique()); @@ -165,7 +164,7 @@ void SaveManager::saveKV() { } } -void SaveManager::addTask(std::function &&f, std::string_view context, uint32_t expiresAfterMs/* = 0*/) { +void SaveManager::addTask(std::function &&f, std::string_view context, uint32_t expiresAfterMs /* = 0*/) { const auto &thread = getThreadTask(); std::scoped_lock lock(thread->mutex); thread->tasks.emplace_back(expiresAfterMs, std::move(f), context); diff --git a/src/io/functions/iologindata_save_player.cpp b/src/io/functions/iologindata_save_player.cpp index a8fb2eb9a13..0d1a89d0781 100644 --- a/src/io/functions/iologindata_save_player.cpp +++ b/src/io/functions/iologindata_save_player.cpp @@ -170,9 +170,9 @@ bool IOLoginDataSave::savePlayerFirst(const std::shared_ptr &player) { // Quick update if `save` flag is 0 if (result->getNumber("save") == 0) { auto quickUpdateTask = [queryStr = fmt::format( - "UPDATE `players` SET `lastlogin` = {}, `lastip` = {} WHERE `id` = {}", - player->lastLoginSaved, player->lastIP, player->getGUID() - )]() { + "UPDATE `players` SET `lastlogin` = {}, `lastip` = {} WHERE `id` = {}", + player->lastLoginSaved, player->lastIP, player->getGUID() + )]() { Database &db = Database::getInstance(); if (!g_database().executeQuery(queryStr)) { g_logger().warn("[SaveManager::quickUpdateTask] - Failed to execute quick update for player."); @@ -370,7 +370,6 @@ bool IOLoginDataSave::savePlayerKills(const std::shared_ptr &player) { } auto killsSaveTask = [deleteQueryStr, killsQuery]() mutable { - if (!g_database().executeQuery(deleteQueryStr)) { g_logger().warn("[SaveManager::killsSaveTask] - Failed to execute delete query for player kills"); return; @@ -391,7 +390,7 @@ bool IOLoginDataSave::savePlayerBestiarySystem(const std::shared_ptr &pl return false; } - Database& db = Database::getInstance(); + Database &db = Database::getInstance(); PropWriteStream propBestiaryStream; for (const auto &trackedType : player->getCyclopediaMonsterTrackerSet(false)) { @@ -508,7 +507,6 @@ bool IOLoginDataSave::savePlayerDepotItems(const std::shared_ptr &player } auto depotItemsSaveTask = [deleteQueryStr, depotQuery]() mutable { - if (!g_database().executeQuery(deleteQueryStr)) { g_logger().warn("[SaveManager::depotItemsSaveTask] - Failed to execute delete query for depot items"); return; @@ -552,7 +550,6 @@ bool IOLoginDataSave::saveRewardItems(const std::shared_ptr &player) { } auto rewardItemsSaveTask = [deleteQueryStr, rewardQuery]() mutable { - if (!g_database().executeQuery(deleteQueryStr)) { g_logger().warn("[SaveManager::rewardItemsSaveTask] - Failed to execute delete query for reward items"); return; @@ -588,7 +585,6 @@ bool IOLoginDataSave::savePlayerInbox(const std::shared_ptr &player) { } auto inboxSaveTask = [deleteQueryStr, inboxQuery]() mutable { - if (!g_database().executeQuery(deleteQueryStr)) { g_logger().warn("[SaveManager::inboxSaveTask] - Failed to execute delete query for inbox items"); return; @@ -611,10 +607,10 @@ bool IOLoginDataSave::savePlayerPreyClass(const std::shared_ptr &player) if (g_configManager().getBoolean(PREY_ENABLED)) { DBInsert preyQuery("INSERT INTO player_prey " - "(`player_id`, `slot`, `state`, `raceid`, `option`, `bonus_type`, `bonus_rarity`, " - "`bonus_percentage`, `bonus_time`, `free_reroll`, `monster_list`) VALUES "); + "(`player_id`, `slot`, `state`, `raceid`, `option`, `bonus_type`, `bonus_rarity`, " + "`bonus_percentage`, `bonus_time`, `free_reroll`, `monster_list`) VALUES "); preyQuery.upsert({ "state", "raceid", "option", "bonus_type", "bonus_rarity", - "bonus_percentage", "bonus_time", "free_reroll", "monster_list" }); + "bonus_percentage", "bonus_time", "free_reroll", "monster_list" }); auto playerGUID = player->getGUID(); for (uint8_t slotId = PreySlot_First; slotId <= PreySlot_Last; slotId++) { @@ -659,10 +655,10 @@ bool IOLoginDataSave::savePlayerTaskHuntingClass(const std::shared_ptr & if (g_configManager().getBoolean(TASK_HUNTING_ENABLED)) { DBInsert taskHuntQuery("INSERT INTO `player_taskhunt` " - "(`player_id`, `slot`, `state`, `raceid`, `upgrade`, `rarity`, " - "`kills`, `disabled_time`, `free_reroll`, `monster_list`) VALUES "); + "(`player_id`, `slot`, `state`, `raceid`, `upgrade`, `rarity`, " + "`kills`, `disabled_time`, `free_reroll`, `monster_list`) VALUES "); taskHuntQuery.upsert({ "state", "raceid", "upgrade", "rarity", "kills", "disabled_time", - "free_reroll", "monster_list" }); + "free_reroll", "monster_list" }); auto playerGUID = player->getGUID(); for (uint8_t slotId = PreySlot_First; slotId <= PreySlot_Last; slotId++) { @@ -706,7 +702,7 @@ bool IOLoginDataSave::savePlayerBosstiary(const std::shared_ptr &player) } DBInsert insertQuery("INSERT INTO `player_bosstiary` " - "(`player_id`, `bossIdSlotOne`, `bossIdSlotTwo`, `removeTimes`, `tracker`) VALUES "); + "(`player_id`, `bossIdSlotOne`, `bossIdSlotTwo`, `removeTimes`, `tracker`) VALUES "); insertQuery.upsert({ "bossIdSlotOne", "bossIdSlotTwo", "removeTimes", "tracker" }); // Prepare tracker data using PropWriteStream