Skip to content

Commit

Permalink
Code format - (Clang-format)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Nov 1, 2024
1 parent d65f309 commit d236ea6
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 66 deletions.
26 changes: 10 additions & 16 deletions src/creatures/players/components/player_forge_history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@
#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<ForgeHistory>& PlayerForgeHistory::get() const {
const std::vector<ForgeHistory> &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);
}

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;
Expand Down Expand Up @@ -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, ", "));
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/creatures/players/components/player_forge_history.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ struct ForgeHistory {
class PlayerForgeHistory {
public:
PlayerForgeHistory(Player &player);
const std::vector<ForgeHistory>& get() const;
void add(const ForgeHistory& history);

const std::vector<ForgeHistory> &get() const;
void add(const ForgeHistory &history);
void remove(int historyId);

bool load();
Expand Down
25 changes: 13 additions & 12 deletions src/creatures/players/components/player_stash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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;
}
Expand All @@ -58,13 +59,13 @@ bool PlayerStash::find(uint16_t itemId) const {
return m_stashItems.find(itemId) != m_stashItems.end();
}

const std::map<uint16_t, uint32_t>& PlayerStash::getItems() const {
const std::map<uint16_t, uint32_t> &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<float_t>(Item::items[itemId].stackSize));
}
return size;
Expand All @@ -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, ", "));
Expand All @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/players/components/player_stash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PlayerStash {

bool find(uint16_t itemId) const;

const std::map<uint16_t, uint32_t>& getItems() const;
const std::map<uint16_t, uint32_t> &getItems() const;

uint16_t getSize() const;

Expand All @@ -36,5 +36,5 @@ class PlayerStash {
std::map<uint16_t, uint32_t> m_stashItems;
std::map<uint16_t, uint32_t> m_modifiedItems;
std::set<uint16_t> m_removedItems;
Player& m_player;
Player &m_player;
};
7 changes: 4 additions & 3 deletions src/creatures/players/components/player_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -167,14 +168,14 @@ 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
uint32_t familiar_key = PSTRG_FAMILIARS_RANGE_START;
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
}
}
12 changes: 6 additions & 6 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10167,29 +10167,29 @@ const std::unique_ptr<PlayerCyclopedia> &Player::cyclopedia() const {
}

// Stash interface
std::unique_ptr<PlayerStash>& Player::stash() {
std::unique_ptr<PlayerStash> &Player::stash() {
return m_stashPlayer;
}

const std::unique_ptr<PlayerStash>& Player::stash() const {
const std::unique_ptr<PlayerStash> &Player::stash() const {
return m_stashPlayer;
}

// Forge history interface
std::unique_ptr<PlayerForgeHistory>& Player::forgeHistory() {
std::unique_ptr<PlayerForgeHistory> &Player::forgeHistory() {
return m_forgeHistoryPlayer;
}

const std::unique_ptr<PlayerForgeHistory>& Player::forgeHistory() const {
const std::unique_ptr<PlayerForgeHistory> &Player::forgeHistory() const {
return m_forgeHistoryPlayer;
}

// Storage interface
std::unique_ptr<PlayerStorage>& Player::storage() {
std::unique_ptr<PlayerStorage> &Player::storage() {
return m_storagePlayer;
}

const std::unique_ptr<PlayerStorage>& Player::storage() const {
const std::unique_ptr<PlayerStorage> &Player::storage() const {
return m_storagePlayer;
}

Expand Down
12 changes: 6 additions & 6 deletions src/creatures/players/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1219,16 +1219,16 @@ class Player final : public Creature, public Cylinder, public Bankable {
const std::unique_ptr<PlayerVIP> &vip() const;

// Player stash methods interface
std::unique_ptr<PlayerStash>& stash();
const std::unique_ptr<PlayerStash>& stash() const;
std::unique_ptr<PlayerStash> &stash();
const std::unique_ptr<PlayerStash> &stash() const;

// Player stash methods interface
std::unique_ptr<PlayerForgeHistory>& forgeHistory();
const std::unique_ptr<PlayerForgeHistory>& forgeHistory() const;
std::unique_ptr<PlayerForgeHistory> &forgeHistory();
const std::unique_ptr<PlayerForgeHistory> &forgeHistory() const;

// Player storage methods interface
std::unique_ptr<PlayerStorage>& storage();
const std::unique_ptr<PlayerStorage>& storage() const;
std::unique_ptr<PlayerStorage> &storage();
const std::unique_ptr<PlayerStorage> &storage() const;

void sendLootMessage(const std::string &message) const;

Expand Down
5 changes: 2 additions & 3 deletions src/game/scheduling/save_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ThreadTask>());
Expand Down Expand Up @@ -165,7 +164,7 @@ void SaveManager::saveKV() {
}
}

void SaveManager::addTask(std::function<void(void)> &&f, std::string_view context, uint32_t expiresAfterMs/* = 0*/) {
void SaveManager::addTask(std::function<void(void)> &&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);
Expand Down
26 changes: 11 additions & 15 deletions src/io/functions/iologindata_save_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ bool IOLoginDataSave::savePlayerFirst(const std::shared_ptr<Player> &player) {
// Quick update if `save` flag is 0
if (result->getNumber<uint16_t>("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.");
Expand Down Expand Up @@ -370,7 +370,6 @@ bool IOLoginDataSave::savePlayerKills(const std::shared_ptr<Player> &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;
Expand All @@ -391,7 +390,7 @@ bool IOLoginDataSave::savePlayerBestiarySystem(const std::shared_ptr<Player> &pl
return false;
}

Database& db = Database::getInstance();
Database &db = Database::getInstance();

PropWriteStream propBestiaryStream;
for (const auto &trackedType : player->getCyclopediaMonsterTrackerSet(false)) {
Expand Down Expand Up @@ -508,7 +507,6 @@ bool IOLoginDataSave::savePlayerDepotItems(const std::shared_ptr<Player> &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;
Expand Down Expand Up @@ -552,7 +550,6 @@ bool IOLoginDataSave::saveRewardItems(const std::shared_ptr<Player> &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;
Expand Down Expand Up @@ -588,7 +585,6 @@ bool IOLoginDataSave::savePlayerInbox(const std::shared_ptr<Player> &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;
Expand All @@ -611,10 +607,10 @@ bool IOLoginDataSave::savePlayerPreyClass(const std::shared_ptr<Player> &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++) {
Expand Down Expand Up @@ -659,10 +655,10 @@ bool IOLoginDataSave::savePlayerTaskHuntingClass(const std::shared_ptr<Player> &

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++) {
Expand Down Expand Up @@ -706,7 +702,7 @@ bool IOLoginDataSave::savePlayerBosstiary(const std::shared_ptr<Player> &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
Expand Down

0 comments on commit d236ea6

Please sign in to comment.