Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: missing configuration warning #2698

Merged
merged 13 commits into from
Jul 18, 2024
3 changes: 3 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 @@ -255,6 +256,7 @@ onlyPremiumAccount = false
-- NOTE: if showLootsInBestiary is true, will cause all loots to be shown in the bestiary even if the player has not reached the required number of kills
-- NOTE: minTownIdToBankTransfer blocks towns less than defined from receiving money transfers
stashMoving = false
stashItemCount = 5000
depotChest = 4
autoLoot = false
autoBank = false
Expand Down Expand Up @@ -539,6 +541,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 @@ -67,7 +66,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 @@ -135,8 +133,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 @@ -221,8 +217,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
18 changes: 12 additions & 6 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 @@ -98,7 +95,6 @@ bool ConfigManager::load() {
loadBoolConfig(L, EMOTE_SPELLS, "emoteSpells", false);
loadBoolConfig(L, ENABLE_PLAYER_PUT_ITEM_IN_AMMO_SLOT, "enablePlayerPutItemInAmmoSlot", false);
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 @@ -193,8 +189,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 @@ -383,11 +377,17 @@ bool ConfigManager::reload() {
return result;
}

void ConfigManager::missingConfigWarning(const char* identifier) {
g_logger().warn(fmt::format("{}: Missing configuration for identifier: {}", __FUNCTION__, std::string(identifier)));
}
lamonato29 marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -399,6 +399,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 @@ -410,6 +412,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 @@ -421,6 +425,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
Loading