diff --git a/src/canary_server.cpp b/src/canary_server.cpp index 0961bc93fde..c40534deb89 100644 --- a/src/canary_server.cpp +++ b/src/canary_server.cpp @@ -389,4 +389,5 @@ void CanaryServer::shutdown() { g_dispatcher().shutdown(); g_metrics().shutdown(); inject().shutdown(); + std::exit(0); } diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 92285c2bca6..516ed7b5cfa 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -6910,8 +6910,9 @@ std::shared_ptr Player::getItemFromDepotSearch(uint16_t itemId, const Posi return nullptr; } -std::pair>, std::map>> Player::requestLockerItems(std::shared_ptr depotLocker, bool sendToClient /*= false*/, uint8_t tier /*= 0*/) const { - if (depotLocker == nullptr) { +std::pair>, std::map>> +Player::requestLockerItems(std::shared_ptr depotLocker, bool sendToClient /*= false*/, uint8_t tier /*= 0*/) const { + if (!depotLocker) { g_logger().error("{} - Depot locker is nullptr", __FUNCTION__); return {}; } @@ -6920,24 +6921,18 @@ std::pair>, std::map> itemVector; std::vector> containers { depotLocker }; - size_t size = 0; - do { - std::shared_ptr container = containers[size]; - size++; + for (size_t i = 0; i < containers.size(); ++i) { + std::shared_ptr container = containers[i]; - for (std::shared_ptr item : container->getItemList()) { + for (const auto &item : container->getItemList()) { std::shared_ptr lockerContainers = item->getContainer(); if (lockerContainers && !lockerContainers->empty()) { containers.push_back(lockerContainers); continue; } - if (item->isStoreItem()) { - continue; - } - const ItemType &itemType = Item::items[item->getID()]; - if (itemType.wareId == 0) { + if (item->isStoreItem() || itemType.wareId == 0) { continue; } @@ -6945,37 +6940,24 @@ std::pair>, std::maphasMarketAttributes()) { - continue; - } - - if (!sendToClient && item->getTier() != tier) { + if (!item->hasMarketAttributes() || (!sendToClient && item->getTier() != tier)) { continue; } - (lockerItems[itemType.wareId])[item->getTier()] += Item::countByType(item, -1); + lockerItems[itemType.wareId][item->getTier()] += Item::countByType(item, -1); itemVector.push_back(item); } - } while (size < containers.size()); - StashItemList stashToSend = getStashItems(); - uint32_t countSize = 0; - for (auto [itemId, itemCount] : stashToSend) { - countSize += itemCount; } - do { - for (auto [itemId, itemCount] : stashToSend) { - const ItemType &itemType = Item::items[itemId]; - if (itemType.wareId == 0) { - continue; - } - - countSize = countSize - itemCount; - (lockerItems[itemType.wareId])[0] += itemCount; + StashItemList stashToSend = getStashItems(); + for (const auto &[itemId, itemCount] : stashToSend) { + const ItemType &itemType = Item::items[itemId]; + if (itemType.wareId != 0) { + lockerItems[itemType.wareId][0] += itemCount; } - } while (countSize > 0); + } - return std::make_pair(itemVector, lockerItems); + return { itemVector, lockerItems }; } std::pair>, uint16_t> Player::getLockerItemsAndCountById(const std::shared_ptr &depotLocker, uint8_t tier, uint16_t itemId) { diff --git a/src/lib/thread/thread_pool.cpp b/src/lib/thread/thread_pool.cpp index e01028810bc..3971d3a6a02 100644 --- a/src/lib/thread/thread_pool.cpp +++ b/src/lib/thread/thread_pool.cpp @@ -8,7 +8,10 @@ */ #include "pch.hpp" + #include "lib/thread/thread_pool.hpp" + +#include "game/game.hpp" #include "utils/tools.hpp" #ifndef DEFAULT_NUMBER_OF_THREADS @@ -65,7 +68,6 @@ void ThreadPool::shutdown() { while (status == std::future_status::timeout && std::chrono::steady_clock::now() - start < timeout) { tries++; if (tries > 5) { - logger.error("Thread pool shutdown timed out."); break; } for (auto &future : futures) { @@ -84,7 +86,9 @@ asio::io_context &ThreadPool::getIoContext() { void ThreadPool::addLoad(const std::function &load) { asio::post(ioService, [this, load]() { if (ioService.stopped()) { - logger.error("Shutting down, cannot execute task."); + if (g_game().getGameState() != GAME_STATE_SHUTDOWN) { + logger.error("Shutting down, cannot execute task."); + } return; }