From 9fb38cabd8e0de60fb3a22110ed5ca5535b0cecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Lu=C3=ADs=20Lucarelo=20Lamonato?= Date: Mon, 1 Apr 2024 11:50:17 -0300 Subject: [PATCH 1/5] fix: duplicated daily rewards bug (#2503) --- data/modules/scripts/daily_reward/daily_reward.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/data/modules/scripts/daily_reward/daily_reward.lua b/data/modules/scripts/daily_reward/daily_reward.lua index 815a7e2611c..1f0e805704c 100644 --- a/data/modules/scripts/daily_reward/daily_reward.lua +++ b/data/modules/scripts/daily_reward/daily_reward.lua @@ -462,14 +462,12 @@ function Player.selectDailyReward(self, msg) local description = "" for k, v in ipairs(items) do if dailyTable.itemCharges then - for i = 1, rewardCount do - local inboxItem = inbox:addItem(v.itemId, dailyTable.itemCharges) -- adding charges for each item - if inboxItem then - inboxItem:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime()) - end + local inboxItem = inbox:addItem(v.itemId, dailyTable.itemCharges) -- adding charges for each item + if inboxItem then + inboxItem:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime()) end else - local inboxItem = inbox:addItem(v.itemId, rewardCount) -- adding single item w/o charges + local inboxItem = inbox:addItem(v.itemId, v.count) -- adding single item w/o charges if inboxItem then inboxItem:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime()) end From 2f41230fce391fa5a7b9508b29d2e69269f9f945 Mon Sep 17 00:00:00 2001 From: Beats Date: Mon, 1 Apr 2024 11:04:38 -0400 Subject: [PATCH 2/5] improve: remove lib jsoncpp and change WildcardTreeNode to shared_ptr (#2508) --- CMakeLists.txt | 2 +- cmake/modules/BaseConfig.cmake | 1 - cmake/modules/CanaryLib.cmake | 4 +--- src/game/game.cpp | 8 +++++--- src/game/game.hpp | 2 +- src/pch.hpp | 4 +--- src/utils/wildcardtree.cpp | 26 +++++++++++++------------- src/utils/wildcardtree.hpp | 12 ++++++------ vcpkg.json | 1 - vcproj/settings.props | 2 -- 10 files changed, 28 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c8ffef6c0a..0cf201ce38f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 3.22 FATAL_ERROR) # VCPKG # cmake -DCMAKE_TOOLCHAIN_FILE=/opt/workspace/vcpkg/scripts/buildsystems/vcpkg.cmake .. # Needed libs is in file vcpkg.json -# Windows required libs: .\vcpkg install --triplet x64-windows asio pugixml spdlog curl jsoncpp protobuf parallel-hashmap magic-enum mio luajit libmariadb mpir abseil +# Windows required libs: .\vcpkg install --triplet x64-windows asio pugixml spdlog curl protobuf parallel-hashmap magic-enum mio luajit libmariadb mpir abseil if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "") diff --git a/cmake/modules/BaseConfig.cmake b/cmake/modules/BaseConfig.cmake index 6f58a2eebdb..6a8ce69ed4b 100644 --- a/cmake/modules/BaseConfig.cmake +++ b/cmake/modules/BaseConfig.cmake @@ -31,7 +31,6 @@ find_package(ZLIB REQUIRED) find_package(absl CONFIG REQUIRED) find_package(asio CONFIG REQUIRED) find_package(eventpp CONFIG REQUIRED) -find_package(jsoncpp CONFIG REQUIRED) find_package(magic_enum CONFIG REQUIRED) find_package(opentelemetry-cpp CONFIG REQUIRED) find_package(prometheus-cpp CONFIG REQUIRED) diff --git a/cmake/modules/CanaryLib.cmake b/cmake/modules/CanaryLib.cmake index 4838935f19e..270bbf59a99 100644 --- a/cmake/modules/CanaryLib.cmake +++ b/cmake/modules/CanaryLib.cmake @@ -124,16 +124,14 @@ endif() if (MSVC) if(BUILD_STATIC_LIBRARY) - target_link_libraries(${PROJECT_NAME}_lib PUBLIC jsoncpp_static) set(VCPKG_TARGET_TRIPLET "x64-windows-static" CACHE STRING "") else() - target_link_libraries(${PROJECT_NAME}_lib PUBLIC jsoncpp_lib) set(VCPKG_TARGET_TRIPLET "x64-windows" CACHE STRING "") endif() target_link_libraries(${PROJECT_NAME}_lib PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${MYSQL_CLIENT_LIBS}) else() - target_link_libraries(${PROJECT_NAME}_lib PUBLIC jsoncpp_static Threads::Threads) + target_link_libraries(${PROJECT_NAME}_lib PUBLIC Threads::Threads) endif (MSVC) # === OpenMP === diff --git a/src/game/game.cpp b/src/game/game.cpp index 11ed432da15..9310f1c9a20 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -207,6 +207,8 @@ Game::Game() { // Create instance of IOWheel to Game class m_IOWheel = std::make_unique(); + wildcardTree = std::make_shared(false); + m_highscoreCategoriesNames = { { static_cast(HighscoreCategories_t::ACHIEVEMENTS), "Achievement Points" }, { static_cast(HighscoreCategories_t::AXE_FIGHTING), "Axe Fighting" }, @@ -886,7 +888,7 @@ ReturnValue Game::getPlayerByNameWildcard(const std::string &s, std::shared_ptr< if (s.back() == '~') { const std::string &query = asLowerCaseString(s.substr(0, strlen - 1)); std::string result; - ReturnValue ret = wildcardTree.findOne(query, result); + ReturnValue ret = wildcardTree->findOne(query, result); if (ret != RETURNVALUE_NOERROR) { return ret; } @@ -9689,14 +9691,14 @@ void Game::updatePlayerSaleItems(uint32_t playerId) { void Game::addPlayer(std::shared_ptr player) { const std::string &lowercase_name = asLowerCaseString(player->getName()); mappedPlayerNames[lowercase_name] = player; - wildcardTree.insert(lowercase_name); + wildcardTree->insert(lowercase_name); players[player->getID()] = player; } void Game::removePlayer(std::shared_ptr player) { const std::string &lowercase_name = asLowerCaseString(player->getName()); mappedPlayerNames.erase(lowercase_name); - wildcardTree.remove(lowercase_name); + wildcardTree->remove(lowercase_name); players.erase(player->getID()); } diff --git a/src/game/game.hpp b/src/game/game.hpp index d70263c1775..708aa4b1782 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -840,7 +840,7 @@ class Game { size_t lastBucket = 0; size_t lastImbuedBucket = 0; - WildcardTreeNode wildcardTree { false }; + std::shared_ptr wildcardTree; std::map> npcs; std::map> monsters; diff --git a/src/pch.hpp b/src/pch.hpp index 522411b5621..7c38a99ee94 100644 --- a/src/pch.hpp +++ b/src/pch.hpp @@ -45,6 +45,7 @@ #include #include #include +#include // -------------------- // System Includes @@ -95,9 +96,6 @@ struct fmt::formatter, char>> : formatter< // GMP #include -// JSON -#include - // LUA #if __has_include("luajit/lua.hpp") #include diff --git a/src/utils/wildcardtree.cpp b/src/utils/wildcardtree.cpp index 1e91b9b4169..4fd830b64cb 100644 --- a/src/utils/wildcardtree.cpp +++ b/src/utils/wildcardtree.cpp @@ -11,37 +11,37 @@ #include "utils/wildcardtree.hpp" -WildcardTreeNode* WildcardTreeNode::getChild(char ch) { +std::shared_ptr WildcardTreeNode::getChild(char ch) { auto it = children.find(ch); if (it == children.end()) { return nullptr; } - return &it->second; + return it->second; } -const WildcardTreeNode* WildcardTreeNode::getChild(char ch) const { +std::shared_ptr WildcardTreeNode::getChild(char ch) const { auto it = children.find(ch); if (it == children.end()) { return nullptr; } - return &it->second; + return it->second; } -WildcardTreeNode* WildcardTreeNode::addChild(char ch, bool breakp) { - WildcardTreeNode* child = getChild(ch); +std::shared_ptr WildcardTreeNode::addChild(char ch, bool breakp) { + std::shared_ptr child = getChild(ch); if (child) { if (breakp && !child->breakpoint) { child->breakpoint = true; } } else { - auto pair = children.emplace(std::piecewise_construct, std::forward_as_tuple(ch), std::forward_as_tuple(breakp)); - child = &pair.first->second; + auto pair = children.emplace(std::piecewise_construct, std::forward_as_tuple(ch), std::forward_as_tuple(std::make_shared(breakp))); + child = pair.first->second; } return child; } void WildcardTreeNode::insert(const std::string &str) { - WildcardTreeNode* cur = this; + std::shared_ptr cur = static_self_cast(); size_t length = str.length() - 1; for (size_t pos = 0; pos < length; ++pos) { @@ -52,9 +52,9 @@ void WildcardTreeNode::insert(const std::string &str) { } void WildcardTreeNode::remove(const std::string &str) { - WildcardTreeNode* cur = this; + std::shared_ptr cur = static_self_cast(); - std::stack path; + std::stack> path; path.push(cur); size_t len = str.length(); for (size_t pos = 0; pos < len; ++pos) { @@ -85,7 +85,7 @@ void WildcardTreeNode::remove(const std::string &str) { } ReturnValue WildcardTreeNode::findOne(const std::string &query, std::string &result) const { - const WildcardTreeNode* cur = this; + auto cur = static_self_cast(); for (char pos : query) { cur = cur->getChild(pos); if (!cur) { @@ -105,6 +105,6 @@ ReturnValue WildcardTreeNode::findOne(const std::string &query, std::string &res auto it = cur->children.begin(); result += it->first; - cur = &it->second; + cur = it->second; } while (true); } diff --git a/src/utils/wildcardtree.hpp b/src/utils/wildcardtree.hpp index 07728ae9849..9f3d2cf8ece 100644 --- a/src/utils/wildcardtree.hpp +++ b/src/utils/wildcardtree.hpp @@ -11,19 +11,19 @@ #include "declarations.hpp" -class WildcardTreeNode { +class WildcardTreeNode : public SharedObject { public: explicit WildcardTreeNode(bool initBreakpoint) : breakpoint(initBreakpoint) { } - WildcardTreeNode(WildcardTreeNode &&other) = default; + WildcardTreeNode(WildcardTreeNode &&other) noexcept = default; // non-copyable WildcardTreeNode(const WildcardTreeNode &) = delete; WildcardTreeNode &operator=(const WildcardTreeNode &) = delete; - WildcardTreeNode* getChild(char ch); - const WildcardTreeNode* getChild(char ch) const; - WildcardTreeNode* addChild(char ch, bool breakpoint); + std::shared_ptr getChild(char ch); + std::shared_ptr getChild(char ch) const; + std::shared_ptr addChild(char ch, bool breakpoint); void insert(const std::string &str); void remove(const std::string &str); @@ -31,6 +31,6 @@ class WildcardTreeNode { ReturnValue findOne(const std::string &query, std::string &result) const; private: - std::map children; + std::map> children; bool breakpoint; }; diff --git a/vcpkg.json b/vcpkg.json index 82f1058bd94..a0bc4a0332b 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -9,7 +9,6 @@ "bext-ut", "curl", "eventpp", - "jsoncpp", "luajit", "magic-enum", "mio", diff --git a/vcproj/settings.props b/vcproj/settings.props index 35625d790b9..6f98969614d 100644 --- a/vcproj/settings.props +++ b/vcproj/settings.props @@ -21,7 +21,6 @@ libcurl.lib; fmt.lib; spdlog.lib; - jsoncpp.lib; abseil_dll.lib; argon2.lib; opentelemetry_common.lib; @@ -60,7 +59,6 @@ libcurl-d.lib; fmtd.lib; spdlogd.lib; - jsoncpp.lib; abseil_dll.lib; argon2.lib; opentelemetry_common.lib; From 0c0e5467b5f35a2404c5052e7ec3402fc84f1992 Mon Sep 17 00:00:00 2001 From: Beats Date: Mon, 1 Apr 2024 11:57:45 -0400 Subject: [PATCH 3/5] feat: disable metrics at compile-time (#2509) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To install the libraries, need to run the following commands: For Windows systems (with static linking): • vcpkg install opentelemetry-cpp[default-features,otlp-http,prometheus] --triplet x64-windows-static For Windows systems (with dynamic linking): • vcpkg install opentelemetry-cpp[default-features,otlp-http,prometheus] --triplet x64-windows For Linux systems: • vcpkg install opentelemetry-cpp[default-features,otlp-http,prometheus] --triplet x64-linux --- CMakeLists.txt | 7 ++ cmake/modules/BaseConfig.cmake | 6 +- cmake/modules/CanaryLib.cmake | 24 ++++--- src/canary_server.cpp | 3 +- src/lib/CMakeLists.txt | 5 +- src/lib/metrics/metrics.cpp | 9 ++- src/lib/metrics/metrics.hpp | 127 +++++++++++++++++++++++---------- src/pch.hpp | 15 ++++ vcpkg.json | 8 --- 9 files changed, 144 insertions(+), 60 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cf201ce38f..e4093f4de2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,11 +48,18 @@ include(LoggingHelper) option(OPTIONS_ENABLE_CCACHE "Enable ccache" OFF) option(OPTIONS_ENABLE_SCCACHE "Use sccache to speed up compilation process" OFF) option(OPTIONS_ENABLE_IPO "Check and Enable interprocedural optimization (IPO/LTO)" ON) +option(FEATURE_METRICS "Enable metrics feature" OFF) # ***************************************************************************** # Options Code # ***************************************************************************** +if(FEATURE_METRIC) + log_option_enabled("metrics") +else () + log_option_disabled("metrics") +endif () + # === CCACHE === if(OPTIONS_ENABLE_CCACHE) find_program(CCACHE ccache) diff --git a/cmake/modules/BaseConfig.cmake b/cmake/modules/BaseConfig.cmake index 6a8ce69ed4b..7e3f6404b3f 100644 --- a/cmake/modules/BaseConfig.cmake +++ b/cmake/modules/BaseConfig.cmake @@ -32,8 +32,10 @@ find_package(absl CONFIG REQUIRED) find_package(asio CONFIG REQUIRED) find_package(eventpp CONFIG REQUIRED) find_package(magic_enum CONFIG REQUIRED) -find_package(opentelemetry-cpp CONFIG REQUIRED) -find_package(prometheus-cpp CONFIG REQUIRED) +if(FEATURE_METRICS) + find_package(opentelemetry-cpp CONFIG REQUIRED) + find_package(prometheus-cpp CONFIG REQUIRED) +endif() find_package(mio REQUIRED) find_package(pugixml CONFIG REQUIRED) find_package(spdlog REQUIRED) diff --git a/cmake/modules/CanaryLib.cmake b/cmake/modules/CanaryLib.cmake index 270bbf59a99..a3f5410b9d8 100644 --- a/cmake/modules/CanaryLib.cmake +++ b/cmake/modules/CanaryLib.cmake @@ -105,17 +105,25 @@ target_link_libraries(${PROJECT_NAME}_lib unofficial::argon2::libargon2 unofficial::libmariadb unofficial::mariadbclient - opentelemetry-cpp::common - opentelemetry-cpp::metrics - opentelemetry-cpp::api - opentelemetry-cpp::ext - opentelemetry-cpp::sdk - opentelemetry-cpp::logs - opentelemetry-cpp::ostream_metrics_exporter - opentelemetry-cpp::prometheus_exporter protobuf ) +if(FEATURE_METRICS) + add_definitions(-DFEATURE_METRICS) + + target_link_libraries(${PROJECT_NAME}_lib + PUBLIC + opentelemetry-cpp::common + opentelemetry-cpp::metrics + opentelemetry-cpp::api + opentelemetry-cpp::ext + opentelemetry-cpp::sdk + opentelemetry-cpp::logs + opentelemetry-cpp::ostream_metrics_exporter + opentelemetry-cpp::prometheus_exporter + ) +endif() + if(CMAKE_BUILD_TYPE MATCHES Debug) target_link_libraries(${PROJECT_NAME}_lib PUBLIC ${ZLIB_LIBRARY_DEBUG}) else() diff --git a/src/canary_server.cpp b/src/canary_server.cpp index 56cd53bf567..0961bc93fde 100644 --- a/src/canary_server.cpp +++ b/src/canary_server.cpp @@ -61,6 +61,7 @@ int CanaryServer::run() { loadConfigLua(); logger.info("Server protocol: {}.{}{}", CLIENT_VERSION_UPPER, CLIENT_VERSION_LOWER, g_configManager().getBoolean(OLD_PROTOCOL, __FUNCTION__) ? " and 10x allowed!" : ""); +#ifdef FEATURE_METRICS metrics::Options metricsOptions; metricsOptions.enablePrometheusExporter = g_configManager().getBoolean(METRICS_ENABLE_PROMETHEUS, __FUNCTION__); if (metricsOptions.enablePrometheusExporter) { @@ -71,7 +72,7 @@ int CanaryServer::run() { metricsOptions.ostreamOptions.export_interval_millis = std::chrono::milliseconds(g_configManager().getNumber(METRICS_OSTREAM_INTERVAL, __FUNCTION__)); } g_metrics().init(metricsOptions); - +#endif rsa.start(); initializeDatabase(); loadModules(); diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 402c6a34a79..55709c59ac3 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -1,6 +1,9 @@ target_sources(${PROJECT_NAME}_lib PRIVATE di/soft_singleton.cpp logging/log_with_spd_log.cpp - metrics/metrics.cpp thread/thread_pool.cpp ) + +if(FEATURE_METRICS) + target_sources(${PROJECT_NAME}_lib PRIVATE metrics/metrics.cpp) +endif() diff --git a/src/lib/metrics/metrics.cpp b/src/lib/metrics/metrics.cpp index 2a65e9a7d5d..cf11060125a 100644 --- a/src/lib/metrics/metrics.cpp +++ b/src/lib/metrics/metrics.cpp @@ -1,3 +1,4 @@ +#ifdef FEATURE_METRICS /** * Canary - A free and open-source MMORPG server emulator * Copyright (©) 2019-2024 OpenTibiaBR @@ -7,8 +8,8 @@ * Website: https://docs.opentibiabr.com/ */ -#include "metrics.hpp" -#include "lib/di/container.hpp" + #include "metrics.hpp" + #include "lib/di/container.hpp" using namespace metrics; @@ -41,7 +42,7 @@ void Metrics::init(Options opts) { initHistograms(); } -void Metrics ::initHistograms() { +void Metrics::initHistograms() { for (auto name : latencyNames) { auto instrumentSelector = metrics_sdk::InstrumentSelectorFactory::Create(metrics_sdk::InstrumentType::kHistogram, name, "us"); auto meterSelector = metrics_sdk::MeterSelectorFactory::Create("performance", otelVersion, otelSchema); @@ -108,3 +109,5 @@ void ScopedLatency::stop() { auto attrskv = opentelemetry::common::KeyValueIterableView { attrs }; histogram->Record(elapsed, attrskv, context); } + +#endif // FEATURE_METRICS diff --git a/src/lib/metrics/metrics.hpp b/src/lib/metrics/metrics.hpp index 0d8c291dfbe..279ea5f91c5 100644 --- a/src/lib/metrics/metrics.hpp +++ b/src/lib/metrics/metrics.hpp @@ -9,43 +9,29 @@ #pragma once -#include "game/scheduling/dispatcher.hpp" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#ifdef FEATURE_METRICS + #include "game/scheduling/dispatcher.hpp" + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include namespace metrics_sdk = opentelemetry::sdk::metrics; namespace common = opentelemetry::common; namespace metrics_exporter = opentelemetry::exporter::metrics; namespace metrics_api = opentelemetry::metrics; -constexpr std::string_view methodName(const char* s) { - std::string_view prettyFunction(s); - size_t bracket = prettyFunction.rfind("("); - size_t space = prettyFunction.rfind(" ", bracket) + 1; - return prettyFunction.substr(space, bracket - space); -} - -#if defined(__GNUC__) || defined(__clang__) - #define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__) -#elif defined(_MSC_VER) - #define __METHOD_NAME__ methodName(__FUNCSIG__) -#else - #error "Compiler not supported" -#endif - namespace metrics { using Meter = opentelemetry::nostd::shared_ptr; @@ -85,12 +71,12 @@ namespace metrics { bool stopped { false }; }; -#define DEFINE_LATENCY_CLASS(class_name, histogram_name, category) \ - class class_name##_latency final : public ScopedLatency { \ - public: \ - class_name##_latency(std::string_view name) : \ - ScopedLatency(name, histogram_name "_latency", category) { } \ - } + #define DEFINE_LATENCY_CLASS(class_name, histogram_name, category) \ + class class_name##_latency final : public ScopedLatency { \ + public: \ + class_name##_latency(std::string_view name) : \ + ScopedLatency(name, histogram_name "_latency", category) { } \ + } DEFINE_LATENCY_CLASS(method, "method", "method"); DEFINE_LATENCY_CLASS(lua, "lua", "scope"); @@ -170,3 +156,70 @@ namespace metrics { constexpr auto g_metrics = metrics::Metrics::getInstance; + +#else // FEATURE_METRICS + + #include "lib/di/container.hpp" + +struct Options { + bool enablePrometheusExporter; + bool enableOStreamExporter; +}; + +class ScopedLatency { +public: + explicit ScopedLatency([[maybe_unused]] std::string_view name, [[maybe_unused]] const std::string &histogramName, [[maybe_unused]] const std::string &scopeKey) {}; + explicit ScopedLatency([[maybe_unused]] std::string_view name, [[maybe_unused]] std::set &histogram, [[maybe_unused]] const std::map &attrs = {}, [[maybe_unused]] const std::string &context = std::string()) {}; + + void stop() {}; + + ~ScopedLatency() = default; +}; + +namespace metrics { + #define DEFINE_LATENCY_CLASS(class_name, histogram_name, category) \ + class class_name##_latency final : public ScopedLatency { \ + public: \ + class_name##_latency(std::string_view name) : \ + ScopedLatency(name, histogram_name "_latency", category) { } \ + } + + DEFINE_LATENCY_CLASS(method, "method", "method"); + DEFINE_LATENCY_CLASS(lua, "lua", "scope"); + DEFINE_LATENCY_CLASS(query, "query", "truncated_query"); + DEFINE_LATENCY_CLASS(task, "task", "task"); + DEFINE_LATENCY_CLASS(lock, "lock", "scope"); + + const std::vector latencyNames { + "method_latency", + "lua_latency", + "query_latency", + "task_latency", + "lock_latency", + }; + + class Metrics final { + public: + Metrics() = default; + ~Metrics() = default; + + void init([[maybe_unused]] Options opts) {}; + void initHistograms() {}; + void shutdown() {}; + + static Metrics &getInstance() { + return inject(); + }; + + void addCounter([[maybe_unused]] std::string_view name, [[maybe_unused]] double value, [[maybe_unused]] const std::map &attrs = {}) { } + + void addUpDownCounter([[maybe_unused]] std::string_view name, [[maybe_unused]] int value, [[maybe_unused]] const std::map &attrs = {}) { } + + friend class ScopedLatency; + }; +} + +constexpr auto g_metrics + = metrics::Metrics::getInstance; + +#endif // FEATURE_METRICS diff --git a/src/pch.hpp b/src/pch.hpp index 7c38a99ee94..e69c27016a4 100644 --- a/src/pch.hpp +++ b/src/pch.hpp @@ -170,3 +170,18 @@ struct fmt::formatter, char>> : formatter< #include #include "lua/global/shared_object.hpp" + +constexpr std::string_view methodName(const char* s) { + std::string_view prettyFunction(s); + size_t bracket = prettyFunction.rfind('('); + size_t space = prettyFunction.rfind(' ', bracket) + 1; + return prettyFunction.substr(space, bracket - space); +} + +#if defined(__GNUC__) || defined(__clang__) + #define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__) +#elif defined(_MSC_VER) + #define __METHOD_NAME__ methodName(__FUNCSIG__) +#else + #error "Compiler not supported" +#endif diff --git a/vcpkg.json b/vcpkg.json index a0bc4a0332b..dda054f3774 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -12,14 +12,6 @@ "luajit", "magic-enum", "mio", - { - "name": "opentelemetry-cpp", - "default-features": true, - "features": [ - "otlp-http", - "prometheus" - ] - }, "parallel-hashmap", "protobuf", "pugixml", From 8479c168913ec423be23bb4e7328d631748afb6f Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Tue, 2 Apr 2024 16:38:41 -0300 Subject: [PATCH 4/5] fix: transform item logic crash (#2517) Resolves #2516 Related to: #2419 In the updated version of the code, we streamlined the condition for item decay by integrating an additional check directly into the initial if statement. Previously, we had a separate check inside the if block to determine if the newType.decayTo value was present, which then set the itemId accordingly. However, this approach had the potential risk of creating unnecessary complexity and possibly leading to a loop if the conditions weren't met as expected. To address this and enhance clarity, we've moved the check for newType.decayTo into the condition of the if statement itself. This adjustment ensures that all necessary conditions are evaluated upfront, making the code more straightforward and preventing the execution from entering the if block unless all criteria are satisfied. This change not only simplifies the logic but also ensures that we avoid any unintended loops by making the transition to the else if statement more predictable when the initial conditions are not met. --- src/game/game.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index 9310f1c9a20..cac0b596ebf 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -2616,12 +2616,10 @@ std::shared_ptr Game::transformItem(std::shared_ptr item, uint16_t n auto decaying = item->getDecaying(); // If the item is decaying, we need to transform it to the new item - if (decaying > DECAYING_FALSE && item->getDuration() <= 1) { + if (decaying > DECAYING_FALSE && item->getDuration() <= 1 && newType.decayTo) { g_logger().debug("Decay duration old type {}, transformEquipTo {}, transformDeEquipTo {}", curType.decayTo, curType.transformEquipTo, curType.transformDeEquipTo); - g_logger().debug("Decay duration new type, decayTo {}, transformEquipTo {}, transformDeEquipTo {}", newType.decayTo, newType.transformEquipTo, newType.transformDeEquipTo); - if (newType.decayTo) { - itemId = newType.decayTo; - } + g_logger().debug("Decay duration new type decayTo {}, transformEquipTo {}, transformDeEquipTo {}", newType.decayTo, newType.transformEquipTo, newType.transformDeEquipTo); + itemId = newType.decayTo; } else if (curType.id != newType.id) { if (newType.group != curType.group) { item->setDefaultSubtype(); From 0bb10ab2cc5c83657a495601f21835e26d173b83 Mon Sep 17 00:00:00 2001 From: Jeswill David Bolivar Mendoza <76903590+jeswilldbm@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:42:54 +0200 Subject: [PATCH 5/5] fix: prismatic ring attribute absorb (#2522) --- data/items/items.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/items/items.xml b/data/items/items.xml index b1a1c6b003f..765c6e9db51 100644 --- a/data/items/items.xml +++ b/data/items/items.xml @@ -34797,7 +34797,7 @@ - +