From 07df814b185e04d2be1c212a0d0ba1cd922336a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Lu=C3=ADs=20Lucarelo=20Lamonato?= Date: Thu, 18 Jul 2024 12:41:55 -0300 Subject: [PATCH] feat: missing configuration warning (#2698) When a configuration is missing in config.lua, you will get a warning in console. You can ignore the warning and, this way, the default value will be used. With the warning, you dont need to conflict your config.lua with configmanager. --- config.lua.dist | 6 ++++++ src/config/config_enums.hpp | 6 ------ src/config/configmanager.cpp | 20 +++++++++++++------- src/config/configmanager.hpp | 2 ++ 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/config.lua.dist b/config.lua.dist index 6823be5e0b1..89bd3e68fc3 100644 --- a/config.lua.dist +++ b/config.lua.dist @@ -239,6 +239,7 @@ onlyPremiumAccount = false -- Customs -- NOTE: stashMoving = true, stow an container inside your stash +-- NOTE: stashItemCount, the maximum items quantity in stash -- NOTE: depotChest, the non-stackable items will be moved to the selected depot chest(I - XVIII). -- NOTE: autoBank = true, the dropped coins from monsters will be automatically deposited to your bank account. -- NOTE: toggleGoldPouchAllowAnything will allow players to move items or gold to gold pouch @@ -256,6 +257,7 @@ onlyPremiumAccount = false -- NOTE: minTownIdToBankTransfer blocks towns less than defined from receiving money transfers -- NOTE: enableSupportOutfit enable GODS and GMS to select support outfit (gamemaster, customer support or community manager) stashMoving = false +stashItemCount = 5000 depotChest = 4 autoLoot = false autoBank = false @@ -504,6 +506,9 @@ rateMonsterHealth = 1.0 rateMonsterAttack = 1.0 rateMonsterDefense = 1.0 +-- Npc rates +rateNpcHealth = 1.0 + -- Boss rates rateBossHealth = 1.0 rateBossAttack = 1.0 @@ -541,6 +546,7 @@ location = "South America" -- Leave empty if you wish to disable. discordWebhookURL = "" discordSendFooter = true +discordWebhookDelayMs = 1000 -- Vip System (Get more info in: https://github.com/opentibiabr/canary/pull/1063) -- NOTE: set vipSystemEnabled to true to enable the vip system functionalities (this overrides premium checks) diff --git a/src/config/config_enums.hpp b/src/config/config_enums.hpp index b1d18b5a32c..bf480505014 100644 --- a/src/config/config_enums.hpp +++ b/src/config/config_enums.hpp @@ -14,7 +14,6 @@ enum ConfigKey_t : uint16_t { ACTIONS_DELAY_INTERVAL, ADVENTURERSBLESSING_LEVEL, AIMBOT_HOTKEY_ENABLED, - ALLOW_BLOCK_SPAWN, ALLOW_CHANGEOUTFIT, ALLOW_RELOAD, AUGMENT_INCREASED_DAMAGE_PERCENT, @@ -68,7 +67,6 @@ enum ConfigKey_t : uint16_t { EXP_FROM_PLAYERS_LEVEL_RANGE, EXPERIENCE_FROM_PLAYERS, FAMILIAR_TIME, - FORCE_MONSTERTYPE_LOAD, FORGE_AMOUNT_MULTIPLIER, FORGE_BASE_SUCCESS_RATE, FORGE_BONUS_SUCCESS_RATE, @@ -136,8 +134,6 @@ enum ConfigKey_t : uint16_t { M_CONST, MAINTAIN_MODE_MESSAGE, MAP_AUTHOR, - MAP_CUSTOM_AUTHOR, - MAP_CUSTOM_NAME, MAP_DOWNLOAD_URL, MAP_NAME, MARKET_OFFER_DURATION, @@ -222,8 +218,6 @@ enum ConfigKey_t : uint16_t { RATE_MONSTER_ATTACK, RATE_MONSTER_DEFENSE, RATE_MONSTER_HEALTH, - RATE_NPC_ATTACK, - RATE_NPC_DEFENSE, RATE_NPC_HEALTH, RATE_OFFLINE_TRAINING_SPEED, RATE_SKILL, diff --git a/src/config/configmanager.cpp b/src/config/configmanager.cpp index 5ade621dff8..6390d0699b3 100644 --- a/src/config/configmanager.cpp +++ b/src/config/configmanager.cpp @@ -72,8 +72,6 @@ bool ConfigManager::load() { loadStringConfig(L, IP, "ip", "127.0.0.1"); loadStringConfig(L, MAINTAIN_MODE_MESSAGE, "maintainModeMessage", ""); loadStringConfig(L, MAP_AUTHOR, "mapAuthor", "Eduardo Dantas"); - loadStringConfig(L, MAP_CUSTOM_AUTHOR, "mapCustomAuthor", "OTServBR"); - loadStringConfig(L, MAP_CUSTOM_NAME, "mapCustomName", ""); loadStringConfig(L, MAP_DOWNLOAD_URL, "mapDownloadUrl", ""); loadStringConfig(L, MAP_NAME, "mapName", "canary"); loadStringConfig(L, MYSQL_DB, "mysqlDatabase", "canary"); @@ -84,7 +82,6 @@ bool ConfigManager::load() { } loadBoolConfig(L, AIMBOT_HOTKEY_ENABLED, "hotkeyAimbotEnabled", true); - loadBoolConfig(L, ALLOW_BLOCK_SPAWN, "allowBlockSpawn", true); loadBoolConfig(L, ALLOW_CHANGEOUTFIT, "allowChangeOutfit", true); loadBoolConfig(L, ALLOW_RELOAD, "allowReload", false); loadBoolConfig(L, AUTOBANK, "autoBank", false); @@ -99,7 +96,6 @@ bool ConfigManager::load() { loadBoolConfig(L, ENABLE_PLAYER_PUT_ITEM_IN_AMMO_SLOT, "enablePlayerPutItemInAmmoSlot", false); loadBoolConfig(L, ENABLE_SUPPORT_OUTFIT, "enableSupportOutfit", true); loadBoolConfig(L, EXPERIENCE_FROM_PLAYERS, "experienceByKillingPlayers", false); - loadBoolConfig(L, FORCE_MONSTERTYPE_LOAD, "forceMonsterTypesOnLoad", true); loadBoolConfig(L, FREE_PREMIUM, "freePremium", false); loadBoolConfig(L, GLOBAL_SERVER_SAVE_CLEAN_MAP, "globalServerSaveCleanMap", false); loadBoolConfig(L, GLOBAL_SERVER_SAVE_CLOSE, "globalServerSaveClose", false); @@ -194,8 +190,6 @@ bool ConfigManager::load() { loadFloatConfig(L, RATE_MONSTER_ATTACK, "rateMonsterAttack", 1.0); loadFloatConfig(L, RATE_MONSTER_DEFENSE, "rateMonsterDefense", 1.0); loadFloatConfig(L, RATE_MONSTER_HEALTH, "rateMonsterHealth", 1.0); - loadFloatConfig(L, RATE_NPC_ATTACK, "rateNpcAttack", 1.0); - loadFloatConfig(L, RATE_NPC_DEFENSE, "rateNpcDefense", 1.0); loadFloatConfig(L, RATE_NPC_HEALTH, "rateNpcHealth", 1.0); loadFloatConfig(L, RATE_OFFLINE_TRAINING_SPEED, "rateOfflineTrainingSpeed", 1.0); loadFloatConfig(L, RATE_SOUL_REGEN_SPEED, "rateSoulRegenSpeed", 1.0); @@ -236,7 +230,7 @@ bool ConfigManager::load() { loadIntConfig(L, FAMILIAR_TIME, "familiarTime", 30); loadIntConfig(L, FORGE_BASE_SUCCESS_RATE, "forgeBaseSuccessRate", 50); loadIntConfig(L, FORGE_BONUS_SUCCESS_RATE, "forgeBonusSuccessRate", 15); - loadIntConfig(L, FORGE_CONVERGENCE_FUSION_DUST_COST, "forgeConvergenceFusionCost", 130); + loadIntConfig(L, FORGE_CONVERGENCE_FUSION_DUST_COST, "forgeConvergenceFusionDustCost", 130); loadIntConfig(L, FORGE_CONVERGENCE_TRANSFER_DUST_COST, "forgeConvergenceTransferCost", 160); loadIntConfig(L, FORGE_CORE_COST, "forgeCoreCost", 50); loadIntConfig(L, FORGE_COST_ONE_SLIVER, "forgeCostOneSliver", 20); @@ -384,11 +378,17 @@ bool ConfigManager::reload() { return result; } +void ConfigManager::missingConfigWarning(const char* identifier) { + g_logger().warn("[{}]: Missing configuration for identifier: {}", __FUNCTION__, identifier); +} + std::string ConfigManager::loadStringConfig(lua_State* L, const ConfigKey_t &key, const char* identifier, const std::string &defaultValue) { std::string value = defaultValue; lua_getglobal(L, identifier); if (lua_isstring(L, -1)) { value = lua_tostring(L, -1); + } else { + missingConfigWarning(identifier); } configs[key] = value; lua_pop(L, 1); @@ -400,6 +400,8 @@ int32_t ConfigManager::loadIntConfig(lua_State* L, const ConfigKey_t &key, const lua_getglobal(L, identifier); if (lua_isnumber(L, -1)) { value = static_cast(lua_tointeger(L, -1)); + } else { + missingConfigWarning(identifier); } configs[key] = value; lua_pop(L, 1); @@ -411,6 +413,8 @@ bool ConfigManager::loadBoolConfig(lua_State* L, const ConfigKey_t &key, const c lua_getglobal(L, identifier); if (lua_isboolean(L, -1)) { value = static_cast(lua_toboolean(L, -1)); + } else { + missingConfigWarning(identifier); } configs[key] = value; lua_pop(L, 1); @@ -422,6 +426,8 @@ float ConfigManager::loadFloatConfig(lua_State* L, const ConfigKey_t &key, const lua_getglobal(L, identifier); if (lua_isnumber(L, -1)) { value = static_cast(lua_tonumber(L, -1)); + } else { + missingConfigWarning(identifier); } configs[key] = value; lua_pop(L, 1); diff --git a/src/config/configmanager.hpp b/src/config/configmanager.hpp index 406ff69891e..2a0c0861955 100644 --- a/src/config/configmanager.hpp +++ b/src/config/configmanager.hpp @@ -26,6 +26,8 @@ class ConfigManager { bool load(); bool reload(); + void missingConfigWarning(const char* identifier); + const std::string &setConfigFileLua(const std::string &what) { configFileLua = { what }; return configFileLua;