Skip to content

Commit

Permalink
feat: missing configuration warning (opentibiabr#2698)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lamonato29 authored Jul 18, 2024
1 parent 72b51f0 commit 07df814
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
6 changes: 6 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions src/config/config_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 13 additions & 7 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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<int32_t>(lua_tointeger(L, -1));
} else {
missingConfigWarning(identifier);
}
configs[key] = value;
lua_pop(L, 1);
Expand All @@ -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<bool>(lua_toboolean(L, -1));
} else {
missingConfigWarning(identifier);
}
configs[key] = value;
lua_pop(L, 1);
Expand All @@ -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<float>(lua_tonumber(L, -1));
} else {
missingConfigWarning(identifier);
}
configs[key] = value;
lua_pop(L, 1);
Expand Down
2 changes: 2 additions & 0 deletions src/config/configmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 07df814

Please sign in to comment.