From 11bd3a689c69d163491dc8667cc2ec29b49fd293 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Tue, 24 Sep 2024 21:37:48 -0300 Subject: [PATCH 1/6] fix: forge correct slots (#2850) Resolves #2718 --- src/server/network/protocol/protocolgame.cpp | 40 ++++++++++++++------ 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 909eef1e92e..7ae02e31b10 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -5370,7 +5370,8 @@ void ProtocolGame::sendForgingData() { void ProtocolGame::sendOpenForge() { // We will use it when sending the bytes to send the item information to the client std::map> fusionItemsMap; - std::map>> convergenceItemsMap; + std::map>> convergenceFusionItemsMap; + std::map>> convergenceTransferItemsMap; std::map> donorTierItemMap; std::map> receiveTierItemMap; @@ -5405,7 +5406,12 @@ void ProtocolGame::sendOpenForge() { getForgeInfoMap(item, receiveTierItemMap); } if (itemClassification == 4) { - getForgeInfoMap(item, convergenceItemsMap[item->getClassification()]); + auto slotPosition = item->getSlotPosition(); + if ((slotPosition & SLOTP_TWO_HAND) != 0) { + slotPosition = SLOTP_HAND; + } + getForgeInfoMap(item, convergenceFusionItemsMap[slotPosition]); + getForgeInfoMap(item, convergenceTransferItemsMap[item->getClassification()]); } } } @@ -5413,7 +5419,7 @@ void ProtocolGame::sendOpenForge() { // Checking size of map to send in the addByte (total fusion items count) uint8_t fusionTotalItemsCount = 0; for (const auto &[itemId, tierAndCountMap] : fusionItemsMap) { - for (const auto [itemTier, itemCount] : tierAndCountMap) { + for (const auto &[itemTier, itemCount] : tierAndCountMap) { if (itemCount >= 2) { fusionTotalItemsCount++; } @@ -5430,7 +5436,7 @@ void ProtocolGame::sendOpenForge() { msg.add(fusionTotalItemsCount); for (const auto &[itemId, tierAndCountMap] : fusionItemsMap) { - for (const auto [itemTier, itemCount] : tierAndCountMap) { + for (const auto &[itemTier, itemCount] : tierAndCountMap) { if (itemCount >= 2) { msg.addByte(0x01); // Number of friend items? msg.add(itemId); @@ -5452,12 +5458,12 @@ void ProtocolGame::sendOpenForge() { 1 byte: tier 2 bytes: count */ - for (const auto &[slot, itemMap] : convergenceItemsMap) { + for (const auto &[slot, itemMap] : convergenceFusionItemsMap) { uint8_t totalItemsCount = 0; auto totalItemsCountPosition = msg.getBufferPosition(); msg.skipBytes(1); // Total items count for (const auto &[itemId, tierAndCountMap] : itemMap) { - for (const auto [tier, itemCount] : tierAndCountMap) { + for (const auto &[tier, itemCount] : tierAndCountMap) { if (tier >= maxConfigTier) { continue; } @@ -5488,11 +5494,15 @@ void ProtocolGame::sendOpenForge() { // Let's access the itemType to check the item's (donator of tier) classification level // Must be the same as the item that will receive the tier const ItemType &donorType = Item::items[itemId]; + auto donorSlotPosition = donorType.slotPosition; + if ((donorSlotPosition & SLOTP_TWO_HAND) != 0) { + donorSlotPosition = SLOTP_HAND; + } // Total count of item (donator of tier) auto donorTierTotalItemsCount = getIterationIncreaseCount(tierAndCountMap); msg.add(donorTierTotalItemsCount); - for (const auto [donorItemTier, donorItemCount] : tierAndCountMap) { + for (const auto &[donorItemTier, donorItemCount] : tierAndCountMap) { msg.add(itemId); msg.addByte(donorItemTier); msg.add(donorItemCount); @@ -5502,7 +5512,11 @@ void ProtocolGame::sendOpenForge() { for (const auto &[iteratorItemId, unusedTierAndCountMap] : receiveTierItemMap) { // Let's access the itemType to check the item's (receiver of tier) classification level const ItemType &receiveType = Item::items[iteratorItemId]; - if (donorType.upgradeClassification == receiveType.upgradeClassification) { + auto receiveSlotPosition = receiveType.slotPosition; + if ((receiveSlotPosition & SLOTP_TWO_HAND) != 0) { + receiveSlotPosition = SLOTP_HAND; + } + if (donorType.upgradeClassification == receiveType.upgradeClassification && donorSlotPosition == receiveSlotPosition) { receiveTierTotalItemCount++; } } @@ -5513,8 +5527,12 @@ void ProtocolGame::sendOpenForge() { for (const auto &[receiveItemId, receiveTierAndCountMap] : receiveTierItemMap) { // Let's access the itemType to check the item's (receiver of tier) classification level const ItemType &receiveType = Item::items[receiveItemId]; - if (donorType.upgradeClassification == receiveType.upgradeClassification) { - for (const auto [receiveItemTier, receiveItemCount] : receiveTierAndCountMap) { + auto receiveSlotPosition = receiveType.slotPosition; + if ((receiveSlotPosition & SLOTP_TWO_HAND) != 0) { + receiveSlotPosition = SLOTP_HAND; + } + if (donorType.upgradeClassification == receiveType.upgradeClassification && donorSlotPosition == receiveSlotPosition) { + for (const auto &[receiveItemTier, receiveItemCount] : receiveTierAndCountMap) { msg.add(receiveItemId); msg.add(receiveItemCount); } @@ -5540,7 +5558,7 @@ void ProtocolGame::sendOpenForge() { 2 bytes: item id 2 bytes: count */ - for (const auto &[slot, itemMap] : convergenceItemsMap) { + for (const auto &[slot, itemMap] : convergenceTransferItemsMap) { uint16_t donorCount = 0; uint16_t receiverCount = 0; auto donorCountPosition = msg.getBufferPosition(); From edeff040b4f058e66c1eb91100ad64da65ecf424 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Fri, 27 Sep 2024 23:46:00 -0300 Subject: [PATCH 2/6] fix: convergence wrong price calculation (#2918) Resolves #2523 --- src/creatures/players/player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 8c49226b621..f9fafee1f14 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -7213,7 +7213,7 @@ void Player::forgeFuseItems(ForgeAction_t actionType, uint16_t firstItemId, uint } for (const auto &[mapTier, mapPrice] : itemClassification->tiers) { - if (mapTier == firstForgingItem->getTier()) { + if (mapTier == firstForgingItem->getTier() + 1) { cost = mapPrice.convergenceFusionPrice; break; } From 09c16ff620b2cd9cfd5a25af97f493aa2c8ad9bf Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Fri, 27 Sep 2024 23:47:15 -0300 Subject: [PATCH 3/6] fix: can't sell containers with items inside (#2911) # Description It will not be possible to sell backpacks that contain items inside. --- src/creatures/npcs/npc.cpp | 7 +++++++ src/creatures/players/player.cpp | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index 6d38524aef3..05f22780ada 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -387,6 +387,13 @@ void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint continue; } + if (const auto &container = item->getContainer()) { + if (container->size() > 0) { + player->sendTextMessage(MESSAGE_EVENT_ADVANCE, "You must empty the container before selling it."); + continue; + } + } + if (parent && item->getParent() != parent) { continue; } diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index f9fafee1f14..b923dd952d2 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -4120,6 +4120,12 @@ std::map &Player::getAllItemTypeCount(std::map &Player::getAllSaleItemIdAndCount(std::map &countMap) const { for (const auto &item : getAllInventoryItems(false, true)) { + if (const auto &container = item->getContainer()) { + if (container->size() > 0) { + continue; + } + } + countMap[item->getID()] += item->getItemCount(); } From 04fa24813d097bd48d0d1b84377526596972ec7a Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Sat, 28 Sep 2024 22:45:51 -0300 Subject: [PATCH 4/6] refactor: replace C-style array with std::array for buffer management (#2914) Refactored buffer management by replacing C-style arrays with std::array in the NetworkMessage and OutputMessage classes. This change enhances memory safety by providing compile-time size checks and prevents buffer overflows through safer access methods. Transitioned all instances of memcpy to std::ranges::copy and replaced memset with std::fill for improved readability and type safety. Removed the use of reinterpret_cast for safer type conversions. Introduced enhanced logging using std::source_location and added an optional function parameter to the addString and getString functions, providing better contextual information for both C++ and Lua scripts. Fixed a bug in the decodeHeader function and added corresponding unit tests to validate the fix. This update addresses potential buffer overflow issues, improves code clarity, and enhances debugging capabilities. It also includes integration tests to ensure the correct behavior of buffer management under various conditions, such as large message handling and stress testing. The changes aim to modernize the codebase, reduce manual memory management risks, and align the implementation with modern C++ best practices. --- .../monsters/spawns/spawn_monster.hpp | 14 +- src/creatures/players/player.cpp | 2 +- .../network/network_message_functions.cpp | 2 +- src/map/utils/astarnodes.cpp | 22 +- src/pch.hpp | 2 + src/server/network/message/networkmessage.cpp | 249 +++++++++++- src/server/network/message/networkmessage.hpp | 150 ++++---- src/server/network/message/outputmessage.hpp | 24 +- src/server/network/protocol/protocolgame.cpp | 358 +++++++++--------- src/server/network/protocol/protocolgame.hpp | 2 +- src/server/network/protocol/protocollogin.cpp | 12 +- .../network/protocol/protocolstatus.cpp | 28 +- src/utils/const.hpp | 2 + tests/build_and_run.sh | 12 +- tests/unit/CMakeLists.txt | 1 + tests/unit/server/CMakeLists.txt | 3 + .../network/message/networkmessage_test.cpp | 144 +++++++ 17 files changed, 698 insertions(+), 329 deletions(-) create mode 100644 tests/unit/server/CMakeLists.txt create mode 100644 tests/unit/server/network/message/networkmessage_test.cpp diff --git a/src/creatures/monsters/spawns/spawn_monster.hpp b/src/creatures/monsters/spawns/spawn_monster.hpp index 81a08973cb7..caf454c41b5 100644 --- a/src/creatures/monsters/spawns/spawn_monster.hpp +++ b/src/creatures/monsters/spawns/spawn_monster.hpp @@ -38,9 +38,12 @@ class SpawnMonster { // moveable SpawnMonster(SpawnMonster &&rhs) noexcept : - spawnMonsterMap(std::move(rhs.spawnMonsterMap)), spawnedMonsterMap(std::move(rhs.spawnedMonsterMap)), - checkSpawnMonsterEvent(rhs.checkSpawnMonsterEvent), centerPos(rhs.centerPos), radius(rhs.radius), interval(rhs.interval) { } + spawnMonsterMap(std::move(rhs.spawnMonsterMap)), + centerPos(rhs.centerPos), + radius(rhs.radius), + interval(rhs.interval), + checkSpawnMonsterEvent(rhs.checkSpawnMonsterEvent) { } SpawnMonster &operator=(SpawnMonster &&rhs) noexcept { if (this != &rhs) { @@ -77,15 +80,12 @@ class SpawnMonster { void setMonsterVariant(const std::string &variant); private: - // map of the spawned creatures + // The map of the spawned creatures std::map> spawnedMonsterMap; - - // map of creatures in the spawn + // The map of creatures in the spawn std::map spawnMonsterMap; - Position centerPos; int32_t radius; - uint32_t interval = 30000; uint32_t checkSpawnMonsterEvent = 0; diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index b923dd952d2..e3790583eff 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -5575,7 +5575,7 @@ int32_t Player::getMagicShieldCapacityPercent(bool useCharges) const { double_t Player::getReflectPercent(CombatType_t combat, bool useCharges) const { double_t result = reflectPercent[combatTypeToIndex(combat)]; - for (const auto item : getEquippedItems()) { + for (const auto &item : getEquippedItems()) { const ItemType &itemType = Item::items[item->getID()]; if (!itemType.abilities) { continue; diff --git a/src/lua/functions/core/network/network_message_functions.cpp b/src/lua/functions/core/network/network_message_functions.cpp index a1b66264fac..e2f4013448d 100644 --- a/src/lua/functions/core/network/network_message_functions.cpp +++ b/src/lua/functions/core/network/network_message_functions.cpp @@ -196,7 +196,7 @@ int NetworkMessageFunctions::luaNetworkMessageAddString(lua_State* L) { const std::string &function = getString(L, 3); const auto &message = getUserdataShared(L, 1); if (message) { - message->addString(string, function); + message->addString(string, std::source_location::current(), function); pushBoolean(L, true); } else { lua_pushnil(L); diff --git a/src/map/utils/astarnodes.cpp b/src/map/utils/astarnodes.cpp index 21ebe5f982f..e7c5b7ce48e 100644 --- a/src/map/utils/astarnodes.cpp +++ b/src/map/utils/astarnodes.cpp @@ -14,7 +14,21 @@ #include "creatures/combat/combat.hpp" AStarNodes::AStarNodes(uint32_t x, uint32_t y, int_fast32_t extraCost) : - openNodes(), nodes() { +#if defined(__AVX2__) || defined(__SSE2__) + nodesTable(), // 1. nodesTable + calculatedNodes(), // 2. calculatedNodes + nodes(), // 3. nodes + closedNodes(0), // 4. closedNodes + curNode(0), // 5. curNode + openNodes() // 6. openNodes +#else + nodes(), // 1. nodes + nodesTable(), // 2. nodesTable + closedNodes(0), // 3. closedNodes + curNode(0), // 4. curNode + openNodes() // 5. openNodes +#endif +{ #if defined(__AVX2__) __m256i defaultCost = _mm256_set1_epi32(std::numeric_limits::max()); for (int32_t i = 0; i < MAX_NODES; i += 32) { @@ -47,7 +61,7 @@ AStarNodes::AStarNodes(uint32_t x, uint32_t y, int_fast32_t extraCost) : startNode.g = 0; startNode.c = extraCost; nodesTable[0] = (x << 16) | y; -#if defined(__SSE2__) +#if defined(__SSE2__) || defined(__AVX2__) calculatedNodes[0] = 0; #endif } @@ -265,9 +279,9 @@ int_fast32_t AStarNodes::getMapWalkCost(AStarNode* node, const Position &neighbo int_fast32_t AStarNodes::getTileWalkCost(const std::shared_ptr &creature, const std::shared_ptr &tile) { int_fast32_t cost = 0; - if (creature) { + if (creature && tile) { + // Destroy creature cost if (tile->getTopVisibleCreature(creature) != nullptr) { - // destroy creature cost cost += MAP_NORMALWALKCOST * 4; } if (const auto &field = tile->getFieldItem()) { diff --git a/src/pch.hpp b/src/pch.hpp index e69c27016a4..ea3c9cd2e73 100644 --- a/src/pch.hpp +++ b/src/pch.hpp @@ -46,6 +46,8 @@ #include #include #include +#include +#include // -------------------- // System Includes diff --git a/src/server/network/message/networkmessage.cpp b/src/server/network/message/networkmessage.cpp index 38acc0b484c..d8cb599a07c 100644 --- a/src/server/network/message/networkmessage.cpp +++ b/src/server/network/message/networkmessage.cpp @@ -13,23 +13,101 @@ #include "items/containers/container.hpp" int32_t NetworkMessage::decodeHeader() { - int32_t newSize = buffer[0] | buffer[1] << 8; - info.length = newSize; - return info.length; + // Ensure there are enough bytes to read the header (2 bytes) + if (!canRead(2)) { + g_logger().error("[{}] Not enough data to decode header. Current position: {}, Length: {}", __FUNCTION__, info.position, info.length); + return {}; + } + + // Log the current position and buffer content before decoding + g_logger().debug("[{}] Decoding header at position: {}", __FUNCTION__, info.position); + g_logger().debug("[{}] Buffer content: ", __FUNCTION__); + + // Log only up to 10 bytes of the buffer or until the end of the buffer + for (size_t i = 0; i < 10 && i < buffer.size(); ++i) { + g_logger().debug("[{}] Buffer[{}]: {}", __FUNCTION__, i, buffer[i]); + } + + // Check if there are enough bytes in the buffer for the header + if (info.position + 1 < buffer.size()) { + // Create a span view for safety + std::span bufferSpan(buffer.data(), buffer.size()); + auto decodedHeader = bufferSpan[info.position] | (bufferSpan[info.position + 1] << 8); + // Update position after reading the header + info.position += sizeof(decodedHeader); + return decodedHeader; + } else { + g_logger().warn("Index out of bounds when trying to access buffer with position: {}", info.position); + } + + // Handle buffer overflow error here + g_logger().error("[{}] attempted to read beyond buffer limits at position: {}", __FUNCTION__, info.position); + return {}; +} + +// Simply read functions for incoming message +uint8_t NetworkMessage::getByte() { + // Check if there is at least 1 byte to read + if (!canRead(1)) { + g_logger().error("[{}] Not enough data to read a byte. Current position: {}, Length: {}", __FUNCTION__, info.position, info.length); + return {}; + } + + // Ensure that position is within bounds before decrementing + if (info.position == 0) { + g_logger().error("[{}] Position is at the beginning of the buffer. Cannot decrement.", __FUNCTION__); + return {}; + } + + try { + // Decrement position safely and return the byte + return buffer.at(info.position++); + } catch (const std::out_of_range &e) { + g_logger().error("[{}] Out of range error: {}. Position: {}, Buffer size: {}", __FUNCTION__, e.what(), info.position, buffer.size()); + } + + return {}; +} + +uint8_t NetworkMessage::getPreviousByte() { + // Check if position is at the beginning of the buffer + if (info.position == 0) { + g_logger().error("[{}] Attempted to get previous byte at position 0", __FUNCTION__); + return {}; // Return default value (0) when at the start of the buffer + } + + try { + // Safely decrement position and access the previous byte using 'at()' + return buffer.at(--info.position); + } catch (const std::out_of_range &e) { + // Log the out-of-range exception if accessing outside buffer limits + g_logger().error("[{}] Out of range error: {}. Position: {}, Buffer size: {}", __FUNCTION__, e.what(), info.position, buffer.size()); + } + + return {}; } -std::string NetworkMessage::getString(uint16_t stringLen /* = 0*/) { +std::string NetworkMessage::getString(uint16_t stringLen /* = 0*/, const std::source_location &location) { if (stringLen == 0) { stringLen = get(); } if (!canRead(stringLen)) { - return std::string(); + g_logger().error("[{}] not enough data to read string of length: {}. Called line {}:{} in {}", __FUNCTION__, stringLen, location.line(), location.column(), location.function_name()); + return {}; } - char* v = reinterpret_cast(buffer) + info.position; // does not break strict aliasing + if (stringLen > NETWORKMESSAGE_MAXSIZE) { + g_logger().error("[{}] exceded NetworkMessage max size: {}, actually size: {}. Called line '{}:{}' in '{}'", __FUNCTION__, NETWORKMESSAGE_MAXSIZE, stringLen, location.line(), location.column(), location.function_name()); + return {}; + } + + g_logger().trace("[{}] called line '{}:{}' in '{}'", __FUNCTION__, location.line(), location.column(), location.function_name()); + + // Copy the string from the buffer + std::string result(buffer.begin() + info.position, buffer.begin() + info.position + stringLen); info.position += stringLen; - return std::string(v, stringLen); + return result; } Position NetworkMessage::getPosition() { @@ -40,29 +118,85 @@ Position NetworkMessage::getPosition() { return pos; } -void NetworkMessage::addString(const std::string &value, const std::string &function /* = ""*/) { +// Skips count unknown/unused bytes in an incoming message +void NetworkMessage::skipBytes(int16_t count) { + info.position += count; +} + +void NetworkMessage::addString(const std::string &value, const std::source_location &location /*= std::source_location::current()*/, const std::string &function /* = ""*/) { size_t stringLen = value.length(); - if (value.empty() && !function.empty()) { - g_logger().debug("[NetworkMessage::addString] - Value string is empty, function '{}'", function); + if (value.empty()) { + if (!function.empty()) { + g_logger().debug("[{}] attempted to add an empty string. Called line '{}'", __FUNCTION__, function); + } else { + g_logger().debug("[{}] attempted to add an empty string. Called line '{}:{}' in '{}'", __FUNCTION__, location.line(), location.column(), location.function_name()); + } + + // Add a 0 length string, the std::array will be filled with 0s + add(uint16_t()); + return; } if (!canAdd(stringLen + 2)) { - g_logger().error("[NetworkMessage::addString] - NetworkMessage size is wrong: {}, function '{}'", stringLen, function); + if (!function.empty()) { + g_logger().error("[{}] NetworkMessage size is wrong: {}. Called line '{}'", __FUNCTION__, stringLen, function); + } else { + g_logger().error("[{}] NetworkMessage size is wrong: {}. Called line '{}:{}' in '{}'", __FUNCTION__, stringLen, location.line(), location.column(), location.function_name()); + } return; } if (stringLen > NETWORKMESSAGE_MAXSIZE) { - g_logger().error("[NetworkMessage::addString] - Exceded NetworkMessage max size: {}, actually size: {}, function '{}'", NETWORKMESSAGE_MAXSIZE, stringLen, function); + if (!function.empty()) { + g_logger().error("[{}] exceeded NetworkMessage max size: {}, actual size: {}. Called line '{}'", __FUNCTION__, NETWORKMESSAGE_MAXSIZE, stringLen, function); + } else { + g_logger().error("[{}] exceeded NetworkMessage max size: {}, actual size: {}. Called line '{}:{}' in '{}'", __FUNCTION__, NETWORKMESSAGE_MAXSIZE, stringLen, location.line(), location.column(), location.function_name()); + } return; } - add(stringLen); - memcpy(buffer + info.position, value.c_str(), stringLen); + if (!function.empty()) { + g_logger().trace("[{}] called line '{}'", __FUNCTION__, function); + } else { + g_logger().trace("[{}] called line '{}:{}' in '{}'", __FUNCTION__, location.line(), location.column(), location.function_name()); + } + + auto len = static_cast(stringLen); + add(len); + // Using to copy the string into the buffer + auto it = std::ranges::copy(value, buffer.begin() + info.position); + g_logger().trace("First value copied from sourceSpan: {}, second value copied from sourceSpan: {}", *it.in, *it.out); info.position += stringLen; info.length += stringLen; } -void NetworkMessage::addDouble(double value, uint8_t precision /* = 2*/) { +void NetworkMessage::addDouble(double value, uint8_t precision /*= 2*/) { addByte(precision); - add((value * std::pow(static_cast(10), precision)) + std::numeric_limits::max()); + add((value * std::pow(static_cast(SCALING_BASE), precision)) + std::numeric_limits::max()); +} + +double NetworkMessage::getDouble() { + // Retrieve the precision byte from the buffer + uint8_t precision = getByte(); + // Retrieve the scaled uint32_t value from the buffer + auto scaledValue = get(); + // Convert the scaled value back to double using the precision factor + double adjustedValue = static_cast(scaledValue) - static_cast(std::numeric_limits::max()); + // Convert back to the original double value using the precision factor + return adjustedValue / std::pow(static_cast(SCALING_BASE), precision); +} + +void NetworkMessage::addByte(uint8_t value, std::source_location location /*= std::source_location::current()*/) { + if (!canAdd(1)) { + g_logger().error("[{}] cannot add byte, buffer overflow. Called line '{}:{}' in '{}'", __FUNCTION__, location.line(), location.column(), location.function_name()); + return; + } + + g_logger().trace("[{}] called line '{}:{}' in '{}'", __FUNCTION__, location.line(), location.column(), location.function_name()); + try { + buffer.at(info.position++) = value; + info.length++; + } catch (const std::out_of_range &e) { + g_logger().error("[{}] buffer access out of range: {}. Called line '{}:{}' in '{}'", __FUNCTION__, e.what(), location.line(), location.column(), location.function_name()); + } } void NetworkMessage::addBytes(const char* bytes, size_t size) { @@ -79,19 +213,20 @@ void NetworkMessage::addBytes(const char* bytes, size_t size) { return; } - memcpy(buffer + info.position, bytes, size); + auto it = std::ranges::copy(bytes, bytes + size, buffer.begin() + info.position); + g_logger().trace("First value copied from sourceSpan: {}, second value copied from sourceSpan: {}", *it.in, *it.out); info.position += size; info.length += size; } void NetworkMessage::addPaddingBytes(size_t n) { -#define canAdd(size) ((size + info.position) < NETWORKMESSAGE_MAXSIZE) if (!canAdd(n)) { + g_logger().error("[NetworkMessage::addPaddingBytes] - Cannot add padding bytes, buffer overflow"); return; } -#undef canAdd - memset(buffer + info.position, 0x33, n); + std::fill(buffer.begin() + info.position, buffer.begin() + info.position + n, 0x33); + info.position += n; info.length += n; } @@ -100,3 +235,77 @@ void NetworkMessage::addPosition(const Position &pos) { add(pos.y); addByte(pos.z); } + +NetworkMessage::MsgSize_t NetworkMessage::getLength() const { + return info.length; +} + +void NetworkMessage::setLength(NetworkMessage::MsgSize_t newLength) { + info.length = newLength; +} + +NetworkMessage::MsgSize_t NetworkMessage::getBufferPosition() const { + return info.position; +} + +void NetworkMessage::setBufferPosition(NetworkMessage::MsgSize_t newPosition) { + info.position = newPosition; +} + +uint16_t NetworkMessage::getLengthHeader() const { + return static_cast(buffer[0] | buffer[1] << 8); +} + +bool NetworkMessage::isOverrun() const { + return info.overrun; +} + +uint8_t* NetworkMessage::getBuffer() { + return buffer.data(); +} + +const uint8_t* NetworkMessage::getBuffer() const { + return buffer.data(); +} + +uint8_t* NetworkMessage::getBodyBuffer() { + info.position = 2; + // Return the pointer to the body of the buffer starting after the header + // Convert HEADER_LENGTH to uintptr_t to ensure safe pointer arithmetic with enum type + return buffer.data() + static_cast(HEADER_LENGTH); +} + +bool NetworkMessage::canAdd(size_t size) const { + return (size + info.position) < MAX_BODY_LENGTH; +} + +bool NetworkMessage::canRead(int32_t size) const { + return size <= (info.length - (info.position - INITIAL_BUFFER_POSITION)); +} + +void NetworkMessage::append(const NetworkMessage &other) { + size_t otherLength = other.getLength(); + size_t otherStartPos = NetworkMessage::INITIAL_BUFFER_POSITION; // Always start copying from the initial buffer position + + g_logger().debug("[{}] appending message, other Length = {}, current length = {}, current position = {}, other start position = {}", __FUNCTION__, otherLength, info.length, info.position, otherStartPos); + + // Ensure there is enough space in the buffer to append the new data + if (!canAdd(otherLength)) { + std::cerr << "Cannot append message: not enough space in buffer.\n"; + return; + } + + // Create a span for the source data (from the other message) + std::span sourceSpan(other.getBuffer() + otherStartPos, otherLength); + // Create a span for the destination in the current buffer + std::span destSpan(buffer.data() + info.position, otherLength); + // Copy the data from the source span to the destination span + auto it = std::ranges::copy(sourceSpan, destSpan.begin()); + g_logger().trace("First value copied from sourceSpan: {}, second value copied from sourceSpan: {}", *it.in, *it.out); + + // Update the buffer information + info.length += otherLength; + info.position += otherLength; + // Debugging output after appending + g_logger().debug("After append: New Length = {}, New Position = {}", info.length, info.position); +} diff --git a/src/server/network/message/networkmessage.hpp b/src/server/network/message/networkmessage.hpp index 02e19253146..1889b7725b6 100644 --- a/src/server/network/message/networkmessage.hpp +++ b/src/server/network/message/networkmessage.hpp @@ -27,62 +27,64 @@ class NetworkMessage { // 2 bytes for encrypted message size static constexpr MsgSize_t INITIAL_BUFFER_POSITION = 8; - NetworkMessage() = default; + int32_t decodeHeader(); void reset() { info = {}; } // simply read functions for incoming message - uint8_t getByte() { - if (!canRead(1)) { - return 0; - } - - return buffer[info.position++]; - } + uint8_t getByte(); - uint8_t getPreviousByte() { - return buffer[--info.position]; - } + uint8_t getPreviousByte(); template T get() { + static_assert(!std::is_same_v, "Error: get() is not allowed. Use getDouble() instead."); + static_assert(std::is_trivially_copyable_v, "Type T must be trivially copyable"); if (!canRead(sizeof(T))) { - return 0; + return T(); } - T v; - memcpy(&v, buffer + info.position, sizeof(T)); + // Create a temporary byte array to store the value read from the buffer. + std::array tempBuffer; + // Copy data from the buffer to the temporary array + std::span sourceSpan(buffer.data() + info.position, sizeof(T)); + auto it = std::ranges::copy(sourceSpan, tempBuffer.begin()); + g_logger().trace("First value copied from sourceSpan: {}, second value copied from sourceSpan: {}", *it.in, *it.out); + // Update the read position in the buffer info.position += sizeof(T); - return v; + // Convert the byte array to type T using std::bit_cast and return the result + return std::bit_cast(tempBuffer); } - std::string getString(uint16_t stringLen = 0); + std::string getString(uint16_t stringLen = 0, const std::source_location &location = std::source_location::current()); Position getPosition(); // skips count unknown/unused bytes in an incoming message - void skipBytes(int16_t count) { - info.position += count; - } + void skipBytes(int16_t count); // simply write functions for outgoing message - void addByte(uint8_t value) { - if (!canAdd(1)) { - return; - } - - buffer[info.position++] = value; - info.length++; - } + void addByte(uint8_t value, std::source_location location = std::source_location::current()); template - void add(T value) { + void add(T value, std::source_location location = std::source_location::current()) { if (!canAdd(sizeof(T))) { + g_logger().error("Cannot add value of size {}, buffer overflow", sizeof(T)); return; } - memcpy(buffer + info.position, &value, sizeof(T)); + g_logger().trace("[{}] called line '{}:{}' in '{}'", __FUNCTION__, location.line(), location.column(), location.function_name()); + + // Ensure that T is trivially copyable + static_assert(std::is_trivially_copyable_v, "Type T must be trivially copyable"); + // Convert the value to an array of unsigned char using std::bit_cast + auto byteArray = std::bit_cast>(value); + // Create a span from the byte array + std::span byteSpan(byteArray); + // Copy the bytes into the buffer + auto it = std::ranges::copy(byteSpan.begin(), byteSpan.end(), buffer.begin() + info.position); + g_logger().trace("First value copied from sourceSpan: {}, second value copied from sourceSpan: {}", *it.in, *it.out); info.position += sizeof(T); info.length += sizeof(T); } @@ -94,74 +96,66 @@ class NetworkMessage { * Adds a string to the network message buffer. * * @param value The string value to be added to the message buffer. - * @param function * @param function An optional parameter that specifies the function name from which `addString` is invoked. - * Including this enhances logging by adding the function name to the debug and error log messages. - * This helps in debugging by indicating the context when issues occur, such as attempting to add an - * empty string or when there are message size errors. * - * When the function parameter is used, it aids in identifying the context in log messages, - * making it easier to diagnose issues related to network message construction, - * especially in complex systems where the same method might be called from multiple places. + * @param location An optional parameter that captures the location from which `addString` is invoked. + * This enhances logging by including the file name, line number, and function name + * in debug and error log messages. It helps in debugging by indicating the context when issues occur, + * such as attempting to add an empty string or when there are message size errors. + * + * Using `std::source_location` automatically captures the caller context, making it easier + * to diagnose issues related to network message construction, especially in complex systems + * where the same method might be called from multiple places. + * + * @param function An optional string parameter provided from Lua that specifies the name of the Lua + * function or context from which `addString` is called. When this parameter is not empty, + * it overrides the information captured by `std::source_location` in log messages. + * This allows for more precise and meaningful logging in scenarios where `addString` is invoked + * directly from Lua scripts, enabling developers to trace the origin of network messages + * back to specific Lua functions or contexts. + * + * This dual-parameter approach ensures flexibility: + * - When called from C++ without specifying `function`, `std::source_location` provides the necessary + * context for logging. + * - When called from Lua with a `function` name, the provided string offers clearer insight into + * the Lua-side invocation, enhancing the ability to debug and maintain Lua-C++ integrations. + * + * @note It is recommended to use the `function` parameter when invoking `addString` from Lua to ensure + * that log messages accurately reflect the Lua context. When invoking from C++, omitting the `function` + * parameter allows `std::source_location` to automatically capture the C++ context. */ - void addString(const std::string &value, const std::string &function = ""); + void addString(const std::string &value, const std::source_location &location = std::source_location::current(), const std::string &function = ""); void addDouble(double value, uint8_t precision = 2); + double getDouble(); // write functions for complex types void addPosition(const Position &pos); - MsgSize_t getLength() const { - return info.length; - } + MsgSize_t getLength() const; - void setLength(MsgSize_t newLength) { - info.length = newLength; - } + void setLength(MsgSize_t newLength); - MsgSize_t getBufferPosition() const { - return info.position; - } + MsgSize_t getBufferPosition() const; - void setBufferPosition(MsgSize_t newPosition) { - info.position = newPosition; - } + void setBufferPosition(MsgSize_t newPosition); - uint16_t getLengthHeader() const { - return static_cast(buffer[0] | buffer[1] << 8); - } + uint16_t getLengthHeader() const; - int32_t decodeHeader(); + bool isOverrun() const; - bool isOverrun() const { - return info.overrun; - } + uint8_t* getBuffer(); - uint8_t* getBuffer() { - return buffer; - } + const uint8_t* getBuffer() const; - const uint8_t* getBuffer() const { - return buffer; - } + uint8_t* getBodyBuffer(); - uint8_t* getBodyBuffer() { - info.position = 2; - return buffer + HEADER_LENGTH; - } + bool canAdd(size_t size) const; -protected: - bool canAdd(size_t size) const { - return (size + info.position) < MAX_BODY_LENGTH; - } + bool canRead(int32_t size) const; - bool canRead(int32_t size) { - if ((info.position + size) > (info.length + 8) || size >= (NETWORKMESSAGE_MAXSIZE - info.position)) { - info.overrun = true; - return false; - } - return true; - } + void append(const NetworkMessage &other); +protected: struct NetworkMessageInfo { MsgSize_t length = 0; MsgSize_t position = INITIAL_BUFFER_POSITION; @@ -169,5 +163,5 @@ class NetworkMessage { }; NetworkMessageInfo info; - uint8_t buffer[NETWORKMESSAGE_MAXSIZE]; + std::array buffer = {}; }; diff --git a/src/server/network/message/outputmessage.hpp b/src/server/network/message/outputmessage.hpp index 1f590fbd214..459e243cea3 100644 --- a/src/server/network/message/outputmessage.hpp +++ b/src/server/network/message/outputmessage.hpp @@ -24,7 +24,7 @@ class OutputMessage : public NetworkMessage { OutputMessage &operator=(const OutputMessage &) = delete; uint8_t* getOutputBuffer() { - return buffer + outputBufferStart; + return buffer.data() + outputBufferStart; } void writeMessageLength() { @@ -41,14 +41,18 @@ class OutputMessage : public NetworkMessage { void append(const NetworkMessage &msg) { auto msgLen = msg.getLength(); - memcpy(buffer + info.position, msg.getBuffer() + INITIAL_BUFFER_POSITION, msgLen); + std::span sourceSpan(msg.getBuffer() + INITIAL_BUFFER_POSITION, msgLen); + std::span destSpan(buffer.data() + info.position, msgLen); + std::ranges::copy(sourceSpan, destSpan.begin()); info.length += msgLen; info.position += msgLen; } void append(const OutputMessage_ptr &msg) { auto msgLen = msg->getLength(); - memcpy(buffer + info.position, msg->getBuffer() + INITIAL_BUFFER_POSITION, msgLen); + std::span sourceSpan(msg->getBuffer() + INITIAL_BUFFER_POSITION, msgLen); + std::span destSpan(buffer.data() + info.position, msgLen); + std::ranges::copy(sourceSpan, destSpan.begin()); info.length += msgLen; info.position += msgLen; } @@ -61,10 +65,20 @@ class OutputMessage : public NetworkMessage { return; } + // Ensure at runtime that outputBufferStart >= sizeof(T) assert(outputBufferStart >= sizeof(T)); + // Move the buffer position back to make space for the header outputBufferStart -= sizeof(T); - memcpy(buffer + outputBufferStart, &addHeader, sizeof(T)); - // added header size to the message size + + static_assert(std::is_trivially_copyable_v, "Type T must be trivially copyable"); + + // Convert the header to an array of unsigned char using std::bit_cast + auto byteArray = std::bit_cast>(addHeader); + + std::span byteSpan(byteArray); + // Copy the bytes into the buffer + std::ranges::copy(byteSpan, buffer.begin() + outputBufferStart); + // Update the message size info.length += sizeof(T); } diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 7ae02e31b10..560ae1168c5 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -242,7 +242,7 @@ namespace { g_logger().debug("Sendding category number '{}', category name '{}'", static_cast(value), magic_enum::enum_name(value).data()); msg.addByte(static_cast(value)); - msg.addString(toStartCaseWithSpace(magic_enum::enum_name(value).data()), "void sendContainerCategory - toStartCaseWithSpace(magic_enum::enum_name(value).data())"); + msg.addString(toStartCaseWithSpace(magic_enum::enum_name(value).data())); } } } // namespace @@ -568,7 +568,7 @@ void ProtocolGame::login(const std::string &name, uint32_t accountId, OperatingS auto output = OutputMessagePool::getOutputMessage(); output->addByte(0x16); - output->addString(ss.str(), "ProtocolGame::login - ss.str()"); + output->addString(ss.str()); output->addByte(retryTime); send(output); disconnect(); @@ -851,7 +851,7 @@ void ProtocolGame::onRecvFirstMessage(NetworkMessage &msg) { auto output = OutputMessagePool::getOutputMessage(); output->addByte(0x14); - output->addString(ss.str(), "ProtocolGame::onRecvFirstMessage - ss.str()"); + output->addString(ss.str()); send(output); g_dispatcher().scheduleEvent( 1000, [self = getThis()] { self->disconnect(); }, "ProtocolGame::disconnect" @@ -893,7 +893,7 @@ void ProtocolGame::onConnect() { void ProtocolGame::disconnectClient(const std::string &message) const { auto output = OutputMessagePool::getOutputMessage(); output->addByte(0x14); - output->addString(message, "ProtocolGame::disconnectClient - message"); + output->addString(message); send(output); disconnect(); } @@ -1317,7 +1317,7 @@ void ProtocolGame::parsePacketFromDispatcher(NetworkMessage msg, uint8_t recvbyt parseWheelGemAction(msg); break; case 0xE8: - parseDebugAssert(msg); + parseOfferDescription(msg); break; case 0xEB: parsePreyAction(msg); @@ -2104,10 +2104,10 @@ void ProtocolGame::sendItemInspection(uint16_t itemId, uint8_t itemCount, std::s const ItemType &it = Item::items[itemId]; if (item) { - msg.addString(item->getName(), "ProtocolGame::sendItemInspection - item->getName()"); + msg.addString(item->getName()); AddItem(msg, item); } else { - msg.addString(it.name, "ProtocolGame::sendItemInspection - it.name"); + msg.addString(it.name); AddItem(msg, it.id, itemCount, 0); } msg.addByte(0); @@ -2115,8 +2115,8 @@ void ProtocolGame::sendItemInspection(uint16_t itemId, uint8_t itemCount, std::s auto descriptions = Item::getDescriptions(it, item); msg.addByte(descriptions.size()); for (const auto &description : descriptions) { - msg.addString(description.first, "ProtocolGame::sendItemInspection - description.first"); - msg.addString(description.second, "ProtocolGame::sendItemInspection - description.second"); + msg.addString(description.first); + msg.addString(description.second); } writeToOutputBuffer(msg); } @@ -2207,8 +2207,8 @@ void ProtocolGame::sendHighscores(const std::vector &charact msg.addByte(1); // Worlds auto serverName = g_configManager().getString(SERVER_NAME, __FUNCTION__); - msg.addString(serverName, "ProtocolGame::sendHighscores - g_configManager().getString(SERVER_NAME)"); // First World - msg.addString(serverName, "ProtocolGame::sendHighscores - g_configManager().getString(SERVER_NAME)"); // Selected World + msg.addString(serverName); // First World + msg.addString(serverName); // Selected World msg.addByte(0); // Game World Category: 0xFF(-1) - Selected World msg.addByte(0); // BattlEye World Type @@ -2218,7 +2218,7 @@ void ProtocolGame::sendHighscores(const std::vector &charact msg.skipBytes(1); // Vocation Count msg.add(0xFFFFFFFF); // All Vocations - hardcoded - msg.addString("(all)", "ProtocolGame::sendHighscores - (all)"); // All Vocations - hardcoded + msg.addString("(all)"); // All Vocations - hardcoded uint32_t selectedVocation = 0xFFFFFFFF; const auto vocationsMap = g_vocations().getVocations(); @@ -2226,7 +2226,7 @@ void ProtocolGame::sendHighscores(const std::vector &charact const auto &vocation = it.second; if (vocation->getFromVocation() == static_cast(vocation->getId())) { msg.add(vocation->getFromVocation()); // Vocation Id - msg.addString(vocation->getVocName(), "ProtocolGame::sendHighscores - vocation.getVocName()"); // Vocation Name + msg.addString(vocation->getVocName()); // Vocation Name ++vocations; if (vocation->getFromVocation() == vocationId) { selectedVocation = vocationId; @@ -2242,7 +2242,7 @@ void ProtocolGame::sendHighscores(const std::vector &charact for (const HighscoreCategory &category : highscoreCategories) { g_logger().debug("[ProtocolGame::sendHighscores] - Category: {} - Name: {}", category.m_id, category.m_name); msg.addByte(category.m_id); // Category Id - msg.addString(category.m_name, "ProtocolGame::sendHighscores - category.name"); // Category Name + msg.addString(category.m_name); // Category Name if (category.m_id == categoryId) { selectedCategory = categoryId; } @@ -2255,10 +2255,10 @@ void ProtocolGame::sendHighscores(const std::vector &charact msg.addByte(characters.size()); // Character Count for (const HighscoreCharacter &character : characters) { msg.add(character.rank); // Rank - msg.addString(character.name, "ProtocolGame::sendHighscores - character.name"); // Character Name - msg.addString(character.loyaltyTitle, "ProtocolGame::sendHighscores - character.loyaltyTitle"); // Character Loyalty Title + msg.addString(character.name); // Character Name + msg.addString(character.loyaltyTitle); // Character Loyalty Title msg.addByte(character.vocation); // Vocation Id - msg.addString(serverName, "ProtocolGame::sendHighscores - g_configManager().getString(SERVER_NAME)"); // World + msg.addString(serverName); // World msg.add(character.level); // Level msg.addByte((player->getGUID() == character.id)); // Player Indicator Boolean msg.add(character.points); // Points @@ -2322,7 +2322,7 @@ void ProtocolGame::parseBestiarysendRaces() { BestClass = mtype->info.bestiaryClass; } } - msg.addString(BestClass, "ProtocolGame::parseBestiarysendRaces - BestClass"); + msg.addString(BestClass); msg.add(count); uint16_t unlockedCount = g_iobestiary().getBestiaryRaceUnlocked(player, static_cast(i)); msg.add(unlockedCount); @@ -2374,7 +2374,7 @@ void ProtocolGame::parseBestiarysendMonsterData(NetworkMessage &msg) { NetworkMessage newmsg; newmsg.addByte(0xd7); newmsg.add(raceId); - newmsg.addString(Class, "ProtocolGame::parseBestiarysendMonsterData - Class"); + newmsg.addString(Class); newmsg.addByte(currentLevel); @@ -2419,7 +2419,7 @@ void ProtocolGame::parseBestiarysendMonsterData(NetworkMessage &msg) { newmsg.addByte(difficult); newmsg.addByte(0); // 1 if special event - 0 if regular loot (?) if (g_configManager().getBoolean(SHOW_LOOTS_IN_BESTIARY, __FUNCTION__) || shouldAddItem == true) { - newmsg.addString(loot.name, "ProtocolGame::parseBestiarysendMonsterData - loot.name"); + newmsg.addString(loot.name); newmsg.addByte(loot.countmax > 0 ? 0x1 : 0x0); } } @@ -2452,7 +2452,7 @@ void ProtocolGame::parseBestiarysendMonsterData(NetworkMessage &msg) { } newmsg.add(1); - newmsg.addString(mtype->info.bestiaryLocations, "ProtocolGame::parseBestiarysendMonsterData - mtype->info.bestiaryLocations"); + newmsg.addString(mtype->info.bestiaryLocations); } if (currentLevel > 3) { @@ -2530,7 +2530,7 @@ void ProtocolGame::sendTeamFinderList() { uint8_t status = 0; uint16_t membersSize = 0; msg.add(leader->getGUID()); - msg.addString(leader->getName(), "ProtocolGame::sendTeamFinderList - leader->getName()"); + msg.addString(leader->getName()); msg.add(teamAssemble->minLevel); msg.add(teamAssemble->maxLevel); msg.addByte(teamAssemble->vocationIDs); @@ -2636,7 +2636,7 @@ void ProtocolGame::sendLeaderTeamFinder(bool reset) { } msg.add(leader->getGUID()); - msg.addString(leader->getName(), "ProtocolGame::sendLeaderTeamFinder - leader->getName()"); + msg.addString(leader->getName()); msg.add(leader->getLevel()); msg.addByte(leader->getVocation()->getClientId()); msg.addByte(3); @@ -2647,7 +2647,7 @@ void ProtocolGame::sendLeaderTeamFinder(bool reset) { continue; } msg.add(member->getGUID()); - msg.addString(member->getName(), "ProtocolGame::sendLeaderTeamFinder - member->getName()"); + msg.addString(member->getName()); msg.add(member->getLevel()); msg.addByte(member->getVocation()->getClientId()); msg.addByte(memberPair.second); @@ -2913,8 +2913,8 @@ void ProtocolGame::BestiarysendCharms() { msg.addByte(charmList.size()); for (const auto &c_type : charmList) { msg.addByte(c_type->id); - msg.addString(c_type->name, "ProtocolGame::BestiarysendCharms - c_type->name"); - msg.addString(c_type->description, "ProtocolGame::BestiarysendCharms - c_type->description"); + msg.addString(c_type->name); + msg.addString(c_type->description); msg.addByte(0); // Unknown msg.add(c_type->points); if (g_iobestiary().hasCharmUnlockedRuneBit(c_type, player->getUnlockedRunesBit())) { @@ -2986,7 +2986,7 @@ void ProtocolGame::parseBestiarysendCreatures(NetworkMessage &msg) { } NetworkMessage newmsg; newmsg.addByte(0xd6); - newmsg.addString(text, "ProtocolGame::parseBestiarysendCreatures - text"); + newmsg.addString(text); newmsg.add(race.size()); std::map creaturesKilled = g_iobestiary().getBestiaryKillCountByMonsterIDs(player, race); @@ -3039,18 +3039,9 @@ void ProtocolGame::parseGreet(NetworkMessage &msg) { g_game().playerNpcGreet(player->getID(), npcId); } -void ProtocolGame::parseDebugAssert(NetworkMessage &msg) { - if (debugAssertSent) { - return; - } - - debugAssertSent = true; - - std::string assertLine = msg.getString(); - std::string date = msg.getString(); - std::string description = msg.getString(); - std::string comment = msg.getString(); - g_game().playerDebugAssert(player->getID(), assertLine, date, description, comment); +void ProtocolGame::parseOfferDescription(NetworkMessage &msg) { + auto offerId = msg.get(); + g_logger().debug("[{}] offer id: {}", __FUNCTION__, offerId); } void ProtocolGame::parsePreyAction(NetworkMessage &msg) { @@ -3214,7 +3205,7 @@ void ProtocolGame::parseSeekInContainer(NetworkMessage &msg) { void ProtocolGame::sendOpenPrivateChannel(const std::string &receiver) { NetworkMessage msg; msg.addByte(0xAD); - msg.addString(receiver, "ProtocolGame::sendOpenPrivateChannel - receiver"); + msg.addString(receiver); writeToOutputBuffer(msg); } @@ -3234,7 +3225,7 @@ void ProtocolGame::sendChannelEvent(uint16_t channelId, const std::string &playe NetworkMessage msg; msg.addByte(0xF3); msg.add(channelId); - msg.addString(playerName, "ProtocolGame::sendChannelEvent - playerName"); + msg.addString(playerName); msg.addByte(channelEvent); writeToOutputBuffer(msg); } @@ -3435,7 +3426,7 @@ void ProtocolGame::sendAddMarker(const Position &pos, uint8_t markType, const st msg.addPosition(pos); msg.addByte(markType); - msg.addString(desc, "ProtocolGame::sendAddMarker - desc"); + msg.addString(desc); writeToOutputBuffer(msg); } @@ -3460,13 +3451,13 @@ void ProtocolGame::sendCyclopediaCharacterBaseInformation() { msg.addByte(0xDA); msg.addByte(CYCLOPEDIA_CHARACTERINFO_BASEINFORMATION); msg.addByte(0x00); - msg.addString(player->getName(), "ProtocolGame::sendCyclopediaCharacterBaseInformation - player->getName()"); - msg.addString(player->getVocation()->getVocName(), "ProtocolGame::sendCyclopediaCharacterBaseInformation - player->getVocation()->getVocName()"); + msg.addString(player->getName()); + msg.addString(player->getVocation()->getVocName()); msg.add(player->getLevel()); AddOutfit(msg, player->getDefaultOutfit(), false); msg.addByte(0x01); // Store summary & Character titles - msg.addString(player->title()->getCurrentTitleName(), "ProtocolGame::sendCyclopediaCharacterBaseInformation - player->title()->getCurrentTitleName()"); // character title + msg.addString(player->title()->getCurrentTitleName()); // character title writeToOutputBuffer(msg); } @@ -3711,7 +3702,7 @@ void ProtocolGame::sendCyclopediaCharacterRecentDeaths(uint16_t page, uint16_t p msg.add(entries.size()); for (const RecentDeathEntry &entry : entries) { msg.add(entry.timestamp); - msg.addString(entry.cause, "ProtocolGame::sendCyclopediaCharacterRecentDeaths - entry.cause"); + msg.addString(entry.cause); } writeToOutputBuffer(msg); @@ -3731,7 +3722,7 @@ void ProtocolGame::sendCyclopediaCharacterRecentPvPKills(uint16_t page, uint16_t msg.add(entries.size()); for (const RecentPvPKillEntry &entry : entries) { msg.add(entry.timestamp); - msg.addString(entry.description, "ProtocolGame::sendCyclopediaCharacterRecentPvPKills - entry.description"); + msg.addString(entry.description); msg.addByte(entry.status); } @@ -3750,15 +3741,13 @@ void ProtocolGame::sendCyclopediaCharacterAchievements(uint16_t secretsUnlocked, msg.add(player->achiev()->getPoints()); msg.add(secretsUnlocked); msg.add(static_cast(achievementsUnlocked.size())); - std::string messageAchievName = "ProtocolGame::sendCyclopediaCharacterAchievements - achievement.name"; - std::string messageAchievDesc = "ProtocolGame::sendCyclopediaCharacterAchievements - achievement.description"; for (const auto &[achievement, addedTimestamp] : achievementsUnlocked) { msg.add(achievement.id); msg.add(addedTimestamp); if (achievement.secret) { msg.addByte(0x01); - msg.addString(achievement.name, messageAchievName); - msg.addString(achievement.description, messageAchievDesc); + msg.addString(achievement.name); + msg.addString(achievement.description); msg.addByte(achievement.grade); } else { msg.addByte(0x00); @@ -3904,7 +3893,7 @@ void ProtocolGame::sendCyclopediaCharacterOutfitsMounts() { ++outfitSize; msg.add(outfit->lookType); - msg.addString(outfit->name, "ProtocolGame::sendCyclopediaCharacterOutfitsMounts - outfit->name"); + msg.addString(outfit->name); msg.addByte(addons); if (from == "store") { msg.addByte(CYCLOPEDIA_CHARACTERINFO_OUTFITTYPE_STORE); @@ -3935,7 +3924,7 @@ void ProtocolGame::sendCyclopediaCharacterOutfitsMounts() { ++mountSize; msg.add(mount->clientId); - msg.addString(mount->name, "ProtocolGame::sendCyclopediaCharacterOutfitsMounts - mount->name"); + msg.addString(mount->name); if (type == "store") { msg.addByte(CYCLOPEDIA_CHARACTERINFO_OUTFITTYPE_STORE); } else if (type == "quest") { @@ -3964,7 +3953,7 @@ void ProtocolGame::sendCyclopediaCharacterOutfitsMounts() { } ++familiarsSize; msg.add(familiar->lookType); - msg.addString(familiar->name, "ProtocolGame::sendCyclopediaCharacterOutfitsMounts - familiar.name"); + msg.addString(familiar->name); if (type == "quest") { msg.addByte(CYCLOPEDIA_CHARACTERINFO_OUTFITTYPE_QUEST); } else { @@ -4000,7 +3989,7 @@ void ProtocolGame::sendCyclopediaCharacterStoreSummary() { msg.addByte(static_cast(magic_enum::enum_count())); for (auto bless : magic_enum::enum_values()) { std::string name = toStartCaseWithSpace(magic_enum::enum_name(bless).data()); - msg.addString(name, "ProtocolGame::sendCyclopediaCharacterStoreSummary - blessing.name"); + msg.addString(name); auto blessValue = enumToValue(bless); if (player->hasBlessing(blessValue)) { msg.addByte(static_cast(player->blessings[blessValue - 1])); @@ -4057,7 +4046,7 @@ void ProtocolGame::sendCyclopediaCharacterStoreSummary() { for (const auto &hItem_it : houseItems) { const ItemType &it = Item::items[hItem_it.first]; msg.add(it.id); // Item ID - msg.addString(it.name, "ProtocolGame::sendCyclopediaCharacterStoreSummary - houseItem.name"); + msg.addString(it.name); msg.addByte(hItem_it.second); } @@ -4082,7 +4071,7 @@ void ProtocolGame::sendCyclopediaCharacterInspection() { ++inventoryItems; msg.addByte(slot); - msg.addString(inventoryItem->getName(), "ProtocolGame::sendCyclopediaCharacterInspection - inventoryItem->getName()"); + msg.addString(inventoryItem->getName()); AddItem(msg, inventoryItem); uint8_t itemImbuements = 0; @@ -4106,12 +4095,12 @@ void ProtocolGame::sendCyclopediaCharacterInspection() { auto descriptions = Item::getDescriptions(Item::items[inventoryItem->getID()], inventoryItem); msg.addByte(descriptions.size()); for (const auto &description : descriptions) { - msg.addString(description.first, "ProtocolGame::sendCyclopediaCharacterInspection - description.first"); - msg.addString(description.second, "ProtocolGame::sendCyclopediaCharacterInspection - description.second"); + msg.addString(description.first); + msg.addString(description.second); } } } - msg.addString(player->getName(), "ProtocolGame::sendCyclopediaCharacterInspection - player->getName()"); + msg.addString(player->getName()); AddOutfit(msg, player->getDefaultOutfit(), false); // Player overall summary @@ -4122,33 +4111,33 @@ void ProtocolGame::sendCyclopediaCharacterInspection() { // Player title if (player->title()->getCurrentTitle() != 0) { playerDescriptionSize++; - msg.addString("Character Title", "ProtocolGame::sendCyclopediaCharacterInspection - Title"); - msg.addString(player->title()->getCurrentTitleName(), "ProtocolGame::sendCyclopediaCharacterInspection - player->title()->getCurrentTitleName()"); + msg.addString("Character Title"); + msg.addString(player->title()->getCurrentTitleName()); } // Level description playerDescriptionSize++; - msg.addString("Level", "ProtocolGame::sendCyclopediaCharacterInspection - Level"); - msg.addString(std::to_string(player->getLevel()), "ProtocolGame::sendCyclopediaCharacterInspection - std::to_string(player->getLevel())"); + msg.addString("Level"); + msg.addString(std::to_string(player->getLevel())); // Vocation description playerDescriptionSize++; - msg.addString("Vocation", "ProtocolGame::sendCyclopediaCharacterInspection - Vocation"); - msg.addString(player->getVocation()->getVocName(), "ProtocolGame::sendCyclopediaCharacterInspection - player->getVocation()->getVocName()"); + msg.addString("Vocation"); + msg.addString(player->getVocation()->getVocName()); // Loyalty title if (!player->getLoyaltyTitle().empty()) { playerDescriptionSize++; - msg.addString("Loyalty Title", "ProtocolGame::sendCyclopediaCharacterInspection - Loyalty Title"); - msg.addString(player->getLoyaltyTitle(), "ProtocolGame::sendCyclopediaCharacterInspection - player->getLoyaltyTitle()"); + msg.addString("Loyalty Title"); + msg.addString(player->getLoyaltyTitle()); } // Marriage description if (const auto spouseId = player->getMarriageSpouse(); spouseId > 0) { if (const auto &spouse = g_game().getPlayerByID(spouseId, true); spouse) { playerDescriptionSize++; - msg.addString("Married to", "ProtocolGame::sendCyclopediaCharacterInspection - Married to"); - msg.addString(spouse->getName(), "ProtocolGame::sendCyclopediaCharacterInspection - spouse->getName()"); + msg.addString("Married to"); + msg.addString(spouse->getName()); } } @@ -4158,7 +4147,7 @@ void ProtocolGame::sendCyclopediaCharacterInspection() { slot && slot->isOccupied()) { playerDescriptionSize++; std::string activePrey = fmt::format("Active Prey {}", slotId + 1); - msg.addString(activePrey, "ProtocolGame::sendCyclopediaCharacterInspection - active prey"); + msg.addString(activePrey); std::string desc; if (auto mtype = g_monsters().getMonsterTypeByRaceId(slot->selectedRaceId)) { @@ -4180,17 +4169,17 @@ void ProtocolGame::sendCyclopediaCharacterInspection() { uint8_t hours = slot->bonusTimeLeft / 3600; uint8_t minutes = (slot->bonusTimeLeft - (hours * 3600)) / 60; desc.append(fmt::format("{}:{}{}h", hours, (minutes < 10 ? "0" : ""), minutes)); - msg.addString(desc, "ProtocolGame::sendCyclopediaCharacterInspection - prey description"); + msg.addString(desc); } } // Outfit description playerDescriptionSize++; - msg.addString("Outfit", "ProtocolGame::sendCyclopediaCharacterInspection - Outfit"); + msg.addString("Outfit"); if (const auto outfit = Outfits::getInstance().getOutfitByLookType(player, player->getDefaultOutfit().lookType)) { - msg.addString(outfit->name, "ProtocolGame::sendCyclopediaCharacterInspection - outfit->name"); + msg.addString(outfit->name); } else { - msg.addString("unknown", "ProtocolGame::sendCyclopediaCharacterInspection - unknown"); + msg.addString("unknown"); } msg.setBufferPosition(startInventory); @@ -4217,7 +4206,7 @@ void ProtocolGame::sendCyclopediaCharacterBadges() { msg.addByte(loggedPlayer ? 0x01 : 0x00); // IsOnline msg.addByte(player->isPremium() ? 0x01 : 0x00); // IsPremium (GOD has always 'Premium') // Character loyalty title - msg.addString(player->getLoyaltyTitle(), "ProtocolGame::sendCyclopediaCharacterBadges - player->getLoyaltyTitle()"); + msg.addString(player->getLoyaltyTitle()); uint8_t badgesSize = 0; auto badgesSizePosition = msg.getBufferPosition(); @@ -4225,7 +4214,7 @@ void ProtocolGame::sendCyclopediaCharacterBadges() { for (const auto &badge : g_game().getBadges()) { if (player->badge()->hasBadge(badge.m_id)) { msg.add(badge.m_id); - msg.addString(badge.m_name, "ProtocolGame::sendCyclopediaCharacterBadges - name"); + msg.addString(badge.m_name); badgesSize++; } } @@ -4249,14 +4238,11 @@ void ProtocolGame::sendCyclopediaCharacterTitles() { msg.addByte(0x00); // 0x00 Here means 'no error' msg.addByte(player->title()->getCurrentTitle()); msg.addByte(static_cast(titles.size())); - - std::string messageTitleName = "ProtocolGame::sendCyclopediaCharacterTitles - title.name"; - std::string messageTitleDesc = "ProtocolGame::sendCyclopediaCharacterTitles - title.description"; for (const auto &title : titles) { msg.addByte(title.m_id); auto titleName = player->title()->getNameBySex(player->getSex(), title.m_maleName, title.m_femaleName); - msg.addString(titleName, messageTitleName); - msg.addString(title.m_description, messageTitleDesc); + msg.addString(titleName); + msg.addString(title.m_description); msg.addByte(title.m_permanent ? 0x01 : 0x00); auto isUnlocked = player->title()->isTitleUnlocked(title.m_id); msg.addByte(isUnlocked ? 0x01 : 0x00); @@ -4503,7 +4489,7 @@ void ProtocolGame::sendTextMessage(const TextMessage &message) { default: break; } - msg.addString(message.text, "ProtocolGame::sendTextMessage - message.text"); + msg.addString(message.text); writeToOutputBuffer(msg); } @@ -4518,9 +4504,9 @@ void ProtocolGame::sendCreatePrivateChannel(uint16_t channelId, const std::strin NetworkMessage msg; msg.addByte(0xB2); msg.add(channelId); - msg.addString(channelName, "ProtocolGame::sendCreatePrivateChannel - channelName"); + msg.addString(channelName); msg.add(0x01); - msg.addString(player->getName(), "ProtocolGame::sendCreatePrivateChannel - player->getName()"); + msg.addString(player->getName()); msg.add(0x00); writeToOutputBuffer(msg); } @@ -4533,7 +4519,7 @@ void ProtocolGame::sendChannelsDialog() { msg.addByte(list.size()); for (const auto &channel : list) { msg.add(channel->getId()); - msg.addString(channel->getName(), "ProtocolGame::sendChannelsDialog - channel->getName()"); + msg.addString(channel->getName()); } writeToOutputBuffer(msg); @@ -4544,12 +4530,12 @@ void ProtocolGame::sendChannel(uint16_t channelId, const std::string &channelNam msg.addByte(0xAC); msg.add(channelId); - msg.addString(channelName, "ProtocolGame::sendChannel - channelName"); + msg.addString(channelName); if (channelUsers) { msg.add(channelUsers->size()); for (const auto &it : *channelUsers) { - msg.addString(it.second->getName(), "ProtocolGame::sendChannel - it.second->getName()"); + msg.addString(it.second->getName()); } } else { msg.add(0x00); @@ -4558,7 +4544,7 @@ void ProtocolGame::sendChannel(uint16_t channelId, const std::string &channelNam if (invitedUsers) { msg.add(invitedUsers->size()); for (const auto &it : *invitedUsers) { - msg.addString(it.second->getName(), "ProtocolGame::sendChannel - it.second->getName()"); + msg.addString(it.second->getName()); } } else { msg.add(0x00); @@ -4570,11 +4556,11 @@ void ProtocolGame::sendChannelMessage(const std::string &author, const std::stri NetworkMessage msg; msg.addByte(0xAA); msg.add(0x00); - msg.addString(author, "ProtocolGame::sendChannelMessage - author"); + msg.addString(author); msg.add(0x00); msg.addByte(type); msg.add(channel); - msg.addString(text, "ProtocolGame::sendChannelMessage - text"); + msg.addString(text); writeToOutputBuffer(msg); } @@ -4634,10 +4620,10 @@ void ProtocolGame::sendContainer(uint8_t cid, std::shared_ptr contain if (container->getID() == ITEM_BROWSEFIELD) { AddItem(msg, ITEM_BAG, 1, container->getTier()); - msg.addString("Browse Field", "ProtocolGame::sendContainer - Browse Field"); + msg.addString("Browse Field"); } else { AddItem(msg, container); - msg.addString(container->getName(), "ProtocolGame::sendContainer - container->getName()"); + msg.addString(container->getName()); } const auto itemsStoreInboxToSend = container->getStoreInboxFilteredItems(); @@ -4793,7 +4779,7 @@ void ProtocolGame::sendLootStats(std::shared_ptr item, uint8_t count) { NetworkMessage msg; msg.addByte(0xCF); AddItem(msg, lootedItem); - msg.addString(lootedItem->getName(), "ProtocolGame::sendLootStats - lootedItem->getName()"); + msg.addString(lootedItem->getName()); item->setIsLootTrackeable(false); writeToOutputBuffer(msg); @@ -4804,7 +4790,7 @@ void ProtocolGame::sendShop(std::shared_ptr npc) { Benchmark brenchmark; NetworkMessage msg; msg.addByte(0x7A); - msg.addString(npc->getName(), "ProtocolGame::sendShop - npc->getName()"); + msg.addString(npc->getName()); if (!oldProtocol) { msg.add(npc->getCurrency()); @@ -5085,7 +5071,7 @@ void ProtocolGame::sendMarketBrowseItem(uint16_t itemId, const MarketOfferList & } else { msg.add(static_cast(offer.price)); } - msg.addString(offer.playerName, "ProtocolGame::sendMarketBrowseItem - offer.playerName"); + msg.addString(offer.playerName); } msg.add(sellOffers.size()); @@ -5098,7 +5084,7 @@ void ProtocolGame::sendMarketBrowseItem(uint16_t itemId, const MarketOfferList & } else { msg.add(static_cast(offer.price)); } - msg.addString(offer.playerName, "ProtocolGame::sendMarketBrowseItem - offer.playerName"); + msg.addString(offer.playerName); } updateCoinBalance(); @@ -5127,7 +5113,7 @@ void ProtocolGame::sendMarketAcceptOffer(const MarketOfferEx &offer) { } else { msg.add(static_cast(offer.price)); } - msg.addString(offer.playerName, "ProtocolGame::sendMarketAcceptOffer - offer.playerName"); + msg.addString(offer.playerName); msg.add(0x00); } else { msg.add(0x00); @@ -5140,7 +5126,7 @@ void ProtocolGame::sendMarketAcceptOffer(const MarketOfferEx &offer) { } else { msg.add(static_cast(offer.price)); } - msg.addString(offer.playerName, "ProtocolGame::sendMarketAcceptOffer - offer.playerName"); + msg.addString(offer.playerName); } writeToOutputBuffer(msg); @@ -5701,7 +5687,7 @@ void ProtocolGame::sendForgeHistory(uint8_t page) { auto action = magic_enum::enum_integer(history.actionType); msg.add(static_cast(history.createdAt)); msg.addByte(action); - msg.addString(history.description, "ProtocolGame::sendForgeHistory - history.description"); + msg.addString(history.description); msg.addByte((history.bonus >= 1 && history.bonus < 8) ? 0x01 : 0x00); } } @@ -5731,7 +5717,7 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { } if (it.armor != 0) { - msg.addString(std::to_string(it.armor), "ProtocolGame::sendMarketDetail - std::to_string(it.armor)"); + msg.addString(std::to_string(it.armor)); } else { msg.add(0x00); } @@ -5759,21 +5745,21 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { } ss << static_cast(it.shootRange) << " fields"; } - msg.addString(ss.str(), "ProtocolGame::sendMarketDetail - ss.str()"); + msg.addString(ss.str()); } else if (!it.isRanged() && it.attack != 0) { if (it.abilities && it.abilities->elementType != COMBAT_NONE && it.abilities->elementDamage != 0) { std::ostringstream ss; ss << it.attack << " physical +" << it.abilities->elementDamage << ' ' << getCombatName(it.abilities->elementType); - msg.addString(ss.str(), "ProtocolGame::sendMarketDetail - ss.str()"); + msg.addString(ss.str()); } else { - msg.addString(std::to_string(it.attack), "ProtocolGame::sendMarketDetail - std::to_string(it.attack)"); + msg.addString(std::to_string(it.attack)); } } else { msg.add(0x00); } if (it.isContainer()) { - msg.addString(std::to_string(it.maxItems), "ProtocolGame::sendMarketDetail - std::to_string(it.maxItems)"); + msg.addString(std::to_string(it.maxItems)); } else { msg.add(0x00); } @@ -5782,9 +5768,9 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { if (it.extraDefense != 0) { std::ostringstream ss; ss << it.defense << ' ' << std::showpos << it.extraDefense << std::noshowpos; - msg.addString(ss.str(), "ProtocolGame::sendMarketDetail - ss.str()"); + msg.addString(ss.str()); } else { - msg.addString(std::to_string(it.defense), "ProtocolGame::sendMarketDetail - std::to_string(it.defense)"); + msg.addString(std::to_string(it.defense)); } } else { msg.add(0x00); @@ -5793,9 +5779,9 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { if (!it.description.empty()) { const std::string &descr = it.description; if (descr.back() == '.') { - msg.addString(std::string(descr, 0, descr.length() - 1), "ProtocolGame::sendMarketDetail - std::string(descr, 0, descr.length() - 1)"); + msg.addString(std::string(descr, 0, descr.length() - 1)); } else { - msg.addString(descr, "ProtocolGame::sendMarketDetail - descr"); + msg.addString(descr); } } else { msg.add(0x00); @@ -5804,7 +5790,7 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { if (it.decayTime != 0) { std::ostringstream ss; ss << it.decayTime << " seconds"; - msg.addString(ss.str(), "ProtocolGame::sendMarketDetail - ss.str()"); + msg.addString(ss.str()); } else { msg.add(0x00); } @@ -5827,25 +5813,25 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { ss << fmt::format("{} {:+}%", getCombatName(indexToCombatType(i)), it.abilities->absorbPercent[i]); } - msg.addString(ss.str(), "ProtocolGame::sendMarketDetail - ss.str()"); + msg.addString(ss.str()); } else { msg.add(0x00); } if (it.minReqLevel != 0) { - msg.addString(std::to_string(it.minReqLevel), "ProtocolGame::sendMarketDetail - std::to_string(it.minReqLevel)"); + msg.addString(std::to_string(it.minReqLevel)); } else { msg.add(0x00); } if (it.minReqMagicLevel != 0) { - msg.addString(std::to_string(it.minReqMagicLevel), "ProtocolGame::sendMarketDetail - std::to_string(it.minReqMagicLevel)"); + msg.addString(std::to_string(it.minReqMagicLevel)); } else { msg.add(0x00); } - msg.addString(it.vocationString, "ProtocolGame::sendMarketDetail - it.vocationString"); - msg.addString(it.runeSpellName, "ProtocolGame::sendMarketDetail - it.runeSpellName"); + msg.addString(it.vocationString); + msg.addString(it.runeSpellName); if (it.abilities) { std::ostringstream ss; @@ -5911,13 +5897,13 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { ss << fmt::format("speed {:+}", (it.abilities->speed >> 1)); } - msg.addString(ss.str(), "ProtocolGame::sendMarketDetail - ss.str()"); + msg.addString(ss.str()); } else { msg.add(0x00); } if (it.charges != 0) { - msg.addString(std::to_string(it.charges), "ProtocolGame::sendMarketDetail - std::to_string(it.charges)"); + msg.addString(std::to_string(it.charges)); } else { msg.add(0x00); } @@ -5932,7 +5918,7 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { } } - msg.addString(weaponName, "ProtocolGame::sendMarketDetail - weaponName"); + msg.addString(weaponName); if (it.weight != 0) { std::ostringstream ss; @@ -5946,7 +5932,7 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { ss << weightString; } ss << " oz"; - msg.addString(ss.str(), "ProtocolGame::sendMarketDetail - ss.str()"); + msg.addString(ss.str()); } else { msg.add(0x00); } @@ -5954,14 +5940,14 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { if (!oldProtocol) { std::string augmentsDescription = it.parseAugmentDescription(true); if (!augmentsDescription.empty()) { - msg.addString(augmentsDescription, "ProtocolGame::sendMarketDetail - augmentsDescription"); + msg.addString(augmentsDescription); } else { msg.add(0x00); // no augments } } if (it.imbuementSlot > 0) { - msg.addString(std::to_string(it.imbuementSlot), "ProtocolGame::sendMarketDetail - std::to_string(it.imbuementSlot)"); + msg.addString(std::to_string(it.imbuementSlot)); } else { msg.add(0x00); } @@ -5973,7 +5959,7 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { if (it.abilities->magicShieldCapacityFlat > 0) { string.clear(); string << std::showpos << it.abilities->magicShieldCapacityFlat << std::noshowpos << " and " << it.abilities->magicShieldCapacityPercent << "%"; - msg.addString(string.str(), "ProtocolGame::sendMarketDetail - string.str()"); + msg.addString(string.str()); } else { msg.add(0x00); } @@ -5981,7 +5967,7 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { if (it.abilities->cleavePercent > 0) { string.clear(); string << it.abilities->cleavePercent << "%"; - msg.addString(string.str(), "ProtocolGame::sendMarketDetail - string.str()"); + msg.addString(string.str()); } else { msg.add(0x00); } @@ -5989,7 +5975,7 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { if (it.abilities->reflectFlat[COMBAT_PHYSICALDAMAGE] > 0) { string.clear(); string << it.abilities->reflectFlat[COMBAT_PHYSICALDAMAGE]; - msg.addString(string.str(), "ProtocolGame::sendMarketDetail - string.str()"); + msg.addString(string.str()); } else { msg.add(0x00); } @@ -5997,7 +5983,7 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { if (it.abilities->perfectShotDamage > 0) { string.clear(); string << std::showpos << it.abilities->perfectShotDamage << std::noshowpos << " at range " << unsigned(it.abilities->perfectShotRange); - msg.addString(string.str(), "ProtocolGame::sendMarketDetail - string.str()"); + msg.addString(string.str()); } else { msg.add(0x00); } @@ -6015,7 +6001,7 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { // Upgrade and tier detail modifier if (it.upgradeClassification > 0 && tier > 0) { - msg.addString(std::to_string(it.upgradeClassification), "ProtocolGame::sendMarketDetail - std::to_string(it.upgradeClassification)"); + msg.addString(std::to_string(it.upgradeClassification)); std::ostringstream ss; double chance; @@ -6029,10 +6015,10 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { chance = (0.0307576 * tier * tier) + (0.440697 * tier) + 0.026; ss << fmt::format("{} ({:.2f}% Ruse)", static_cast(tier), chance); } - msg.addString(ss.str(), "ProtocolGame::sendMarketDetail - ss.str()"); + msg.addString(ss.str()); } else if (it.upgradeClassification > 0 && tier == 0) { - msg.addString(std::to_string(it.upgradeClassification), "ProtocolGame::sendMarketDetail - std::to_string(it.upgradeClassification)"); - msg.addString(std::to_string(tier), "ProtocolGame::sendMarketDetail - std::to_string(tier)"); + msg.addString(std::to_string(it.upgradeClassification)); + msg.addString(std::to_string(tier)); } else { msg.add(0x00); msg.add(0x00); @@ -6101,7 +6087,7 @@ void ProtocolGame::sendTradeItemRequest(const std::string &traderName, std::shar msg.addByte(0x7E); } - msg.addString(traderName, "ProtocolGame::sendTradeItemRequest - traderName"); + msg.addString(traderName); if (std::shared_ptr tradeContainer = item->getContainer()) { std::list> listContainer { tradeContainer }; @@ -6166,7 +6152,7 @@ void ProtocolGame::sendCreatureSay(std::shared_ptr creature, SpeakClas static uint32_t statementId = 0; msg.add(++statementId); - msg.addString(creature->getName(), "ProtocolGame::sendCreatureSay - creature->getName()"); + msg.addString(creature->getName()); if (!oldProtocol) { msg.addByte(0x00); // Show (Traded) @@ -6191,7 +6177,7 @@ void ProtocolGame::sendCreatureSay(std::shared_ptr creature, SpeakClas msg.addPosition(creature->getPosition()); } - msg.addString(text, "ProtocolGame::sendCreatureSay - text"); + msg.addString(text); writeToOutputBuffer(msg); } @@ -6213,7 +6199,7 @@ void ProtocolGame::sendToChannel(std::shared_ptr creature, SpeakClasse } type = TALKTYPE_CHANNEL_R1; } else { - msg.addString(creature->getName(), "ProtocolGame::sendToChannel - creature->getName()"); + msg.addString(creature->getName()); if (!oldProtocol && statementId != 0) { msg.addByte(0x00); // Show (Traded) } @@ -6233,7 +6219,7 @@ void ProtocolGame::sendToChannel(std::shared_ptr creature, SpeakClasse } msg.add(channelId); - msg.addString(text, "ProtocolGame::sendToChannel - text"); + msg.addString(text); writeToOutputBuffer(msg); } @@ -6243,7 +6229,7 @@ void ProtocolGame::sendPrivateMessage(std::shared_ptr speaker, SpeakClas static uint32_t statementId = 0; msg.add(++statementId); if (speaker) { - msg.addString(speaker->getName(), "ProtocolGame::sendPrivateMessage - speaker->getName()"); + msg.addString(speaker->getName()); if (!oldProtocol && statementId != 0) { msg.addByte(0x00); // Show (Traded) } @@ -6261,7 +6247,7 @@ void ProtocolGame::sendPrivateMessage(std::shared_ptr speaker, SpeakClas msg.addByte(type); } - msg.addString(text, "ProtocolGame::sendPrivateMessage - text"); + msg.addString(text); writeToOutputBuffer(msg); } @@ -6349,7 +6335,7 @@ void ProtocolGame::sendRestingStatus(uint8_t protection) { msg.addByte(dailyStreak < 2 ? 0 : 1); if (dailyStreak < 2) { - msg.addString("Resting Area (no active bonus)", "ProtocolGame::sendRestingStatus - Resting Area (no active bonus)"); + msg.addString("Resting Area (no active bonus)"); } else { std::ostringstream ss; ss << "Active Resting Area Bonuses: "; @@ -6372,7 +6358,7 @@ void ProtocolGame::sendRestingStatus(uint8_t protection) { ss << ",\nSoul Points Regeneration"; } ss << "."; - msg.addString(ss.str(), "ProtocolGame::sendRestingStatus - ss.str()"); + msg.addString(ss.str()); } writeToOutputBuffer(msg); } @@ -6568,7 +6554,7 @@ void ProtocolGame::sendPlayerVocation(std::shared_ptr target) { void ProtocolGame::sendFYIBox(const std::string &message) { NetworkMessage msg; msg.addByte(0x15); - msg.addString(message, "ProtocolGame::sendFYIBox - message"); + msg.addString(message); writeToOutputBuffer(msg); } @@ -6748,7 +6734,7 @@ void ProtocolGame::sendAddCreature(std::shared_ptr creature, const Pos msg.addByte(0x00); // can change pvp framing option msg.addByte(0x00); // expert mode button enabled - msg.addString(g_configManager().getString(STORE_IMAGES_URL, __FUNCTION__), "ProtocolGame::sendAddCreature - g_configManager().getString(STORE_IMAGES_URL)"); + msg.addString(g_configManager().getString(STORE_IMAGES_URL, __FUNCTION__)); msg.add(static_cast(g_configManager().getNumber(STORE_COIN_PACKET, __FUNCTION__))); if (!oldProtocol) { @@ -6990,16 +6976,16 @@ void ProtocolGame::sendTextWindow(uint32_t windowTextId, std::shared_ptr i if (canWrite) { msg.add(maxlen); - msg.addString(item->getAttribute(ItemAttribute_t::TEXT), "ProtocolGame::sendTextWindow - item->getAttribute(ItemAttribute_t::TEXT)"); + msg.addString(item->getAttribute(ItemAttribute_t::TEXT)); } else { const std::string &text = item->getAttribute(ItemAttribute_t::TEXT); msg.add(text.size()); - msg.addString(text, "ProtocolGame::sendTextWindow - text"); + msg.addString(text); } const std::string &writer = item->getAttribute(ItemAttribute_t::WRITER); if (!writer.empty()) { - msg.addString(writer, "ProtocolGame::sendTextWindow - writer"); + msg.addString(writer); } else { msg.add(0x00); } @@ -7010,7 +6996,7 @@ void ProtocolGame::sendTextWindow(uint32_t windowTextId, std::shared_ptr i auto writtenDate = item->getAttribute(ItemAttribute_t::DATE); if (writtenDate != 0) { - msg.addString(formatDateShort(writtenDate), "ProtocolGame::sendTextWindow - formatDateShort(writtenDate)"); + msg.addString(formatDateShort(writtenDate)); } else { msg.add(0x00); } @@ -7024,7 +7010,7 @@ void ProtocolGame::sendTextWindow(uint32_t windowTextId, uint32_t itemId, const msg.add(windowTextId); AddItem(msg, itemId, 1, 0); msg.add(text.size()); - msg.addString(text, "ProtocolGame::sendTextWindow - text"); + msg.addString(text); msg.add(0x00); if (!oldProtocol) { @@ -7040,7 +7026,7 @@ void ProtocolGame::sendHouseWindow(uint32_t windowTextId, const std::string &tex msg.addByte(0x97); msg.addByte(0x00); msg.add(windowTextId); - msg.addString(text, "ProtocolGame::sendHouseWindow - text"); + msg.addString(text); writeToOutputBuffer(msg); } @@ -7084,7 +7070,7 @@ void ProtocolGame::sendOutfitWindow() { msg.addByte(protocolOutfits.size()); for (const ProtocolOutfit &outfit : protocolOutfits) { msg.add(outfit.lookType); - msg.addString(outfit.name, "ProtocolGame::sendOutfitWindow - outfit.name"); + msg.addString(outfit.name); msg.addByte(outfit.addons); } @@ -7098,7 +7084,7 @@ void ProtocolGame::sendOutfitWindow() { msg.addByte(mounts.size()); for (const auto &mount : mounts) { msg.add(mount->clientId); - msg.addString(mount->name, "ProtocolGame::sendOutfitWindow - mount->name"); + msg.addString(mount->name); } writeToOutputBuffer(msg); @@ -7119,19 +7105,19 @@ void ProtocolGame::sendOutfitWindow() { if (player->isAccessPlayer() && g_configManager().getBoolean(ENABLE_SUPPORT_OUTFIT, __FUNCTION__)) { msg.add(75); - msg.addString("Gamemaster", "ProtocolGame::sendOutfitWindow - Gamemaster"); + msg.addString("Gamemaster"); msg.addByte(0); msg.addByte(0x00); ++outfitSize; msg.add(266); - msg.addString("Customer Support", "ProtocolGame::sendOutfitWindow - Customer Support"); + msg.addString("Customer Support"); msg.addByte(0); msg.addByte(0x00); ++outfitSize; msg.add(302); - msg.addString("Community Manager", "ProtocolGame::sendOutfitWindow - Community Manager"); + msg.addString("Community Manager"); msg.addByte(0); msg.addByte(0x00); ++outfitSize; @@ -7143,14 +7129,14 @@ void ProtocolGame::sendOutfitWindow() { uint8_t addons; if (player->getOutfitAddons(outfit, addons)) { msg.add(outfit->lookType); - msg.addString(outfit->name, "ProtocolGame::sendOutfitWindow - outfit->name"); + msg.addString(outfit->name); msg.addByte(addons); msg.addByte(0x00); ++outfitSize; } else if (outfit->lookType == 1210 || outfit->lookType == 1211) { if (player->canWear(1210, 0) || player->canWear(1211, 0)) { msg.add(outfit->lookType); - msg.addString(outfit->name, "ProtocolGame::sendOutfitWindow - outfit->name"); + msg.addString(outfit->name); msg.addByte(3); msg.addByte(0x02); ++outfitSize; @@ -7158,14 +7144,14 @@ void ProtocolGame::sendOutfitWindow() { } else if (outfit->lookType == 1456 || outfit->lookType == 1457) { if (player->canWear(1456, 0) || player->canWear(1457, 0)) { msg.add(outfit->lookType); - msg.addString(outfit->name, "ProtocolGame::sendOutfitWindow - outfit->name"); + msg.addString(outfit->name); msg.addByte(3); msg.addByte(0x03); ++outfitSize; } } else if (outfit->from == "store") { msg.add(outfit->lookType); - msg.addString(outfit->name, "ProtocolGame::sendOutfitWindow - outfit->name"); + msg.addString(outfit->name); msg.addByte(outfit->lookType >= 962 && outfit->lookType <= 975 ? 0 : 3); msg.addByte(0x01); msg.add(0x00); @@ -7191,12 +7177,12 @@ void ProtocolGame::sendOutfitWindow() { for (const auto &mount : mounts) { if (player->hasMount(mount)) { msg.add(mount->clientId); - msg.addString(mount->name, "ProtocolGame::sendOutfitWindow - mount->name"); + msg.addString(mount->name); msg.addByte(0x00); ++mountSize; } else if (mount->type == "store") { msg.add(mount->clientId); - msg.addString(mount->name, "ProtocolGame::sendOutfitWindow - mount->name"); + msg.addString(mount->name); msg.addByte(0x01); msg.add(0x00); ++mountSize; @@ -7225,7 +7211,7 @@ void ProtocolGame::sendOutfitWindow() { } msg.add(familiar->lookType); - msg.addString(familiar->name, "ProtocolGame::sendOutfitWindow - familiar.name"); + msg.addString(familiar->name); msg.addByte(0x00); if (++familiarSize == limitFamiliars) { break; @@ -7289,7 +7275,7 @@ void ProtocolGame::sendPodiumWindow(std::shared_ptr podium, const Position } msg.add(outfit->lookType); - msg.addString(outfit->name, "ProtocolGame::sendPodiumWindow - outfit->name"); + msg.addString(outfit->name); msg.addByte(addons); msg.addByte(0x00); if (++outfitSize == limitOutfits) { @@ -7311,7 +7297,7 @@ void ProtocolGame::sendPodiumWindow(std::shared_ptr podium, const Position for (const auto &mount : mounts) { if (player->hasMount(mount)) { msg.add(mount->clientId); - msg.addString(mount->name, "ProtocolGame::sendPodiumWindow - mount->name"); + msg.addString(mount->name); msg.addByte(0x00); if (++mountSize == limitMounts) { break; @@ -7361,8 +7347,8 @@ void ProtocolGame::sendVIP(uint32_t guid, const std::string &name, const std::st NetworkMessage msg; msg.addByte(0xD2); msg.add(guid); - msg.addString(name, "ProtocolGame::sendVIP - name"); - msg.addString(description, "ProtocolGame::sendVIP - description"); + msg.addString(name); + msg.addString(description); msg.add(std::min(10, icon)); msg.addByte(notify ? 0x01 : 0x00); msg.addByte(enumToValue(status)); @@ -7391,7 +7377,7 @@ void ProtocolGame::sendVIPGroups() { msg.addByte(vipGroups.size()); // vipGroups.size() for (const auto &vipGroup : vipGroups) { msg.addByte(vipGroup->id); - msg.addString(vipGroup->name, "ProtocolGame::sendVIP - vipGroup.name"); + msg.addString(vipGroup->name); msg.addByte(vipGroup->customizable ? 0x01 : 0x00); // 0x00 = not Customizable, 0x01 = Customizable } msg.addByte(player->vip()->getMaxGroupEntries() - vipGroups.size()); // max vip groups @@ -7486,7 +7472,7 @@ void ProtocolGame::sendPreyData(const std::unique_ptr &slot) { // Empty } else if (slot->state == PreyDataState_Active) { if (const auto mtype = g_monsters().getMonsterTypeByRaceId(slot->selectedRaceId)) { - msg.addString(mtype->name, "ProtocolGame::sendPreyData - mtype->name"); + msg.addString(mtype->name); const Outfit_t outfit = mtype->info.outfit; msg.add(outfit.lookType); if (outfit.lookType == 0) { @@ -7512,7 +7498,7 @@ void ProtocolGame::sendPreyData(const std::unique_ptr &slot) { continue; } - msg.addString(mtype->name, "ProtocolGame::sendPreyData - mtype->name"); + msg.addString(mtype->name); const Outfit_t outfit = mtype->info.outfit; msg.add(outfit.lookType); if (outfit.lookType == 0) { @@ -7537,7 +7523,7 @@ void ProtocolGame::sendPreyData(const std::unique_ptr &slot) { continue; } - msg.addString(mtype->name, "ProtocolGame::sendPreyData - mtype->name"); + msg.addString(mtype->name); const Outfit_t outfit = mtype->info.outfit; msg.add(outfit.lookType); if (outfit.lookType == 0) { @@ -7605,18 +7591,18 @@ void ProtocolGame::sendModalWindow(const ModalWindow &modalWindow) { msg.addByte(0xFA); msg.add(modalWindow.id); - msg.addString(modalWindow.title, "ProtocolGame::sendModalWindow - modalWindow.title"); - msg.addString(modalWindow.message, "ProtocolGame::sendModalWindow - modalWindow.message"); + msg.addString(modalWindow.title); + msg.addString(modalWindow.message); msg.addByte(modalWindow.buttons.size()); for (const auto &it : modalWindow.buttons) { - msg.addString(it.first, "ProtocolGame::sendModalWindow - it.first"); + msg.addString(it.first); msg.addByte(it.second); } msg.addByte(modalWindow.choices.size()); for (const auto &it : modalWindow.choices) { - msg.addString(it.first, "ProtocolGame::sendModalWindow - it.first"); + msg.addString(it.first); msg.addByte(it.second); } @@ -7656,7 +7642,7 @@ void ProtocolGame::AddCreature(NetworkMessage &msg, std::shared_ptr cr if (!oldProtocol && creature->isHealthHidden()) { msg.addString(std::string()); } else { - msg.addString(creature->getName(), "ProtocolGame::AddCreature - creature->getName()"); + msg.addString(creature->getName()); } } @@ -7875,10 +7861,9 @@ void ProtocolGame::addImbuementInfo(NetworkMessage &msg, uint16_t imbuementId) c const CategoryImbuement* categoryImbuement = g_imbuements().getCategoryByID(imbuement->getCategory()); msg.add(imbuementId); - msg.addString(baseImbuement->name + " " + imbuement->getName(), "ProtocolGame::addImbuementInfo - baseImbuement->name + " - " + imbuement->getName()"); - msg.addString(imbuement->getDescription(), "ProtocolGame::addImbuementInfo - imbuement->getDescription()"); - msg.addString(categoryImbuement->name + imbuement->getSubGroup(), "ProtocolGame::addImbuementInfo - categoryImbuement->name + imbuement->getSubGroup()"); + msg.addString(baseImbuement->name + " " + imbuement->getName()); + msg.addString(imbuement->getDescription()); + msg.addString(categoryImbuement->name + imbuement->getSubGroup()); msg.add(imbuement->getIconID()); msg.add(baseImbuement->duration); @@ -7891,7 +7876,7 @@ void ProtocolGame::addImbuementInfo(NetworkMessage &msg, uint16_t imbuementId) c for (const auto &itm : items) { const ItemType &it = Item::items[itm.first]; msg.add(itm.first); - msg.addString(it.name, "ProtocolGame::addImbuementInfo - it.name"); + msg.addString(it.name); msg.add(itm.second); } @@ -7963,7 +7948,7 @@ void ProtocolGame::sendMessageDialog(const std::string &message) { NetworkMessage msg; msg.addByte(0xED); msg.addByte(0x14); // Unknown type - msg.addString(message, "ProtocolGame::sendMessageDialog - message"); + msg.addString(message); writeToOutputBuffer(msg); } @@ -7971,7 +7956,7 @@ void ProtocolGame::sendImbuementResult(const std::string message) { NetworkMessage msg; msg.addByte(0xED); msg.addByte(0x01); - msg.addString(message, "ProtocolGame::sendImbuementResult - message"); + msg.addString(message); writeToOutputBuffer(msg); } @@ -8032,7 +8017,7 @@ void ProtocolGame::updatePartyTrackerAnalyzer(const std::shared_ptr party msg.addByte(static_cast(party->membersData.size())); for (const std::shared_ptr &analyzer : party->membersData) { msg.add(analyzer->id); - msg.addString(analyzer->name, "ProtocolGame::updatePartyTrackerAnalyzer - analyzer->name"); + msg.addString(analyzer->name); } } @@ -8068,7 +8053,7 @@ void ProtocolGame::sendKillTrackerUpdate(std::shared_ptr corpse, cons NetworkMessage msg; msg.addByte(0xD1); - msg.addString(name, "ProtocolGame::sendKillTrackerUpdate - name"); + msg.addString(name); msg.add(creatureOutfit.lookType ? creatureOutfit.lookType : 21); msg.addByte(creatureOutfit.lookType ? creatureOutfit.lookHead : 0x00); msg.addByte(creatureOutfit.lookType ? creatureOutfit.lookBody : 0x00); @@ -8136,7 +8121,7 @@ void ProtocolGame::sendUpdateInputAnalyzer(CombatType_t type, int32_t amount, st msg.addByte(ANALYZER_DAMAGE_RECEIVED); msg.add(amount); msg.addByte(clientElement); - msg.addString(target, "ProtocolGame::sendUpdateInputAnalyzer - target"); + msg.addString(target); writeToOutputBuffer(msg); } @@ -8323,9 +8308,9 @@ void ProtocolGame::AddShopItem(NetworkMessage &msg, const ShopBlock &shopBlock) // If not send "itemName" variable from the npc shop, will registered the name that is in items.xml if (shopBlock.itemName.empty()) { - msg.addString(it.name, "ProtocolGame::AddShopItem - it.name"); + msg.addString(it.name); } else { - msg.addString(shopBlock.itemName, "ProtocolGame::AddShopItem - shopBlock.itemName"); + msg.addString(shopBlock.itemName); } msg.add(it.weight); msg.add(shopBlock.itemBuyPrice == 4294967295 ? 0 : shopBlock.itemBuyPrice); @@ -8407,8 +8392,7 @@ void ProtocolGame::sendInventoryImbuements(const std::mapgetBaseID()); msg.addByte(0x01); - msg.addString(baseImbuement->name + " " + imbuement->getName(), "ProtocolGame::sendInventoryImbuements - baseImbuement->name + " - " + imbuement->getName()"); + msg.addString(baseImbuement->name + " " + imbuement->getName()); msg.add(imbuement->getIconID()); msg.add(imbuementInfo.duration); @@ -9007,9 +8991,9 @@ void ProtocolGame::sendPodiumDetails(NetworkMessage &msg, const std::vectorname, "ProtocolGame::sendPodiumDetails - mType->name"); + msg.addString(mType->name); } msg.add(monsterOutfit.lookType); if (isLookType) { diff --git a/src/server/network/protocol/protocolgame.hpp b/src/server/network/protocol/protocolgame.hpp index 2a5fde6c6c4..769771c975a 100644 --- a/src/server/network/protocol/protocolgame.hpp +++ b/src/server/network/protocol/protocolgame.hpp @@ -143,7 +143,7 @@ class ProtocolGame final : public Protocol { void parseGreet(NetworkMessage &msg); void parseBugReport(NetworkMessage &msg); - void parseDebugAssert(NetworkMessage &msg); + void parseOfferDescription(NetworkMessage &msg); void parsePreyAction(NetworkMessage &msg); void parseSendResourceBalance(); void parseRuleViolationReport(NetworkMessage &msg); diff --git a/src/server/network/protocol/protocollogin.cpp b/src/server/network/protocol/protocollogin.cpp index f8c68634f64..9cf6cc1c370 100644 --- a/src/server/network/protocol/protocollogin.cpp +++ b/src/server/network/protocol/protocollogin.cpp @@ -23,7 +23,7 @@ void ProtocolLogin::disconnectClient(const std::string &message) { auto output = OutputMessagePool::getOutputMessage(); output->addByte(0x0B); - output->addString(message, "ProtocolLogin::disconnectClient - message"); + output->addString(message); send(output); disconnect(); @@ -57,12 +57,12 @@ void ProtocolLogin::getCharacterList(const std::string &accountDescriptor, const std::ostringstream ss; ss << g_game().getMotdNum() << "\n" << motd; - output->addString(ss.str(), "ProtocolLogin::getCharacterList - ss.str()"); + output->addString(ss.str()); } // Add session key output->addByte(0x28); - output->addString(accountDescriptor + "\n" + password, "ProtocolLogin::getCharacterList - accountDescriptor + password"); + output->addString(accountDescriptor + "\n" + password); // Add char list auto [players, result] = account.getAccountPlayers(); @@ -75,8 +75,8 @@ void ProtocolLogin::getCharacterList(const std::string &accountDescriptor, const output->addByte(1); // number of worlds output->addByte(0); // world id - output->addString(g_configManager().getString(SERVER_NAME, __FUNCTION__), "ProtocolLogin::getCharacterList - _configManager().getString(SERVER_NAME)"); - output->addString(g_configManager().getString(IP, __FUNCTION__), "ProtocolLogin::getCharacterList - g_configManager().getString(IP)"); + output->addString(g_configManager().getString(SERVER_NAME, __FUNCTION__)); + output->addString(g_configManager().getString(IP, __FUNCTION__)); output->add(g_configManager().getNumber(GAME_PORT, __FUNCTION__)); @@ -86,7 +86,7 @@ void ProtocolLogin::getCharacterList(const std::string &accountDescriptor, const output->addByte(size); for (const auto &[name, deletion] : players) { output->addByte(0); - output->addString(name, "ProtocolLogin::getCharacterList - name"); + output->addString(name); } // Get premium days, check is premium and get lastday diff --git a/src/server/network/protocol/protocolstatus.cpp b/src/server/network/protocol/protocolstatus.cpp index f9ec878eda9..1e7e68e1542 100644 --- a/src/server/network/protocol/protocolstatus.cpp +++ b/src/server/network/protocol/protocolstatus.cpp @@ -167,22 +167,22 @@ void ProtocolStatus::sendInfo(uint16_t requestedInfo, const std::string &charact if (requestedInfo & REQUEST_BASIC_SERVER_INFO) { output->addByte(0x10); - output->addString(g_configManager().getString(ConfigKey_t::SERVER_NAME, __FUNCTION__), "ProtocolStatus::sendInfo - g_configManager().getString(stringConfig_t::SERVER_NAME)"); - output->addString(g_configManager().getString(IP, __FUNCTION__), "ProtocolStatus::sendInfo - g_configManager().getString(IP)"); - output->addString(std::to_string(g_configManager().getNumber(LOGIN_PORT, __FUNCTION__)), "ProtocolStatus::sendInfo - std::to_string(g_configManager().getNumber(LOGIN_PORT))"); + output->addString(g_configManager().getString(ConfigKey_t::SERVER_NAME, __FUNCTION__)); + output->addString(g_configManager().getString(IP, __FUNCTION__)); + output->addString(std::to_string(g_configManager().getNumber(LOGIN_PORT, __FUNCTION__))); } if (requestedInfo & REQUEST_OWNER_SERVER_INFO) { output->addByte(0x11); - output->addString(g_configManager().getString(OWNER_NAME, __FUNCTION__), "ProtocolStatus::sendInfo - g_configManager().getString(OWNER_NAME)"); - output->addString(g_configManager().getString(OWNER_EMAIL, __FUNCTION__), "ProtocolStatus::sendInfo - g_configManager().getString(OWNER_EMAIL)"); + output->addString(g_configManager().getString(OWNER_NAME, __FUNCTION__)); + output->addString(g_configManager().getString(OWNER_EMAIL, __FUNCTION__)); } if (requestedInfo & REQUEST_MISC_SERVER_INFO) { output->addByte(0x12); - output->addString(g_configManager().getString(SERVER_MOTD, __FUNCTION__), "ProtocolStatus::sendInfo - g_configManager().getString(SERVER_MOTD)"); - output->addString(g_configManager().getString(LOCATION, __FUNCTION__), "ProtocolStatus::sendInfo - g_configManager().getString(LOCATION)"); - output->addString(g_configManager().getString(URL, __FUNCTION__), "ProtocolStatus::sendInfo - g_configManager().getString(URL)"); + output->addString(g_configManager().getString(SERVER_MOTD, __FUNCTION__)); + output->addString(g_configManager().getString(LOCATION, __FUNCTION__)); + output->addString(g_configManager().getString(URL, __FUNCTION__)); output->add((OTSYS_TIME() - ProtocolStatus::start) / 1000); } @@ -195,8 +195,8 @@ void ProtocolStatus::sendInfo(uint16_t requestedInfo, const std::string &charact if (requestedInfo & REQUEST_MAP_INFO) { output->addByte(0x30); - output->addString(g_configManager().getString(MAP_NAME, __FUNCTION__), "ProtocolStatus::sendInfo - g_configManager().getString(MAP_NAME)"); - output->addString(g_configManager().getString(MAP_AUTHOR, __FUNCTION__), "ProtocolStatus::sendInfo - g_configManager().getString(MAP_AUTHOR)"); + output->addString(g_configManager().getString(MAP_NAME, __FUNCTION__)); + output->addString(g_configManager().getString(MAP_AUTHOR, __FUNCTION__)); uint32_t mapWidth, mapHeight; g_game().getMapDimensions(mapWidth, mapHeight); output->add(mapWidth); @@ -209,7 +209,7 @@ void ProtocolStatus::sendInfo(uint16_t requestedInfo, const std::string &charact const auto players = g_game().getPlayers(); output->add(players.size()); for (const auto &it : players) { - output->addString(it.second->getName(), "ProtocolStatus::sendInfo - it.second->getName()"); + output->addString(it.second->getName()); output->add(it.second->getLevel()); } } @@ -225,9 +225,9 @@ void ProtocolStatus::sendInfo(uint16_t requestedInfo, const std::string &charact if (requestedInfo & REQUEST_SERVER_SOFTWARE_INFO) { output->addByte(0x23); // server software info - output->addString(ProtocolStatus::SERVER_NAME, "ProtocolStatus::sendInfo - ProtocolStatus::SERVER_NAME"); - output->addString(ProtocolStatus::SERVER_VERSION, "ProtocolStatus::sendInfo - ProtocolStatus::SERVER_VERSION)"); - output->addString(fmt::format("{}.{}", CLIENT_VERSION_UPPER, CLIENT_VERSION_LOWER), "ProtocolStatus::sendInfo - fmt::format(CLIENT_VERSION_UPPER, CLIENT_VERSION_LOWER)"); + output->addString(ProtocolStatus::SERVER_NAME); + output->addString(ProtocolStatus::SERVER_VERSION); + output->addString(fmt::format("{}.{}", CLIENT_VERSION_UPPER, CLIENT_VERSION_LOWER)); } send(output); disconnect(); diff --git a/src/utils/const.hpp b/src/utils/const.hpp index c3f82df7ff7..4cc296e4a7e 100644 --- a/src/utils/const.hpp +++ b/src/utils/const.hpp @@ -35,6 +35,8 @@ static constexpr int32_t STORAGEVALUE_HAZARDCOUNT = 112550; // Wheel of destiny static constexpr int32_t STORAGEVALUE_GIFT_OF_LIFE_COOLDOWN_WOD = 43200; +constexpr double SCALING_BASE = 10.0; + // Reserved player storage key ranges; // [10000000 - 20000000]; static constexpr int32_t PSTRG_RESERVED_RANGE_START = 10000000; diff --git a/tests/build_and_run.sh b/tests/build_and_run.sh index 3d5531ebf0b..ac4ccad512c 100755 --- a/tests/build_and_run.sh +++ b/tests/build_and_run.sh @@ -3,10 +3,12 @@ docker-compose down --rmi all -v --remove-orphans docker-compose up --build -d cd .. -mkdir build -cd build -cmake -DPACKAGE_TESTS=On .. ; make -j`nproc` -./tests/canary_unittest --reporter compact --success -d yes +if [ ! -d "build" ]; then + mkdir build +fi +cd build || exit +cmake -DCMAKE_BUILD_TYPE=Debug -DPACKAGE_TESTS=On .. ; make -j"$(nproc)" +./tests/unit/canary_ut --reporter compact --success cd .. -cd tests +cd tests || exit docker-compose down --rmi all -v --remove-orphans diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 8d234a676a2..5da4ec590ce 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -4,4 +4,5 @@ add_subdirectory(account) add_subdirectory(kv) add_subdirectory(lib) add_subdirectory(security) +add_subdirectory(server) add_subdirectory(utils) diff --git a/tests/unit/server/CMakeLists.txt b/tests/unit/server/CMakeLists.txt new file mode 100644 index 00000000000..ec98d50a3f9 --- /dev/null +++ b/tests/unit/server/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(canary_ut PRIVATE + network/message/networkmessage_test.cpp +) diff --git a/tests/unit/server/network/message/networkmessage_test.cpp b/tests/unit/server/network/message/networkmessage_test.cpp new file mode 100644 index 00000000000..f1ec904a3bf --- /dev/null +++ b/tests/unit/server/network/message/networkmessage_test.cpp @@ -0,0 +1,144 @@ +#include "pch.hpp" + +#include + +#include "lib/logging/in_memory_logger.hpp" + +#include "server/network/message/networkmessage.hpp" +#include "utils/tools.hpp" + +using namespace boost::ut; + +// Define a test suite for NetworkMessage +suite<"networkmessage"> networkMessageTest = [] { + di::extension::injector<> injector {}; + DI::setTestContainer(&InMemoryLogger::install(injector)); + auto& logger = dynamic_cast(injector.create()); + + test("NetworkMessage::addByte and getByte") = [&]() { + NetworkMessage msg; + uint8_t byteToAdd = 100; + msg.addByte(byteToAdd); + msg.setBufferPosition(NetworkMessage::INITIAL_BUFFER_POSITION); + auto byte = msg.getByte(); + expect(eq(byte, byteToAdd)) << "Expected: " << byteToAdd << ", Got: " << byte; + }; + + test("NetworkMessage::addString and getString") = [&]() { + NetworkMessage msg; + std::string testStr = "TestString"; + msg.addString(testStr); + msg.setBufferPosition(NetworkMessage::INITIAL_BUFFER_POSITION); + std::string retrievedStr = msg.getString(); + expect(eq(retrievedStr, testStr)) << "Expected: \"" << testStr << "\", Got: \"" << retrievedStr << "\""; + }; + + test("NetworkMessage::addString should handle empty string") = [&]() { + NetworkMessage msg; + msg.addString(""); + msg.setBufferPosition(NetworkMessage::INITIAL_BUFFER_POSITION); + expect(eq(msg.getString(), std::string {})) << "Expected to retrieve an empty string"; + }; + + test("NetworkMessage::addString should fail with oversized string") = [&]() { + NetworkMessage msg; + std::string oversizedString(NETWORKMESSAGE_MAXSIZE + 1, 'a'); + msg.addString(oversizedString); + msg.setBufferPosition(NetworkMessage::INITIAL_BUFFER_POSITION); + expect(eq(msg.getString(), std::string {})) << "Expected to retrieve an empty string due to oversized input"; + }; + + test("NetworkMessage::canAdd should return false when exceeding max size") = [&]() { + NetworkMessage msg; + expect(not msg.canAdd(NETWORKMESSAGE_MAXSIZE)) << "Should have enough space in buffer"; + expect(not msg.canAdd(NETWORKMESSAGE_MAXSIZE + 1)) << "Should not be able to add data exceeding the max buffer size"; + }; + + test("NetworkMessage::addDouble and getDouble") = [&]() { + NetworkMessage msg; + double testValue = 123.123; + uint8_t precision = 3; + msg.addDouble(testValue, precision); + msg.setBufferPosition(NetworkMessage::INITIAL_BUFFER_POSITION); + double retrievedValue = msg.getDouble(); + expect(abs(retrievedValue - testValue) < 1e-6) << "Expected: " << testValue << ", Got: " << retrievedValue; + }; + + test("NetworkMessage::addPosition and getPosition") = [&]() { + NetworkMessage msg; + Position pos { 100, 200, 7 }; + msg.addPosition(pos); + msg.setBufferPosition(NetworkMessage::INITIAL_BUFFER_POSITION); + Position retrievedPos = msg.getPosition(); + expect(eq(retrievedPos, pos)) << "Expected to retrieve the same position values"; + }; + + test("NetworkMessage::reset should clear buffer") = [&]() { + NetworkMessage msg; + msg.addByte(0x64); + msg.reset(); + expect(eq(msg.getLength(), 0)) << "Expected the message length to be zero after reset"; + }; + + test("NetworkMessage::append should merge messages correctly") = [&]() { + NetworkMessage msg1, msg2; + + // Adding initial byte and string to msg1 + msg1.addByte(1); // Byte value 1 + msg1.addString("Hello"); // String value "Hello" + // Adding initial byte and string to msg2 + msg2.addByte(2); // Byte value 2 + msg2.addString("World"); // String value "World" + // Append msg2 to msg1 + msg1.append(msg2); + msg1.setBufferPosition(NetworkMessage::INITIAL_BUFFER_POSITION); // Reset read position to start + // Verify the first byte (msg1) + uint8_t byte1 = msg1.getByte(); + expect(eq(byte1, 1)) << "Expected the first byte of the first message (1)"; + // Verify the first string (msg1) + std::string str1 = msg1.getString(); + expect(eq(str1, std::string("Hello"))) << "Expected the first string of the first message"; + // Verify the second byte (msg2) + uint8_t byte2 = msg1.getByte(); + expect(eq(byte2, 2)) << "Expected the first byte of the second message (2)"; + // Verify the second string (msg2) + std::string str2 = msg1.getString(); + expect(eq(str2, std::string("World"))) << "Expected the first string of the second message"; + }; + + test("NetworkMessage::getString should handle out-of-bounds access safely") = [&]() { + NetworkMessage msg; + std::string testStr = "Short"; + msg.addString(testStr); + + // Move the position to simulate incomplete data read + msg.setBufferPosition(msg.getBufferPosition() + 10); + expect(eq(msg.getString(), std::string {})) << "Expected empty string due to out-of-bounds access"; + }; + + test("NetworkMessage::decodeHeader should correctly decode the header") = [&]() { + NetworkMessage msg; + msg.addByte(0x12); + msg.addByte(0x34); + + msg.setBufferPosition(NetworkMessage::INITIAL_BUFFER_POSITION); + int32_t header = msg.decodeHeader(); + expect(eq(header, 0x3412)) << "Expected header to be decoded correctly"; + }; + + test("NetworkMessage::addBytes and validate content") = [&]() { + NetworkMessage msg; + std::string testData = "testBytes"; + + // Add bytes to the buffer + msg.addBytes(testData.data(), testData.size()); + // Set buffer position to the initial position for reading the added data + msg.setBufferPosition(NetworkMessage::INITIAL_BUFFER_POSITION); + // Verify the content of the buffer before extracting the data + auto buffer = msg.getBuffer(); + std::string extractedData(buffer + NetworkMessage::INITIAL_BUFFER_POSITION, + buffer + NetworkMessage::INITIAL_BUFFER_POSITION + testData.size()); + // Check if the extracted data matches the added data + expect(eq(extractedData, testData)) << "Expected the same bytes added"; + }; +}; From 899c1eb9e474bcaa9219510612c54eaaf38734d4 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Sun, 29 Sep 2024 13:32:05 -0300 Subject: [PATCH 5/6] fix: player lose items with wrong loading offline informations (#2919) When the player is offline, in some scenarios the empty items would load and the items would be overlapped with the empty table of the offline player. Resolves #2917 Related to: https://github.com/opentibiabr/canary/pull/2910 --- .../players/cyclopedia/player_badge.cpp | 2 +- src/game/game.cpp | 10 ++- src/io/functions/iologindata_load_player.cpp | 63 ++++++++++--------- src/io/functions/iologindata_load_player.hpp | 2 +- src/io/iologindata.cpp | 20 +++--- src/io/iologindata.hpp | 6 +- 6 files changed, 53 insertions(+), 50 deletions(-) diff --git a/src/creatures/players/cyclopedia/player_badge.cpp b/src/creatures/players/cyclopedia/player_badge.cpp index 639640b2ffe..5f78c1a2e3c 100644 --- a/src/creatures/players/cyclopedia/player_badge.cpp +++ b/src/creatures/players/cyclopedia/player_badge.cpp @@ -116,7 +116,7 @@ bool PlayerBadge::loyalty(uint8_t amount) { } bool PlayerBadge::accountAllLevel(uint8_t amount) { - const auto &players = g_game().getPlayersByAccount(m_player.getAccount(), true); + auto players = g_game().getPlayersByAccount(m_player.getAccount(), true); uint16_t total = std::accumulate(players.begin(), players.end(), 0, [](uint16_t sum, const std::shared_ptr &player) { return sum + player->getLevel(); }); diff --git a/src/game/game.cpp b/src/game/game.cpp index 3a579ec2fdf..77dffe532f0 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -1014,8 +1014,9 @@ std::shared_ptr Game::getPlayerByGUID(const uint32_t &guid, bool allowOf if (!allowOffline) { return nullptr; } + std::shared_ptr tmpPlayer = std::make_shared(nullptr); - if (!IOLoginData::loadPlayerById(tmpPlayer, guid)) { + if (!IOLoginData::loadPlayerById(tmpPlayer, guid, false)) { return nullptr; } tmpPlayer->setOnline(false); @@ -1029,7 +1030,9 @@ std::string Game::getPlayerNameByGUID(const uint32_t &guid) { if (m_playerNameCache.contains(guid)) { return m_playerNameCache.at(guid); } - auto player = getPlayerByGUID(guid, true); + + // This player need read-only purposes and never saved + const auto &player = getPlayerByGUID(guid, true); auto name = player ? player->getName() : ""; if (!name.empty()) { m_playerNameCache[guid] = name; @@ -1068,9 +1071,10 @@ std::vector> Game::getPlayersByAccount(std::shared_ptr> ret; for (const auto &[name, _] : accountPlayers) { - auto player = getPlayerByName(name, allowOffline); + const auto &player = getPlayerByName(name, allowOffline); if (player) { ret.push_back(player); } diff --git a/src/io/functions/iologindata_load_player.cpp b/src/io/functions/iologindata_load_player.cpp index 63ca7939c46..66be7927692 100644 --- a/src/io/functions/iologindata_load_player.cpp +++ b/src/io/functions/iologindata_load_player.cpp @@ -105,9 +105,9 @@ bool IOLoginDataLoad::preLoadPlayer(std::shared_ptr player, const std::s return true; } -bool IOLoginDataLoad::loadPlayerFirst(std::shared_ptr player, DBResult_ptr result) { +bool IOLoginDataLoad::loadPlayerBasicInfo(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return false; } @@ -184,12 +184,15 @@ bool IOLoginDataLoad::loadPlayerFirst(std::shared_ptr player, DBResult_p player->setMaxManaShield(result->getNumber("max_manashield")); player->setMarriageSpouse(result->getNumber("marriage_spouse")); + + // Experience load + IOLoginDataLoad::loadPlayerExperience(player, result); return true; } void IOLoginDataLoad::loadPlayerExperience(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -212,7 +215,7 @@ void IOLoginDataLoad::loadPlayerExperience(std::shared_ptr player, DBRes void IOLoginDataLoad::loadPlayerBlessings(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -223,7 +226,7 @@ void IOLoginDataLoad::loadPlayerBlessings(std::shared_ptr player, DBResu void IOLoginDataLoad::loadPlayerConditions(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -243,13 +246,13 @@ void IOLoginDataLoad::loadPlayerConditions(std::shared_ptr player, DBRes void IOLoginDataLoad::loadPlayerDefaultOutfit(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } player->defaultOutfit.lookType = result->getNumber("looktype"); if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS, __FUNCTION__) && player->defaultOutfit.lookType != 0 && !g_game().isLookTypeRegistered(player->defaultOutfit.lookType)) { - g_logger().warn("[IOLoginData::loadPlayer] An unregistered creature looktype type with id '{}' was blocked to prevent client crash.", player->defaultOutfit.lookType); + g_logger().warn("[{}] An unregistered creature looktype type with id '{}' was blocked to prevent client crash.", __FUNCTION__, player->defaultOutfit.lookType); return; } @@ -265,7 +268,7 @@ void IOLoginDataLoad::loadPlayerDefaultOutfit(std::shared_ptr player, DB player->defaultOutfit.lookFamiliarsType = result->getNumber("lookfamiliarstype"); if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS, __FUNCTION__) && player->defaultOutfit.lookFamiliarsType != 0 && !g_game().isLookTypeRegistered(player->defaultOutfit.lookFamiliarsType)) { - g_logger().warn("[IOLoginData::loadPlayer] An unregistered creature looktype type with id '{}' was blocked to prevent client crash.", player->defaultOutfit.lookFamiliarsType); + g_logger().warn("[{}] An unregistered creature looktype type with id '{}' was blocked to prevent client crash.", __FUNCTION__, player->defaultOutfit.lookFamiliarsType); return; } @@ -274,7 +277,7 @@ void IOLoginDataLoad::loadPlayerDefaultOutfit(std::shared_ptr player, DB void IOLoginDataLoad::loadPlayerSkullSystem(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -296,7 +299,7 @@ void IOLoginDataLoad::loadPlayerSkullSystem(std::shared_ptr player, DBRe void IOLoginDataLoad::loadPlayerSkill(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -318,7 +321,7 @@ void IOLoginDataLoad::loadPlayerSkill(std::shared_ptr player, DBResult_p void IOLoginDataLoad::loadPlayerKills(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -337,7 +340,7 @@ void IOLoginDataLoad::loadPlayerKills(std::shared_ptr player, DBResult_p void IOLoginDataLoad::loadPlayerGuild(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -387,7 +390,7 @@ void IOLoginDataLoad::loadPlayerGuild(std::shared_ptr player, DBResult_p void IOLoginDataLoad::loadPlayerStashItems(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -403,7 +406,7 @@ void IOLoginDataLoad::loadPlayerStashItems(std::shared_ptr player, DBRes void IOLoginDataLoad::loadPlayerBestiaryCharms(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -456,7 +459,7 @@ void IOLoginDataLoad::loadPlayerBestiaryCharms(std::shared_ptr player, D void IOLoginDataLoad::loadPlayerInstantSpellList(std::shared_ptr player, DBResult_ptr result) { if (!player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player nullptr", __FUNCTION__); return; } @@ -472,7 +475,7 @@ void IOLoginDataLoad::loadPlayerInstantSpellList(std::shared_ptr player, void IOLoginDataLoad::loadPlayerInventoryItems(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -554,7 +557,7 @@ void IOLoginDataLoad::loadPlayerInventoryItems(std::shared_ptr player, D void IOLoginDataLoad::loadPlayerStoreInbox(std::shared_ptr player) { if (!player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player nullptr", __FUNCTION__); return; } @@ -565,7 +568,7 @@ void IOLoginDataLoad::loadPlayerStoreInbox(std::shared_ptr player) { void IOLoginDataLoad::loadRewardItems(std::shared_ptr player) { if (!player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player nullptr", __FUNCTION__); return; } @@ -583,7 +586,7 @@ void IOLoginDataLoad::loadRewardItems(std::shared_ptr player) { void IOLoginDataLoad::loadPlayerDepotItems(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -622,7 +625,7 @@ void IOLoginDataLoad::loadPlayerDepotItems(std::shared_ptr player, DBRes void IOLoginDataLoad::loadPlayerInboxItems(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -658,7 +661,7 @@ void IOLoginDataLoad::loadPlayerInboxItems(std::shared_ptr player, DBRes void IOLoginDataLoad::loadPlayerStorageMap(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -674,7 +677,7 @@ void IOLoginDataLoad::loadPlayerStorageMap(std::shared_ptr player, DBRes void IOLoginDataLoad::loadPlayerVip(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -712,7 +715,7 @@ void IOLoginDataLoad::loadPlayerVip(std::shared_ptr player, DBResult_ptr void IOLoginDataLoad::loadPlayerPreyClass(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -759,7 +762,7 @@ void IOLoginDataLoad::loadPlayerPreyClass(std::shared_ptr player, DBResu void IOLoginDataLoad::loadPlayerTaskHuntingClass(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -809,7 +812,7 @@ void IOLoginDataLoad::loadPlayerTaskHuntingClass(std::shared_ptr player, void IOLoginDataLoad::loadPlayerForgeHistory(std::shared_ptr player, DBResult_ptr result) { if (!result || !player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player or Result nullptr", __FUNCTION__); return; } @@ -830,12 +833,12 @@ void IOLoginDataLoad::loadPlayerForgeHistory(std::shared_ptr player, DBR void IOLoginDataLoad::loadPlayerBosstiary(std::shared_ptr player, DBResult_ptr result) { if (!result) { - g_logger().warn("[IOLoginData::loadPlayer] - Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Result nullptr", __FUNCTION__); return; } if (!player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player or Result nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player nullptr", __FUNCTION__); return; } @@ -867,7 +870,7 @@ void IOLoginDataLoad::loadPlayerBosstiary(std::shared_ptr player, DBResu void IOLoginDataLoad::bindRewardBag(std::shared_ptr player, ItemsMap &rewardItemsMap) { if (!player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player nullptr", __FUNCTION__); return; } @@ -907,7 +910,7 @@ void IOLoginDataLoad::insertItemsIntoRewardBag(const ItemsMap &rewardItemsMap) { void IOLoginDataLoad::loadPlayerInitializeSystem(std::shared_ptr player) { if (!player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player nullptr", __FUNCTION__); return; } @@ -926,7 +929,7 @@ void IOLoginDataLoad::loadPlayerInitializeSystem(std::shared_ptr player) void IOLoginDataLoad::loadPlayerUpdateSystem(std::shared_ptr player) { if (!player) { - g_logger().warn("[IOLoginData::loadPlayer] - Player nullptr: {}", __FUNCTION__); + g_logger().warn("[{}] - Player nullptr", __FUNCTION__); return; } diff --git a/src/io/functions/iologindata_load_player.hpp b/src/io/functions/iologindata_load_player.hpp index 07a478d2dc3..e67faf4d8c1 100644 --- a/src/io/functions/iologindata_load_player.hpp +++ b/src/io/functions/iologindata_load_player.hpp @@ -13,7 +13,7 @@ class IOLoginDataLoad : public IOLoginData { public: - static bool loadPlayerFirst(std::shared_ptr player, DBResult_ptr result); + static bool loadPlayerBasicInfo(std::shared_ptr player, DBResult_ptr result); static bool preLoadPlayer(std::shared_ptr player, const std::string &name); static void loadPlayerExperience(std::shared_ptr player, DBResult_ptr result); static void loadPlayerBlessings(std::shared_ptr player, DBResult_ptr result); diff --git a/src/io/iologindata.cpp b/src/io/iologindata.cpp index 41f8cea8985..de445bb70f8 100644 --- a/src/io/iologindata.cpp +++ b/src/io/iologindata.cpp @@ -94,22 +94,22 @@ void IOLoginData::updateOnlineStatus(uint32_t guid, bool login) { Database::getInstance().executeQuery(query.str()); } -// The boolean "disableIrrelevantInfo" will deactivate the loading of information that is not relevant to the preload, for example, forge, bosstiary, etc. None of this we need to access if the player is offline -bool IOLoginData::loadPlayerById(std::shared_ptr player, uint32_t id, bool disableIrrelevantInfo /* = true*/) { +// The boolean "loadBasicInfoOnly" will deactivate the loading of information that is not relevant to the preload, for example, forge, bosstiary, etc. None of this we need to access if the player is offline +bool IOLoginData::loadPlayerById(std::shared_ptr player, uint32_t id, bool loadBasicInfoOnly /* = true*/) { Database &db = Database::getInstance(); std::ostringstream query; query << "SELECT * FROM `players` WHERE `id` = " << id; - return loadPlayer(player, db.storeQuery(query.str()), disableIrrelevantInfo); + return loadPlayer(player, db.storeQuery(query.str()), loadBasicInfoOnly); } -bool IOLoginData::loadPlayerByName(std::shared_ptr player, const std::string &name, bool disableIrrelevantInfo /* = true*/) { +bool IOLoginData::loadPlayerByName(std::shared_ptr player, const std::string &name, bool loadBasicInfoOnly /* = true*/) { Database &db = Database::getInstance(); std::ostringstream query; query << "SELECT * FROM `players` WHERE `name` = " << db.escapeString(name); - return loadPlayer(player, db.storeQuery(query.str()), disableIrrelevantInfo); + return loadPlayer(player, db.storeQuery(query.str()), loadBasicInfoOnly); } -bool IOLoginData::loadPlayer(std::shared_ptr player, DBResult_ptr result, bool disableIrrelevantInfo /* = false*/) { +bool IOLoginData::loadPlayer(std::shared_ptr player, DBResult_ptr result, bool loadBasicInfoOnly /* = false*/) { if (!result || !player) { std::string nullptrType = !result ? "Result" : "Player"; g_logger().warn("[{}] - {} is nullptr", __FUNCTION__, nullptrType); @@ -118,12 +118,8 @@ bool IOLoginData::loadPlayer(std::shared_ptr player, DBResult_ptr result try { // First - IOLoginDataLoad::loadPlayerFirst(player, result); - - // Experience load - IOLoginDataLoad::loadPlayerExperience(player, result); - - if (disableIrrelevantInfo) { + IOLoginDataLoad::loadPlayerBasicInfo(player, result); + if (loadBasicInfoOnly) { return true; } diff --git a/src/io/iologindata.hpp b/src/io/iologindata.hpp index 79fa3b59ad7..26e200cbf2f 100644 --- a/src/io/iologindata.hpp +++ b/src/io/iologindata.hpp @@ -20,9 +20,9 @@ class IOLoginData { static bool gameWorldAuthentication(const std::string &accountDescriptor, const std::string &sessionOrPassword, std::string &characterName, uint32_t &accountId, bool oldProcotol, const uint32_t ip); static uint8_t getAccountType(uint32_t accountId); static void updateOnlineStatus(uint32_t guid, bool login); - static bool loadPlayerById(std::shared_ptr player, uint32_t id, bool disableIrrelevantInfo = true); - static bool loadPlayerByName(std::shared_ptr player, const std::string &name, bool disableIrrelevantInfo = true); - static bool loadPlayer(std::shared_ptr player, DBResult_ptr result, bool disableIrrelevantInfo = false); + static bool loadPlayerById(std::shared_ptr player, uint32_t id, bool loadBasicInfoOnly = true); + static bool loadPlayerByName(std::shared_ptr player, const std::string &name, bool loadBasicInfoOnly = true); + static bool loadPlayer(std::shared_ptr player, DBResult_ptr result, bool loadBasicInfoOnly = false); static bool savePlayer(std::shared_ptr player); static uint32_t getGuidByName(const std::string &name); static bool getGuidByNameEx(uint32_t &guid, bool &specialVip, std::string &name); From e938b75c9e37c0d0b45f83738f86abc7f56dd33a Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Sun, 29 Sep 2024 14:57:41 -0300 Subject: [PATCH 6/6] fix: circular inclusion related to network/protocol/connection (#2924) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug Fixes and Improvements • Fixed a minor bug in the unit test. • Improved the tests build and run scripts. • Removed all redundant pch.hpp includes from the .cpp files as the directive ```target_precompile_headers(${PROJECT_NAME}_lib PUBLIC pch.hpp)``` now handles that automatically. • Added the precompiled file correctly in the visual studio solution • Resolved several circular dependencies involving the following components: - Connection - KV - Protocol --- CMakeLists.txt | 2 +- cmake/modules/CanaryLib.cmake | 4 +- src/account/account.cpp | 2 - src/account/account_repository.cpp | 2 - src/account/account_repository_db.cpp | 2 - src/canary_server.cpp | 2 - src/config/configmanager.cpp | 2 - src/creatures/appearance/mounts/mounts.cpp | 2 - src/creatures/appearance/outfit/outfit.cpp | 2 - src/creatures/combat/combat.cpp | 2 - src/creatures/combat/condition.cpp | 2 - src/creatures/combat/spells.cpp | 2 - src/creatures/creature.cpp | 2 - src/creatures/interactions/chat.cpp | 2 - src/creatures/monsters/monster.cpp | 2 - src/creatures/monsters/monsters.cpp | 2 - .../monsters/spawns/spawn_monster.cpp | 2 - src/creatures/npcs/npc.cpp | 2 - src/creatures/npcs/npcs.cpp | 2 - src/creatures/npcs/spawns/spawn_npc.cpp | 2 - .../achievement/player_achievement.cpp | 2 - .../players/cyclopedia/player_badge.cpp | 2 - .../players/cyclopedia/player_cyclopedia.cpp | 2 - .../players/cyclopedia/player_title.cpp | 2 - src/creatures/players/grouping/familiars.cpp | 2 - src/creatures/players/grouping/groups.cpp | 2 - src/creatures/players/grouping/guild.cpp | 2 - src/creatures/players/grouping/party.cpp | 2 - .../players/imbuements/imbuements.cpp | 1 - src/creatures/players/management/ban.cpp | 2 - src/creatures/players/management/waitlist.cpp | 2 - src/creatures/players/player.cpp | 6 +- src/creatures/players/storages/storages.cpp | 2 - src/creatures/players/vip/player_vip.cpp | 2 - src/creatures/players/vocations/vocation.cpp | 2 - src/creatures/players/wheel/player_wheel.cpp | 52 +++++- src/creatures/players/wheel/player_wheel.hpp | 53 +----- src/creatures/players/wheel/wheel_gems.cpp | 3 +- src/creatures/players/wheel/wheel_gems.hpp | 159 +--------------- src/database/database.cpp | 2 - src/database/databasemanager.cpp | 2 - src/database/databasetasks.cpp | 2 - src/enums/player_wheel.hpp | 171 ++++++++++++++++++ src/game/bank/bank.cpp | 2 - src/game/functions/game_reload.cpp | 2 - src/game/game.cpp | 2 - src/game/movement/position.cpp | 2 - src/game/movement/teleport.cpp | 2 - src/game/scheduling/dispatcher.cpp | 2 - src/game/scheduling/events_scheduler.cpp | 2 - src/game/scheduling/save_manager.cpp | 13 +- src/game/scheduling/save_manager.hpp | 7 +- src/game/scheduling/task.cpp | 2 - src/game/zones/zone.cpp | 2 - src/io/fileloader.cpp | 2 - src/io/filestream.cpp | 2 - src/io/functions/iologindata_load_player.cpp | 6 +- src/io/functions/iologindata_save_player.cpp | 2 - src/io/io_bosstiary.cpp | 2 - src/io/io_wheel.cpp | 4 +- src/io/iobestiary.cpp | 2 - src/io/ioguild.cpp | 2 - src/io/iologindata.cpp | 2 - src/io/iomap.cpp | 1 - src/io/iomapserialize.cpp | 2 - src/io/iomarket.cpp | 2 - src/io/ioprey.cpp | 16 +- src/io/ioprey.hpp | 16 +- src/items/bed.cpp | 2 - src/items/containers/container.cpp | 2 - src/items/containers/depot/depotchest.cpp | 2 - src/items/containers/depot/depotlocker.cpp | 2 - src/items/containers/inbox/inbox.cpp | 2 - src/items/containers/mailbox/mailbox.cpp | 2 - src/items/containers/rewards/reward.cpp | 2 - src/items/containers/rewards/rewardchest.cpp | 2 - src/items/cylinder.cpp | 2 - src/items/decay/decay.cpp | 2 - src/items/functions/item/attribute.cpp | 2 - src/items/functions/item/custom_attribute.cpp | 2 - src/items/functions/item/item_parse.cpp | 2 - src/items/item.cpp | 2 - src/items/items.cpp | 2 - src/items/thing.cpp | 2 - src/items/tile.cpp | 2 - src/items/tile.hpp | 2 +- src/items/trashholder.cpp | 2 - src/items/weapons/weapons.cpp | 2 - src/kv/kv.cpp | 4 +- src/kv/kv_definitions.hpp | 29 +++ src/kv/kv_sql.cpp | 14 +- src/kv/kv_sql.hpp | 16 +- src/kv/value_wrapper.cpp | 2 - src/kv/value_wrapper.hpp | 11 +- src/kv/value_wrapper_proto.cpp | 2 - src/lib/di/soft_singleton.cpp | 1 - src/lib/logging/log_with_spd_log.cpp | 1 - src/lib/thread/thread_pool.cpp | 2 - src/lua/callbacks/event_callback.cpp | 2 - src/lua/callbacks/events_callbacks.cpp | 2 - src/lua/creature/actions.cpp | 2 - src/lua/creature/creatureevent.cpp | 2 - src/lua/creature/events.cpp | 2 - src/lua/creature/movement.cpp | 2 - src/lua/creature/raids.cpp | 2 - src/lua/creature/talkaction.cpp | 2 - .../functions/core/game/bank_functions.cpp | 10 +- .../functions/core/game/config_functions.cpp | 2 - .../functions/core/game/game_functions.cpp | 2 - .../functions/core/game/global_functions.cpp | 2 - src/lua/functions/core/game/lua_enums.cpp | 2 - .../core/game/modal_window_functions.cpp | 2 - .../functions/core/game/zone_functions.cpp | 10 +- src/lua/functions/core/libs/bit_functions.cpp | 2 - src/lua/functions/core/libs/db_functions.cpp | 2 - src/lua/functions/core/libs/kv_functions.cpp | 2 - .../functions/core/libs/logger_functions.cpp | 2 - .../functions/core/libs/metrics_functions.cpp | 2 - .../functions/core/libs/result_functions.cpp | 2 - .../network/network_message_functions.cpp | 2 - .../core/network/webhook_functions.cpp | 2 - .../creatures/combat/combat_functions.cpp | 2 - .../creatures/combat/condition_functions.cpp | 2 - .../creatures/combat/spell_functions.cpp | 2 - .../creatures/combat/variant_functions.cpp | 2 - .../creatures/creature_functions.cpp | 2 - .../creatures/monster/charm_functions.cpp | 2 - .../creatures/monster/loot_functions.cpp | 2 - .../creatures/monster/monster_functions.cpp | 2 - .../monster/monster_spell_functions.cpp | 2 - .../monster/monster_type_functions.cpp | 2 - .../functions/creatures/npc/npc_functions.cpp | 2 - .../creatures/npc/npc_type_functions.cpp | 2 - .../creatures/npc/shop_functions.cpp | 2 - .../creatures/player/group_functions.cpp | 2 - .../creatures/player/guild_functions.cpp | 2 - .../creatures/player/mount_functions.cpp | 2 - .../creatures/player/party_functions.cpp | 2 - .../creatures/player/player_functions.cpp | 2 - .../creatures/player/vocation_functions.cpp | 2 - src/lua/functions/events/action_functions.cpp | 2 - .../events/creature_event_functions.cpp | 2 - .../events/event_callback_functions.cpp | 2 - .../events/events_scheduler_functions.cpp | 2 - .../events/global_event_functions.cpp | 2 - .../functions/events/move_event_functions.cpp | 2 - .../events/talk_action_functions.cpp | 2 - .../functions/items/container_functions.cpp | 2 - .../functions/items/imbuement_functions.cpp | 2 - .../items/item_classification_functions.cpp | 2 - src/lua/functions/items/item_functions.cpp | 2 - .../functions/items/item_type_functions.cpp | 2 - src/lua/functions/items/weapon_functions.cpp | 2 - src/lua/functions/lua_functions_loader.cpp | 2 - src/lua/functions/map/house_functions.cpp | 2 - src/lua/functions/map/position_functions.cpp | 2 - src/lua/functions/map/teleport_functions.cpp | 2 - src/lua/functions/map/tile_functions.cpp | 2 - src/lua/functions/map/town_functions.cpp | 2 - src/lua/global/baseevents.cpp | 2 - src/lua/global/globalevent.cpp | 2 - src/lua/modules/modules.cpp | 2 - src/lua/scripts/lua_environment.cpp | 2 - src/lua/scripts/luascript.cpp | 2 - src/lua/scripts/script_environment.cpp | 2 - src/lua/scripts/scripts.cpp | 2 - src/main.cpp | 1 - src/map/house/house.cpp | 2 - src/map/house/housetile.cpp | 2 - src/map/map.cpp | 2 - src/map/mapcache.cpp | 2 - src/map/spectators.cpp | 2 - src/map/utils/astarnodes.cpp | 2 - src/map/utils/mapsector.cpp | 2 - src/pch.cpp | 11 ++ src/security/argon.cpp | 2 - src/security/rsa.cpp | 2 - src/server/network/connection/connection.cpp | 46 +++-- src/server/network/connection/connection.hpp | 11 +- src/server/network/message/networkmessage.cpp | 2 - src/server/network/message/outputmessage.cpp | 8 +- src/server/network/message/outputmessage.hpp | 4 +- src/server/network/protocol/protocol.cpp | 65 +++++-- src/server/network/protocol/protocol.hpp | 52 ++---- src/server/network/protocol/protocolgame.cpp | 4 +- src/server/network/protocol/protocolgame.hpp | 2 +- src/server/network/protocol/protocollogin.cpp | 2 - .../network/protocol/protocolstatus.cpp | 2 - src/server/network/webhook/webhook.cpp | 2 - src/server/server.cpp | 2 - src/server/server_definitions.hpp | 2 + src/server/signals.cpp | 2 - src/utils/pugicast.cpp | 2 +- src/utils/tools.cpp | 2 - src/utils/wildcardtree.cpp | 2 - tests/build_and_run.sh | 14 +- tests/integration/main.cpp | 1 + vcproj/canary.vcxproj | 11 +- 198 files changed, 486 insertions(+), 674 deletions(-) create mode 100644 src/enums/player_wheel.hpp create mode 100644 src/kv/kv_definitions.hpp create mode 100644 src/pch.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d5853366d80..5bee518ecd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,6 +125,6 @@ option(RUN_TESTS_AFTER_BUILD "Run tests when building" OFF) # By default, tests # ***************************************************************************** add_subdirectory(src) -if(BUILD_TESTS) +if(BUILD_TESTS OR PACKAGE_TESTS) add_subdirectory(tests) endif() diff --git a/cmake/modules/CanaryLib.cmake b/cmake/modules/CanaryLib.cmake index a3f5410b9d8..84d1c96c214 100644 --- a/cmake/modules/CanaryLib.cmake +++ b/cmake/modules/CanaryLib.cmake @@ -23,9 +23,7 @@ add_subdirectory(utils) target_sources(${PROJECT_NAME}_lib PRIVATE canary_server.cpp) # Add public pre compiler header to lib, to pass down to related targets -if (NOT SPEED_UP_BUILD_UNITY) - target_precompile_headers(${PROJECT_NAME}_lib PUBLIC pch.hpp) -endif() +target_precompile_headers(${PROJECT_NAME}_lib PUBLIC pch.hpp) if(NOT SPEED_UP_BUILD_UNITY AND USE_PRECOMPILED_HEADERS) target_compile_definitions(${PROJECT_NAME}_lib PUBLIC -DUSE_PRECOMPILED_HEADERS) diff --git a/src/account/account.cpp b/src/account/account.cpp index 2e5f58dd864..8b67c09ebca 100644 --- a/src/account/account.cpp +++ b/src/account/account.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "account/account.hpp" #include "account/account_repository_db.hpp" diff --git a/src/account/account_repository.cpp b/src/account/account_repository.cpp index babca847043..f329825645d 100644 --- a/src/account/account_repository.cpp +++ b/src/account/account_repository.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "account/account_repository.hpp" #include "lib/di/container.hpp" diff --git a/src/account/account_repository_db.cpp b/src/account/account_repository_db.cpp index 81da30c08c5..a6d169ef4af 100644 --- a/src/account/account_repository_db.cpp +++ b/src/account/account_repository_db.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "account/account_repository_db.hpp" #include "database/database.hpp" diff --git a/src/canary_server.cpp b/src/canary_server.cpp index f71fc71ba9a..f46d34f7104 100644 --- a/src/canary_server.cpp +++ b/src/canary_server.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "canary_server.hpp" #include "declarations.hpp" diff --git a/src/config/configmanager.cpp b/src/config/configmanager.cpp index 9ce861665de..1d0138483a9 100644 --- a/src/config/configmanager.cpp +++ b/src/config/configmanager.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "config/configmanager.hpp" #include "lib/di/container.hpp" #include "game/game.hpp" diff --git a/src/creatures/appearance/mounts/mounts.cpp b/src/creatures/appearance/mounts/mounts.cpp index 7014d0b026b..ada9fb1c4ff 100644 --- a/src/creatures/appearance/mounts/mounts.cpp +++ b/src/creatures/appearance/mounts/mounts.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/appearance/mounts/mounts.hpp" #include "game/game.hpp" #include "utils/pugicast.hpp" diff --git a/src/creatures/appearance/outfit/outfit.cpp b/src/creatures/appearance/outfit/outfit.cpp index 251bf7bde35..40c28a1d7bb 100644 --- a/src/creatures/appearance/outfit/outfit.cpp +++ b/src/creatures/appearance/outfit/outfit.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/appearance/outfit/outfit.hpp" #include "utils/pugicast.hpp" #include "utils/tools.hpp" diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index d65d10e4e6f..4920e8cdc4e 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "declarations.hpp" #include "creatures/combat/combat.hpp" #include "lua/creature/events.hpp" diff --git a/src/creatures/combat/condition.cpp b/src/creatures/combat/condition.cpp index b308c05a5bc..f07126ed868 100644 --- a/src/creatures/combat/condition.cpp +++ b/src/creatures/combat/condition.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/combat/condition.hpp" #include "game/game.hpp" #include "game/scheduling/dispatcher.hpp" diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index 105bf734c23..263d7041887 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/combat/combat.hpp" #include "creatures/combat/spells.hpp" #include "creatures/monsters/monster.hpp" diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 56ed1770039..438355cbf07 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/creature.hpp" #include "declarations.hpp" #include "game/scheduling/dispatcher.hpp" diff --git a/src/creatures/interactions/chat.cpp b/src/creatures/interactions/chat.cpp index 900247e457a..84f4dd67e23 100644 --- a/src/creatures/interactions/chat.cpp +++ b/src/creatures/interactions/chat.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/interactions/chat.hpp" #include "game/game.hpp" #include "utils/pugicast.hpp" diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 4a6d07fe8d7..1db78747947 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/monsters/monster.hpp" #include "creatures/combat/spells.hpp" #include "creatures/players/wheel/player_wheel.hpp" diff --git a/src/creatures/monsters/monsters.cpp b/src/creatures/monsters/monsters.cpp index 7e192a79575..9a1c2b70634 100644 --- a/src/creatures/monsters/monsters.cpp +++ b/src/creatures/monsters/monsters.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/monsters/monsters.hpp" #include "creatures/combat/spells.hpp" diff --git a/src/creatures/monsters/spawns/spawn_monster.cpp b/src/creatures/monsters/spawns/spawn_monster.cpp index 93b381da061..828549e7153 100644 --- a/src/creatures/monsters/spawns/spawn_monster.cpp +++ b/src/creatures/monsters/spawns/spawn_monster.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/monsters/spawns/spawn_monster.hpp" #include "game/game.hpp" #include "creatures/monsters/monster.hpp" diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index 05f22780ada..4a767dee320 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/npcs/npc.hpp" #include "creatures/npcs/npcs.hpp" #include "declarations.hpp" diff --git a/src/creatures/npcs/npcs.cpp b/src/creatures/npcs/npcs.cpp index 6fe7f0b8320..05fc48a63d8 100644 --- a/src/creatures/npcs/npcs.cpp +++ b/src/creatures/npcs/npcs.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "declarations.hpp" #include "creatures/combat/combat.hpp" #include "lua/scripts/lua_environment.hpp" diff --git a/src/creatures/npcs/spawns/spawn_npc.cpp b/src/creatures/npcs/spawns/spawn_npc.cpp index 694822c2386..0976e96b68f 100644 --- a/src/creatures/npcs/spawns/spawn_npc.cpp +++ b/src/creatures/npcs/spawns/spawn_npc.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/npcs/spawns/spawn_npc.hpp" #include "creatures/npcs/npc.hpp" #include "game/game.hpp" diff --git a/src/creatures/players/achievement/player_achievement.cpp b/src/creatures/players/achievement/player_achievement.cpp index cd0735ab54c..5a9c1f55858 100644 --- a/src/creatures/players/achievement/player_achievement.cpp +++ b/src/creatures/players/achievement/player_achievement.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "player_achievement.hpp" #include "creatures/players/player.hpp" diff --git a/src/creatures/players/cyclopedia/player_badge.cpp b/src/creatures/players/cyclopedia/player_badge.cpp index 5f78c1a2e3c..c19e2443db1 100644 --- a/src/creatures/players/cyclopedia/player_badge.cpp +++ b/src/creatures/players/cyclopedia/player_badge.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "player_badge.hpp" #include "creatures/players/player.hpp" diff --git a/src/creatures/players/cyclopedia/player_cyclopedia.cpp b/src/creatures/players/cyclopedia/player_cyclopedia.cpp index eb7e05d2338..de34e1d8250 100644 --- a/src/creatures/players/cyclopedia/player_cyclopedia.cpp +++ b/src/creatures/players/cyclopedia/player_cyclopedia.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "player_cyclopedia.hpp" #include "database/databasetasks.hpp" diff --git a/src/creatures/players/cyclopedia/player_title.cpp b/src/creatures/players/cyclopedia/player_title.cpp index 7c348cbf79d..38e4e6428d0 100644 --- a/src/creatures/players/cyclopedia/player_title.cpp +++ b/src/creatures/players/cyclopedia/player_title.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "player_title.hpp" #include "creatures/players/player.hpp" diff --git a/src/creatures/players/grouping/familiars.cpp b/src/creatures/players/grouping/familiars.cpp index 6312aaa285d..1e09fd5cd7f 100644 --- a/src/creatures/players/grouping/familiars.cpp +++ b/src/creatures/players/grouping/familiars.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/players/grouping/familiars.hpp" #include "lib/di/container.hpp" #include "config/configmanager.hpp" diff --git a/src/creatures/players/grouping/groups.cpp b/src/creatures/players/grouping/groups.cpp index c4dab4a9039..189d2ecc165 100644 --- a/src/creatures/players/grouping/groups.cpp +++ b/src/creatures/players/grouping/groups.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "config/configmanager.hpp" #include "game/game.hpp" #include "creatures/players/grouping/groups.hpp" diff --git a/src/creatures/players/grouping/guild.cpp b/src/creatures/players/grouping/guild.cpp index bbd662d1a1d..240593c1047 100644 --- a/src/creatures/players/grouping/guild.cpp +++ b/src/creatures/players/grouping/guild.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/players/grouping/guild.hpp" #include "game/game.hpp" diff --git a/src/creatures/players/grouping/party.cpp b/src/creatures/players/grouping/party.cpp index b56e0c68605..067a1acd399 100644 --- a/src/creatures/players/grouping/party.cpp +++ b/src/creatures/players/grouping/party.cpp @@ -9,8 +9,6 @@ #include -#include "pch.hpp" - #include "creatures/players/grouping/party.hpp" #include "game/game.hpp" #include "lua/creature/events.hpp" diff --git a/src/creatures/players/imbuements/imbuements.cpp b/src/creatures/players/imbuements/imbuements.cpp index 4bfb0de836b..069a77475e2 100644 --- a/src/creatures/players/imbuements/imbuements.cpp +++ b/src/creatures/players/imbuements/imbuements.cpp @@ -7,7 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" #include "creatures/players/imbuements/imbuements.hpp" #include "lua/creature/events.hpp" #include "utils/pugicast.hpp" diff --git a/src/creatures/players/management/ban.cpp b/src/creatures/players/management/ban.cpp index d81045c5344..748b784a77a 100644 --- a/src/creatures/players/management/ban.cpp +++ b/src/creatures/players/management/ban.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/players/management/ban.hpp" #include "database/database.hpp" #include "database/databasetasks.hpp" diff --git a/src/creatures/players/management/waitlist.cpp b/src/creatures/players/management/waitlist.cpp index 345c20f2650..f20843ea248 100644 --- a/src/creatures/players/management/waitlist.cpp +++ b/src/creatures/players/management/waitlist.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/players/management/waitlist.hpp" #include "game/game.hpp" diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index e3790583eff..6f5ed27d079 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/combat/combat.hpp" #include "creatures/interactions/chat.hpp" #include "creatures/monsters/monster.hpp" @@ -6206,7 +6204,9 @@ void Player::sendIcons() { // Remove the last icon so that Bakragore's is added auto iconSet = getClientIcons(); if (iconSet.size() >= 9 && iconBakragore != IconBakragore::None) { - iconSet.erase(std::prev(iconSet.end())); + std::vector tempVector(iconSet.begin(), iconSet.end()); + tempVector.pop_back(); + iconSet = std::unordered_set(tempVector.begin(), tempVector.end()); } client->sendIcons(iconSet, iconBakragore); diff --git a/src/creatures/players/storages/storages.cpp b/src/creatures/players/storages/storages.cpp index 7fe925ce9e3..8f53bff0cec 100644 --- a/src/creatures/players/storages/storages.cpp +++ b/src/creatures/players/storages/storages.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/players/storages/storages.hpp" #include "config/configmanager.hpp" diff --git a/src/creatures/players/vip/player_vip.cpp b/src/creatures/players/vip/player_vip.cpp index 95ebe91ad5f..9d7bb7c27c7 100644 --- a/src/creatures/players/vip/player_vip.cpp +++ b/src/creatures/players/vip/player_vip.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/players/vip/player_vip.hpp" #include "io/iologindata.hpp" diff --git a/src/creatures/players/vocations/vocation.cpp b/src/creatures/players/vocations/vocation.cpp index 6fec2725164..3da025f7b4a 100644 --- a/src/creatures/players/vocations/vocation.cpp +++ b/src/creatures/players/vocations/vocation.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/players/vocations/vocation.hpp" #include "utils/pugicast.hpp" diff --git a/src/creatures/players/wheel/player_wheel.cpp b/src/creatures/players/wheel/player_wheel.cpp index b78f136312b..6500420adfc 100644 --- a/src/creatures/players/wheel/player_wheel.cpp +++ b/src/creatures/players/wheel/player_wheel.cpp @@ -7,17 +7,16 @@ * Website: https://docs.opentibiabr.org/ */ -#include "pch.hpp" - #include "creatures/players/wheel/player_wheel.hpp" +#include "config/configmanager.hpp" #include "io/io_wheel.hpp" - #include "game/game.hpp" +#include "server/network/message/networkmessage.hpp" #include "creatures/players/player.hpp" #include "creatures/combat/spells.hpp" - -#include "config/configmanager.hpp" +#include "kv/kv.hpp" +#include "creatures/players/wheel/wheel_gems.hpp" const static std::vector wheelGemBasicSlot1Allowed = { WheelGemBasicModifier_t::General_FireResistance, @@ -3151,3 +3150,46 @@ WheelGemBasicModifier_t PlayerWheel::selectBasicModifier2(WheelGemBasicModifier_ } return modifier; } + +void PlayerWheelGem::save(const std::shared_ptr &kv) const { + kv->scoped("revealed")->set(uuid, serialize()); +} +void PlayerWheelGem::remove(const std::shared_ptr &kv) const { + kv->scoped("revealed")->remove(uuid); +} + +PlayerWheelGem PlayerWheelGem::load(const std::shared_ptr &kv, const std::string &uuid) { + auto val = kv->scoped("revealed")->get(uuid); + if (!val || !val.has_value()) { + return {}; + } + return deserialize(uuid, val.value()); +} + +ValueWrapper PlayerWheelGem::serialize() const { + return { + { "uuid", uuid }, + { "locked", locked }, + { "affinity", static_cast(affinity) }, + { "quality", static_cast(quality) }, + { "basicModifier1", static_cast(basicModifier1) }, + { "basicModifier2", static_cast(basicModifier2) }, + { "supremeModifier", static_cast(supremeModifier) } + }; +} + +PlayerWheelGem PlayerWheelGem::deserialize(const std::string &uuid, const ValueWrapper &val) { + auto map = val.get(); + if (map.empty()) { + return {}; + } + return { + uuid, + map["locked"]->get(), + static_cast(map["affinity"]->get()), + static_cast(map["quality"]->get()), + static_cast(map["basicModifier1"]->get()), + static_cast(map["basicModifier2"]->get()), + static_cast(map["supremeModifier"]->get()) + }; +} diff --git a/src/creatures/players/wheel/player_wheel.hpp b/src/creatures/players/wheel/player_wheel.hpp index e94f605930c..b01b1c5a1b3 100644 --- a/src/creatures/players/wheel/player_wheel.hpp +++ b/src/creatures/players/wheel/player_wheel.hpp @@ -9,16 +9,17 @@ #pragma once -#include "io/io_wheel.hpp" #include "utils/utils_definitions.hpp" -#include "kv/kv.hpp" -#include "wheel_gems.hpp" +#include "enums/player_wheel.hpp" +#include "creatures/players/wheel/wheel_definitions.hpp" +#include "kv/kv_definitions.hpp" class Spell; class Player; class Creature; class NetworkMessage; -class IOWheel; +class KV; +class WheelModifierContext; struct PlayerWheelGem { std::string uuid; @@ -33,50 +34,16 @@ struct PlayerWheelGem { return fmt::format("[PlayerWheelGem] uuid: {}, locked: {}, affinity: {}, quality: {}, basicModifier1: {}, basicModifier2: {}, supremeModifier: {}", uuid, locked, static_cast(affinity), static_cast(quality), static_cast(basicModifier1), static_cast(basicModifier2), static_cast(supremeModifier)); } - void save(const std::shared_ptr &kv) const { - kv->scoped("revealed")->set(uuid, serialize()); - } + void save(const std::shared_ptr &kv) const; - void remove(const std::shared_ptr &kv) const { - kv->scoped("revealed")->remove(uuid); - } + void remove(const std::shared_ptr &kv) const; - static PlayerWheelGem load(const std::shared_ptr &kv, const std::string &uuid) { - auto val = kv->scoped("revealed")->get(uuid); - if (!val || !val.has_value()) { - return {}; - } - return deserialize(uuid, val.value()); - } + static PlayerWheelGem load(const std::shared_ptr &kv, const std::string &uuid); private: - ValueWrapper serialize() const { - return { - { "uuid", uuid }, - { "locked", locked }, - { "affinity", static_cast(affinity) }, - { "quality", static_cast(quality) }, - { "basicModifier1", static_cast(basicModifier1) }, - { "basicModifier2", static_cast(basicModifier2) }, - { "supremeModifier", static_cast(supremeModifier) } - }; - } + ValueWrapper serialize() const; - static PlayerWheelGem deserialize(const std::string &uuid, const ValueWrapper &val) { - auto map = val.get(); - if (map.empty()) { - return {}; - } - return { - uuid, - map["locked"]->get(), - static_cast(map["affinity"]->get()), - static_cast(map["quality"]->get()), - static_cast(map["basicModifier1"]->get()), - static_cast(map["basicModifier2"]->get()), - static_cast(map["supremeModifier"]->get()) - }; - } + static PlayerWheelGem deserialize(const std::string &uuid, const ValueWrapper &val); }; class PlayerWheel { diff --git a/src/creatures/players/wheel/wheel_gems.cpp b/src/creatures/players/wheel/wheel_gems.cpp index c3653298c12..186a6939186 100644 --- a/src/creatures/players/wheel/wheel_gems.cpp +++ b/src/creatures/players/wheel/wheel_gems.cpp @@ -7,9 +7,10 @@ * Website: https://docs.opentibiabr.org/ */ -#include "pch.hpp" +#include "creatures/players/wheel/wheel_gems.hpp" #include "creatures/players/wheel/player_wheel.hpp" +#include "enums/player_wheel.hpp" void GemModifierResistanceStrategy::execute() { m_wheel.addResistance(m_combatType, m_resistance); diff --git a/src/creatures/players/wheel/wheel_gems.hpp b/src/creatures/players/wheel/wheel_gems.hpp index 668d8fe05db..dc691fa2b26 100644 --- a/src/creatures/players/wheel/wheel_gems.hpp +++ b/src/creatures/players/wheel/wheel_gems.hpp @@ -9,167 +9,12 @@ #pragma once +#include "creatures/creatures_definitions.hpp" #include "wheel_definitions.hpp" +#include "enums/player_wheel.hpp" class PlayerWheel; -enum class WheelGemAction_t : uint8_t { - Destroy, - Reveal, - SwitchDomain, - ToggleLock, -}; - -enum class WheelGemAffinity_t : uint8_t { - Green, - Red, - Blue, - Purple, -}; - -enum class WheelGemQuality_t : uint8_t { - Lesser, - Regular, - Greater, -}; - -enum class WheelGemBasicModifier_t : uint8_t { - General_PhysicalResistance, - General_HolyResistance, - General_DeathResistance, - General_FireResistance, - General_EarthResistance, - General_IceResistance, - General_EnergyResistance, - - General_HolyResistance_DeathWeakness, - General_DeathResistance_HolyWeakness, - General_FireResistance_EarthResistance, - General_FireResistance_IceResistance, - General_FireResistance_EnergyResistance, - General_EarthResistance_IceResistance, - General_EarthResistance_EnergyResistance, - General_IceResistance_EnergyResistance, - - General_FireResistance_EarthWeakness, - General_FireResistance_IceWeakness, - General_FireResistance_EnergyWeakness, - General_EarthResistance_FireWeakness, - General_EarthResistance_IceWeakness, - General_EarthResistance_EnergyWeakness, - General_IceResistance_EarthWeakness, - General_IceResistance_FireWeakness, - General_IceResistance_EnergyWeakness, - General_EnergyResistance_EarthWeakness, - General_EnergyResistance_IceWeakness, - General_EnergyResistance_FireWeakness, - General_ManaDrainResistance, - General_LifeDrainResistance, - General_ManaDrainResistance_LifeDrainResistance, - General_MitigationMultiplier, - - Vocation_Health, - Vocation_Capacity, - Vocation_Mana_FireResistance, - Vocation_Mana_EnergyResistance, - Vocation_Mana_Earth_Resistance, - Vocation_Mana_Ice_Resistance, - Vocation_Mana, - Vocation_Health_FireResistance, - Vocation_Health_EnergyResistance, - Vocation_Health_EarthResistance, - Vocation_Health_IceResistance, - Vocation_Mixed, - Vocation_Mixed2, - Vocation_Capacity_FireResistance, - Vocation_Capacity_EnergyResistance, - Vocation_Capacity_EarthResistance, - Vocation_Capacity_IceResistance, -}; - -enum class WheelGemSupremeModifier_t : uint8_t { - General_Dodge, - General_CriticalDamage, - General_LifeLeech, - General_ManaLeech, - SorcererDruid_UltimateHealing, - General_RevelationMastery_GiftOfLife, - - Knight_AvatarOfSteel_Cooldown, - Knight_ExecutionersThrow_Cooldown, - Knight_ExecutionersThrow_DamageIncrease, - Knight_ExecutionersThrow_CriticalExtraDamage, - Knight_Fierce_Berserk_DamageIncrease, - Knight_Fierce_Berserk_CriticalExtraDamage, - Knight_Berserk_DamageIncrease, - Knight_Berserk_CriticalExtraDamage, - Knight_Front_Sweep_CriticalExtraDamage, - Knight_Front_Sweep_DamageIncrease, - Knight_Groundshaker_DamageIncrease, - Knight_Groundshaker_CriticalExtraDamage, - Knight_Annihilation_CriticalExtraDamage, - Knight_Annihilation_DamageIncrease, - Knight_FairWoundCleansing_HealingIncrease, - Knight_RevelationMastery_AvatarOfSteel, - Knight_RevelationMastery_ExecutionersThrow, - Knight_RevelationMastery_CombatMastery, - - Paladin_AvatarOfLight_Cooldown, - Paladin_DivineDazzle_Cooldown, - Paladin_DivineGrenade_DamageIncrease, - Paladin_DivineGrenade_CriticalExtraDamage, - Paladin_DivineCaldera_DamageIncrease, - Paladin_DivineCaldera_CriticalExtraDamage, - Paladin_DivineMissile_DamageIncrease, - Paladin_DivineMissile_CriticalExtraDamage, - Paladin_EtherealSpear_DamageIncrease, - Paladin_EtherealSpear_CriticalExtraDamage, - Paladin_StrongEtherealSpear_DamageIncrease, - Paladin_StrongEtherealSpear_CriticalExtraDamage, - Paladin_DivineEmpowerment_Cooldown, - Paladin_DivineGrenade_Cooldown, - Paladin_Salvation_HealingIncrease, - Paladin_RevelationMastery_AvatarOfLight, - Paladin_RevelationMastery_DivineGrenade, - Paladin_RevelationMastery_DivineEmpowerment, - - Sorcerer_AvatarOfStorm_Cooldown, - Sorcerer_EnergyWave_Cooldown, - Sorcerer_GreatDeathBeam_DamageIncrease, - Sorcerer_GreatDeathBeam_CriticalExtraDamage, - Sorcerer_HellsCore_DamageIncrease, - Sorcerer_HellsCore_CriticalExtraDamage, - Sorcerer_EnergyWave_DamageIncrease, - Sorcerer_EnergyWave_CriticalExtraDamage, - Sorcerer_GreatFireWave_DamageIncrease, - Sorcerer_GreatFireWave_CriticalExtraDamage, - Sorcerer_RageOfTheSkies_DamageIncrease, - Sorcerer_RageOfTheSkies_CriticalExtraDamage, - Sorcerer_GreatEnergyBeam_DamageIncrease, - Sorcerer_GreatEnergyBeam_CriticalExtraDamage, - Sorcerer_RevelationMastery_AvatarOfStorm, - Sorcerer_RevelationMastery_BeamMastery, - Sorcerer_RevelationMastery_DrainBody, - - Druid_AvatarOfNature_Cooldown, - Druid_NaturesEmbrace_Cooldown, - Druid_TerraBurst_DamageIncrease, - Druid_TerraBurst_CriticalExtraDamage, - Druid_IceBurst_DamageIncrease, - Druid_IceBurst_CriticalExtraDamage, - Druid_EternalWinter_CriticalExtraDamage, - Druid_EternalWinter_DamageIncrease, - Druid_TerraWave_DamageIncrease, - Druid_TerraWave_CriticalExtraDamage, - Druid_StrongIceWave_DamageIncrease, - Druid_StrongIceWave_CriticalExtraDamage, - Druid_HealFriend_HealingIncrease, - Druid_MassHealing_HealingIncrease, - Druid_RevelationMastery_AvatarOfNature, - Druid_RevelationMastery_BlessingOfTheGrove, - Druid_RevelationMastery_TwinBursts, -}; - class GemModifierStrategy { public: explicit GemModifierStrategy(PlayerWheel &wheel) : diff --git a/src/database/database.cpp b/src/database/database.cpp index f226587c511..50b795455d3 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "config/configmanager.hpp" #include "database/database.hpp" #include "lib/di/container.hpp" diff --git a/src/database/databasemanager.cpp b/src/database/databasemanager.cpp index dfbb7d9a64a..3e55799e45a 100644 --- a/src/database/databasemanager.cpp +++ b/src/database/databasemanager.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "config/configmanager.hpp" #include "database/databasemanager.hpp" #include "lua/functions/core/libs/core_libs_functions.hpp" diff --git a/src/database/databasetasks.cpp b/src/database/databasetasks.cpp index 8a660f1c031..010b3f16320 100644 --- a/src/database/databasetasks.cpp +++ b/src/database/databasetasks.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "database/databasetasks.hpp" #include "game/scheduling/dispatcher.hpp" #include "lib/thread/thread_pool.hpp" diff --git a/src/enums/player_wheel.hpp b/src/enums/player_wheel.hpp new file mode 100644 index 00000000000..81cde57f651 --- /dev/null +++ b/src/enums/player_wheel.hpp @@ -0,0 +1,171 @@ +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2024 OpenTibiaBR + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ + +#pragma once + +#ifndef USE_PRECOMPILED_HEADERS + #include +#endif + +enum class WheelGemAction_t : uint8_t { + Destroy, + Reveal, + SwitchDomain, + ToggleLock, +}; + +enum class WheelGemAffinity_t : uint8_t { + Green, + Red, + Blue, + Purple, +}; + +enum class WheelGemQuality_t : uint8_t { + Lesser, + Regular, + Greater, +}; + +enum class WheelGemBasicModifier_t : uint8_t { + General_PhysicalResistance, + General_HolyResistance, + General_DeathResistance, + General_FireResistance, + General_EarthResistance, + General_IceResistance, + General_EnergyResistance, + + General_HolyResistance_DeathWeakness, + General_DeathResistance_HolyWeakness, + General_FireResistance_EarthResistance, + General_FireResistance_IceResistance, + General_FireResistance_EnergyResistance, + General_EarthResistance_IceResistance, + General_EarthResistance_EnergyResistance, + General_IceResistance_EnergyResistance, + + General_FireResistance_EarthWeakness, + General_FireResistance_IceWeakness, + General_FireResistance_EnergyWeakness, + General_EarthResistance_FireWeakness, + General_EarthResistance_IceWeakness, + General_EarthResistance_EnergyWeakness, + General_IceResistance_EarthWeakness, + General_IceResistance_FireWeakness, + General_IceResistance_EnergyWeakness, + General_EnergyResistance_EarthWeakness, + General_EnergyResistance_IceWeakness, + General_EnergyResistance_FireWeakness, + General_ManaDrainResistance, + General_LifeDrainResistance, + General_ManaDrainResistance_LifeDrainResistance, + General_MitigationMultiplier, + + Vocation_Health, + Vocation_Capacity, + Vocation_Mana_FireResistance, + Vocation_Mana_EnergyResistance, + Vocation_Mana_Earth_Resistance, + Vocation_Mana_Ice_Resistance, + Vocation_Mana, + Vocation_Health_FireResistance, + Vocation_Health_EnergyResistance, + Vocation_Health_EarthResistance, + Vocation_Health_IceResistance, + Vocation_Mixed, + Vocation_Mixed2, + Vocation_Capacity_FireResistance, + Vocation_Capacity_EnergyResistance, + Vocation_Capacity_EarthResistance, + Vocation_Capacity_IceResistance, +}; + +enum class WheelGemSupremeModifier_t : uint8_t { + General_Dodge, + General_CriticalDamage, + General_LifeLeech, + General_ManaLeech, + SorcererDruid_UltimateHealing, + General_RevelationMastery_GiftOfLife, + + Knight_AvatarOfSteel_Cooldown, + Knight_ExecutionersThrow_Cooldown, + Knight_ExecutionersThrow_DamageIncrease, + Knight_ExecutionersThrow_CriticalExtraDamage, + Knight_Fierce_Berserk_DamageIncrease, + Knight_Fierce_Berserk_CriticalExtraDamage, + Knight_Berserk_DamageIncrease, + Knight_Berserk_CriticalExtraDamage, + Knight_Front_Sweep_CriticalExtraDamage, + Knight_Front_Sweep_DamageIncrease, + Knight_Groundshaker_DamageIncrease, + Knight_Groundshaker_CriticalExtraDamage, + Knight_Annihilation_CriticalExtraDamage, + Knight_Annihilation_DamageIncrease, + Knight_FairWoundCleansing_HealingIncrease, + Knight_RevelationMastery_AvatarOfSteel, + Knight_RevelationMastery_ExecutionersThrow, + Knight_RevelationMastery_CombatMastery, + + Paladin_AvatarOfLight_Cooldown, + Paladin_DivineDazzle_Cooldown, + Paladin_DivineGrenade_DamageIncrease, + Paladin_DivineGrenade_CriticalExtraDamage, + Paladin_DivineCaldera_DamageIncrease, + Paladin_DivineCaldera_CriticalExtraDamage, + Paladin_DivineMissile_DamageIncrease, + Paladin_DivineMissile_CriticalExtraDamage, + Paladin_EtherealSpear_DamageIncrease, + Paladin_EtherealSpear_CriticalExtraDamage, + Paladin_StrongEtherealSpear_DamageIncrease, + Paladin_StrongEtherealSpear_CriticalExtraDamage, + Paladin_DivineEmpowerment_Cooldown, + Paladin_DivineGrenade_Cooldown, + Paladin_Salvation_HealingIncrease, + Paladin_RevelationMastery_AvatarOfLight, + Paladin_RevelationMastery_DivineGrenade, + Paladin_RevelationMastery_DivineEmpowerment, + + Sorcerer_AvatarOfStorm_Cooldown, + Sorcerer_EnergyWave_Cooldown, + Sorcerer_GreatDeathBeam_DamageIncrease, + Sorcerer_GreatDeathBeam_CriticalExtraDamage, + Sorcerer_HellsCore_DamageIncrease, + Sorcerer_HellsCore_CriticalExtraDamage, + Sorcerer_EnergyWave_DamageIncrease, + Sorcerer_EnergyWave_CriticalExtraDamage, + Sorcerer_GreatFireWave_DamageIncrease, + Sorcerer_GreatFireWave_CriticalExtraDamage, + Sorcerer_RageOfTheSkies_DamageIncrease, + Sorcerer_RageOfTheSkies_CriticalExtraDamage, + Sorcerer_GreatEnergyBeam_DamageIncrease, + Sorcerer_GreatEnergyBeam_CriticalExtraDamage, + Sorcerer_RevelationMastery_AvatarOfStorm, + Sorcerer_RevelationMastery_BeamMastery, + Sorcerer_RevelationMastery_DrainBody, + + Druid_AvatarOfNature_Cooldown, + Druid_NaturesEmbrace_Cooldown, + Druid_TerraBurst_DamageIncrease, + Druid_TerraBurst_CriticalExtraDamage, + Druid_IceBurst_DamageIncrease, + Druid_IceBurst_CriticalExtraDamage, + Druid_EternalWinter_CriticalExtraDamage, + Druid_EternalWinter_DamageIncrease, + Druid_TerraWave_DamageIncrease, + Druid_TerraWave_CriticalExtraDamage, + Druid_StrongIceWave_DamageIncrease, + Druid_StrongIceWave_CriticalExtraDamage, + Druid_HealFriend_HealingIncrease, + Druid_MassHealing_HealingIncrease, + Druid_RevelationMastery_AvatarOfNature, + Druid_RevelationMastery_BlessingOfTheGrove, + Druid_RevelationMastery_TwinBursts, +}; diff --git a/src/game/bank/bank.cpp b/src/game/bank/bank.cpp index 33d97c92ee5..0a876e62210 100644 --- a/src/game/bank/bank.cpp +++ b/src/game/bank/bank.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "bank.hpp" #include "game/game.hpp" #include "creatures/players/player.hpp" diff --git a/src/game/functions/game_reload.cpp b/src/game/functions/game_reload.cpp index d9d9eb1f449..d42f7ec3c78 100644 --- a/src/game/functions/game_reload.cpp +++ b/src/game/functions/game_reload.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/functions/game_reload.hpp" #include "config/configmanager.hpp" diff --git a/src/game/game.cpp b/src/game/game.cpp index 77dffe532f0..381792c3092 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "lua/creature/actions.hpp" diff --git a/src/game/movement/position.cpp b/src/game/movement/position.cpp index 807a65ad458..46ea6ea573d 100644 --- a/src/game/movement/position.cpp +++ b/src/game/movement/position.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/movement/position.hpp" #include "utils/tools.hpp" diff --git a/src/game/movement/teleport.cpp b/src/game/movement/teleport.cpp index 44050100eb6..595fe5f33ca 100644 --- a/src/game/movement/teleport.cpp +++ b/src/game/movement/teleport.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "game/movement/teleport.hpp" diff --git a/src/game/scheduling/dispatcher.cpp b/src/game/scheduling/dispatcher.cpp index eaedaa86ac5..db0aae845a6 100644 --- a/src/game/scheduling/dispatcher.cpp +++ b/src/game/scheduling/dispatcher.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/scheduling/dispatcher.hpp" #include "lib/thread/thread_pool.hpp" #include "lib/di/container.hpp" diff --git a/src/game/scheduling/events_scheduler.cpp b/src/game/scheduling/events_scheduler.cpp index a86254fa35c..3089d9cdcd6 100644 --- a/src/game/scheduling/events_scheduler.cpp +++ b/src/game/scheduling/events_scheduler.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "config/configmanager.hpp" #include "game/scheduling/events_scheduler.hpp" #include "lua/scripts/scripts.hpp" diff --git a/src/game/scheduling/save_manager.cpp b/src/game/scheduling/save_manager.cpp index fbad528598b..4d98da9900f 100644 --- a/src/game/scheduling/save_manager.cpp +++ b/src/game/scheduling/save_manager.cpp @@ -1,8 +1,17 @@ -#include "pch.hpp" +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2024 OpenTibiaBR + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ -#include "game/game.hpp" #include "game/scheduling/save_manager.hpp" + +#include "game/game.hpp" #include "io/iologindata.hpp" +#include "kv/kv.hpp" SaveManager::SaveManager(ThreadPool &threadPool, KVStore &kvStore, Logger &logger, Game &game) : threadPool(threadPool), kv(kvStore), logger(logger), game(game) { } diff --git a/src/game/scheduling/save_manager.hpp b/src/game/scheduling/save_manager.hpp index 745231c0075..4bd66a7966f 100644 --- a/src/game/scheduling/save_manager.hpp +++ b/src/game/scheduling/save_manager.hpp @@ -10,7 +10,12 @@ #pragma once #include "lib/thread/thread_pool.hpp" -#include "kv/kv.hpp" + +class KVStore; +class Logger; +class Game; +class Player; +class Guild; class SaveManager { public: diff --git a/src/game/scheduling/task.cpp b/src/game/scheduling/task.cpp index 96355968bd1..0e1f6489516 100644 --- a/src/game/scheduling/task.cpp +++ b/src/game/scheduling/task.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "task.hpp" #include "lib/logging/log_with_spd_log.hpp" diff --git a/src/game/zones/zone.cpp b/src/game/zones/zone.cpp index 7ffa4b594f4..9215ef2570f 100644 --- a/src/game/zones/zone.cpp +++ b/src/game/zones/zone.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "zone.hpp" #include "game/game.hpp" #include "creatures/monsters/monster.hpp" diff --git a/src/io/fileloader.cpp b/src/io/fileloader.cpp index 38bf2be19e3..a4269ffdd30 100644 --- a/src/io/fileloader.cpp +++ b/src/io/fileloader.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "io/fileloader.hpp" namespace OTB { diff --git a/src/io/filestream.cpp b/src/io/filestream.cpp index fc8ae6116fc..71b2dd4aa2f 100644 --- a/src/io/filestream.cpp +++ b/src/io/filestream.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "io/filestream.hpp" #include "io/fileloader.hpp" diff --git a/src/io/functions/iologindata_load_player.cpp b/src/io/functions/iologindata_load_player.cpp index 66be7927692..3042f4ce03b 100644 --- a/src/io/functions/iologindata_load_player.cpp +++ b/src/io/functions/iologindata_load_player.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/players/wheel/player_wheel.hpp" #include "creatures/players/achievement/player_achievement.hpp" #include "io/functions/iologindata_load_player.hpp" @@ -723,7 +721,7 @@ void IOLoginDataLoad::loadPlayerPreyClass(std::shared_ptr player, DBResu Database &db = Database::getInstance(); std::ostringstream query; query << "SELECT * FROM `player_prey` WHERE `player_id` = " << player->getGUID(); - if (result = db.storeQuery(query.str())) { + if ((result = db.storeQuery(query.str()))) { do { auto slot = std::make_unique(static_cast(result->getNumber("slot"))); auto state = static_cast(result->getNumber("state")); @@ -770,7 +768,7 @@ void IOLoginDataLoad::loadPlayerTaskHuntingClass(std::shared_ptr player, Database &db = Database::getInstance(); std::ostringstream query; query << "SELECT * FROM `player_taskhunt` WHERE `player_id` = " << player->getGUID(); - if (result = db.storeQuery(query.str())) { + if ((result = db.storeQuery(query.str()))) { do { auto slot = std::make_unique(static_cast(result->getNumber("slot"))); auto state = static_cast(result->getNumber("state")); diff --git a/src/io/functions/iologindata_save_player.cpp b/src/io/functions/iologindata_save_player.cpp index eccb88c8229..9ff8fe94f64 100644 --- a/src/io/functions/iologindata_save_player.cpp +++ b/src/io/functions/iologindata_save_player.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "io/functions/iologindata_save_player.hpp" #include "game/game.hpp" diff --git a/src/io/io_bosstiary.cpp b/src/io/io_bosstiary.cpp index 7c7c8108ce7..0bb0ff15699 100644 --- a/src/io/io_bosstiary.cpp +++ b/src/io/io_bosstiary.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "io/io_bosstiary.hpp" #include "creatures/monsters/monsters.hpp" diff --git a/src/io/io_wheel.cpp b/src/io/io_wheel.cpp index e8ad30a5d80..1d2a7884e82 100644 --- a/src/io/io_wheel.cpp +++ b/src/io/io_wheel.cpp @@ -7,14 +7,12 @@ * Website: https://docs.opentibiabr.org/ */ -#include "pch.hpp" - #include "io/io_wheel.hpp" +#include "kv/kv.hpp" #include "creatures/players/wheel/player_wheel.hpp" #include "creatures/players/player.hpp" #include "creatures/combat/spells.hpp" - #include "utils/tools.hpp" #define MITIGATION_INCREASE 0.03 diff --git a/src/io/iobestiary.cpp b/src/io/iobestiary.cpp index 9cd964e7c7c..83dd2ed806e 100644 --- a/src/io/iobestiary.cpp +++ b/src/io/iobestiary.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "declarations.hpp" #include "game/game.hpp" #include "io/iobestiary.hpp" diff --git a/src/io/ioguild.cpp b/src/io/ioguild.cpp index 99e1e750676..9d3d628a42d 100644 --- a/src/io/ioguild.cpp +++ b/src/io/ioguild.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "database/database.hpp" #include "creatures/players/grouping/guild.hpp" #include "io/ioguild.hpp" diff --git a/src/io/iologindata.cpp b/src/io/iologindata.cpp index de445bb70f8..d6873243919 100644 --- a/src/io/iologindata.cpp +++ b/src/io/iologindata.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "io/iologindata.hpp" #include "io/functions/iologindata_load_player.hpp" #include "io/functions/iologindata_save_player.hpp" diff --git a/src/io/iomap.cpp b/src/io/iomap.cpp index 1f5c5205113..d39988caa71 100644 --- a/src/io/iomap.cpp +++ b/src/io/iomap.cpp @@ -7,7 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" #include "io/iomap.hpp" #include "game/movement/teleport.hpp" #include "game/game.hpp" diff --git a/src/io/iomapserialize.cpp b/src/io/iomapserialize.cpp index e2a367c4ec4..7351cde1cb9 100644 --- a/src/io/iomapserialize.cpp +++ b/src/io/iomapserialize.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "io/iomapserialize.hpp" #include "io/iologindata.hpp" #include "game/game.hpp" diff --git a/src/io/iomarket.cpp b/src/io/iomarket.cpp index a0253e2ea01..71e707e0bd9 100644 --- a/src/io/iomarket.cpp +++ b/src/io/iomarket.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "io/iomarket.hpp" #include "database/databasetasks.hpp" #include "io/iologindata.hpp" diff --git a/src/io/ioprey.cpp b/src/io/ioprey.cpp index 93a91abade1..abea75aa6c9 100644 --- a/src/io/ioprey.cpp +++ b/src/io/ioprey.cpp @@ -7,14 +7,16 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" +#include "io/ioprey.hpp" +#include "lib/di/container.hpp" #include "creatures/monsters/monster.hpp" #include "creatures/players/player.hpp" #include "config/configmanager.hpp" #include "game/game.hpp" -#include "io/ioprey.hpp" #include "lib/metrics/metrics.hpp" +#include "server/network/message/networkmessage.hpp" +#include "server/network/protocol/protocolgame.hpp" // Prey class PreySlot::PreySlot(PreySlot_t id) : @@ -245,6 +247,10 @@ void TaskHuntingSlot::reloadReward() { } } +IOPrey &IOPrey::getInstance() { + return inject(); +} + // Prey/Task hunting global class void IOPrey::checkPlayerPreys(std::shared_ptr player, uint8_t amount) const { if (!player) { @@ -595,7 +601,11 @@ void IOPrey::initializeTaskHuntOptions() { msg.add(option->secondKills); msg.add(option->secondReward); }); - baseDataMessage = msg; + m_baseDataMessage = msg; +} + +NetworkMessage IOPrey::getTaskHuntingBaseDate() const { + return m_baseDataMessage; } const std::unique_ptr &IOPrey::getTaskRewardOption(const std::unique_ptr &slot) const { diff --git a/src/io/ioprey.hpp b/src/io/ioprey.hpp index 221f2ce5562..df7243df6d6 100644 --- a/src/io/ioprey.hpp +++ b/src/io/ioprey.hpp @@ -9,12 +9,14 @@ #pragma once -#include "lib/di/container.hpp" -#include "server/network/protocol/protocolgame.hpp" +// TODO: Remove circular includes (maybe shared_ptr?) +#include "server/network/message/networkmessage.hpp" class PreySlot; class TaskHuntingSlot; class TaskHuntingOption; +class NetworkMessage; +class Player; static const std::unique_ptr &PreySlotNull {}; static const std::unique_ptr &TaskHuntingSlotNull {}; @@ -221,9 +223,7 @@ class IOPrey { IOPrey(const IOPrey &) = delete; void operator=(const IOPrey &) = delete; - static IOPrey &getInstance() { - return inject(); - } + static IOPrey &getInstance(); void checkPlayerPreys(std::shared_ptr player, uint8_t amount) const; void parsePreyAction(std::shared_ptr player, PreySlot_t slotId, PreyAction_t action, PreyOption_t option, int8_t index, uint16_t raceId) const; @@ -233,11 +233,9 @@ class IOPrey { void initializeTaskHuntOptions(); const std::unique_ptr &getTaskRewardOption(const std::unique_ptr &slot) const; - NetworkMessage getTaskHuntingBaseDate() const { - return baseDataMessage; - } + NetworkMessage getTaskHuntingBaseDate() const; - NetworkMessage baseDataMessage; + NetworkMessage m_baseDataMessage; std::vector> taskOption; }; diff --git a/src/items/bed.cpp b/src/items/bed.cpp index 4b38be3b474..8bfd6d119a5 100644 --- a/src/items/bed.cpp +++ b/src/items/bed.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/bed.hpp" #include "game/game.hpp" #include "io/iologindata.hpp" diff --git a/src/items/containers/container.cpp b/src/items/containers/container.cpp index 6c526a8500a..be2e63ae95b 100644 --- a/src/items/containers/container.cpp +++ b/src/items/containers/container.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/containers/container.hpp" #include "items/decay/decay.hpp" #include "io/iomap.hpp" diff --git a/src/items/containers/depot/depotchest.cpp b/src/items/containers/depot/depotchest.cpp index 15488267f04..2c7d21ed199 100644 --- a/src/items/containers/depot/depotchest.cpp +++ b/src/items/containers/depot/depotchest.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/containers/depot/depotchest.hpp" #include "utils/tools.hpp" diff --git a/src/items/containers/depot/depotlocker.cpp b/src/items/containers/depot/depotlocker.cpp index 0be000794ef..c7320293efd 100644 --- a/src/items/containers/depot/depotlocker.cpp +++ b/src/items/containers/depot/depotlocker.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/containers/depot/depotlocker.hpp" DepotLocker::DepotLocker(uint16_t type, uint16_t size) : diff --git a/src/items/containers/inbox/inbox.cpp b/src/items/containers/inbox/inbox.cpp index 9b22c53748a..220f119645f 100644 --- a/src/items/containers/inbox/inbox.cpp +++ b/src/items/containers/inbox/inbox.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/containers/inbox/inbox.hpp" #include "utils/tools.hpp" diff --git a/src/items/containers/mailbox/mailbox.cpp b/src/items/containers/mailbox/mailbox.cpp index c2c9b2f61e1..c558b85e30d 100644 --- a/src/items/containers/mailbox/mailbox.cpp +++ b/src/items/containers/mailbox/mailbox.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/containers/mailbox/mailbox.hpp" #include "game/game.hpp" #include "io/iologindata.hpp" diff --git a/src/items/containers/rewards/reward.cpp b/src/items/containers/rewards/reward.cpp index 4b1757bd6c8..6a8374e8060 100644 --- a/src/items/containers/rewards/reward.cpp +++ b/src/items/containers/rewards/reward.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/containers/rewards/reward.hpp" Reward::Reward() : diff --git a/src/items/containers/rewards/rewardchest.cpp b/src/items/containers/rewards/rewardchest.cpp index c9bb8112f90..96cf9c2edcc 100644 --- a/src/items/containers/rewards/rewardchest.cpp +++ b/src/items/containers/rewards/rewardchest.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/containers/rewards/rewardchest.hpp" RewardChest::RewardChest(uint16_t type) : diff --git a/src/items/cylinder.cpp b/src/items/cylinder.cpp index 0636e5ff34c..fa61eab2fcb 100644 --- a/src/items/cylinder.cpp +++ b/src/items/cylinder.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/cylinder.hpp" std::shared_ptr VirtualCylinder::virtualCylinder = std::make_shared(); diff --git a/src/items/decay/decay.cpp b/src/items/decay/decay.cpp index 5eaff61a7a9..bdf9ed36040 100644 --- a/src/items/decay/decay.cpp +++ b/src/items/decay/decay.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/decay/decay.hpp" #include "lib/di/container.hpp" diff --git a/src/items/functions/item/attribute.cpp b/src/items/functions/item/attribute.cpp index c67c6ce38f7..747b8c90c39 100644 --- a/src/items/functions/item/attribute.cpp +++ b/src/items/functions/item/attribute.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/functions/item/attribute.hpp" /* diff --git a/src/items/functions/item/custom_attribute.cpp b/src/items/functions/item/custom_attribute.cpp index 202c57c0960..462ba4b520a 100644 --- a/src/items/functions/item/custom_attribute.cpp +++ b/src/items/functions/item/custom_attribute.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/functions/item/custom_attribute.hpp" #include "lua/scripts/luascript.hpp" diff --git a/src/items/functions/item/item_parse.cpp b/src/items/functions/item/item_parse.cpp index 9b63b9aee0e..96fa33c2a7b 100644 --- a/src/items/functions/item/item_parse.cpp +++ b/src/items/functions/item/item_parse.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/functions/item/item_parse.hpp" #include "items/weapons/weapons.hpp" #include "lua/creature/movement.hpp" diff --git a/src/items/item.cpp b/src/items/item.cpp index 2ad0cfa4abd..43c172b8e7d 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/item.hpp" #include "items/containers/container.hpp" #include "items/decay/decay.hpp" diff --git a/src/items/items.cpp b/src/items/items.cpp index 2d4020c5416..bcd055a8db5 100644 --- a/src/items/items.cpp +++ b/src/items/items.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/functions/item/item_parse.hpp" #include "items/items.hpp" #include "items/weapons/weapons.hpp" diff --git a/src/items/thing.cpp b/src/items/thing.cpp index 6eec7994df8..647f312b227 100644 --- a/src/items/thing.cpp +++ b/src/items/thing.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/thing.hpp" #include "items/tile.hpp" diff --git a/src/items/tile.cpp b/src/items/tile.cpp index fc16dd5799c..e9b0b9e8115 100644 --- a/src/items/tile.cpp +++ b/src/items/tile.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/tile.hpp" #include "creatures/creature.hpp" #include "creatures/combat/combat.hpp" diff --git a/src/items/tile.hpp b/src/items/tile.hpp index 71f9d4ae09c..1790cd2972a 100644 --- a/src/items/tile.hpp +++ b/src/items/tile.hpp @@ -256,7 +256,7 @@ class Tile : public Cylinder, public SharedObject { resetTileFlags(ground); } - if (ground = item) { + if ((ground = item)) { setTileFlags(item); } } diff --git a/src/items/trashholder.cpp b/src/items/trashholder.cpp index 65676a75a37..fe95557ce50 100644 --- a/src/items/trashholder.cpp +++ b/src/items/trashholder.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/trashholder.hpp" #include "game/game.hpp" diff --git a/src/items/weapons/weapons.cpp b/src/items/weapons/weapons.cpp index 69d20d43e06..109f0d27218 100644 --- a/src/items/weapons/weapons.cpp +++ b/src/items/weapons/weapons.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/combat/combat.hpp" #include "game/game.hpp" #include "lua/creature/events.hpp" diff --git a/src/kv/kv.cpp b/src/kv/kv.cpp index 29a9787f72f..0a7cfe6827d 100644 --- a/src/kv/kv.cpp +++ b/src/kv/kv.cpp @@ -7,10 +7,10 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "kv/kv.hpp" + #include "lib/di/container.hpp" +#include "database/database.hpp" int64_t KV::lastTimestamp_ = 0; uint64_t KV::counter_ = 0; diff --git a/src/kv/kv_definitions.hpp b/src/kv/kv_definitions.hpp new file mode 100644 index 00000000000..e53c8b0f24a --- /dev/null +++ b/src/kv/kv_definitions.hpp @@ -0,0 +1,29 @@ +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2024 OpenTibiaBR + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ + +#pragma once + +class ValueWrapper; + +#ifndef USE_PRECOMPILED_HEADERS + #include + #include + #include + #include + #include +#endif + +using StringType = std::string; +using BooleanType = bool; +using IntType = int; +using DoubleType = double; +using ArrayType = std::vector; +using MapType = phmap::flat_hash_map>; + +using ValueVariant = std::variant; diff --git a/src/kv/kv_sql.cpp b/src/kv/kv_sql.cpp index 57d2cc57a10..0391425884c 100644 --- a/src/kv/kv_sql.cpp +++ b/src/kv/kv_sql.cpp @@ -7,14 +7,18 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "kv/kv_sql.hpp" + +#include "database/database.hpp" +#include "lib/logging/logger.hpp" #include "kv/value_wrapper_proto.hpp" #include "utils/tools.hpp" #include +KVSQL::KVSQL(Database &db, Logger &logger) : + KVStore(logger), db(db) { } + std::optional KVSQL::load(const std::string &key) { auto query = fmt::format("SELECT `key_name`, `timestamp`, `value` FROM `kv_store` WHERE `key_name` = {}", db.escapeString(key)); auto result = db.storeQuery(query); @@ -97,3 +101,9 @@ bool KVSQL::saveAll() { return success; } + +DBInsert KVSQL::dbUpdate() { + auto insert = DBInsert("INSERT INTO `kv_store` (`key_name`, `timestamp`, `value`) VALUES"); + insert.upsert({ "key_name", "timestamp", "value" }); + return insert; +} diff --git a/src/kv/kv_sql.hpp b/src/kv/kv_sql.hpp index 1d7a6387d68..43bedada82f 100644 --- a/src/kv/kv_sql.hpp +++ b/src/kv/kv_sql.hpp @@ -11,16 +11,14 @@ #include "kv/kv.hpp" -#include "database/database.hpp" -#include "lib/logging/logger.hpp" - class Database; +class Logger; +class DBInsert; +class ValueWrapper; class KVSQL final : public KVStore { public: - explicit KVSQL(Database &db, Logger &logger) : - KVStore(logger), - db(db) { } + explicit KVSQL(Database &db, Logger &logger); bool saveAll() override; @@ -30,11 +28,7 @@ class KVSQL final : public KVStore { bool save(const std::string &key, const ValueWrapper &value) override; bool prepareSave(const std::string &key, const ValueWrapper &value, DBInsert &update); - DBInsert dbUpdate() { - auto insert = DBInsert("INSERT INTO `kv_store` (`key_name`, `timestamp`, `value`) VALUES"); - insert.upsert({ "key_name", "timestamp", "value" }); - return insert; - } + DBInsert dbUpdate(); Database &db; }; diff --git a/src/kv/value_wrapper.cpp b/src/kv/value_wrapper.cpp index 78f828248a1..72920b6972a 100644 --- a/src/kv/value_wrapper.cpp +++ b/src/kv/value_wrapper.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "kv/value_wrapper.hpp" #include "utils/tools.hpp" diff --git a/src/kv/value_wrapper.hpp b/src/kv/value_wrapper.hpp index 0b388187dc3..889b1776de2 100644 --- a/src/kv/value_wrapper.hpp +++ b/src/kv/value_wrapper.hpp @@ -19,16 +19,7 @@ #include #include -class ValueWrapper; - -using StringType = std::string; -using BooleanType = bool; -using IntType = int; -using DoubleType = double; -using ArrayType = std::vector; -using MapType = phmap::flat_hash_map>; - -using ValueVariant = std::variant; +#include "kv/kv_definitions.hpp" class ValueWrapper { public: diff --git a/src/kv/value_wrapper_proto.cpp b/src/kv/value_wrapper_proto.cpp index 4362101957e..e4d60bed354 100644 --- a/src/kv/value_wrapper_proto.cpp +++ b/src/kv/value_wrapper_proto.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "kv/value_wrapper_proto.hpp" #include "kv/value_wrapper.hpp" diff --git a/src/lib/di/soft_singleton.cpp b/src/lib/di/soft_singleton.cpp index 64ea514d140..8fb90288cee 100644 --- a/src/lib/di/soft_singleton.cpp +++ b/src/lib/di/soft_singleton.cpp @@ -6,7 +6,6 @@ * Contributors: https://github.com/opentibiabr/canary/graphs/contributors * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" #include "lib/di/soft_singleton.hpp" #include "utils/tools.hpp" diff --git a/src/lib/logging/log_with_spd_log.cpp b/src/lib/logging/log_with_spd_log.cpp index f8cfe16946d..a1893e3d501 100644 --- a/src/lib/logging/log_with_spd_log.cpp +++ b/src/lib/logging/log_with_spd_log.cpp @@ -8,7 +8,6 @@ */ #include -#include "pch.hpp" #include "lib/di/container.hpp" LogWithSpdLog::LogWithSpdLog() { diff --git a/src/lib/thread/thread_pool.cpp b/src/lib/thread/thread_pool.cpp index b2f51ef8f9d..9a44c0d6dbe 100644 --- a/src/lib/thread/thread_pool.cpp +++ b/src/lib/thread/thread_pool.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lib/thread/thread_pool.hpp" #include "game/game.hpp" diff --git a/src/lua/callbacks/event_callback.cpp b/src/lua/callbacks/event_callback.cpp index 8280bad6d2b..6591755d18f 100644 --- a/src/lua/callbacks/event_callback.cpp +++ b/src/lua/callbacks/event_callback.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/callbacks/event_callback.hpp" #include "utils/tools.hpp" diff --git a/src/lua/callbacks/events_callbacks.cpp b/src/lua/callbacks/events_callbacks.cpp index 13a42baa15a..ac14fd17c5a 100644 --- a/src/lua/callbacks/events_callbacks.cpp +++ b/src/lua/callbacks/events_callbacks.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/callbacks/events_callbacks.hpp" #include "lua/callbacks/event_callback.hpp" diff --git a/src/lua/creature/actions.cpp b/src/lua/creature/actions.cpp index 9e16ee7b33e..3d9028ce406 100644 --- a/src/lua/creature/actions.cpp +++ b/src/lua/creature/actions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/creature/actions.hpp" #include "items/bed.hpp" #include "items/containers/container.hpp" diff --git a/src/lua/creature/creatureevent.cpp b/src/lua/creature/creatureevent.cpp index 90d09d2b7f9..3b7dfdceb4c 100644 --- a/src/lua/creature/creatureevent.cpp +++ b/src/lua/creature/creatureevent.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/creature/creatureevent.hpp" #include "utils/tools.hpp" #include "creatures/players/player.hpp" diff --git a/src/lua/creature/events.cpp b/src/lua/creature/events.cpp index 144c188e900..354a8ac78e8 100644 --- a/src/lua/creature/events.cpp +++ b/src/lua/creature/events.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/creature/events.hpp" #include "utils/tools.hpp" #include "items/item.hpp" diff --git a/src/lua/creature/movement.cpp b/src/lua/creature/movement.cpp index b75ff31c661..64e290d8990 100644 --- a/src/lua/creature/movement.cpp +++ b/src/lua/creature/movement.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "lua/creature/events.hpp" #include "lua/callbacks/event_callback.hpp" diff --git a/src/lua/creature/raids.cpp b/src/lua/creature/raids.cpp index 8064bf52b81..c801c4cdee4 100644 --- a/src/lua/creature/raids.cpp +++ b/src/lua/creature/raids.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/creature/raids.hpp" #include "utils/pugicast.hpp" #include "game/game.hpp" diff --git a/src/lua/creature/talkaction.cpp b/src/lua/creature/talkaction.cpp index c1b8c028ddc..ae07bfe6765 100644 --- a/src/lua/creature/talkaction.cpp +++ b/src/lua/creature/talkaction.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/players/player.hpp" #include "lua/scripts/scripts.hpp" #include "lua/creature/talkaction.hpp" diff --git a/src/lua/functions/core/game/bank_functions.cpp b/src/lua/functions/core/game/bank_functions.cpp index eb0bbf00280..26005db41e3 100644 --- a/src/lua/functions/core/game/bank_functions.cpp +++ b/src/lua/functions/core/game/bank_functions.cpp @@ -1,4 +1,12 @@ -#include "pch.hpp" +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2024 OpenTibiaBR + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ + #include "lua/functions/core/game/bank_functions.hpp" #include "game/bank/bank.hpp" #include "game/game.hpp" diff --git a/src/lua/functions/core/game/config_functions.cpp b/src/lua/functions/core/game/config_functions.cpp index b839f720057..acd4e8c0c1c 100644 --- a/src/lua/functions/core/game/config_functions.cpp +++ b/src/lua/functions/core/game/config_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/functions/core/game/config_functions.hpp" #include "config/configmanager.hpp" diff --git a/src/lua/functions/core/game/game_functions.cpp b/src/lua/functions/core/game/game_functions.cpp index 83544ded535..73516ce53de 100644 --- a/src/lua/functions/core/game/game_functions.cpp +++ b/src/lua/functions/core/game/game_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "core.hpp" #include "creatures/monsters/monster.hpp" #include "game/functions/game_reload.hpp" diff --git a/src/lua/functions/core/game/global_functions.cpp b/src/lua/functions/core/game/global_functions.cpp index 6b5175b06cf..79cb3d398fa 100644 --- a/src/lua/functions/core/game/global_functions.cpp +++ b/src/lua/functions/core/game/global_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/interactions/chat.hpp" #include "game/game.hpp" #include "game/scheduling/dispatcher.hpp" diff --git a/src/lua/functions/core/game/lua_enums.cpp b/src/lua/functions/core/game/lua_enums.cpp index e4dc252be0d..22b93351911 100644 --- a/src/lua/functions/core/game/lua_enums.cpp +++ b/src/lua/functions/core/game/lua_enums.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/functions/core/game/lua_enums.hpp" #include "creatures/players/wheel/wheel_gems.hpp" diff --git a/src/lua/functions/core/game/modal_window_functions.cpp b/src/lua/functions/core/game/modal_window_functions.cpp index 0221a9e9a59..a4851cfc85a 100644 --- a/src/lua/functions/core/game/modal_window_functions.cpp +++ b/src/lua/functions/core/game/modal_window_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/players/player.hpp" #include "lua/functions/core/game/modal_window_functions.hpp" #include "game/modal_window/modal_window.hpp" diff --git a/src/lua/functions/core/game/zone_functions.cpp b/src/lua/functions/core/game/zone_functions.cpp index 0f19c94f789..d973f1b003c 100644 --- a/src/lua/functions/core/game/zone_functions.cpp +++ b/src/lua/functions/core/game/zone_functions.cpp @@ -1,4 +1,12 @@ -#include "pch.hpp" +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2024 OpenTibiaBR + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ + #include "lua/functions/core/game/zone_functions.hpp" #include "game/zones/zone.hpp" #include "game/game.hpp" diff --git a/src/lua/functions/core/libs/bit_functions.cpp b/src/lua/functions/core/libs/bit_functions.cpp index 86f76a77a26..94e5f709b5d 100644 --- a/src/lua/functions/core/libs/bit_functions.cpp +++ b/src/lua/functions/core/libs/bit_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/functions/core/libs/bit_functions.hpp" #ifndef LUAJIT_VERSION diff --git a/src/lua/functions/core/libs/db_functions.cpp b/src/lua/functions/core/libs/db_functions.cpp index d5f5a62e0f8..bdfbac8f501 100644 --- a/src/lua/functions/core/libs/db_functions.cpp +++ b/src/lua/functions/core/libs/db_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "database/databasemanager.hpp" #include "database/databasetasks.hpp" #include "lua/functions/core/libs/db_functions.hpp" diff --git a/src/lua/functions/core/libs/kv_functions.cpp b/src/lua/functions/core/libs/kv_functions.cpp index 5ed9c9cfe5d..7ef21f861f7 100644 --- a/src/lua/functions/core/libs/kv_functions.cpp +++ b/src/lua/functions/core/libs/kv_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include #include "kv/kv.hpp" diff --git a/src/lua/functions/core/libs/logger_functions.cpp b/src/lua/functions/core/libs/logger_functions.cpp index 1b2605f6421..741d35fec9d 100644 --- a/src/lua/functions/core/libs/logger_functions.cpp +++ b/src/lua/functions/core/libs/logger_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/functions/core/libs/logger_functions.hpp" void LoggerFunctions::init(lua_State* L) { diff --git a/src/lua/functions/core/libs/metrics_functions.cpp b/src/lua/functions/core/libs/metrics_functions.cpp index 9dc9fa528cb..bcb233bb5aa 100644 --- a/src/lua/functions/core/libs/metrics_functions.cpp +++ b/src/lua/functions/core/libs/metrics_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/functions/core/libs/metrics_functions.hpp" #include "lib/metrics/metrics.hpp" diff --git a/src/lua/functions/core/libs/result_functions.cpp b/src/lua/functions/core/libs/result_functions.cpp index 512f90f7da5..46acc07af9f 100644 --- a/src/lua/functions/core/libs/result_functions.cpp +++ b/src/lua/functions/core/libs/result_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/functions/core/libs/result_functions.hpp" int ResultFunctions::luaResultGetNumber(lua_State* L) { diff --git a/src/lua/functions/core/network/network_message_functions.cpp b/src/lua/functions/core/network/network_message_functions.cpp index e2f4013448d..c7572b4488b 100644 --- a/src/lua/functions/core/network/network_message_functions.cpp +++ b/src/lua/functions/core/network/network_message_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/functions/core/network/network_message_functions.hpp" #include "creatures/players/player.hpp" #include "server/network/protocol/protocolstatus.hpp" diff --git a/src/lua/functions/core/network/webhook_functions.cpp b/src/lua/functions/core/network/webhook_functions.cpp index 37372f8b23a..b24e6184ce3 100644 --- a/src/lua/functions/core/network/webhook_functions.cpp +++ b/src/lua/functions/core/network/webhook_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/functions/core/network/webhook_functions.hpp" #include "server/network/webhook/webhook.hpp" diff --git a/src/lua/functions/creatures/combat/combat_functions.cpp b/src/lua/functions/creatures/combat/combat_functions.cpp index 3bba21d179c..f073cde6aba 100644 --- a/src/lua/functions/creatures/combat/combat_functions.cpp +++ b/src/lua/functions/creatures/combat/combat_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/combat/combat.hpp" #include "game/game.hpp" #include "lua/functions/creatures/combat/combat_functions.hpp" diff --git a/src/lua/functions/creatures/combat/condition_functions.cpp b/src/lua/functions/creatures/combat/condition_functions.cpp index 27f21867f76..e7b1dd331ea 100644 --- a/src/lua/functions/creatures/combat/condition_functions.cpp +++ b/src/lua/functions/creatures/combat/condition_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/combat/condition.hpp" #include "game/game.hpp" #include "lua/functions/creatures/combat/condition_functions.hpp" diff --git a/src/lua/functions/creatures/combat/spell_functions.cpp b/src/lua/functions/creatures/combat/spell_functions.cpp index a24407c1682..79ecb29b957 100644 --- a/src/lua/functions/creatures/combat/spell_functions.cpp +++ b/src/lua/functions/creatures/combat/spell_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/combat/spells.hpp" #include "creatures/players/vocations/vocation.hpp" #include "lua/functions/creatures/combat/spell_functions.hpp" diff --git a/src/lua/functions/creatures/combat/variant_functions.cpp b/src/lua/functions/creatures/combat/variant_functions.cpp index 3b0299983fd..4723e9e8543 100644 --- a/src/lua/functions/creatures/combat/variant_functions.cpp +++ b/src/lua/functions/creatures/combat/variant_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/cylinder.hpp" #include "lua/functions/creatures/combat/variant_functions.hpp" #include "lua/global/lua_variant.hpp" diff --git a/src/lua/functions/creatures/creature_functions.cpp b/src/lua/functions/creatures/creature_functions.cpp index 81a4a0b5304..4d4a4202903 100644 --- a/src/lua/functions/creatures/creature_functions.cpp +++ b/src/lua/functions/creatures/creature_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "creatures/creature.hpp" #include "lua/functions/creatures/creature_functions.hpp" diff --git a/src/lua/functions/creatures/monster/charm_functions.cpp b/src/lua/functions/creatures/monster/charm_functions.cpp index d456f1c96a8..492820b76fa 100644 --- a/src/lua/functions/creatures/monster/charm_functions.cpp +++ b/src/lua/functions/creatures/monster/charm_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "io/iobestiary.hpp" #include "lua/functions/creatures/monster/charm_functions.hpp" diff --git a/src/lua/functions/creatures/monster/loot_functions.cpp b/src/lua/functions/creatures/monster/loot_functions.cpp index 47e0d8778e3..e05d86b6340 100644 --- a/src/lua/functions/creatures/monster/loot_functions.cpp +++ b/src/lua/functions/creatures/monster/loot_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/monsters/monsters.hpp" #include "lua/functions/creatures/monster/loot_functions.hpp" diff --git a/src/lua/functions/creatures/monster/monster_functions.cpp b/src/lua/functions/creatures/monster/monster_functions.cpp index 917e90f85f4..e7b22842640 100644 --- a/src/lua/functions/creatures/monster/monster_functions.cpp +++ b/src/lua/functions/creatures/monster/monster_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "creatures/creature.hpp" #include "creatures/monsters/monster.hpp" diff --git a/src/lua/functions/creatures/monster/monster_spell_functions.cpp b/src/lua/functions/creatures/monster/monster_spell_functions.cpp index a20d57008d2..e9beb607bfc 100644 --- a/src/lua/functions/creatures/monster/monster_spell_functions.cpp +++ b/src/lua/functions/creatures/monster/monster_spell_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/functions/creatures/monster/monster_spell_functions.hpp" #include "creatures/monsters/monsters.hpp" diff --git a/src/lua/functions/creatures/monster/monster_type_functions.cpp b/src/lua/functions/creatures/monster/monster_type_functions.cpp index 2a6e3d1b581..f4d524a533c 100644 --- a/src/lua/functions/creatures/monster/monster_type_functions.cpp +++ b/src/lua/functions/creatures/monster/monster_type_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "io/io_bosstiary.hpp" #include "creatures/combat/spells.hpp" diff --git a/src/lua/functions/creatures/npc/npc_functions.cpp b/src/lua/functions/creatures/npc/npc_functions.cpp index 13e9b499abc..3a161ba3501 100644 --- a/src/lua/functions/creatures/npc/npc_functions.cpp +++ b/src/lua/functions/creatures/npc/npc_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "creatures/creature.hpp" #include "creatures/npcs/npc.hpp" diff --git a/src/lua/functions/creatures/npc/npc_type_functions.cpp b/src/lua/functions/creatures/npc/npc_type_functions.cpp index ef79b671a34..8084688deea 100644 --- a/src/lua/functions/creatures/npc/npc_type_functions.cpp +++ b/src/lua/functions/creatures/npc/npc_type_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/npcs/npcs.hpp" #include "lua/functions/creatures/npc/npc_type_functions.hpp" #include "lua/scripts/scripts.hpp" diff --git a/src/lua/functions/creatures/npc/shop_functions.cpp b/src/lua/functions/creatures/npc/shop_functions.cpp index 122e249a8db..388bda0e977 100644 --- a/src/lua/functions/creatures/npc/shop_functions.cpp +++ b/src/lua/functions/creatures/npc/shop_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/npcs/npcs.hpp" #include "lua/functions/creatures/npc/shop_functions.hpp" diff --git a/src/lua/functions/creatures/player/group_functions.cpp b/src/lua/functions/creatures/player/group_functions.cpp index f547eec1590..2fd414a2e4a 100644 --- a/src/lua/functions/creatures/player/group_functions.cpp +++ b/src/lua/functions/creatures/player/group_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/players/grouping/groups.hpp" #include "game/game.hpp" #include "lua/functions/creatures/player/group_functions.hpp" diff --git a/src/lua/functions/creatures/player/guild_functions.cpp b/src/lua/functions/creatures/player/guild_functions.cpp index 196f0f9d31e..d5706e0609b 100644 --- a/src/lua/functions/creatures/player/guild_functions.cpp +++ b/src/lua/functions/creatures/player/guild_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "creatures/players/grouping/guild.hpp" #include "lua/functions/creatures/player/guild_functions.hpp" diff --git a/src/lua/functions/creatures/player/mount_functions.cpp b/src/lua/functions/creatures/player/mount_functions.cpp index 49b16db6caa..3decd6b2321 100644 --- a/src/lua/functions/creatures/player/mount_functions.cpp +++ b/src/lua/functions/creatures/player/mount_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/appearance/mounts/mounts.hpp" #include "game/game.hpp" #include "lua/functions/creatures/player/mount_functions.hpp" diff --git a/src/lua/functions/creatures/player/party_functions.cpp b/src/lua/functions/creatures/player/party_functions.cpp index d739cde3ceb..1791016bde3 100644 --- a/src/lua/functions/creatures/player/party_functions.cpp +++ b/src/lua/functions/creatures/player/party_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/players/grouping/party.hpp" #include "creatures/players/player.hpp" #include "game/game.hpp" diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index 421ceefcb0d..d148acf8397 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/functions/creatures/player/player_functions.hpp" #include "creatures/combat/spells.hpp" diff --git a/src/lua/functions/creatures/player/vocation_functions.cpp b/src/lua/functions/creatures/player/vocation_functions.cpp index 15cf888bf8a..15e1603cc54 100644 --- a/src/lua/functions/creatures/player/vocation_functions.cpp +++ b/src/lua/functions/creatures/player/vocation_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/players/vocations/vocation.hpp" #include "lua/functions/creatures/player/vocation_functions.hpp" diff --git a/src/lua/functions/events/action_functions.cpp b/src/lua/functions/events/action_functions.cpp index 31b202465c7..c5cf4c73c29 100644 --- a/src/lua/functions/events/action_functions.cpp +++ b/src/lua/functions/events/action_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/creature/actions.hpp" #include "lua/functions/events/action_functions.hpp" #include "game/game.hpp" diff --git a/src/lua/functions/events/creature_event_functions.cpp b/src/lua/functions/events/creature_event_functions.cpp index 7edbabad1d3..ddba9f153fd 100644 --- a/src/lua/functions/events/creature_event_functions.cpp +++ b/src/lua/functions/events/creature_event_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/creature/creatureevent.hpp" #include "lua/functions/events/creature_event_functions.hpp" #include "utils/tools.hpp" diff --git a/src/lua/functions/events/event_callback_functions.cpp b/src/lua/functions/events/event_callback_functions.cpp index ef1c348c113..0968df435ba 100644 --- a/src/lua/functions/events/event_callback_functions.cpp +++ b/src/lua/functions/events/event_callback_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/functions/events/event_callback_functions.hpp" #include "lua/callbacks/event_callback.hpp" diff --git a/src/lua/functions/events/events_scheduler_functions.cpp b/src/lua/functions/events/events_scheduler_functions.cpp index e26794e218a..eb16cf5c340 100644 --- a/src/lua/functions/events/events_scheduler_functions.cpp +++ b/src/lua/functions/events/events_scheduler_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/scheduling/events_scheduler.hpp" #include "lua/functions/events/events_scheduler_functions.hpp" diff --git a/src/lua/functions/events/global_event_functions.cpp b/src/lua/functions/events/global_event_functions.cpp index 129a466e97c..c858ee9a831 100644 --- a/src/lua/functions/events/global_event_functions.cpp +++ b/src/lua/functions/events/global_event_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/functions/events/global_event_functions.hpp" #include "game/game.hpp" #include "lua/global/globalevent.hpp" diff --git a/src/lua/functions/events/move_event_functions.cpp b/src/lua/functions/events/move_event_functions.cpp index 8340dded92f..cfd8588d19b 100644 --- a/src/lua/functions/events/move_event_functions.cpp +++ b/src/lua/functions/events/move_event_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/creature.hpp" #include "lua/creature/movement.hpp" #include "lua/functions/events/move_event_functions.hpp" diff --git a/src/lua/functions/events/talk_action_functions.cpp b/src/lua/functions/events/talk_action_functions.cpp index 559e251eb8e..4a8e9850d7f 100644 --- a/src/lua/functions/events/talk_action_functions.cpp +++ b/src/lua/functions/events/talk_action_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "account/account.hpp" #include "lua/creature/talkaction.hpp" #include "lua/functions/events/talk_action_functions.hpp" diff --git a/src/lua/functions/items/container_functions.cpp b/src/lua/functions/items/container_functions.cpp index 30eb26c6801..7cc06745b18 100644 --- a/src/lua/functions/items/container_functions.cpp +++ b/src/lua/functions/items/container_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "items/item.hpp" #include "lua/functions/items/container_functions.hpp" diff --git a/src/lua/functions/items/imbuement_functions.cpp b/src/lua/functions/items/imbuement_functions.cpp index f24a3f564d7..1faed911621 100644 --- a/src/lua/functions/items/imbuement_functions.cpp +++ b/src/lua/functions/items/imbuement_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/weapons/weapons.hpp" #include "creatures/players/imbuements/imbuements.hpp" #include "lua/functions/items/imbuement_functions.hpp" diff --git a/src/lua/functions/items/item_classification_functions.cpp b/src/lua/functions/items/item_classification_functions.cpp index aa8cf19d589..4df6d6f9ea8 100644 --- a/src/lua/functions/items/item_classification_functions.cpp +++ b/src/lua/functions/items/item_classification_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "lua/functions/items/item_classification_functions.hpp" diff --git a/src/lua/functions/items/item_functions.cpp b/src/lua/functions/items/item_functions.cpp index 361a469da32..5d22b6d3102 100644 --- a/src/lua/functions/items/item_functions.cpp +++ b/src/lua/functions/items/item_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/functions/items/item_functions.hpp" #include "game/game.hpp" diff --git a/src/lua/functions/items/item_type_functions.cpp b/src/lua/functions/items/item_type_functions.cpp index b528795a050..333e00bf763 100644 --- a/src/lua/functions/items/item_type_functions.cpp +++ b/src/lua/functions/items/item_type_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/item.hpp" #include "items/items.hpp" #include "lua/functions/items/item_type_functions.hpp" diff --git a/src/lua/functions/items/weapon_functions.cpp b/src/lua/functions/items/weapon_functions.cpp index 61eff2dfb66..cd0acf94849 100644 --- a/src/lua/functions/items/weapon_functions.cpp +++ b/src/lua/functions/items/weapon_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/functions/items/weapon_functions.hpp" #include "game/game.hpp" diff --git a/src/lua/functions/lua_functions_loader.cpp b/src/lua/functions/lua_functions_loader.cpp index c2dedfb57b6..ad52431a661 100644 --- a/src/lua/functions/lua_functions_loader.cpp +++ b/src/lua/functions/lua_functions_loader.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/combat/spells.hpp" #include "creatures/monsters/monster.hpp" #include "creatures/npcs/npc.hpp" diff --git a/src/lua/functions/map/house_functions.cpp b/src/lua/functions/map/house_functions.cpp index ffba0d0b5a9..b13e47eae10 100644 --- a/src/lua/functions/map/house_functions.cpp +++ b/src/lua/functions/map/house_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/bed.hpp" #include "game/game.hpp" #include "game/movement/position.hpp" diff --git a/src/lua/functions/map/position_functions.cpp b/src/lua/functions/map/position_functions.cpp index 0e4397f3fce..b9f5b5947f6 100644 --- a/src/lua/functions/map/position_functions.cpp +++ b/src/lua/functions/map/position_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "game/movement/position.hpp" #include "lua/functions/map/position_functions.hpp" diff --git a/src/lua/functions/map/teleport_functions.cpp b/src/lua/functions/map/teleport_functions.cpp index 32fce583057..5a5a25a20e6 100644 --- a/src/lua/functions/map/teleport_functions.cpp +++ b/src/lua/functions/map/teleport_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/movement/teleport.hpp" #include "items/item.hpp" #include "lua/functions/map/teleport_functions.hpp" diff --git a/src/lua/functions/map/tile_functions.cpp b/src/lua/functions/map/tile_functions.cpp index cdd82abda8c..8ff44064079 100644 --- a/src/lua/functions/map/tile_functions.cpp +++ b/src/lua/functions/map/tile_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "lua/functions/map/tile_functions.hpp" diff --git a/src/lua/functions/map/town_functions.cpp b/src/lua/functions/map/town_functions.cpp index 053aca36b82..3ccf112e772 100644 --- a/src/lua/functions/map/town_functions.cpp +++ b/src/lua/functions/map/town_functions.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "lua/functions/map/town_functions.hpp" #include "map/town.hpp" diff --git a/src/lua/global/baseevents.cpp b/src/lua/global/baseevents.cpp index 3b312100d3b..e4f4dfa05a5 100644 --- a/src/lua/global/baseevents.cpp +++ b/src/lua/global/baseevents.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/global/baseevents.hpp" #include "lua/scripts/lua_environment.hpp" #include "utils/tools.hpp" diff --git a/src/lua/global/globalevent.cpp b/src/lua/global/globalevent.cpp index a9d589a1f76..9cb24292b12 100644 --- a/src/lua/global/globalevent.cpp +++ b/src/lua/global/globalevent.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/global/globalevent.hpp" #include "utils/tools.hpp" #include "game/game.hpp" diff --git a/src/lua/modules/modules.cpp b/src/lua/modules/modules.cpp index 8b79524ec2c..04cddc43443 100644 --- a/src/lua/modules/modules.cpp +++ b/src/lua/modules/modules.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/modules/modules.hpp" #include "creatures/players/player.hpp" #include "game/game.hpp" diff --git a/src/lua/scripts/lua_environment.cpp b/src/lua/scripts/lua_environment.cpp index cd5023a8d4b..04afd75f958 100644 --- a/src/lua/scripts/lua_environment.cpp +++ b/src/lua/scripts/lua_environment.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "declarations.hpp" #include "lua/scripts/lua_environment.hpp" #include "lua/functions/lua_functions_loader.hpp" diff --git a/src/lua/scripts/luascript.cpp b/src/lua/scripts/luascript.cpp index d67b90e9d18..2daab6c0532 100644 --- a/src/lua/scripts/luascript.cpp +++ b/src/lua/scripts/luascript.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lua/scripts/luascript.hpp" #include "lua/scripts/lua_environment.hpp" #include "lib/metrics/metrics.hpp" diff --git a/src/lua/scripts/script_environment.cpp b/src/lua/scripts/script_environment.cpp index 4a7ad7acd94..e1c5e3a9c85 100644 --- a/src/lua/scripts/script_environment.cpp +++ b/src/lua/scripts/script_environment.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "lua/scripts/luascript.hpp" #include "lua/scripts/script_environment.hpp" diff --git a/src/lua/scripts/scripts.cpp b/src/lua/scripts/scripts.cpp index cb92c1cc29a..3a35750c1af 100644 --- a/src/lua/scripts/scripts.cpp +++ b/src/lua/scripts/scripts.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/players/imbuements/imbuements.hpp" #include "lua/global/globalevent.hpp" #include "items/weapons/weapons.hpp" diff --git a/src/main.cpp b/src/main.cpp index be289d397f6..8534bbb6911 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" #include "canary_server.hpp" #include "lib/di/container.hpp" diff --git a/src/map/house/house.cpp b/src/map/house/house.cpp index f2cb26114bf..ba5e782e5de 100644 --- a/src/map/house/house.cpp +++ b/src/map/house/house.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "utils/pugicast.hpp" #include "map/house/house.hpp" #include "io/iologindata.hpp" diff --git a/src/map/house/housetile.cpp b/src/map/house/housetile.cpp index 5e728a14ea3..8a3217cc011 100644 --- a/src/map/house/housetile.cpp +++ b/src/map/house/housetile.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "items/tile.hpp" #include "creatures/monsters/monster.hpp" #include "map/house/housetile.hpp" diff --git a/src/map/map.cpp b/src/map/map.cpp index b1706be0759..ce73464b80c 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "map.hpp" #include "utils/astarnodes.hpp" diff --git a/src/map/mapcache.cpp b/src/map/mapcache.cpp index ad3c909a8bf..33a069f5ae9 100644 --- a/src/map/mapcache.cpp +++ b/src/map/mapcache.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "mapcache.hpp" #include "game/movement/teleport.hpp" diff --git a/src/map/spectators.cpp b/src/map/spectators.cpp index 405119b83e9..29c81617019 100644 --- a/src/map/spectators.cpp +++ b/src/map/spectators.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "spectators.hpp" #include "game/game.hpp" diff --git a/src/map/utils/astarnodes.cpp b/src/map/utils/astarnodes.cpp index e7c5b7ce48e..4645cd30b62 100644 --- a/src/map/utils/astarnodes.cpp +++ b/src/map/utils/astarnodes.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "astarnodes.hpp" #include "creatures/monsters/monster.hpp" #include "creatures/combat/combat.hpp" diff --git a/src/map/utils/mapsector.cpp b/src/map/utils/mapsector.cpp index de036728b76..064ff837e8b 100644 --- a/src/map/utils/mapsector.cpp +++ b/src/map/utils/mapsector.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/creature.hpp" #include "mapsector.hpp" diff --git a/src/pch.cpp b/src/pch.cpp new file mode 100644 index 00000000000..c76b9e42cf8 --- /dev/null +++ b/src/pch.cpp @@ -0,0 +1,11 @@ +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2024 OpenTibiaBR + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ + +// The visual studio solution requires a pch.cpp including the pch.hpp +#include "pch.hpp" diff --git a/src/security/argon.cpp b/src/security/argon.cpp index fe11ab0724a..41b65b64908 100644 --- a/src/security/argon.cpp +++ b/src/security/argon.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "config/configmanager.hpp" #include "database/database.hpp" #include "security/argon.hpp" diff --git a/src/security/rsa.cpp b/src/security/rsa.cpp index fc28d931f66..220ba94a43d 100644 --- a/src/security/rsa.cpp +++ b/src/security/rsa.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "lib/di/container.hpp" #include "security/rsa.hpp" diff --git a/src/server/network/connection/connection.cpp b/src/server/network/connection/connection.cpp index a3782d56cba..b5ebdebc648 100644 --- a/src/server/network/connection/connection.cpp +++ b/src/server/network/connection/connection.cpp @@ -7,14 +7,20 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "server/network/connection/connection.hpp" + +#include "config/configmanager.hpp" +#include "lib/di/container.hpp" #include "server/network/message/outputmessage.hpp" #include "server/network/protocol/protocol.hpp" #include "game/scheduling/dispatcher.hpp" +#include "server/network/message/networkmessage.hpp" #include "server/server.hpp" +ConnectionManager &ConnectionManager::getInstance() { + return inject(); +} + Connection_ptr ConnectionManager::createConnection(asio::io_service &io_service, ConstServicePort_ptr servicePort) { auto connection = std::make_shared(io_service, servicePort); connections.emplace(connection); @@ -47,7 +53,7 @@ Connection::Connection(asio::io_service &initIoService, ConstServicePort_ptr ini readTimer(initIoService), writeTimer(initIoService), service_port(std::move(initservicePort)), - socket(initIoService) { + socket(initIoService), m_msg() { } void Connection::close(bool force) { @@ -108,7 +114,7 @@ void Connection::acceptInternal(bool toggleParseHeader) { readTimer.async_wait([self = std::weak_ptr(shared_from_this())](const std::error_code &error) { Connection::handleTimeout(self, error); }); try { - asio::async_read(socket, asio::buffer(msg.getBuffer(), HEADER_LENGTH), [self = shared_from_this(), toggleParseHeader](const std::error_code &error, std::size_t N) { + asio::async_read(socket, asio::buffer(m_msg.getBuffer(), HEADER_LENGTH), [self = shared_from_this(), toggleParseHeader](const std::error_code &error, std::size_t N) { if (toggleParseHeader) { self->parseHeader(error); } else { @@ -132,7 +138,7 @@ void Connection::parseProxyIdentification(const std::error_code &error) { return; } - uint8_t* msgBuffer = msg.getBuffer(); + uint8_t* msgBuffer = m_msg.getBuffer(); auto charData = static_cast(static_cast(msgBuffer)); std::string serverName = g_configManager().getString(SERVER_NAME, __FUNCTION__) + "\n"; if (connectionState == CONNECTION_STATE_IDENTIFYING) { @@ -150,7 +156,7 @@ void Connection::parseProxyIdentification(const std::error_code &error) { readTimer.async_wait([self = std::weak_ptr(shared_from_this())](const std::error_code &error) { Connection::handleTimeout(self, error); }); // Read the remainder of proxy identification - asio::async_read(socket, asio::buffer(msg.getBuffer(), remainder), [self = shared_from_this()](const std::error_code &error, std::size_t N) { self->parseProxyIdentification(error); }); + asio::async_read(socket, asio::buffer(m_msg.getBuffer(), remainder), [self = shared_from_this()](const std::error_code &error, std::size_t N) { self->parseProxyIdentification(error); }); } catch (const std::system_error &e) { g_logger().error("Connection::parseProxyIdentification] - error: {}", e.what()); close(FORCE_CLOSE); @@ -200,7 +206,7 @@ void Connection::parseHeader(const std::error_code &error) { packetsSent = 0; } - uint16_t size = msg.getLengthHeader(); + uint16_t size = m_msg.getLengthHeader(); if (size == 0 || size > INPUTMESSAGE_MAXSIZE) { close(FORCE_CLOSE); return; @@ -211,9 +217,9 @@ void Connection::parseHeader(const std::error_code &error) { readTimer.async_wait([self = std::weak_ptr(shared_from_this())](const std::error_code &error) { Connection::handleTimeout(self, error); }); // Read packet content - msg.setLength(size + HEADER_LENGTH); + m_msg.setLength(size + HEADER_LENGTH); // Read the remainder of proxy identification - asio::async_read(socket, asio::buffer(msg.getBodyBuffer(), size), [self = shared_from_this()](const std::error_code &error, std::size_t N) { self->parsePacket(error); }); + asio::async_read(socket, asio::buffer(m_msg.getBodyBuffer(), size), [self = shared_from_this()](const std::error_code &error, std::size_t N) { self->parsePacket(error); }); } catch (const std::system_error &e) { g_logger().error("[Connection::parseHeader] - error: {}", e.what()); close(FORCE_CLOSE); @@ -240,21 +246,21 @@ void Connection::parsePacket(const std::error_code &error) { if (!protocol) { // Check packet checksum uint32_t checksum; - if (int32_t len = msg.getLength() - msg.getBufferPosition() - CHECKSUM_LENGTH; + if (int32_t len = m_msg.getLength() - m_msg.getBufferPosition() - CHECKSUM_LENGTH; len > 0) { - checksum = adlerChecksum(msg.getBuffer() + msg.getBufferPosition() + CHECKSUM_LENGTH, len); + checksum = adlerChecksum(m_msg.getBuffer() + m_msg.getBufferPosition() + CHECKSUM_LENGTH, len); } else { checksum = 0; } - uint32_t recvChecksum = msg.get(); + uint32_t recvChecksum = m_msg.get(); if (recvChecksum != checksum) { // it might not have been the checksum, step back - msg.skipBytes(-CHECKSUM_LENGTH); + m_msg.skipBytes(-CHECKSUM_LENGTH); } // Game protocol has already been created at this point - protocol = service_port->make_protocol(recvChecksum == checksum, msg, shared_from_this()); + protocol = service_port->make_protocol(recvChecksum == checksum, m_msg, shared_from_this()); if (!protocol) { close(FORCE_CLOSE); return; @@ -262,15 +268,15 @@ void Connection::parsePacket(const std::error_code &error) { } else { // It is rather hard to detect if we have checksum or sequence method here so let's skip checksum check // it doesn't generate any problem because olders protocol don't use 'server sends first' feature - msg.get(); + m_msg.get(); // Skip protocol ID - msg.skipBytes(1); + m_msg.skipBytes(1); } - protocol->onRecvFirstMessage(msg); + protocol->onRecvFirstMessage(m_msg); } else { // Send the packet to the current protocol - skipReadingNextPacket = protocol->onRecvMessage(msg); + skipReadingNextPacket = protocol->onRecvMessage(m_msg); } try { @@ -279,7 +285,7 @@ void Connection::parsePacket(const std::error_code &error) { if (!skipReadingNextPacket) { // Wait to the next packet - asio::async_read(socket, asio::buffer(msg.getBuffer(), HEADER_LENGTH), [self = shared_from_this()](const std::error_code &error, std::size_t N) { self->parseHeader(error); }); + asio::async_read(socket, asio::buffer(m_msg.getBuffer(), HEADER_LENGTH), [self = shared_from_this()](const std::error_code &error, std::size_t N) { self->parseHeader(error); }); } } catch (const std::system_error &e) { g_logger().error("[Connection::parsePacket] - error: {}", e.what()); @@ -292,7 +298,7 @@ void Connection::resumeWork() { readTimer.async_wait([self = std::weak_ptr(shared_from_this())](const std::error_code &error) { Connection::handleTimeout(self, error); }); try { - asio::async_read(socket, asio::buffer(msg.getBuffer(), HEADER_LENGTH), [self = shared_from_this()](const std::error_code &error, std::size_t N) { self->parseHeader(error); }); + asio::async_read(socket, asio::buffer(m_msg.getBuffer(), HEADER_LENGTH), [self = shared_from_this()](const std::error_code &error, std::size_t N) { self->parseHeader(error); }); } catch (const std::system_error &e) { g_logger().error("[Connection::resumeWork] - Exception in async_read: {}", e.what()); close(FORCE_CLOSE); diff --git a/src/server/network/connection/connection.hpp b/src/server/network/connection/connection.hpp index 76d9b1c1876..0666ef35d8d 100644 --- a/src/server/network/connection/connection.hpp +++ b/src/server/network/connection/connection.hpp @@ -10,7 +10,7 @@ #pragma once #include "declarations.hpp" -#include "lib/di/container.hpp" +// TODO: Remove circular includes (maybe shared_ptr?) #include "server/network/message/networkmessage.hpp" static constexpr int32_t CONNECTION_WRITE_TIMEOUT = 30; @@ -28,14 +28,13 @@ using Service_ptr = std::shared_ptr; class ServicePort; using ServicePort_ptr = std::shared_ptr; using ConstServicePort_ptr = std::shared_ptr; +class NetworkMessage; class ConnectionManager { public: ConnectionManager() = default; - static ConnectionManager &getInstance() { - return inject(); - } + static ConnectionManager &getInstance(); Connection_ptr createConnection(asio::io_service &io_service, ConstServicePort_ptr servicePort); void releaseConnection(const Connection_ptr &connection); @@ -86,8 +85,6 @@ class Connection : public std::enable_shared_from_this { return socket; } - NetworkMessage msg; - asio::high_resolution_timer readTimer; asio::high_resolution_timer writeTimer; @@ -100,6 +97,8 @@ class Connection : public std::enable_shared_from_this { asio::ip::tcp::socket socket; + NetworkMessage m_msg; + std::time_t timeConnected = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); uint32_t packetsSent = 0; uint32_t ip = 1; diff --git a/src/server/network/message/networkmessage.cpp b/src/server/network/message/networkmessage.cpp index d8cb599a07c..3f7147e8411 100644 --- a/src/server/network/message/networkmessage.cpp +++ b/src/server/network/message/networkmessage.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "server/network/message/networkmessage.hpp" #include "items/containers/container.hpp" diff --git a/src/server/network/message/outputmessage.cpp b/src/server/network/message/outputmessage.cpp index efed7fe8367..bb4dab4526d 100644 --- a/src/server/network/message/outputmessage.cpp +++ b/src/server/network/message/outputmessage.cpp @@ -7,14 +7,18 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "outputmessage.hpp" + +#include "lib/di/container.hpp" #include "server/network/protocol/protocol.hpp" #include "game/scheduling/dispatcher.hpp" const std::chrono::milliseconds OUTPUTMESSAGE_AUTOSEND_DELAY { 10 }; +OutputMessagePool &OutputMessagePool::getInstance() { + return inject(); +} + void OutputMessagePool::scheduleSendAll() { g_dispatcher().scheduleEvent( OUTPUTMESSAGE_AUTOSEND_DELAY.count(), [this] { sendAll(); }, "OutputMessagePool::sendAll" diff --git a/src/server/network/message/outputmessage.hpp b/src/server/network/message/outputmessage.hpp index 459e243cea3..a7e2e72d63f 100644 --- a/src/server/network/message/outputmessage.hpp +++ b/src/server/network/message/outputmessage.hpp @@ -93,9 +93,7 @@ class OutputMessagePool { OutputMessagePool(const OutputMessagePool &) = delete; OutputMessagePool &operator=(const OutputMessagePool &) = delete; - static OutputMessagePool &getInstance() { - return inject(); - } + static OutputMessagePool &getInstance(); void sendAll(); void scheduleSendAll(); diff --git a/src/server/network/protocol/protocol.cpp b/src/server/network/protocol/protocol.cpp index c40ead17ab0..ce3d1339648 100644 --- a/src/server/network/protocol/protocol.cpp +++ b/src/server/network/protocol/protocol.cpp @@ -7,13 +7,17 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "server/network/protocol/protocol.hpp" + +#include "config/configmanager.hpp" +#include "server/network/connection/connection.hpp" #include "server/network/message/outputmessage.hpp" #include "security/rsa.hpp" #include "game/scheduling/dispatcher.hpp" +Protocol::Protocol(Connection_ptr initConnection) : + connectionPtr(initConnection) { } + void Protocol::onSendMessage(const OutputMessage_ptr &msg) { if (!rawMessages) { const uint32_t sendMessageChecksum = msg->getLength() >= 128 && compression(*msg) ? (1U << 31) : 0; @@ -109,17 +113,29 @@ OutputMessage_ptr Protocol::getOutputBuffer(int32_t size) { return outputBuffer; } -void Protocol::XTEA_encrypt(OutputMessage &msg) const { +void Protocol::send(OutputMessage_ptr msg) const { + if (auto connection = getConnection()) { + connection->send(msg); + } +} + +void Protocol::disconnect() const { + if (auto connection = getConnection()) { + connection->close(); + } +} + +void Protocol::XTEA_encrypt(OutputMessage &outputMessage) const { const uint32_t delta = 0x61C88647; // The message must be a multiple of 8 - size_t paddingBytes = msg.getLength() & 7; + size_t paddingBytes = outputMessage.getLength() & 7; if (paddingBytes != 0) { - msg.addPaddingBytes(8 - paddingBytes); + outputMessage.addPaddingBytes(8 - paddingBytes); } - uint8_t* buffer = msg.getOutputBuffer(); - auto messageLength = static_cast(msg.getLength()); + uint8_t* buffer = outputMessage.getOutputBuffer(); + auto messageLength = static_cast(outputMessage.getLength()); int32_t readPos = 0; const std::array newKey = { key[0], key[1], key[2], key[3] }; // TODO: refactor this for not use c-style @@ -193,6 +209,14 @@ bool Protocol::RSA_decrypt(NetworkMessage &msg) { return (msg.getByte() == 0); } +bool Protocol::isConnectionExpired() const { + return connectionPtr.expired(); +} + +Connection_ptr Protocol::getConnection() const { + return connectionPtr.lock(); +} + uint32_t Protocol::getIP() const { if (auto protocolConnection = getConnection()) { return protocolConnection->getIP(); @@ -201,7 +225,7 @@ uint32_t Protocol::getIP() const { return 0; } -bool Protocol::compression(OutputMessage &msg) const { +bool Protocol::compression(OutputMessage &outputMessage) const { if (checksumMethod != CHECKSUM_METHOD_SEQUENCE) { return false; } @@ -211,13 +235,13 @@ bool Protocol::compression(OutputMessage &msg) const { return false; } - const auto outputMessageSize = msg.getLength(); + const auto outputMessageSize = outputMessage.getLength(); if (outputMessageSize > NETWORKMESSAGE_MAXSIZE) { g_logger().error("[NetworkMessage::compression] - Exceded NetworkMessage max size: {}, actually size: {}", NETWORKMESSAGE_MAXSIZE, outputMessageSize); return false; } - compress->stream->next_in = msg.getOutputBuffer(); + compress->stream->next_in = outputMessage.getOutputBuffer(); compress->stream->avail_in = outputMessageSize; compress->stream->next_out = reinterpret_cast(compress->buffer.data()); compress->stream->avail_out = NETWORKMESSAGE_MAXSIZE; @@ -234,8 +258,25 @@ bool Protocol::compression(OutputMessage &msg) const { return false; } - msg.reset(); - msg.addBytes(compress->buffer.data(), totalSize); + outputMessage.reset(); + outputMessage.addBytes(compress->buffer.data(), totalSize); return true; } + +Protocol::ZStream::ZStream() noexcept { + const int32_t compressionLevel = g_configManager().getNumber(COMPRESSION_LEVEL, __FUNCTION__); + if (compressionLevel <= 0) { + return; + } + + stream = std::make_unique(); + stream->zalloc = nullptr; + stream->zfree = nullptr; + stream->opaque = nullptr; + + if (deflateInit2(stream.get(), compressionLevel, Z_DEFLATED, -15, 9, Z_DEFAULT_STRATEGY) != Z_OK) { + stream.reset(); + g_logger().error("[Protocol::enableCompression()] - Zlib deflateInit2 error: {}", (stream->msg ? stream->msg : " unknown error")); + } +} diff --git a/src/server/network/protocol/protocol.hpp b/src/server/network/protocol/protocol.hpp index 54e3dcfd4c3..033e2069ff5 100644 --- a/src/server/network/protocol/protocol.hpp +++ b/src/server/network/protocol/protocol.hpp @@ -9,13 +9,19 @@ #pragma once -#include "server/network/connection/connection.hpp" -#include "config/configmanager.hpp" +#include "server/server_definitions.hpp" + +class OutputMessage; +using OutputMessage_ptr = std::shared_ptr; +class Connection; +using Connection_ptr = std::shared_ptr; +using ConnectionWeak_ptr = std::weak_ptr; + +class NetworkMessage; class Protocol : public std::enable_shared_from_this { public: - explicit Protocol(Connection_ptr initConnection) : - connectionPtr(initConnection) { } + explicit Protocol(Connection_ptr initConnection); virtual ~Protocol() = default; @@ -31,13 +37,9 @@ class Protocol : public std::enable_shared_from_this { virtual void onRecvFirstMessage(NetworkMessage &msg) = 0; virtual void onConnect() { } - bool isConnectionExpired() const { - return connectionPtr.expired(); - } + bool isConnectionExpired() const; - Connection_ptr getConnection() const { - return connectionPtr.lock(); - } + Connection_ptr getConnection() const; uint32_t getIP() const; @@ -48,19 +50,10 @@ class Protocol : public std::enable_shared_from_this { return outputBuffer; } - void send(OutputMessage_ptr msg) const { - if (auto connection = getConnection(); - connection != nullptr) { - connection->send(msg); - } - } + void send(OutputMessage_ptr msg) const; protected: - void disconnect() const { - if (auto connection = getConnection()) { - connection->close(); - } - } + void disconnect() const; void enableXTEAEncryption() { encryptionEnabled = true; @@ -82,22 +75,7 @@ class Protocol : public std::enable_shared_from_this { private: struct ZStream { - ZStream() noexcept { - const int32_t compressionLevel = g_configManager().getNumber(COMPRESSION_LEVEL, __FUNCTION__); - if (compressionLevel <= 0) { - return; - } - - stream = std::make_unique(); - stream->zalloc = nullptr; - stream->zfree = nullptr; - stream->opaque = nullptr; - - if (deflateInit2(stream.get(), compressionLevel, Z_DEFLATED, -15, 9, Z_DEFAULT_STRATEGY) != Z_OK) { - stream.reset(); - g_logger().error("[Protocol::enableCompression()] - Zlib deflateInit2 error: {}", (stream->msg ? stream->msg : " unknown error")); - } - } + ZStream() noexcept; ~ZStream() { deflateEnd(stream.get()); diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 560ae1168c5..e3d94942670 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "creatures/players/management/ban.hpp" #include "core.hpp" #include "declarations.hpp" @@ -984,7 +982,7 @@ void ProtocolGame::addBless() { player->checkAndShowBlessingMessage(); } -void ProtocolGame::parsePacketFromDispatcher(NetworkMessage msg, uint8_t recvbyte) { +void ProtocolGame::parsePacketFromDispatcher(NetworkMessage &msg, uint8_t recvbyte) { if (!acceptPackets || g_game().getGameState() == GAME_STATE_SHUTDOWN) { return; } diff --git a/src/server/network/protocol/protocolgame.hpp b/src/server/network/protocol/protocolgame.hpp index 769771c975a..fe83ed01cf1 100644 --- a/src/server/network/protocol/protocolgame.hpp +++ b/src/server/network/protocol/protocolgame.hpp @@ -96,7 +96,7 @@ class ProtocolGame final : public Protocol { // we have all the parse methods void parsePacket(NetworkMessage &msg) override; - void parsePacketFromDispatcher(NetworkMessage msg, uint8_t recvbyte); + void parsePacketFromDispatcher(NetworkMessage &msg, uint8_t recvbyte); void onRecvFirstMessage(NetworkMessage &msg) override; void onConnect() override; diff --git a/src/server/network/protocol/protocollogin.cpp b/src/server/network/protocol/protocollogin.cpp index 9cf6cc1c370..d3ee6030e1d 100644 --- a/src/server/network/protocol/protocollogin.cpp +++ b/src/server/network/protocol/protocollogin.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "server/network/protocol/protocollogin.hpp" #include "server/network/message/outputmessage.hpp" #include "game/scheduling/dispatcher.hpp" diff --git a/src/server/network/protocol/protocolstatus.cpp b/src/server/network/protocol/protocolstatus.cpp index 1e7e68e1542..4239d6f2300 100644 --- a/src/server/network/protocol/protocolstatus.cpp +++ b/src/server/network/protocol/protocolstatus.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "core.hpp" #include "server/network/protocol/protocolstatus.hpp" diff --git a/src/server/network/webhook/webhook.cpp b/src/server/network/webhook/webhook.cpp index f80ff4e59b3..7ee4ca31f09 100644 --- a/src/server/network/webhook/webhook.cpp +++ b/src/server/network/webhook/webhook.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "server/network/webhook/webhook.hpp" #include "config/configmanager.hpp" #include "game/scheduling/dispatcher.hpp" diff --git a/src/server/server.cpp b/src/server/server.cpp index fc8690468fe..5ed528f5045 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "server/network/message/outputmessage.hpp" #include "server/server.hpp" #include "config/configmanager.hpp" diff --git a/src/server/server_definitions.hpp b/src/server/server_definitions.hpp index b957292b579..79dd89df511 100644 --- a/src/server/server_definitions.hpp +++ b/src/server/server_definitions.hpp @@ -9,6 +9,8 @@ #pragma once +#include "utils/const.hpp" + // Enums // Connection and networkmessage. enum { FORCE_CLOSE = true }; diff --git a/src/server/signals.cpp b/src/server/signals.cpp index ae71d833c93..cb4e083b60c 100644 --- a/src/server/signals.cpp +++ b/src/server/signals.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "game/game.hpp" #include "game/scheduling/dispatcher.hpp" #include "game/scheduling/save_manager.hpp" diff --git a/src/utils/pugicast.cpp b/src/utils/pugicast.cpp index 62717c33621..2269e62b1fb 100644 --- a/src/utils/pugicast.cpp +++ b/src/utils/pugicast.cpp @@ -6,7 +6,7 @@ * Contributors: https://github.com/opentibiabr/canary/graphs/contributors * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" + #include "lib/logging/log_with_spd_log.hpp" namespace pugi { diff --git a/src/utils/tools.cpp b/src/utils/tools.cpp index f89b2c2f217..8df1fde1065 100644 --- a/src/utils/tools.cpp +++ b/src/utils/tools.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "core.hpp" #include "items/item.hpp" #include "utils/tools.hpp" diff --git a/src/utils/wildcardtree.cpp b/src/utils/wildcardtree.cpp index 4fd830b64cb..a8ddf98e442 100644 --- a/src/utils/wildcardtree.cpp +++ b/src/utils/wildcardtree.cpp @@ -7,8 +7,6 @@ * Website: https://docs.opentibiabr.com/ */ -#include "pch.hpp" - #include "utils/wildcardtree.hpp" std::shared_ptr WildcardTreeNode::getChild(char ch) { diff --git a/tests/build_and_run.sh b/tests/build_and_run.sh index ac4ccad512c..f885525353f 100755 --- a/tests/build_and_run.sh +++ b/tests/build_and_run.sh @@ -1,14 +1,22 @@ #!/usr/bin/env bash +# Clean up existing containers, images and volumes and start over docker-compose down --rmi all -v --remove-orphans docker-compose up --build -d + +# Check if the build directory exists, if it doesn't exist it creates it cd .. if [ ! -d "build" ]; then mkdir build fi cd build || exit -cmake -DCMAKE_BUILD_TYPE=Debug -DPACKAGE_TESTS=On .. ; make -j"$(nproc)" + +# Configure the build using vcpkg and compile the project with 6 threads +cmake -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_BUILD_TYPE=Debug -DPACKAGE_TESTS=On .. ; make -j"$(nproc)" + +# Run tests after compilation ./tests/unit/canary_ut --reporter compact --success -cd .. -cd tests || exit + +# Go back to the tests folder and clean the Docker environment again +cd ../tests || exit docker-compose down --rmi all -v --remove-orphans diff --git a/tests/integration/main.cpp b/tests/integration/main.cpp index 3a34285f163..6fb0c291e49 100644 --- a/tests/integration/main.cpp +++ b/tests/integration/main.cpp @@ -1,6 +1,7 @@ #include #include "account/account_repository_db.hpp" +#include "database/database.hpp" #include "lib/logging/in_memory_logger.hpp" #include "utils/tools.hpp" #include "enums/account_type.hpp" diff --git a/vcproj/canary.vcxproj b/vcproj/canary.vcxproj index 77ece957935..eafe0b8000c 100644 --- a/vcproj/canary.vcxproj +++ b/vcproj/canary.vcxproj @@ -414,9 +414,10 @@ - + Create Create + Create @@ -544,7 +545,7 @@ Level1 true stdcpp20 - + pch.hpp true ProgramDatabase true @@ -552,6 +553,7 @@ true /Zc:__cplusplus %(AdditionalOptions) _DISABLE_VECTOR_ANNOTATION;_DISABLE_STRING_ANNOTATION;NDEBUG;%(PreprocessorDefinitions) + Use Console @@ -594,14 +596,15 @@ false + NotUsing false + NotUsing - - + \ No newline at end of file