diff --git a/src/actions.cpp b/src/actions.cpp index 935c786..689d3dd 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -15,7 +15,6 @@ extern Game g_game; extern Spells* g_spells; extern Actions* g_actions; -extern ConfigManager g_config; Actions::Actions() : scriptInterface("Action Interface") { scriptInterface.initState(); } @@ -383,7 +382,7 @@ static void showUseHotkeyMessage(Player* player, const Item* item, uint32_t coun bool Actions::useItem(Player* player, const Position& pos, uint8_t index, Item* item, bool isHotkey) { - player->setNextAction(OTSYS_TIME() + g_config[ConfigKeysInteger::ACTIONS_DELAY_INTERVAL]); + player->setNextAction(OTSYS_TIME() + getInteger(ConfigManager::ACTIONS_DELAY_INTERVAL)); if (isHotkey) { uint16_t subType = item->getSubType(); @@ -391,7 +390,7 @@ bool Actions::useItem(Player* player, const Position& pos, uint8_t index, Item* player->getItemTypeCount(item->getID(), subType != item->getItemCount() ? subType : -1)); } - if (g_config[ConfigKeysBoolean::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS]) { + if (getBoolean(ConfigManager::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { if (HouseTile* houseTile = dynamic_cast(item->getTile())) { House* house = houseTile->getHouse(); if (house && !house->isInvited(player)) { @@ -418,7 +417,7 @@ bool Actions::useItem(Player* player, const Position& pos, uint8_t index, Item* bool Actions::useItemEx(Player* player, const Position& fromPos, const Position& toPos, uint8_t toStackPos, Item* item, bool isHotkey, Creature* creature /* = nullptr*/) { - player->setNextAction(OTSYS_TIME() + g_config[ConfigKeysInteger::EX_ACTIONS_DELAY_INTERVAL]); + player->setNextAction(OTSYS_TIME() + getInteger(ConfigManager::EX_ACTIONS_DELAY_INTERVAL)); Action* action = getAction(item); if (!action) { diff --git a/src/combat.cpp b/src/combat.cpp index 7b534af..c08aeac 100644 --- a/src/combat.cpp +++ b/src/combat.cpp @@ -13,7 +13,6 @@ extern Game g_game; extern Weapons* g_weapons; -extern ConfigManager g_config; extern Events* g_events; std::vector getList(const MatrixArea& area, const Position& targetPos, const Direction dir) @@ -271,7 +270,7 @@ bool Combat::isInPvpZone(const Creature* attacker, const Creature* target) bool Combat::isProtected(const Player* attacker, const Player* target) { - const int64_t protectionLevel = g_config[ConfigKeysInteger::PROTECTION_LEVEL]; + const int64_t protectionLevel = getInteger(ConfigManager::PROTECTION_LEVEL); if (target->getLevel() < protectionLevel || attacker->getLevel() < protectionLevel) { return true; } diff --git a/src/condition.cpp b/src/condition.cpp index bbe873d..786e0c9 100644 --- a/src/condition.cpp +++ b/src/condition.cpp @@ -9,7 +9,6 @@ #include "game.h" extern Game g_game; -extern ConfigManager g_config; bool Condition::setParam(ConditionParam_t param, int32_t value) { @@ -1029,7 +1028,7 @@ bool ConditionRegeneration::executeCondition(Creature* creature, int32_t interva player->sendTextMessage(message); g_game.addAnimatedText(fmt::format("{:+d}", realHealthGain), player->getPosition(), - static_cast(g_config[ConfigKeysInteger::HEALTH_GAIN_COLOUR])); + static_cast(getInteger(ConfigManager::HEALTH_GAIN_COLOUR))); SpectatorVec spectators; g_game.map.getSpectators(spectators, player->getPosition(), false, true); @@ -1067,7 +1066,7 @@ bool ConditionRegeneration::executeCondition(Creature* creature, int32_t interva player->sendTextMessage(message); g_game.addAnimatedText(fmt::format("{:+d}", realManaGain), player->getPosition(), - static_cast(g_config[ConfigKeysInteger::MANA_GAIN_COLOUR])); + static_cast(getInteger(ConfigManager::MANA_GAIN_COLOUR))); SpectatorVec spectators; g_game.map.getSpectators(spectators, player->getPosition(), false, true); diff --git a/src/configmanager.cpp b/src/configmanager.cpp index c49120c..7a9529a 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -25,6 +25,18 @@ extern Game g_game; namespace { +std::array strings = {}; +std::array integers = {}; +std::array booleans = {}; + +using ExperienceStages = std::vector>; +ExperienceStages expStages; + +using OTCFeatures = std::vector; +OTCFeatures otcFeatures; + +bool loaded = false; + template auto getEnv(const char* envVar, T&& defaultValue) { @@ -81,12 +93,6 @@ bool getGlobalBoolean(lua_State* L, const char* identifier, const bool defaultVa return val != 0; } -} // namespace - -ConfigManager::ConfigManager() { strings[ConfigKeysString::CONFIG_FILE] = "config.lua"; } - -namespace { - ExperienceStages loadLuaStages(lua_State* L) { ExperienceStages stages; @@ -179,7 +185,8 @@ bool ConfigManager::load() luaL_openlibs(L); - if (luaL_dofile(L, getString(ConfigKeysString::CONFIG_FILE).data())) { + strings[CONFIG_FILE] = "config.lua"; + if (luaL_dofile(L, getString(String::CONFIG_FILE).data())) { std::cout << "[Error - ConfigManager::load] " << lua_tostring(L, -1) << std::endl; lua_close(L); return false; @@ -187,142 +194,138 @@ bool ConfigManager::load() // parse config if (!loaded) { // info that must be loaded one time (unless we reset the modules involved) - booleans[ConfigKeysBoolean::BIND_ONLY_GLOBAL_ADDRESS] = getGlobalBoolean(L, "bindOnlyGlobalAddress", false); - booleans[ConfigKeysBoolean::OPTIMIZE_DATABASE] = getGlobalBoolean(L, "startupDatabaseOptimization", true); + booleans[Boolean::BIND_ONLY_GLOBAL_ADDRESS] = getGlobalBoolean(L, "bindOnlyGlobalAddress", false); + booleans[Boolean::OPTIMIZE_DATABASE] = getGlobalBoolean(L, "startupDatabaseOptimization", true); - if (strings[ConfigKeysString::IP] == "") { - strings[ConfigKeysString::IP] = getGlobalString(L, "ip", "127.0.0.1"); + if (strings[String::IP] == "") { + strings[String::IP] = getGlobalString(L, "ip", "127.0.0.1"); } - strings[ConfigKeysString::MAP_NAME] = getGlobalString(L, "mapName", "forgotten"); - strings[ConfigKeysString::MAP_AUTHOR] = getGlobalString(L, "mapAuthor", "Unknown"); - strings[ConfigKeysString::HOUSE_RENT_PERIOD] = getGlobalString(L, "houseRentPeriod", "never"); + strings[String::MAP_NAME] = getGlobalString(L, "mapName", "forgotten"); + strings[String::MAP_AUTHOR] = getGlobalString(L, "mapAuthor", "Unknown"); + strings[String::HOUSE_RENT_PERIOD] = getGlobalString(L, "houseRentPeriod", "never"); - strings[ConfigKeysString::MYSQL_HOST] = getGlobalString(L, "mysqlHost", getEnv("MYSQL_HOST", "127.0.0.1")); - strings[ConfigKeysString::MYSQL_USER] = - getGlobalString(L, "mysqlUser", getEnv("MYSQL_USER", "forgottenserver")); - strings[ConfigKeysString::MYSQL_PASS] = getGlobalString(L, "mysqlPass", getEnv("MYSQL_PASSWORD", "")); - strings[ConfigKeysString::MYSQL_DB] = - getGlobalString(L, "mysqlDatabase", getEnv("MYSQL_DATABASE", "forgottenserver")); - strings[ConfigKeysString::MYSQL_SOCK] = getGlobalString(L, "mysqlSock", getEnv("MYSQL_SOCK", "")); + strings[String::MYSQL_HOST] = getGlobalString(L, "mysqlHost", getEnv("MYSQL_HOST", "127.0.0.1")); + strings[String::MYSQL_USER] = getGlobalString(L, "mysqlUser", getEnv("MYSQL_USER", "forgottenserver")); + strings[String::MYSQL_PASS] = getGlobalString(L, "mysqlPass", getEnv("MYSQL_PASSWORD", "")); + strings[String::MYSQL_DB] = getGlobalString(L, "mysqlDatabase", getEnv("MYSQL_DATABASE", "forgottenserver")); + strings[String::MYSQL_SOCK] = getGlobalString(L, "mysqlSock", getEnv("MYSQL_SOCK", "")); - integers[ConfigKeysInteger::SQL_PORT] = getGlobalInteger(L, "mysqlPort", getEnv("MYSQL_PORT", 3306)); + integers[Integer::SQL_PORT] = getGlobalInteger(L, "mysqlPort", getEnv("MYSQL_PORT", 3306)); - if (integers[ConfigKeysInteger::GAME_PORT] == 0) { - integers[ConfigKeysInteger::GAME_PORT] = getGlobalInteger(L, "gameProtocolPort", 7172); + if (integers[Integer::GAME_PORT] == 0) { + integers[Integer::GAME_PORT] = getGlobalInteger(L, "gameProtocolPort", 7172); } - if (integers[ConfigKeysInteger::LOGIN_PORT] == 0) { - integers[ConfigKeysInteger::LOGIN_PORT] = getGlobalInteger(L, "loginProtocolPort", 7171); + if (integers[Integer::LOGIN_PORT] == 0) { + integers[Integer::LOGIN_PORT] = getGlobalInteger(L, "loginProtocolPort", 7171); } - integers[ConfigKeysInteger::STATUS_PORT] = getGlobalInteger(L, "statusProtocolPort", 7171); + integers[Integer::STATUS_PORT] = getGlobalInteger(L, "statusProtocolPort", 7171); - integers[ConfigKeysInteger::MARKET_OFFER_DURATION] = - getGlobalInteger(L, "marketOfferDuration", 30 * 24 * 60 * 60); + integers[Integer::MARKET_OFFER_DURATION] = getGlobalInteger(L, "marketOfferDuration", 30 * 24 * 60 * 60); } - booleans[ConfigKeysBoolean::ALLOW_CHANGEOUTFIT] = getGlobalBoolean(L, "allowChangeOutfit", true); - booleans[ConfigKeysBoolean::ONE_PLAYER_ON_ACCOUNT] = getGlobalBoolean(L, "onePlayerOnlinePerAccount", true); - booleans[ConfigKeysBoolean::AIMBOT_HOTKEY_ENABLED] = getGlobalBoolean(L, "hotkeyAimbotEnabled", true); - booleans[ConfigKeysBoolean::REMOVE_RUNE_CHARGES] = getGlobalBoolean(L, "removeChargesFromRunes", true); - booleans[ConfigKeysBoolean::REMOVE_WEAPON_AMMO] = getGlobalBoolean(L, "removeWeaponAmmunition", true); - booleans[ConfigKeysBoolean::REMOVE_WEAPON_CHARGES] = getGlobalBoolean(L, "removeWeaponCharges", true); - booleans[ConfigKeysBoolean::REMOVE_POTION_CHARGES] = getGlobalBoolean(L, "removeChargesFromPotions", true); - booleans[ConfigKeysBoolean::EXPERIENCE_FROM_PLAYERS] = getGlobalBoolean(L, "experienceByKillingPlayers", false); - booleans[ConfigKeysBoolean::FREE_PREMIUM] = getGlobalBoolean(L, "freePremium", false); - booleans[ConfigKeysBoolean::REPLACE_KICK_ON_LOGIN] = getGlobalBoolean(L, "replaceKickOnLogin", true); - booleans[ConfigKeysBoolean::ALLOW_CLONES] = getGlobalBoolean(L, "allowClones", false); - booleans[ConfigKeysBoolean::ALLOW_WALKTHROUGH] = getGlobalBoolean(L, "allowWalkthrough", true); - booleans[ConfigKeysBoolean::MARKET_PREMIUM] = getGlobalBoolean(L, "premiumToCreateMarketOffer", true); - booleans[ConfigKeysBoolean::EMOTE_SPELLS] = getGlobalBoolean(L, "emoteSpells", false); - booleans[ConfigKeysBoolean::STAMINA_SYSTEM] = getGlobalBoolean(L, "staminaSystem", true); - booleans[ConfigKeysBoolean::WARN_UNSAFE_SCRIPTS] = getGlobalBoolean(L, "warnUnsafeScripts", true); - booleans[ConfigKeysBoolean::CONVERT_UNSAFE_SCRIPTS] = getGlobalBoolean(L, "convertUnsafeScripts", true); - booleans[ConfigKeysBoolean::CLASSIC_EQUIPMENT_SLOTS] = getGlobalBoolean(L, "classicEquipmentSlots", false); - booleans[ConfigKeysBoolean::CLASSIC_ATTACK_SPEED] = getGlobalBoolean(L, "classicAttackSpeed", false); - booleans[ConfigKeysBoolean::SCRIPTS_CONSOLE_LOGS] = getGlobalBoolean(L, "showScriptsLogInConsole", true); - booleans[ConfigKeysBoolean::SERVER_SAVE_NOTIFY_MESSAGE] = getGlobalBoolean(L, "serverSaveNotifyMessage", true); - booleans[ConfigKeysBoolean::SERVER_SAVE_CLEAN_MAP] = getGlobalBoolean(L, "serverSaveCleanMap", false); - booleans[ConfigKeysBoolean::SERVER_SAVE_CLOSE] = getGlobalBoolean(L, "serverSaveClose", false); - booleans[ConfigKeysBoolean::SERVER_SAVE_SHUTDOWN] = getGlobalBoolean(L, "serverSaveShutdown", true); - booleans[ConfigKeysBoolean::ONLINE_OFFLINE_CHARLIST] = getGlobalBoolean(L, "showOnlineStatusInCharlist", false); - booleans[ConfigKeysBoolean::YELL_ALLOW_PREMIUM] = getGlobalBoolean(L, "yellAlwaysAllowPremium", false); - booleans[ConfigKeysBoolean::PREMIUM_TO_SEND_PRIVATE] = getGlobalBoolean(L, "premiumToSendPrivate", false); - booleans[ConfigKeysBoolean::FORCE_MONSTERTYPE_LOAD] = getGlobalBoolean(L, "forceMonsterTypesOnLoad", true); - booleans[ConfigKeysBoolean::DEFAULT_WORLD_LIGHT] = getGlobalBoolean(L, "defaultWorldLight", true); - booleans[ConfigKeysBoolean::HOUSE_OWNED_BY_ACCOUNT] = getGlobalBoolean(L, "houseOwnedByAccount", false); - booleans[ConfigKeysBoolean::CLEAN_PROTECTION_ZONES] = getGlobalBoolean(L, "cleanProtectionZones", false); - booleans[ConfigKeysBoolean::HOUSE_DOOR_SHOW_PRICE] = getGlobalBoolean(L, "houseDoorShowPrice", true); - booleans[ConfigKeysBoolean::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS] = - getGlobalBoolean(L, "onlyInvitedCanMoveHouseItems", true); - booleans[ConfigKeysBoolean::REMOVE_ON_DESPAWN] = getGlobalBoolean(L, "removeOnDespawn", true); - booleans[ConfigKeysBoolean::MONSTER_OVERSPAWN] = getGlobalBoolean(L, "monsterOverspawn", false); - booleans[ConfigKeysBoolean::ACCOUNT_MANAGER] = getGlobalBoolean(L, "accountManager", true); - - strings[ConfigKeysString::DEFAULT_PRIORITY] = getGlobalString(L, "defaultPriority", "high"); - strings[ConfigKeysString::SERVER_NAME] = getGlobalString(L, "serverName", ""); - strings[ConfigKeysString::OWNER_NAME] = getGlobalString(L, "ownerName", ""); - strings[ConfigKeysString::OWNER_EMAIL] = getGlobalString(L, "ownerEmail", ""); - strings[ConfigKeysString::URL] = getGlobalString(L, "url", ""); - strings[ConfigKeysString::LOCATION] = getGlobalString(L, "location", ""); - strings[ConfigKeysString::MOTD] = getGlobalString(L, "motd", ""); - strings[ConfigKeysString::WORLD_TYPE] = getGlobalString(L, "worldType", "pvp"); + booleans[Boolean::ALLOW_CHANGEOUTFIT] = getGlobalBoolean(L, "allowChangeOutfit", true); + booleans[Boolean::ONE_PLAYER_ON_ACCOUNT] = getGlobalBoolean(L, "onePlayerOnlinePerAccount", true); + booleans[Boolean::AIMBOT_HOTKEY_ENABLED] = getGlobalBoolean(L, "hotkeyAimbotEnabled", true); + booleans[Boolean::REMOVE_RUNE_CHARGES] = getGlobalBoolean(L, "removeChargesFromRunes", true); + booleans[Boolean::REMOVE_WEAPON_AMMO] = getGlobalBoolean(L, "removeWeaponAmmunition", true); + booleans[Boolean::REMOVE_WEAPON_CHARGES] = getGlobalBoolean(L, "removeWeaponCharges", true); + booleans[Boolean::REMOVE_POTION_CHARGES] = getGlobalBoolean(L, "removeChargesFromPotions", true); + booleans[Boolean::EXPERIENCE_FROM_PLAYERS] = getGlobalBoolean(L, "experienceByKillingPlayers", false); + booleans[Boolean::FREE_PREMIUM] = getGlobalBoolean(L, "freePremium", false); + booleans[Boolean::REPLACE_KICK_ON_LOGIN] = getGlobalBoolean(L, "replaceKickOnLogin", true); + booleans[Boolean::ALLOW_CLONES] = getGlobalBoolean(L, "allowClones", false); + booleans[Boolean::ALLOW_WALKTHROUGH] = getGlobalBoolean(L, "allowWalkthrough", true); + booleans[Boolean::MARKET_PREMIUM] = getGlobalBoolean(L, "premiumToCreateMarketOffer", true); + booleans[Boolean::EMOTE_SPELLS] = getGlobalBoolean(L, "emoteSpells", false); + booleans[Boolean::STAMINA_SYSTEM] = getGlobalBoolean(L, "staminaSystem", true); + booleans[Boolean::WARN_UNSAFE_SCRIPTS] = getGlobalBoolean(L, "warnUnsafeScripts", true); + booleans[Boolean::CONVERT_UNSAFE_SCRIPTS] = getGlobalBoolean(L, "convertUnsafeScripts", true); + booleans[Boolean::CLASSIC_EQUIPMENT_SLOTS] = getGlobalBoolean(L, "classicEquipmentSlots", false); + booleans[Boolean::CLASSIC_ATTACK_SPEED] = getGlobalBoolean(L, "classicAttackSpeed", false); + booleans[Boolean::SCRIPTS_CONSOLE_LOGS] = getGlobalBoolean(L, "showScriptsLogInConsole", true); + booleans[Boolean::SERVER_SAVE_NOTIFY_MESSAGE] = getGlobalBoolean(L, "serverSaveNotifyMessage", true); + booleans[Boolean::SERVER_SAVE_CLEAN_MAP] = getGlobalBoolean(L, "serverSaveCleanMap", false); + booleans[Boolean::SERVER_SAVE_CLOSE] = getGlobalBoolean(L, "serverSaveClose", false); + booleans[Boolean::SERVER_SAVE_SHUTDOWN] = getGlobalBoolean(L, "serverSaveShutdown", true); + booleans[Boolean::ONLINE_OFFLINE_CHARLIST] = getGlobalBoolean(L, "showOnlineStatusInCharlist", false); + booleans[Boolean::YELL_ALLOW_PREMIUM] = getGlobalBoolean(L, "yellAlwaysAllowPremium", false); + booleans[Boolean::PREMIUM_TO_SEND_PRIVATE] = getGlobalBoolean(L, "premiumToSendPrivate", false); + booleans[Boolean::FORCE_MONSTERTYPE_LOAD] = getGlobalBoolean(L, "forceMonsterTypesOnLoad", true); + booleans[Boolean::DEFAULT_WORLD_LIGHT] = getGlobalBoolean(L, "defaultWorldLight", true); + booleans[Boolean::HOUSE_OWNED_BY_ACCOUNT] = getGlobalBoolean(L, "houseOwnedByAccount", false); + booleans[Boolean::CLEAN_PROTECTION_ZONES] = getGlobalBoolean(L, "cleanProtectionZones", false); + booleans[Boolean::HOUSE_DOOR_SHOW_PRICE] = getGlobalBoolean(L, "houseDoorShowPrice", true); + booleans[Boolean::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS] = getGlobalBoolean(L, "onlyInvitedCanMoveHouseItems", true); + booleans[Boolean::REMOVE_ON_DESPAWN] = getGlobalBoolean(L, "removeOnDespawn", true); + booleans[Boolean::MONSTER_OVERSPAWN] = getGlobalBoolean(L, "monsterOverspawn", false); + booleans[Boolean::ACCOUNT_MANAGER] = getGlobalBoolean(L, "accountManager", true); + booleans[Boolean::MANASHIELD_BREAKABLE] = getGlobalBoolean(L, "useBreakableManaShield", false); + + strings[String::DEFAULT_PRIORITY] = getGlobalString(L, "defaultPriority", "high"); + strings[String::SERVER_NAME] = getGlobalString(L, "serverName", ""); + strings[String::OWNER_NAME] = getGlobalString(L, "ownerName", ""); + strings[String::OWNER_EMAIL] = getGlobalString(L, "ownerEmail", ""); + strings[String::URL] = getGlobalString(L, "url", ""); + strings[String::LOCATION] = getGlobalString(L, "location", ""); + strings[String::MOTD] = getGlobalString(L, "motd", ""); + strings[String::WORLD_TYPE] = getGlobalString(L, "worldType", "pvp"); Monster::despawnRange = getGlobalInteger(L, "deSpawnRange", 2); Monster::despawnRadius = getGlobalInteger(L, "deSpawnRadius", 50); - integers[ConfigKeysInteger::MAX_PLAYERS] = getGlobalInteger(L, "maxPlayers"); - integers[ConfigKeysInteger::PZ_LOCKED] = getGlobalInteger(L, "pzLocked", 60000); - integers[ConfigKeysInteger::DEFAULT_DESPAWNRANGE] = Monster::despawnRange; - integers[ConfigKeysInteger::DEFAULT_DESPAWNRADIUS] = Monster::despawnRadius; - integers[ConfigKeysInteger::DEFAULT_WALKTOSPAWNRADIUS] = getGlobalInteger(L, "walkToSpawnRadius", 15); - integers[ConfigKeysInteger::RATE_EXPERIENCE] = getGlobalInteger(L, "rateExp", 5); - integers[ConfigKeysInteger::RATE_SKILL] = getGlobalInteger(L, "rateSkill", 3); - integers[ConfigKeysInteger::RATE_LOOT] = getGlobalInteger(L, "rateLoot", 2); - integers[ConfigKeysInteger::RATE_MAGIC] = getGlobalInteger(L, "rateMagic", 3); - integers[ConfigKeysInteger::RATE_SPAWN] = getGlobalInteger(L, "rateSpawn", 1); - integers[ConfigKeysInteger::HOUSE_PRICE] = getGlobalInteger(L, "housePriceEachSQM", 1000); - integers[ConfigKeysInteger::KILLS_TO_RED] = getGlobalInteger(L, "killsToRedSkull", 3); - integers[ConfigKeysInteger::KILLS_TO_BLACK] = getGlobalInteger(L, "killsToBlackSkull", 6); - integers[ConfigKeysInteger::ACTIONS_DELAY_INTERVAL] = getGlobalInteger(L, "timeBetweenActions", 200); - integers[ConfigKeysInteger::EX_ACTIONS_DELAY_INTERVAL] = getGlobalInteger(L, "timeBetweenExActions", 1000); - integers[ConfigKeysInteger::MAX_MESSAGEBUFFER] = getGlobalInteger(L, "maxMessageBuffer", 4); - integers[ConfigKeysInteger::KICK_AFTER_MINUTES] = getGlobalInteger(L, "kickIdlePlayerAfterMinutes", 15); - integers[ConfigKeysInteger::PROTECTION_LEVEL] = getGlobalInteger(L, "protectionLevel", 1); - integers[ConfigKeysInteger::DEATH_LOSE_PERCENT] = getGlobalInteger(L, "deathLosePercent", -1); - integers[ConfigKeysInteger::STATUSQUERY_TIMEOUT] = getGlobalInteger(L, "statusTimeout", 5000); - integers[ConfigKeysInteger::FRAG_TIME] = getGlobalInteger(L, "timeToDecreaseFrags", 24 * 60 * 60); - integers[ConfigKeysInteger::WHITE_SKULL_TIME] = getGlobalInteger(L, "whiteSkullTime", 15 * 60); - integers[ConfigKeysInteger::STAIRHOP_DELAY] = getGlobalInteger(L, "stairJumpExhaustion", 2000); - integers[ConfigKeysInteger::EXP_FROM_PLAYERS_LEVEL_RANGE] = getGlobalInteger(L, "expFromPlayersLevelRange", 75); - integers[ConfigKeysInteger::MAX_PACKETS_PER_SECOND] = getGlobalInteger(L, "maxPacketsPerSecond", 25); - integers[ConfigKeysInteger::SERVER_SAVE_NOTIFY_DURATION] = getGlobalInteger(L, "serverSaveNotifyDuration", 5); - integers[ConfigKeysInteger::YELL_MINIMUM_LEVEL] = getGlobalInteger(L, "yellMinimumLevel", 2); - integers[ConfigKeysInteger::MINIMUM_LEVEL_TO_SEND_PRIVATE] = getGlobalInteger(L, "minimumLevelToSendPrivate", 1); - integers[ConfigKeysInteger::VIP_FREE_LIMIT] = getGlobalInteger(L, "vipFreeLimit", 20); - integers[ConfigKeysInteger::VIP_PREMIUM_LIMIT] = getGlobalInteger(L, "vipPremiumLimit", 100); - integers[ConfigKeysInteger::DEPOT_FREE_LIMIT] = getGlobalInteger(L, "depotFreeLimit", 2000); - integers[ConfigKeysInteger::DEPOT_PREMIUM_LIMIT] = getGlobalInteger(L, "depotPremiumLimit", 15000); - integers[ConfigKeysInteger::STAMINA_REGEN_MINUTE] = getGlobalInteger(L, "timeToRegenMinuteStamina", 3 * 60); - integers[ConfigKeysInteger::STAMINA_REGEN_PREMIUM] = getGlobalInteger(L, "timeToRegenMinutePremiumStamina", 6 * 60); - integers[ConfigKeysInteger::HEALTH_GAIN_COLOUR] = getGlobalInteger(L, "healthGainColour", TEXTCOLOR_MAYABLUE); - integers[ConfigKeysInteger::MANA_GAIN_COLOUR] = getGlobalInteger(L, "manaGainColour", TEXTCOLOR_BLUE); - integers[ConfigKeysInteger::MANA_LOSS_COLOUR] = getGlobalInteger(L, "manaLossColour", TEXTCOLOR_BLUE); - integers[ConfigKeysInteger::MAX_PROTOCOL_OUTFITS] = getGlobalInteger(L, "maxProtocolOutfits", 50); - integers[ConfigKeysInteger::MOVE_CREATURE_INTERVAL] = - getGlobalInteger(L, "MOVE_CREATURE_INTERVAL", MOVE_CREATURE_INTERVAL); - integers[ConfigKeysInteger::RANGE_MOVE_CREATURE_INTERVAL] = + integers[Integer::MAX_PLAYERS] = getGlobalInteger(L, "maxPlayers"); + integers[Integer::PZ_LOCKED] = getGlobalInteger(L, "pzLocked", 60000); + integers[Integer::DEFAULT_DESPAWNRANGE] = Monster::despawnRange; + integers[Integer::DEFAULT_DESPAWNRADIUS] = Monster::despawnRadius; + integers[Integer::DEFAULT_WALKTOSPAWNRADIUS] = getGlobalInteger(L, "walkToSpawnRadius", 15); + integers[Integer::RATE_EXPERIENCE] = getGlobalInteger(L, "rateExp", 5); + integers[Integer::RATE_SKILL] = getGlobalInteger(L, "rateSkill", 3); + integers[Integer::RATE_LOOT] = getGlobalInteger(L, "rateLoot", 2); + integers[Integer::RATE_MAGIC] = getGlobalInteger(L, "rateMagic", 3); + integers[Integer::RATE_SPAWN] = getGlobalInteger(L, "rateSpawn", 1); + integers[Integer::HOUSE_PRICE] = getGlobalInteger(L, "housePriceEachSQM", 1000); + integers[Integer::KILLS_TO_RED] = getGlobalInteger(L, "killsToRedSkull", 3); + integers[Integer::KILLS_TO_BLACK] = getGlobalInteger(L, "killsToBlackSkull", 6); + integers[Integer::ACTIONS_DELAY_INTERVAL] = getGlobalInteger(L, "timeBetweenActions", 200); + integers[Integer::EX_ACTIONS_DELAY_INTERVAL] = getGlobalInteger(L, "timeBetweenExActions", 1000); + integers[Integer::MAX_MESSAGEBUFFER] = getGlobalInteger(L, "maxMessageBuffer", 4); + integers[Integer::KICK_AFTER_MINUTES] = getGlobalInteger(L, "kickIdlePlayerAfterMinutes", 15); + integers[Integer::PROTECTION_LEVEL] = getGlobalInteger(L, "protectionLevel", 1); + integers[Integer::DEATH_LOSE_PERCENT] = getGlobalInteger(L, "deathLosePercent", -1); + integers[Integer::STATUSQUERY_TIMEOUT] = getGlobalInteger(L, "statusTimeout", 5000); + integers[Integer::FRAG_TIME] = getGlobalInteger(L, "timeToDecreaseFrags", 24 * 60 * 60); + integers[Integer::WHITE_SKULL_TIME] = getGlobalInteger(L, "whiteSkullTime", 15 * 60); + integers[Integer::STAIRHOP_DELAY] = getGlobalInteger(L, "stairJumpExhaustion", 2000); + integers[Integer::EXP_FROM_PLAYERS_LEVEL_RANGE] = getGlobalInteger(L, "expFromPlayersLevelRange", 75); + integers[Integer::MAX_PACKETS_PER_SECOND] = getGlobalInteger(L, "maxPacketsPerSecond", 25); + integers[Integer::SERVER_SAVE_NOTIFY_DURATION] = getGlobalInteger(L, "serverSaveNotifyDuration", 5); + integers[Integer::YELL_MINIMUM_LEVEL] = getGlobalInteger(L, "yellMinimumLevel", 2); + integers[Integer::MINIMUM_LEVEL_TO_SEND_PRIVATE] = getGlobalInteger(L, "minimumLevelToSendPrivate", 1); + integers[Integer::VIP_FREE_LIMIT] = getGlobalInteger(L, "vipFreeLimit", 20); + integers[Integer::VIP_PREMIUM_LIMIT] = getGlobalInteger(L, "vipPremiumLimit", 100); + integers[Integer::DEPOT_FREE_LIMIT] = getGlobalInteger(L, "depotFreeLimit", 2000); + integers[Integer::DEPOT_PREMIUM_LIMIT] = getGlobalInteger(L, "depotPremiumLimit", 15000); + integers[Integer::STAMINA_REGEN_MINUTE] = getGlobalInteger(L, "timeToRegenMinuteStamina", 3 * 60); + integers[Integer::STAMINA_REGEN_PREMIUM] = getGlobalInteger(L, "timeToRegenMinutePremiumStamina", 6 * 60); + integers[Integer::HEALTH_GAIN_COLOUR] = getGlobalInteger(L, "healthGainColour", TEXTCOLOR_MAYABLUE); + integers[Integer::MANA_GAIN_COLOUR] = getGlobalInteger(L, "manaGainColour", TEXTCOLOR_BLUE); + integers[Integer::MANA_LOSS_COLOUR] = getGlobalInteger(L, "manaLossColour", TEXTCOLOR_BLUE); + integers[Integer::MAX_PROTOCOL_OUTFITS] = getGlobalInteger(L, "maxProtocolOutfits", 50); + integers[Integer::MOVE_CREATURE_INTERVAL] = getGlobalInteger(L, "MOVE_CREATURE_INTERVAL", MOVE_CREATURE_INTERVAL); + integers[Integer::RANGE_MOVE_CREATURE_INTERVAL] = getGlobalInteger(L, "RANGE_MOVE_CREATURE_INTERVAL", RANGE_MOVE_CREATURE_INTERVAL); - integers[ConfigKeysInteger::RANGE_USE_WITH_CREATURE_INTERVAL] = + integers[Integer::RANGE_USE_WITH_CREATURE_INTERVAL] = getGlobalInteger(L, "RANGE_USE_WITH_CREATURE_INTERVAL", RANGE_USE_WITH_CREATURE_INTERVAL); - integers[ConfigKeysInteger::RANGE_MOVE_ITEM_INTERVAL] = + integers[Integer::RANGE_MOVE_ITEM_INTERVAL] = getGlobalInteger(L, "RANGE_MOVE_ITEM_INTERVAL", RANGE_MOVE_ITEM_INTERVAL); - integers[ConfigKeysInteger::RANGE_USE_ITEM_INTERVAL] = + integers[Integer::RANGE_USE_ITEM_INTERVAL] = getGlobalInteger(L, "RANGE_USE_ITEM_INTERVAL", RANGE_USE_ITEM_INTERVAL); - integers[ConfigKeysInteger::RANGE_USE_ITEM_EX_INTERVAL] = + integers[Integer::RANGE_USE_ITEM_EX_INTERVAL] = getGlobalInteger(L, "RANGE_USE_ITEM_EX_INTERVAL", RANGE_USE_ITEM_EX_INTERVAL); - integers[ConfigKeysInteger::RANGE_ROTATE_ITEM_INTERVAL] = + integers[Integer::RANGE_ROTATE_ITEM_INTERVAL] = getGlobalInteger(L, "RANGE_ROTATE_ITEM_INTERVAL", RANGE_ROTATE_ITEM_INTERVAL); expStages = loadXMLStages(); @@ -343,37 +346,34 @@ bool ConfigManager::load() return true; } -bool ConfigManager::getBoolean(ConfigKeysBoolean what) const +bool ConfigManager::getBoolean(Boolean what) { - if (what >= ConfigKeysBoolean::LAST) { - std::cout << "[Warning - ConfigManager::getBoolean] Accessing invalid index: " << static_cast(what) - << std::endl; + if (what >= Boolean::LAST_BOOLEAN) { + std::cout << "[Warning - ConfigManager::getBoolean] Accessing invalid index: " << what << std::endl; return false; } return booleans[what]; } -std::string_view ConfigManager::getString(ConfigKeysString what) const +std::string_view ConfigManager::getString(String what) { - if (what >= ConfigKeysString::LAST) { - std::cout << "[Warning - ConfigManager::getString] Accessing invalid index: " << static_cast(what) - << std::endl; + if (what >= String::LAST_STRING) { + std::cout << "[Warning - ConfigManager::getString] Accessing invalid index: " << what << std::endl; return ""; } return strings[what]; } -int64_t ConfigManager::getInteger(ConfigKeysInteger what) const +int64_t ConfigManager::getInteger(Integer what) { - if (what >= ConfigKeysInteger::LAST) { - std::cout << "[Warning - ConfigManager::getInteger] Accessing invalid index: " << static_cast(what) - << std::endl; + if (what >= Integer::LAST_INTEGER) { + std::cout << "[Warning - ConfigManager::getInteger] Accessing invalid index: " << what << std::endl; return 0; } return integers[what]; } -float ConfigManager::getExperienceStage(const uint32_t level) const +float ConfigManager::getExperienceStage(uint32_t level) { auto it = std::find_if(expStages.begin(), expStages.end(), [level](auto&& stage) { auto&& [minLevel, maxLevel, _] = stage; @@ -381,17 +381,16 @@ float ConfigManager::getExperienceStage(const uint32_t level) const }); if (it == expStages.end()) { - return getInteger(ConfigKeysInteger::RATE_EXPERIENCE); + return getInteger(Integer::RATE_EXPERIENCE); } return std::get<2>(*it); } -bool ConfigManager::setBoolean(ConfigKeysBoolean what, const bool value) +bool ConfigManager::setBoolean(Boolean what, bool value) { - if (what >= ConfigKeysBoolean::LAST) { - std::cout << "[Warning - ConfigManager::setBoolean] Accessing invalid index: " << static_cast(what) - << std::endl; + if (what >= Boolean::LAST_BOOLEAN) { + std::cout << "[Warning - ConfigManager::setBoolean] Accessing invalid index: " << what << std::endl; return false; } @@ -399,11 +398,10 @@ bool ConfigManager::setBoolean(ConfigKeysBoolean what, const bool value) return true; } -bool ConfigManager::setString(ConfigKeysString what, std::string_view value) +bool ConfigManager::setString(String what, std::string_view value) { - if (what >= ConfigKeysString::LAST) { - std::cout << "[Warning - ConfigManager::setString] Accessing invalid index: " << static_cast(what) - << std::endl; + if (what >= String::LAST_STRING) { + std::cout << "[Warning - ConfigManager::setString] Accessing invalid index: " << what << std::endl; return false; } @@ -411,11 +409,10 @@ bool ConfigManager::setString(ConfigKeysString what, std::string_view value) return true; } -bool ConfigManager::setInteger(ConfigKeysInteger what, const int64_t value) +bool ConfigManager::setInteger(Integer what, int64_t value) { - if (what >= ConfigKeysInteger::LAST) { - std::cout << "[Warning - ConfigManager::setInteger] Accessing invalid index: " << static_cast(what) - << std::endl; + if (what >= Integer::LAST_INTEGER) { + std::cout << "[Warning - ConfigManager::setInteger] Accessing invalid index: " << what << std::endl; return false; } @@ -423,4 +420,4 @@ bool ConfigManager::setInteger(ConfigKeysInteger what, const int64_t value) return true; } -OTCFeatures ConfigManager::getOTCFeatures() const { return otcFeatures; } +const OTCFeatures& ConfigManager::getOTCFeatures() { return otcFeatures; } diff --git a/src/configmanager.h b/src/configmanager.h index dc3f0a0..1cb83b3 100644 --- a/src/configmanager.h +++ b/src/configmanager.h @@ -4,10 +4,9 @@ #ifndef FS_CONFIGMANAGER_H #define FS_CONFIGMANAGER_H -using ExperienceStages = std::vector>; -using OTCFeatures = std::vector; +namespace ConfigManager { -enum class ConfigKeysBoolean +enum Boolean { ALLOW_CHANGEOUTFIT, ONE_PLAYER_ON_ACCOUNT, @@ -47,11 +46,12 @@ enum class ConfigKeysBoolean REMOVE_ON_DESPAWN, MONSTER_OVERSPAWN, ACCOUNT_MANAGER, + MANASHIELD_BREAKABLE, - LAST /* this must be the last one */ + LAST_BOOLEAN /* this must be the last one */ }; -enum class ConfigKeysString +enum String { MAP_NAME, HOUSE_RENT_PERIOD, @@ -72,10 +72,10 @@ enum class ConfigKeysString MAP_AUTHOR, CONFIG_FILE, - LAST /* this must be the last one */ + LAST_STRING /* this must be the last one */ }; -enum class ConfigKeysInteger +enum Integer { SQL_PORT, MAX_PLAYERS, @@ -128,52 +128,20 @@ enum class ConfigKeysInteger RANGE_USE_ITEM_EX_INTERVAL, RANGE_ROTATE_ITEM_INTERVAL, - LAST /* this must be the last one */ + LAST_INTEGER /* this must be the last one */ }; -template -struct ConfigValues -{ - using Container = std::array(E::LAST)>; - -public: - T& operator[](E key) { return values[static_cast(key)]; } - const T& operator[](E key) const { return values[static_cast(key)]; } - -private: - Container values; -}; - -class ConfigManager -{ -public: - ConfigManager(); +bool load(); - bool load(); +bool getBoolean(Boolean what); +std::string_view getString(String what); +int64_t getInteger(Integer what); +float getExperienceStage(uint32_t level); +const std::vector& getOTCFeatures(); - bool getBoolean(ConfigKeysBoolean what) const; - std::string_view getString(ConfigKeysString what) const; - int64_t getInteger(ConfigKeysInteger what) const; - float getExperienceStage(const uint32_t level) const; - OTCFeatures getOTCFeatures() const; - - bool setBoolean(ConfigKeysBoolean what, const bool value); - bool setString(ConfigKeysString what, std::string_view value); - bool setInteger(ConfigKeysInteger what, const int64_t value); - - auto operator[](ConfigKeysBoolean what) const { return getBoolean(what); } - auto operator[](ConfigKeysString what) const { return getString(what); } - auto operator[](ConfigKeysInteger what) const { return getInteger(what); } - -private: - ConfigValues booleans; - ConfigValues strings; - ConfigValues integers; - - ExperienceStages expStages = {}; - OTCFeatures otcFeatures = {}; - - bool loaded = false; -}; +bool setBoolean(Boolean what, bool value); +bool setString(String what, std::string_view value); +bool setInteger(Integer what, int64_t value); +} // namespace ConfigManager #endif // FS_CONFIGMANAGER_H diff --git a/src/connection.cpp b/src/connection.cpp index 35e3ae1..dddbf7f 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -11,8 +11,6 @@ #include "scheduler.h" #include "server.h" -extern ConfigManager g_config; - Connection_ptr ConnectionManager::createConnection(boost::asio::io_service& io_service, ConstServicePort_ptr servicePort) { @@ -129,7 +127,7 @@ void Connection::parseHeader(const boost::system::error_code& error) } uint32_t timePassed = std::max(1, (time(nullptr) - timeConnected) + 1); - if ((++packetsSent / timePassed) > g_config[ConfigKeysInteger::MAX_PACKETS_PER_SECOND]) { + if ((++packetsSent / timePassed) > getInteger(ConfigManager::MAX_PACKETS_PER_SECOND)) { std::cout << convertIPToString(getIP()) << " disconnected for exceeding packet per second limit." << std::endl; close(); return; diff --git a/src/container.cpp b/src/container.cpp index 931ddcc..5c17f25 100644 --- a/src/container.cpp +++ b/src/container.cpp @@ -32,7 +32,7 @@ Item* Container::clone() const return clone; } -Container* Container::getParentContainer() +Container* Container::getParentContainer() const { Thing* thing = getParent(); if (!thing) { @@ -135,7 +135,7 @@ bool Container::isHoldingItem(const Item* item) const return false; } -void Container::onAddContainerItem(Item* item) +void Container::onAddContainerItem(Item* item) const { SpectatorVec spectators; g_game.map.getSpectators(spectators, getPosition(), false, true, 1, 1, 1, 1); @@ -153,7 +153,7 @@ void Container::onAddContainerItem(Item* item) } } -void Container::onUpdateContainerItem(uint32_t index, Item* oldItem, Item* newItem) +void Container::onUpdateContainerItem(uint32_t index, Item* oldItem, Item* newItem) const { SpectatorVec spectators; g_game.map.getSpectators(spectators, getPosition(), false, true, 1, 1, 1, 1); @@ -171,7 +171,7 @@ void Container::onUpdateContainerItem(uint32_t index, Item* oldItem, Item* newIt } } -void Container::onRemoveContainerItem(uint32_t index, Item* item) +void Container::onRemoveContainerItem(uint32_t index, Item* item) const { SpectatorVec spectators; g_game.map.getSpectators(spectators, getPosition(), false, true, 1, 1, 1, 1); @@ -236,7 +236,15 @@ ReturnValue Container::queryAdd(int32_t index, const Thing& thing, uint32_t coun } } - const Cylinder* topParent = getTopParent(); + const Cylinder* const topParent = getTopParent(); + if (actor && getBoolean(ConfigManager::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { + if (const HouseTile* houseTile = dynamic_cast(topParent->getTile())) { + if (!topParent->getCreature() && !houseTile->getHouse()->isInvited(actor->getPlayer())) { + return RETURNVALUE_PLAYERISNOTINVITED; + } + } + } + if (topParent != this) { return topParent->queryAdd(INDEX_WHEREEVER, *item, count, flags | FLAG_CHILDISOWNER, actor); } @@ -316,9 +324,13 @@ ReturnValue Container::queryRemove(const Thing& thing, uint32_t count, uint32_t return RETURNVALUE_NOTMOVEABLE; } - const HouseTile* houseTile = dynamic_cast(getTopParent()); - if (houseTile) { - return houseTile->queryRemove(thing, count, flags, actor); + if (actor && getBoolean(ConfigManager::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { + const Cylinder* const topParent = getTopParent(); + if (const HouseTile* const houseTile = dynamic_cast(topParent->getTile())) { + if (!topParent->getCreature() && !houseTile->getHouse()->isInvited(actor->getPlayer())) { + return RETURNVALUE_PLAYERISNOTINVITED; + } + } } return RETURNVALUE_NOERROR; diff --git a/src/container.h b/src/container.h index 74fce90..124f158 100644 --- a/src/container.h +++ b/src/container.h @@ -116,11 +116,11 @@ class Container : public Item, public Cylinder uint32_t totalWeight = 0; uint32_t serializationCount = 0; - void onAddContainerItem(Item* item); - void onUpdateContainerItem(uint32_t index, Item* oldItem, Item* newItem); - void onRemoveContainerItem(uint32_t index, Item* item); + void onAddContainerItem(Item* item) const; + void onUpdateContainerItem(uint32_t index, Item* oldItem, Item* newItem) const; + void onRemoveContainerItem(uint32_t index, Item* item) const; - Container* getParentContainer(); + Container* getParentContainer() const; void updateItemWeight(int32_t diff); friend class ContainerIterator; diff --git a/src/creature.cpp b/src/creature.cpp index 2fb2013..76a9aff 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -11,7 +11,6 @@ #include "monster.h" #include "scheduler.h" -extern ConfigManager g_config; extern CreatureEvents* g_creatureEvents; extern Events* g_events; extern Game g_game; @@ -635,7 +634,7 @@ CreatureVector Creature::getKillers() { CreatureVector killers; const int64_t timeNow = OTSYS_TIME(); - const int64_t inFightTicks = g_config[ConfigKeysInteger::PZ_LOCKED]; + const int64_t inFightTicks = getInteger(ConfigManager::PZ_LOCKED); for (const auto& it : damageMap) { Creature* attacker = g_game.getCreatureByID(it.first); if (attacker && attacker != this && timeNow - it.second.ticks <= inFightTicks) { @@ -661,7 +660,7 @@ void Creature::onDeath() Creature* mostDamageCreature = nullptr; const int64_t timeNow = OTSYS_TIME(); - const int64_t inFightTicks = g_config[ConfigKeysInteger::PZ_LOCKED]; + const int64_t inFightTicks = getInteger(ConfigManager::PZ_LOCKED); int32_t mostDamage = 0; std::map experienceMap; for (const auto& it : damageMap) { @@ -787,7 +786,7 @@ bool Creature::hasBeenAttacked(uint32_t attackerId) if (it == damageMap.end()) { return false; } - return (OTSYS_TIME() - it->second.ticks) <= g_config[ConfigKeysInteger::PZ_LOCKED]; + return (OTSYS_TIME() - it->second.ticks) <= getInteger(ConfigManager::PZ_LOCKED); } Item* Creature::getCorpse(Creature*, Creature*) { return Item::CreateItem(getLookCorpse()); } diff --git a/src/database.cpp b/src/database.cpp index 1bf1d41..b2506ae 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -9,8 +9,6 @@ #include -extern ConfigManager g_config; - static bool connectToDatabase(MYSQL*& handle, const bool retryIfError) { bool isFirstAttemptToConnect = true; @@ -30,10 +28,10 @@ static bool connectToDatabase(MYSQL*& handle, const bool retryIfError) goto error; } // connects to database - if (!mysql_real_connect(handle, g_config[ConfigKeysString::MYSQL_HOST].data(), - g_config[ConfigKeysString::MYSQL_USER].data(), - g_config[ConfigKeysString::MYSQL_PASS].data(), g_config[ConfigKeysString::MYSQL_DB].data(), - g_config[ConfigKeysInteger::SQL_PORT], g_config[ConfigKeysString::MYSQL_SOCK].data(), 0)) { + if (!mysql_real_connect(handle, getString(ConfigManager::MYSQL_HOST).data(), + getString(ConfigManager::MYSQL_USER).data(), getString(ConfigManager::MYSQL_PASS).data(), + getString(ConfigManager::MYSQL_DB).data(), getInteger(ConfigManager::SQL_PORT), + getString(ConfigManager::MYSQL_SOCK).data(), 0)) { std::cout << std::endl << "MySQL Error Message: " << mysql_error(handle) << std::endl; goto error; } diff --git a/src/databasemanager.cpp b/src/databasemanager.cpp index b136c4c..64b2a53 100644 --- a/src/databasemanager.cpp +++ b/src/databasemanager.cpp @@ -8,15 +8,13 @@ #include "configmanager.h" #include "luascript.h" -extern ConfigManager g_config; - bool DatabaseManager::optimizeTables() { Database& db = Database::getInstance(); DBResult_ptr result = db.storeQuery(fmt::format( "SELECT `TABLE_NAME` FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = {:s} AND `DATA_FREE` > 0", - db.escapeString(g_config[ConfigKeysString::MYSQL_DB]))); + db.escapeString(getString(ConfigManager::MYSQL_DB)))); if (!result) { return false; } @@ -40,7 +38,7 @@ bool DatabaseManager::tableExists(std::string_view tableName) return db .storeQuery(fmt::format( "SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `TABLE_SCHEMA` = {:s} AND `TABLE_NAME` = {:s} LIMIT 1", - db.escapeString(g_config[ConfigKeysString::MYSQL_DB]), db.escapeString(tableName))) + db.escapeString(getString(ConfigManager::MYSQL_DB)), db.escapeString(tableName))) .get() != nullptr; } @@ -49,7 +47,7 @@ bool DatabaseManager::isDatabaseSetup() Database& db = Database::getInstance(); return db.storeQuery( fmt::format("SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `TABLE_SCHEMA` = {:s}", - db.escapeString(g_config[ConfigKeysString::MYSQL_DB]))) + db.escapeString(getString(ConfigManager::MYSQL_DB)))) .get() != nullptr; } diff --git a/src/game.cpp b/src/game.cpp index 151360f..4570c86 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -25,7 +25,6 @@ #include "talkaction.h" #include "weapons.h" -extern ConfigManager g_config; extern Actions* g_actions; extern Chat* g_chat; extern TalkActions* g_talkActions; @@ -614,7 +613,7 @@ void Game::playerMoveThing(uint32_t playerId, const Position& fromPos, uint16_t if (movingCreature->getPosition().isInRange(player->getPosition(), 1, 1, 0)) { SchedulerTask* task = - createSchedulerTask(static_cast(g_config[ConfigKeysInteger::RANGE_MOVE_CREATURE_INTERVAL]), + createSchedulerTask(static_cast(getInteger(ConfigManager::RANGE_MOVE_CREATURE_INTERVAL)), [=, this, playerID = player->getID(), creatureID = movingCreature->getID()]() { playerMoveCreatureByID(playerID, creatureID, fromPos, toPos); }); @@ -696,7 +695,7 @@ void Game::playerMoveCreature(Player* player, Creature* movingCreature, const Po playerAutoWalk(playerID, listDir); }); SchedulerTask* task = createSchedulerTask( - static_cast(g_config[ConfigKeysInteger::RANGE_MOVE_CREATURE_INTERVAL]), + static_cast(getInteger(ConfigManager::RANGE_MOVE_CREATURE_INTERVAL)), [=, this, playerID = player->getID(), movingCreatureID = movingCreature->getID(), toPos = toTile->getPosition()] { playerMoveCreatureByID(playerID, movingCreatureID, movingCreatureOrigPos, toPos); @@ -983,7 +982,7 @@ void Game::playerMoveItem(Player* player, const Position& fromPos, uint16_t spri }); SchedulerTask* task = createSchedulerTask( - static_cast(g_config[ConfigKeysInteger::RANGE_MOVE_ITEM_INTERVAL]), + static_cast(getInteger(ConfigManager::RANGE_MOVE_ITEM_INTERVAL)), [this, playerID = player->getID(), itemPos, spriteId, itemStackPos, toPos, count]() { playerMoveItemByPlayerID(playerID, itemPos, spriteId, itemStackPos, toPos, count); }); @@ -1045,7 +1044,7 @@ void Game::playerMoveItem(Player* player, const Position& fromPos, uint16_t spri }); SchedulerTask* task = createSchedulerTask( - static_cast(g_config[ConfigKeysInteger::RANGE_MOVE_ITEM_INTERVAL]), + static_cast(getInteger(ConfigManager::RANGE_MOVE_ITEM_INTERVAL)), [=, this, playerID = player->getID()]() { playerMoveItemByPlayerID(playerID, fromPos, spriteId, fromStackPos, toPos, count); }); @@ -2080,7 +2079,7 @@ void Game::playerUseItemEx(uint32_t playerId, const Position& fromPos, uint8_t f } bool isHotkey = (fromPos.x == 0xFFFF && fromPos.y == 0 && fromPos.z == 0); - if (isHotkey && !g_config[ConfigKeysBoolean::AIMBOT_HOTKEY_ENABLED]) { + if (isHotkey && !getBoolean(ConfigManager::AIMBOT_HOTKEY_ENABLED)) { return; } @@ -2140,7 +2139,7 @@ void Game::playerUseItemEx(uint32_t playerId, const Position& fromPos, uint8_t f }); SchedulerTask* task = createSchedulerTask( - static_cast(g_config[ConfigKeysInteger::RANGE_USE_ITEM_EX_INTERVAL]), [=, this]() { + static_cast(getInteger(ConfigManager::RANGE_USE_ITEM_EX_INTERVAL)), [=, this]() { playerUseItemEx(playerId, itemPos, itemStackPos, fromSpriteId, toPos, toStackPos, toSpriteId); }); player->setNextWalkActionTask(task); @@ -2177,7 +2176,7 @@ void Game::playerUseItem(uint32_t playerId, const Position& pos, uint8_t stackPo } bool isHotkey = (pos.x == 0xFFFF && pos.y == 0 && pos.z == 0); - if (isHotkey && !g_config[ConfigKeysBoolean::AIMBOT_HOTKEY_ENABLED]) { + if (isHotkey && !getBoolean(ConfigManager::AIMBOT_HOTKEY_ENABLED)) { return; } @@ -2211,7 +2210,7 @@ void Game::playerUseItem(uint32_t playerId, const Position& pos, uint8_t stackPo }); SchedulerTask* task = - createSchedulerTask(static_cast(g_config[ConfigKeysInteger::RANGE_USE_ITEM_INTERVAL]), + createSchedulerTask(static_cast(getInteger(ConfigManager::RANGE_USE_ITEM_INTERVAL)), [=, this]() { playerUseItem(playerId, pos, stackPos, index, spriteId); }); player->setNextWalkActionTask(task); return; @@ -2277,7 +2276,7 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position& fromPos, uin } bool isHotkey = (fromPos.x == 0xFFFF && fromPos.y == 0 && fromPos.z == 0); - if (!g_config[ConfigKeysBoolean::AIMBOT_HOTKEY_ENABLED]) { + if (!getBoolean(ConfigManager::AIMBOT_HOTKEY_ENABLED)) { if (creature->getPlayer() || isHotkey) { player->sendCancelMessage(RETURNVALUE_DIRECTPLAYERSHOOT); return; @@ -2332,7 +2331,7 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position& fromPos, uin }); SchedulerTask* task = createSchedulerTask( - static_cast(g_config[ConfigKeysInteger::RANGE_USE_WITH_CREATURE_INTERVAL]), + static_cast(getInteger(ConfigManager::RANGE_USE_WITH_CREATURE_INTERVAL)), [=, this]() { playerUseWithCreature(playerId, itemPos, itemStackPos, creatureId, spriteId); }); player->setNextWalkActionTask(task); } else { @@ -2442,7 +2441,7 @@ void Game::playerRotateItem(uint32_t playerId, const Position& pos, uint8_t stac }); SchedulerTask* task = - createSchedulerTask(static_cast(g_config[ConfigKeysInteger::RANGE_ROTATE_ITEM_INTERVAL]), + createSchedulerTask(static_cast(getInteger(ConfigManager::RANGE_ROTATE_ITEM_INTERVAL)), [=, this]() { playerRotateItem(playerId, pos, stackPos, spriteId); }); player->setNextWalkActionTask(task); } else { @@ -2687,7 +2686,7 @@ void Game::playerRequestTrade(uint32_t playerId, const Position& pos, uint8_t st return; } - if (g_config[ConfigKeysBoolean::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS]) { + if (getBoolean(ConfigManager::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { if (HouseTile* houseTile = dynamic_cast(tradeItem->getTile())) { House* house = houseTile->getHouse(); if (house && !house->isInvited(player)) { @@ -3373,7 +3372,7 @@ void Game::playerTurn(uint32_t playerId, Direction dir) void Game::playerRequestOutfit(uint32_t playerId) { - if (!g_config[ConfigKeysBoolean::ALLOW_CHANGEOUTFIT]) { + if (!getBoolean(ConfigManager::ALLOW_CHANGEOUTFIT)) { return; } @@ -3387,7 +3386,7 @@ void Game::playerRequestOutfit(uint32_t playerId) void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit, bool randomizeMount /* = false*/) { - if (!g_config[ConfigKeysBoolean::ALLOW_CHANGEOUTFIT]) { + if (!getBoolean(ConfigManager::ALLOW_CHANGEOUTFIT)) { return; } @@ -3535,7 +3534,7 @@ bool Game::playerSaySpell(Player* player, SpeakClasses type, std::string_view te result = g_spells->playerSaySpell(player, words); if (result == TalkActionResult::BREAK) { - if (!g_config[ConfigKeysBoolean::EMOTE_SPELLS]) { + if (!getBoolean(ConfigManager::EMOTE_SPELLS)) { return internalCreatureSay(player, TALKTYPE_SAY, words, false); } else { return internalCreatureSay(player, TALKTYPE_MONSTER_SAY, words, false); @@ -3579,9 +3578,9 @@ bool Game::playerYell(Player* player, std::string_view text) } if (!player->isAccessPlayer() && !player->hasFlag(PlayerFlag_IgnoreYellCheck)) { - const int64_t minimumLevel = g_config[ConfigKeysInteger::YELL_MINIMUM_LEVEL]; + const int64_t minimumLevel = getInteger(ConfigManager::YELL_MINIMUM_LEVEL); if (player->getLevel() < minimumLevel) { - if (g_config[ConfigKeysBoolean::YELL_ALLOW_PREMIUM]) { + if (getBoolean(ConfigManager::YELL_ALLOW_PREMIUM)) { if (!player->isPremium()) { player->sendTextMessage( MESSAGE_STATUS_SMALL, @@ -3621,9 +3620,9 @@ bool Game::playerSpeakTo(Player* player, SpeakClasses type, std::string_view rec } if (!player->isAccessPlayer() && !player->hasFlag(PlayerFlag_IgnoreSendPrivateCheck)) { - const int64_t minimumLevel = g_config[ConfigKeysInteger::MINIMUM_LEVEL_TO_SEND_PRIVATE]; + const int64_t minimumLevel = getInteger(ConfigManager::MINIMUM_LEVEL_TO_SEND_PRIVATE); if (player->getLevel() < minimumLevel) { - if (g_config[ConfigKeysBoolean::PREMIUM_TO_SEND_PRIVATE]) { + if (getBoolean(ConfigManager::PREMIUM_TO_SEND_PRIVATE)) { if (!player->isPremium()) { player->sendTextMessage( MESSAGE_STATUS_SMALL, @@ -4095,7 +4094,7 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage TextMessage message; addAnimatedText(fmt::format("{:+d}", realHealthChange), targetPos, - static_cast(g_config[ConfigKeysInteger::HEALTH_GAIN_COLOUR])); + static_cast(getInteger(ConfigManager::HEALTH_GAIN_COLOUR))); SpectatorVec spectators; map.getSpectators(spectators, targetPos, false, true); @@ -4195,7 +4194,7 @@ bool Game::combatChangeHealth(Creature* attacker, Creature* target, CombatDamage std::string spectatorMessage; addAnimatedText(fmt::format("{:+d}", -manaDamage), targetPos, - static_cast(g_config[ConfigKeysInteger::MANA_GAIN_COLOUR])); + static_cast(getInteger(ConfigManager::MANA_GAIN_COLOUR))); for (Creature* spectator : spectators) { assert(dynamic_cast(spectator) != nullptr); @@ -4452,7 +4451,7 @@ bool Game::combatChangeMana(Creature* attacker, Creature* target, CombatDamage& TextMessage message; addAnimatedText(fmt::format("{:+d}", manaLoss), targetPos, - static_cast(g_config[ConfigKeysInteger::MANA_LOSS_COLOUR])); + static_cast(getInteger(ConfigManager::MANA_LOSS_COLOUR))); SpectatorVec spectators; map.getSpectators(spectators, targetPos, false, true); @@ -4833,7 +4832,7 @@ void Game::loadMotdNum() result = db.storeQuery("SELECT `value` FROM `server_config` WHERE `config` = 'motd_hash'"); if (result) { motdHash = result->getString("value"); - if (motdHash != transformToSHA1(g_config[ConfigKeysString::MOTD])) { + if (motdHash != transformToSHA1(getString(ConfigManager::MOTD))) { ++motdNum; } } else { @@ -4846,7 +4845,7 @@ void Game::saveMotdNum() const Database& db = Database::getInstance(); db.executeQuery(fmt::format("UPDATE `server_config` SET `value` = '{:d}' WHERE `config` = 'motd_num'", motdNum)); db.executeQuery(fmt::format("UPDATE `server_config` SET `value` = '{:s}' WHERE `config` = 'motd_hash'", - transformToSHA1(g_config[ConfigKeysString::MOTD]))); + transformToSHA1(getString(ConfigManager::MOTD)))); } void Game::checkPlayersRecord() @@ -5233,7 +5232,7 @@ bool Game::reload(ReloadTypes_t reloadType) case RELOAD_TYPE_CHAT: return g_chat->load(); case RELOAD_TYPE_CONFIG: - return g_config.load(); + return ConfigManager::load(); case RELOAD_TYPE_CREATURESCRIPTS: { g_creatureEvents->reload(); g_creatureEvents->removeInvalidEvents(); @@ -5295,7 +5294,7 @@ bool Game::reload(ReloadTypes_t reloadType) Npcs::reload(); raids.reload() && raids.startup(); Item::items.reload(); - g_config.reload(); + ConfigManager::reload(); g_events->load(); g_chat->load(); */ @@ -5312,7 +5311,7 @@ bool Game::reload(ReloadTypes_t reloadType) } g_actions->reload(); - g_config.load(); + ConfigManager::load(); g_creatureEvents->reload(); g_monsters.reload(); g_moveEvents->reload(); diff --git a/src/globalevent.cpp b/src/globalevent.cpp index cc3836c..25fe456 100644 --- a/src/globalevent.cpp +++ b/src/globalevent.cpp @@ -10,8 +10,6 @@ #include "scheduler.h" #include "tools.h" -extern ConfigManager g_config; - GlobalEvents::GlobalEvents() : scriptInterface("GlobalEvent Interface") { scriptInterface.initState(); } GlobalEvents::~GlobalEvents() { clear(false); } diff --git a/src/house.cpp b/src/house.cpp index f24e3a3..06e0c3e 100644 --- a/src/house.cpp +++ b/src/house.cpp @@ -11,7 +11,6 @@ #include "iologindata.h" #include "pugicast.h" -extern ConfigManager g_config; extern Game g_game; House::House(uint32_t houseId) : id(houseId) {} @@ -71,7 +70,7 @@ void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, Player* pla } } else { auto strRentPeriod = - boost::algorithm::to_lower_copy(std::string{g_config[ConfigKeysString::HOUSE_RENT_PERIOD]}); + boost::algorithm::to_lower_copy(std::string{getString(ConfigManager::HOUSE_RENT_PERIOD)}); time_t currentTime = time(nullptr); if (strRentPeriod == "yearly") { currentTime += 24 * 60 * 60 * 365; @@ -106,7 +105,7 @@ AccessHouseLevel_t House::getHouseAccessLevel(const Player* player) const return HOUSE_OWNER; } - if (g_config[ConfigKeysBoolean::HOUSE_OWNED_BY_ACCOUNT]) { + if (getBoolean(ConfigManager::HOUSE_OWNED_BY_ACCOUNT)) { if (ownerAccountId == player->getAccount()) { return HOUSE_OWNER; } @@ -252,7 +251,7 @@ std::optional House::getAccessList(uint32_t listId) const return door->getAccessList(); } -bool House::isInvited(const Player* player) { return getHouseAccessLevel(player) != HOUSE_NOT_INVITED; } +bool House::isInvited(const Player* player) const { return getHouseAccessLevel(player) != HOUSE_NOT_INVITED; } void House::addDoor(Door* door) { @@ -451,7 +450,7 @@ void AccessList::addGuild(std::string_view name) { const Guild* guild = getGuildByName(name); if (guild) { - for (auto rank : guild->getRanks()) { + for (GuildRank_ptr rank : guild->getRanks()) { guildRankList.insert(rank->id); } } diff --git a/src/house.h b/src/house.h index f0b4538..3049073 100644 --- a/src/house.h +++ b/src/house.h @@ -115,7 +115,7 @@ class House void setAccessList(uint32_t listId, std::string_view textlist); std::optional getAccessList(uint32_t listId) const; - bool isInvited(const Player* player); + bool isInvited(const Player* player) const; AccessHouseLevel_t getHouseAccessLevel(const Player* player) const; bool kickPlayer(Player* player, Player* target) const; diff --git a/src/housetile.cpp b/src/housetile.cpp index 2437767..ccd1a53 100644 --- a/src/housetile.cpp +++ b/src/housetile.cpp @@ -10,7 +10,6 @@ #include "house.h" extern Game g_game; -extern ConfigManager g_config; HouseTile::HouseTile(uint16_t x, uint16_t y, uint8_t z, House* house) : DynamicTile(x, y, z), house(house) {} @@ -121,11 +120,11 @@ ReturnValue HouseTile::queryRemove(const Thing& thing, uint32_t count, uint32_t return RETURNVALUE_NOTPOSSIBLE; } - if (actor && g_config[ConfigKeysBoolean::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS]) { - Player* actorPlayer = actor->getPlayer(); - if (!house->isInvited(actorPlayer)) { - return RETURNVALUE_NOTPOSSIBLE; + if (actor && getBoolean(ConfigManager::ONLY_INVITED_CAN_MOVE_HOUSE_ITEMS)) { + if (!house->isInvited(actor->getPlayer())) { + return RETURNVALUE_PLAYERISNOTINVITED; } } + return Tile::queryRemove(thing, count, flags); } diff --git a/src/housetile.h b/src/housetile.h index 65010cb..59845f4 100644 --- a/src/housetile.h +++ b/src/housetile.h @@ -27,7 +27,7 @@ class HouseTile final : public DynamicTile void addThing(int32_t index, Thing* thing) override; void internalAddThing(uint32_t index, Thing* thing) override; - House* getHouse() { return house; } + House* getHouse() const { return house; } private: void updateHouse(Item* item); diff --git a/src/iologindata.cpp b/src/iologindata.cpp index 9e0aced..57a27be 100644 --- a/src/iologindata.cpp +++ b/src/iologindata.cpp @@ -8,7 +8,6 @@ #include "configmanager.h" #include "game.h" -extern ConfigManager g_config; extern Game g_game; Account IOLoginData::loadAccount(uint32_t accno) @@ -81,7 +80,7 @@ bool IOLoginData::loginserverAuthentication(std::string_view name, std::string_v account.premiumEndsAt = result->getNumber("premium_ends_at"); account.tibiaCoins = result->getNumber("tibia_coins"); - if (g_config[ConfigKeysBoolean::ACCOUNT_MANAGER] && account.id != ACCOUNT_MANAGER_ACCOUNT_ID) { + if (getBoolean(ConfigManager::ACCOUNT_MANAGER) && account.id != ACCOUNT_MANAGER_ACCOUNT_ID) { account.characters.push_back(ACCOUNT_MANAGER_PLAYER_NAME); } @@ -186,7 +185,7 @@ void IOLoginData::setAccountType(uint32_t accountId, AccountType_t accountType) void IOLoginData::updateOnlineStatus(uint32_t guid, bool login) { - if (g_config[ConfigKeysBoolean::ALLOW_CLONES]) { + if (getBoolean(ConfigManager::ALLOW_CLONES)) { return; } diff --git a/src/iomap.h b/src/iomap.h index f14e392..080d3dd 100644 --- a/src/iomap.h +++ b/src/iomap.h @@ -10,8 +10,6 @@ #include "map.h" #include "spawn.h" -extern ConfigManager g_config; - enum OTBM_AttrTypes_t { OTBM_ATTR_DESCRIPTION = 1, @@ -108,7 +106,7 @@ class IOMap if (map->spawnfile.empty()) { // OTBM file doesn't tell us about the spawnfile, // lets guess it is mapname-spawn.xml. - map->spawnfile = g_config[ConfigKeysString::MAP_NAME]; + map->spawnfile = getString(ConfigManager::MAP_NAME); map->spawnfile += "-spawn.xml"; } @@ -124,7 +122,7 @@ class IOMap if (map->housefile.empty()) { // OTBM file doesn't tell us about the housefile, // lets guess it is mapname-house.xml. - map->housefile = g_config[ConfigKeysString::MAP_NAME]; + map->housefile = getString(ConfigManager::MAP_NAME); map->housefile += "-house.xml"; } diff --git a/src/luagame.cpp b/src/luagame.cpp index a8ad58f..e82712c 100644 --- a/src/luagame.cpp +++ b/src/luagame.cpp @@ -14,7 +14,6 @@ extern Events* g_events; extern Vocations g_vocations; -extern ConfigManager g_config; extern Game g_game; extern Monsters g_monsters; extern Scripts* g_scripts; @@ -85,7 +84,7 @@ int luaGameGetExperienceStage(lua_State* L) { // Game.getExperienceStage(level) uint32_t level = getInteger(L, 1); - lua_pushnumber(L, g_config.getExperienceStage(level)); + lua_pushnumber(L, ConfigManager::getExperienceStage(level)); return 1; } diff --git a/src/luascript.cpp b/src/luascript.cpp index aac0542..9255564 100644 --- a/src/luascript.cpp +++ b/src/luascript.cpp @@ -30,7 +30,6 @@ extern Chat* g_chat; extern Game g_game; -extern ConfigManager g_config; extern Vocations g_vocations; extern Scripts* g_scripts; extern Spells* g_spells; @@ -2028,87 +2027,87 @@ void LuaScriptInterface::registerFunctions() // configKeys registerTable("configKeys"); - registerEnumIn("configKeys", ConfigKeysBoolean::ALLOW_CHANGEOUTFIT); - registerEnumIn("configKeys", ConfigKeysBoolean::ONE_PLAYER_ON_ACCOUNT); - registerEnumIn("configKeys", ConfigKeysBoolean::AIMBOT_HOTKEY_ENABLED); - registerEnumIn("configKeys", ConfigKeysBoolean::REMOVE_RUNE_CHARGES); - registerEnumIn("configKeys", ConfigKeysBoolean::REMOVE_WEAPON_AMMO); - registerEnumIn("configKeys", ConfigKeysBoolean::REMOVE_WEAPON_CHARGES); - registerEnumIn("configKeys", ConfigKeysBoolean::REMOVE_POTION_CHARGES); - registerEnumIn("configKeys", ConfigKeysBoolean::EXPERIENCE_FROM_PLAYERS); - registerEnumIn("configKeys", ConfigKeysBoolean::FREE_PREMIUM); - registerEnumIn("configKeys", ConfigKeysBoolean::REPLACE_KICK_ON_LOGIN); - registerEnumIn("configKeys", ConfigKeysBoolean::ALLOW_CLONES); - registerEnumIn("configKeys", ConfigKeysBoolean::BIND_ONLY_GLOBAL_ADDRESS); - registerEnumIn("configKeys", ConfigKeysBoolean::OPTIMIZE_DATABASE); - registerEnumIn("configKeys", ConfigKeysBoolean::MARKET_PREMIUM); - registerEnumIn("configKeys", ConfigKeysBoolean::EMOTE_SPELLS); - registerEnumIn("configKeys", ConfigKeysBoolean::STAMINA_SYSTEM); - registerEnumIn("configKeys", ConfigKeysBoolean::WARN_UNSAFE_SCRIPTS); - registerEnumIn("configKeys", ConfigKeysBoolean::CONVERT_UNSAFE_SCRIPTS); - registerEnumIn("configKeys", ConfigKeysBoolean::CLASSIC_EQUIPMENT_SLOTS); - registerEnumIn("configKeys", ConfigKeysBoolean::CLASSIC_ATTACK_SPEED); - registerEnumIn("configKeys", ConfigKeysBoolean::SERVER_SAVE_NOTIFY_MESSAGE); - registerEnumIn("configKeys", ConfigKeysBoolean::SERVER_SAVE_CLEAN_MAP); - registerEnumIn("configKeys", ConfigKeysBoolean::SERVER_SAVE_CLOSE); - registerEnumIn("configKeys", ConfigKeysBoolean::SERVER_SAVE_SHUTDOWN); - registerEnumIn("configKeys", ConfigKeysBoolean::ONLINE_OFFLINE_CHARLIST); - registerEnumIn("configKeys", ConfigKeysBoolean::HOUSE_DOOR_SHOW_PRICE); - registerEnumIn("configKeys", ConfigKeysBoolean::MONSTER_OVERSPAWN); - registerEnumIn("configKeys", ConfigKeysBoolean::REMOVE_ON_DESPAWN); - registerEnumIn("configKeys", ConfigKeysBoolean::ACCOUNT_MANAGER); - - registerEnumIn("configKeys", ConfigKeysString::MAP_NAME); - registerEnumIn("configKeys", ConfigKeysString::HOUSE_RENT_PERIOD); - registerEnumIn("configKeys", ConfigKeysString::SERVER_NAME); - registerEnumIn("configKeys", ConfigKeysString::OWNER_NAME); - registerEnumIn("configKeys", ConfigKeysString::OWNER_EMAIL); - registerEnumIn("configKeys", ConfigKeysString::URL); - registerEnumIn("configKeys", ConfigKeysString::LOCATION); - registerEnumIn("configKeys", ConfigKeysString::IP); - registerEnumIn("configKeys", ConfigKeysString::MOTD); - registerEnumIn("configKeys", ConfigKeysString::WORLD_TYPE); - registerEnumIn("configKeys", ConfigKeysString::MYSQL_HOST); - registerEnumIn("configKeys", ConfigKeysString::MYSQL_USER); - registerEnumIn("configKeys", ConfigKeysString::MYSQL_PASS); - registerEnumIn("configKeys", ConfigKeysString::MYSQL_DB); - registerEnumIn("configKeys", ConfigKeysString::MYSQL_SOCK); - registerEnumIn("configKeys", ConfigKeysString::DEFAULT_PRIORITY); - registerEnumIn("configKeys", ConfigKeysString::MAP_AUTHOR); - - registerEnumIn("configKeys", ConfigKeysInteger::SERVER_SAVE_NOTIFY_DURATION); - registerEnumIn("configKeys", ConfigKeysInteger::SQL_PORT); - registerEnumIn("configKeys", ConfigKeysInteger::MAX_PLAYERS); - registerEnumIn("configKeys", ConfigKeysInteger::PZ_LOCKED); - registerEnumIn("configKeys", ConfigKeysInteger::DEFAULT_DESPAWNRANGE); - registerEnumIn("configKeys", ConfigKeysInteger::DEFAULT_DESPAWNRADIUS); - registerEnumIn("configKeys", ConfigKeysInteger::DEFAULT_WALKTOSPAWNRADIUS); - registerEnumIn("configKeys", ConfigKeysInteger::RATE_EXPERIENCE); - registerEnumIn("configKeys", ConfigKeysInteger::RATE_SKILL); - registerEnumIn("configKeys", ConfigKeysInteger::RATE_LOOT); - registerEnumIn("configKeys", ConfigKeysInteger::RATE_MAGIC); - registerEnumIn("configKeys", ConfigKeysInteger::RATE_SPAWN); - registerEnumIn("configKeys", ConfigKeysInteger::HOUSE_PRICE); - registerEnumIn("configKeys", ConfigKeysInteger::KILLS_TO_RED); - registerEnumIn("configKeys", ConfigKeysInteger::KILLS_TO_BLACK); - registerEnumIn("configKeys", ConfigKeysInteger::MAX_MESSAGEBUFFER); - registerEnumIn("configKeys", ConfigKeysInteger::ACTIONS_DELAY_INTERVAL); - registerEnumIn("configKeys", ConfigKeysInteger::EX_ACTIONS_DELAY_INTERVAL); - registerEnumIn("configKeys", ConfigKeysInteger::KICK_AFTER_MINUTES); - registerEnumIn("configKeys", ConfigKeysInteger::PROTECTION_LEVEL); - registerEnumIn("configKeys", ConfigKeysInteger::DEATH_LOSE_PERCENT); - registerEnumIn("configKeys", ConfigKeysInteger::STATUSQUERY_TIMEOUT); - registerEnumIn("configKeys", ConfigKeysInteger::FRAG_TIME); - registerEnumIn("configKeys", ConfigKeysInteger::WHITE_SKULL_TIME); - registerEnumIn("configKeys", ConfigKeysInteger::GAME_PORT); - registerEnumIn("configKeys", ConfigKeysInteger::LOGIN_PORT); - registerEnumIn("configKeys", ConfigKeysInteger::STATUS_PORT); - registerEnumIn("configKeys", ConfigKeysInteger::STAIRHOP_DELAY); - registerEnumIn("configKeys", ConfigKeysInteger::MARKET_OFFER_DURATION); - registerEnumIn("configKeys", ConfigKeysInteger::EXP_FROM_PLAYERS_LEVEL_RANGE); - registerEnumIn("configKeys", ConfigKeysInteger::MAX_PACKETS_PER_SECOND); - registerEnumIn("configKeys", ConfigKeysInteger::STAMINA_REGEN_MINUTE); - registerEnumIn("configKeys", ConfigKeysInteger::STAMINA_REGEN_PREMIUM); + registerEnumIn("configKeys", ConfigManager::ALLOW_CHANGEOUTFIT); + registerEnumIn("configKeys", ConfigManager::ONE_PLAYER_ON_ACCOUNT); + registerEnumIn("configKeys", ConfigManager::AIMBOT_HOTKEY_ENABLED); + registerEnumIn("configKeys", ConfigManager::REMOVE_RUNE_CHARGES); + registerEnumIn("configKeys", ConfigManager::REMOVE_WEAPON_AMMO); + registerEnumIn("configKeys", ConfigManager::REMOVE_WEAPON_CHARGES); + registerEnumIn("configKeys", ConfigManager::REMOVE_POTION_CHARGES); + registerEnumIn("configKeys", ConfigManager::EXPERIENCE_FROM_PLAYERS); + registerEnumIn("configKeys", ConfigManager::FREE_PREMIUM); + registerEnumIn("configKeys", ConfigManager::REPLACE_KICK_ON_LOGIN); + registerEnumIn("configKeys", ConfigManager::ALLOW_CLONES); + registerEnumIn("configKeys", ConfigManager::BIND_ONLY_GLOBAL_ADDRESS); + registerEnumIn("configKeys", ConfigManager::OPTIMIZE_DATABASE); + registerEnumIn("configKeys", ConfigManager::MARKET_PREMIUM); + registerEnumIn("configKeys", ConfigManager::EMOTE_SPELLS); + registerEnumIn("configKeys", ConfigManager::STAMINA_SYSTEM); + registerEnumIn("configKeys", ConfigManager::WARN_UNSAFE_SCRIPTS); + registerEnumIn("configKeys", ConfigManager::CONVERT_UNSAFE_SCRIPTS); + registerEnumIn("configKeys", ConfigManager::CLASSIC_EQUIPMENT_SLOTS); + registerEnumIn("configKeys", ConfigManager::CLASSIC_ATTACK_SPEED); + registerEnumIn("configKeys", ConfigManager::SERVER_SAVE_NOTIFY_MESSAGE); + registerEnumIn("configKeys", ConfigManager::SERVER_SAVE_CLEAN_MAP); + registerEnumIn("configKeys", ConfigManager::SERVER_SAVE_CLOSE); + registerEnumIn("configKeys", ConfigManager::SERVER_SAVE_SHUTDOWN); + registerEnumIn("configKeys", ConfigManager::ONLINE_OFFLINE_CHARLIST); + registerEnumIn("configKeys", ConfigManager::HOUSE_DOOR_SHOW_PRICE); + registerEnumIn("configKeys", ConfigManager::MONSTER_OVERSPAWN); + registerEnumIn("configKeys", ConfigManager::REMOVE_ON_DESPAWN); + registerEnumIn("configKeys", ConfigManager::ACCOUNT_MANAGER); + + registerEnumIn("configKeys", ConfigManager::MAP_NAME); + registerEnumIn("configKeys", ConfigManager::HOUSE_RENT_PERIOD); + registerEnumIn("configKeys", ConfigManager::SERVER_NAME); + registerEnumIn("configKeys", ConfigManager::OWNER_NAME); + registerEnumIn("configKeys", ConfigManager::OWNER_EMAIL); + registerEnumIn("configKeys", ConfigManager::URL); + registerEnumIn("configKeys", ConfigManager::LOCATION); + registerEnumIn("configKeys", ConfigManager::IP); + registerEnumIn("configKeys", ConfigManager::MOTD); + registerEnumIn("configKeys", ConfigManager::WORLD_TYPE); + registerEnumIn("configKeys", ConfigManager::MYSQL_HOST); + registerEnumIn("configKeys", ConfigManager::MYSQL_USER); + registerEnumIn("configKeys", ConfigManager::MYSQL_PASS); + registerEnumIn("configKeys", ConfigManager::MYSQL_DB); + registerEnumIn("configKeys", ConfigManager::MYSQL_SOCK); + registerEnumIn("configKeys", ConfigManager::DEFAULT_PRIORITY); + registerEnumIn("configKeys", ConfigManager::MAP_AUTHOR); + + registerEnumIn("configKeys", ConfigManager::SERVER_SAVE_NOTIFY_DURATION); + registerEnumIn("configKeys", ConfigManager::SQL_PORT); + registerEnumIn("configKeys", ConfigManager::MAX_PLAYERS); + registerEnumIn("configKeys", ConfigManager::PZ_LOCKED); + registerEnumIn("configKeys", ConfigManager::DEFAULT_DESPAWNRANGE); + registerEnumIn("configKeys", ConfigManager::DEFAULT_DESPAWNRADIUS); + registerEnumIn("configKeys", ConfigManager::DEFAULT_WALKTOSPAWNRADIUS); + registerEnumIn("configKeys", ConfigManager::RATE_EXPERIENCE); + registerEnumIn("configKeys", ConfigManager::RATE_SKILL); + registerEnumIn("configKeys", ConfigManager::RATE_LOOT); + registerEnumIn("configKeys", ConfigManager::RATE_MAGIC); + registerEnumIn("configKeys", ConfigManager::RATE_SPAWN); + registerEnumIn("configKeys", ConfigManager::HOUSE_PRICE); + registerEnumIn("configKeys", ConfigManager::KILLS_TO_RED); + registerEnumIn("configKeys", ConfigManager::KILLS_TO_BLACK); + registerEnumIn("configKeys", ConfigManager::MAX_MESSAGEBUFFER); + registerEnumIn("configKeys", ConfigManager::ACTIONS_DELAY_INTERVAL); + registerEnumIn("configKeys", ConfigManager::EX_ACTIONS_DELAY_INTERVAL); + registerEnumIn("configKeys", ConfigManager::KICK_AFTER_MINUTES); + registerEnumIn("configKeys", ConfigManager::PROTECTION_LEVEL); + registerEnumIn("configKeys", ConfigManager::DEATH_LOSE_PERCENT); + registerEnumIn("configKeys", ConfigManager::STATUSQUERY_TIMEOUT); + registerEnumIn("configKeys", ConfigManager::FRAG_TIME); + registerEnumIn("configKeys", ConfigManager::WHITE_SKULL_TIME); + registerEnumIn("configKeys", ConfigManager::GAME_PORT); + registerEnumIn("configKeys", ConfigManager::LOGIN_PORT); + registerEnumIn("configKeys", ConfigManager::STATUS_PORT); + registerEnumIn("configKeys", ConfigManager::STAIRHOP_DELAY); + registerEnumIn("configKeys", ConfigManager::MARKET_OFFER_DURATION); + registerEnumIn("configKeys", ConfigManager::EXP_FROM_PLAYERS_LEVEL_RANGE); + registerEnumIn("configKeys", ConfigManager::MAX_PACKETS_PER_SECOND); + registerEnumIn("configKeys", ConfigManager::STAMINA_REGEN_MINUTE); + registerEnumIn("configKeys", ConfigManager::STAMINA_REGEN_PREMIUM); // os registerMethod("os", "mtime", LuaScriptInterface::luaSystemTime); @@ -2726,7 +2725,7 @@ int LuaScriptInterface::luaAddEvent(lua_State* L) return 1; } - if (g_config[ConfigKeysBoolean::WARN_UNSAFE_SCRIPTS] || g_config[ConfigKeysBoolean::CONVERT_UNSAFE_SCRIPTS]) { + if (getBoolean(ConfigManager::WARN_UNSAFE_SCRIPTS) || getBoolean(ConfigManager::CONVERT_UNSAFE_SCRIPTS)) { std::vector> indexes; for (int i = 3; i <= parameters; ++i) { if (lua_getmetatable(L, i) == 0) { @@ -2768,7 +2767,7 @@ int LuaScriptInterface::luaAddEvent(lua_State* L) } if (!indexes.empty()) { - if (g_config[ConfigKeysBoolean::WARN_UNSAFE_SCRIPTS]) { + if (getBoolean(ConfigManager::WARN_UNSAFE_SCRIPTS)) { bool plural = indexes.size() > 1; std::string warningString = "Argument"; @@ -2797,7 +2796,7 @@ int LuaScriptInterface::luaAddEvent(lua_State* L) reportErrorFunc(L, warningString); } - if (g_config[ConfigKeysBoolean::CONVERT_UNSAFE_SCRIPTS]) { + if (getBoolean(ConfigManager::CONVERT_UNSAFE_SCRIPTS)) { for (const auto& entry : indexes) { switch (entry.second) { case LuaData_Item: @@ -2980,19 +2979,19 @@ const luaL_Reg LuaScriptInterface::luaConfigManagerTable[] = { int LuaScriptInterface::luaConfigManagerGetString(lua_State* L) { - Lua::pushString(L, g_config[Lua::getInteger(L, -1)]); + Lua::pushString(L, getString(Lua::getInteger(L, -1))); return 1; } int LuaScriptInterface::luaConfigManagerGetNumber(lua_State* L) { - lua_pushinteger(L, g_config[Lua::getInteger(L, -1)]); + lua_pushinteger(L, getInteger(Lua::getInteger(L, -1))); return 1; } int LuaScriptInterface::luaConfigManagerGetBoolean(lua_State* L) { - Lua::pushBoolean(L, g_config[Lua::getInteger(L, -1)]); + Lua::pushBoolean(L, getBoolean(Lua::getInteger(L, -1))); return 1; } diff --git a/src/main.cpp b/src/main.cpp index 43a0756..e5f966e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,8 +4,6 @@ #include "otserv.h" #include "tools.h" -extern ConfigManager g_config; - static bool argumentsHandler(const std::vector& args) { for (const auto& arg : args) { @@ -26,13 +24,13 @@ static bool argumentsHandler(const std::vector& args) auto tmp = explodeString(arg, "="); if (tmp[0] == "--config") - g_config.setString(ConfigKeysString::CONFIG_FILE, tmp[1]); + ConfigManager::setString(ConfigManager::CONFIG_FILE, tmp[1]); else if (tmp[0] == "--ip") - g_config.setString(ConfigKeysString::IP, tmp[1]); + ConfigManager::setString(ConfigManager::IP, tmp[1]); else if (tmp[0] == "--login-port") - g_config.setInteger(ConfigKeysInteger::LOGIN_PORT, std::stoi(tmp[1].data())); + ConfigManager::setInteger(ConfigManager::LOGIN_PORT, std::stoi(tmp[1].data())); else if (tmp[0] == "--game-port") - g_config.setInteger(ConfigKeysInteger::GAME_PORT, std::stoi(tmp[1].data())); + ConfigManager::setInteger(ConfigManager::GAME_PORT, std::stoi(tmp[1].data())); } return true; diff --git a/src/monster.cpp b/src/monster.cpp index a5e356d..f95ab44 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -13,7 +13,6 @@ extern Game g_game; extern Monsters g_monsters; extern Events* g_events; -extern ConfigManager g_config; int32_t Monster::despawnRange; int32_t Monster::despawnRadius; @@ -487,7 +486,7 @@ void Monster::onCreatureLeave(Creature* creature) updateIdleStatus(); if (!isSummon() && targetList.empty()) { - const int64_t walkToSpawnRadius = g_config[ConfigKeysInteger::DEFAULT_WALKTOSPAWNRADIUS]; + const int64_t walkToSpawnRadius = getInteger(ConfigManager::DEFAULT_WALKTOSPAWNRADIUS); if (walkToSpawnRadius > 0 && !position.isInRange(masterPos, walkToSpawnRadius, walkToSpawnRadius)) { walkToSpawn(); } @@ -731,7 +730,7 @@ void Monster::onThink(uint32_t interval) if (!isInSpawnRange(position)) { g_game.addMagicEffect(this->getPosition(), CONST_ME_POFF); - if (g_config[ConfigKeysBoolean::REMOVE_ON_DESPAWN]) { + if (getBoolean(ConfigManager::REMOVE_ON_DESPAWN)) { g_game.removeCreature(this, false); } else { g_game.internalTeleport(this, masterPos); diff --git a/src/monsters.cpp b/src/monsters.cpp index 27e8624..ab76c04 100644 --- a/src/monsters.cpp +++ b/src/monsters.cpp @@ -17,7 +17,6 @@ extern Game g_game; extern Spells* g_spells; extern Monsters g_monsters; -extern ConfigManager g_config; spellBlock_t::~spellBlock_t() { @@ -59,7 +58,7 @@ bool Monsters::loadFromXml(bool reloading /*= false*/) unloadedMonsters.emplace(name, file); } - const bool& forceLoad = g_config[ConfigKeysBoolean::FORCE_MONSTERTYPE_LOAD]; + bool forceLoad = getBoolean(ConfigManager::FORCE_MONSTERTYPE_LOAD); for (const auto& [monsterName, file] : unloadedMonsters) { if (forceLoad || (reloading && monsters.find(monsterName) != monsters.end())) { diff --git a/src/otserv.cpp b/src/otserv.cpp index 349b090..f71c998 100644 --- a/src/otserv.cpp +++ b/src/otserv.cpp @@ -29,7 +29,6 @@ Dispatcher g_dispatcher; Scheduler g_scheduler; Game g_game; -ConfigManager g_config; Monsters g_monsters; Vocations g_vocations; extern Scripts* g_scripts; @@ -67,7 +66,7 @@ void mainLoader(ServiceManager* services) printServerVersion(); // check if config.lua or config.lua.dist exist - auto configFile = g_config[ConfigKeysString::CONFIG_FILE]; + auto configFile = getString(ConfigManager::CONFIG_FILE); std::ifstream c_test(fmt::format("./{}", configFile)); if (!c_test.is_open()) { std::ifstream config_lua_dist("./config.lua.dist"); @@ -84,13 +83,13 @@ void mainLoader(ServiceManager* services) // read global config std::cout << ">> Loading config" << std::endl; - if (!g_config.load()) { + if (!ConfigManager::load()) { startupErrorMessage(fmt::format("Unable to load {}!", configFile)); return; } #ifdef _WIN32 - auto defaultPriority = g_config[ConfigKeysString::DEFAULT_PRIORITY]; + auto defaultPriority = getString(ConfigManager::DEFAULT_PRIORITY); if (caseInsensitiveEqual(defaultPriority, "high")) { SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); } else if (caseInsensitiveEqual(defaultPriority, "above-normal")) { @@ -127,7 +126,7 @@ void mainLoader(ServiceManager* services) DatabaseManager::updateDatabase(); - if (g_config[ConfigKeysBoolean::OPTIMIZE_DATABASE] && !DatabaseManager::optimizeTables()) { + if (getBoolean(ConfigManager::OPTIMIZE_DATABASE) && !DatabaseManager::optimizeTables()) { std::cout << "> No tables were optimized." << std::endl; } @@ -184,7 +183,7 @@ void mainLoader(ServiceManager* services) } std::cout << ">> Checking world type... " << std::flush; - auto worldType = boost::algorithm::to_lower_copy(std::string{g_config[ConfigKeysString::WORLD_TYPE]}); + auto worldType = boost::algorithm::to_lower_copy(std::string{getString(ConfigManager::WORLD_TYPE)}); if (worldType == "pvp") { g_game.setWorldType(WORLD_TYPE_PVP); } else if (worldType == "no-pvp") { @@ -195,13 +194,13 @@ void mainLoader(ServiceManager* services) std::cout << std::endl; startupErrorMessage( fmt::format("Unknown world type: {:s}, valid world types are: pvp, no-pvp and pvp-enforced.", - g_config[ConfigKeysString::WORLD_TYPE])); + getString(ConfigManager::WORLD_TYPE))); return; } std::cout << boost::algorithm::to_upper_copy(worldType) << std::endl; std::cout << ">> Loading map" << std::endl; - if (!g_game.loadMainMap(std::string{g_config[ConfigKeysString::MAP_NAME]})) { + if (!g_game.loadMainMap(std::string{getString(ConfigManager::MAP_NAME)})) { startupErrorMessage("Failed to load map"); return; } @@ -210,18 +209,18 @@ void mainLoader(ServiceManager* services) g_game.setGameState(GAME_STATE_INIT); // Game client protocols - services->add(static_cast(g_config[ConfigKeysInteger::GAME_PORT])); - services->add(static_cast(g_config[ConfigKeysInteger::LOGIN_PORT])); + services->add(static_cast(getInteger(ConfigManager::GAME_PORT))); + services->add(static_cast(getInteger(ConfigManager::LOGIN_PORT))); // OT protocols - services->add(static_cast(g_config[ConfigKeysInteger::STATUS_PORT])); + services->add(static_cast(getInteger(ConfigManager::STATUS_PORT))); // Legacy login protocol - services->add(static_cast(g_config[ConfigKeysInteger::LOGIN_PORT])); + services->add(static_cast(getInteger(ConfigManager::LOGIN_PORT))); RentPeriod_t rentPeriod; auto strRentPeriod = - boost::algorithm::to_lower_copy(std::string{g_config[ConfigKeysString::HOUSE_RENT_PERIOD]}); + boost::algorithm::to_lower_copy(std::string{getString(ConfigManager::HOUSE_RENT_PERIOD)}); if (strRentPeriod == "yearly") { rentPeriod = RENTPERIOD_YEARLY; @@ -276,7 +275,7 @@ void startServer() g_loaderSignal.wait(g_loaderUniqueLock); if (serviceManager.is_running()) { - std::cout << ">> " << g_config[ConfigKeysString::SERVER_NAME] << " Server Online!" << std::endl << std::endl; + std::cout << ">> " << getString(ConfigManager::SERVER_NAME) << " Server Online!" << std::endl << std::endl; serviceManager.run(); } else { std::cout << ">> No services running. The server is NOT online." << std::endl; diff --git a/src/party.cpp b/src/party.cpp index 1d2211f..ceac249 100644 --- a/src/party.cpp +++ b/src/party.cpp @@ -10,7 +10,6 @@ #include "game.h" extern Game g_game; -extern ConfigManager g_config; extern Events* g_events; Party::Party(Player* leader) : leader(leader) { leader->setParty(this); } @@ -382,7 +381,7 @@ bool Party::canUseSharedExperience(const Player* player) const } uint64_t timeDiff = OTSYS_TIME() - it->second; - if (timeDiff > static_cast(g_config[ConfigKeysInteger::PZ_LOCKED])) { + if (timeDiff > static_cast(getInteger(ConfigManager::PZ_LOCKED))) { return false; } } diff --git a/src/player.cpp b/src/player.cpp index 9a1532e..104e922 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -16,7 +16,6 @@ #include "scheduler.h" #include "weapons.h" -extern ConfigManager g_config; extern Game g_game; extern Chat* g_chat; extern Vocations g_vocations; @@ -665,13 +664,13 @@ bool Player::canWalkthrough(const Creature* creature) const } const Player* player = creature->getPlayer(); - if (!player || !g_config[ConfigKeysBoolean::ALLOW_WALKTHROUGH]) { + if (!player || !getBoolean(ConfigManager::ALLOW_WALKTHROUGH)) { return false; } const Tile* playerTile = player->getTile(); if (!playerTile || (!playerTile->hasFlag(TILESTATE_PROTECTIONZONE) && - player->getLevel() > g_config[ConfigKeysInteger::PROTECTION_LEVEL])) { + player->getLevel() > getInteger(ConfigManager::PROTECTION_LEVEL))) { return false; } @@ -702,13 +701,13 @@ bool Player::canWalkthroughEx(const Creature* creature) const } const Player* player = creature->getPlayer(); - if (!player || !g_config[ConfigKeysBoolean::ALLOW_WALKTHROUGH]) { + if (!player || !getBoolean(ConfigManager::ALLOW_WALKTHROUGH)) { return false; } const Tile* playerTile = player->getTile(); return playerTile && (playerTile->hasFlag(TILESTATE_PROTECTIONZONE) || - player->getLevel() <= g_config[ConfigKeysInteger::PROTECTION_LEVEL]); + player->getLevel() <= getInteger(ConfigManager::PROTECTION_LEVEL)); } void Player::onReceiveMail() const @@ -1199,7 +1198,7 @@ void Player::onCreatureMove(Creature* creature, const Tile* newTile, const Posit } if (teleport || oldPos.z != newPos.z) { - const int64_t ticks = g_config[ConfigKeysInteger::STAIRHOP_DELAY]; + const int64_t ticks = getInteger(ConfigManager::STAIRHOP_DELAY); if (ticks > 0) { if (auto condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_PACIFIED, ticks, 0)) { addCondition(condition); @@ -1365,7 +1364,7 @@ void Player::onThink(uint32_t interval) if (!getTile()->hasFlag(TILESTATE_NOLOGOUT) && !isAccessPlayer()) { idleTime += interval; - const int32_t kickAfterMinutes = g_config[ConfigKeysInteger::KICK_AFTER_MINUTES]; + const int32_t kickAfterMinutes = getInteger(ConfigManager::KICK_AFTER_MINUTES); if (idleTime > (kickAfterMinutes * 60000) + 60000) { kickPlayer(true); } else if (client && idleTime == 60000 * kickAfterMinutes) { @@ -1399,7 +1398,7 @@ uint32_t Player::isMuted() const void Player::addMessageBuffer() { - if (MessageBufferCount > 0 && g_config[ConfigKeysInteger::MAX_MESSAGEBUFFER] != 0 && + if (MessageBufferCount > 0 && getInteger(ConfigManager::MAX_MESSAGEBUFFER) != 0 && !hasFlag(PlayerFlag_CannotBeMuted)) { --MessageBufferCount; } @@ -1411,7 +1410,7 @@ void Player::removeMessageBuffer() return; } - const int64_t maxMessageBuffer = g_config[ConfigKeysInteger::MAX_MESSAGEBUFFER]; + const int64_t maxMessageBuffer = getInteger(ConfigManager::MAX_MESSAGEBUFFER); if (maxMessageBuffer != 0 && MessageBufferCount <= maxMessageBuffer + 1) { if (++MessageBufferCount > maxMessageBuffer) { uint32_t muteCount = 1; @@ -1607,7 +1606,7 @@ void Player::addExperience(Creature* source, uint64_t exp, bool sendText /* = fa g_game.changeSpeed(this, 0); g_game.addCreatureHealth(this); - const uint64_t protectionLevel = g_config[ConfigKeysInteger::PROTECTION_LEVEL]; + const uint64_t protectionLevel = getInteger(ConfigManager::PROTECTION_LEVEL); if (prevLevel < protectionLevel && level >= protectionLevel) { g_game.updateCreatureWalkthrough(this); } @@ -1688,7 +1687,7 @@ void Player::removeExperience(uint64_t exp, bool sendText /* = false*/) g_game.changeSpeed(this, 0); g_game.addCreatureHealth(this); - const uint64_t protectionLevel = g_config[ConfigKeysInteger::PROTECTION_LEVEL]; + const uint64_t protectionLevel = getInteger(ConfigManager::PROTECTION_LEVEL); if (oldLevel >= protectionLevel && level < protectionLevel) { g_game.updateCreatureWalkthrough(this); } @@ -2074,13 +2073,13 @@ void Player::addInFightTicks(bool pzlock /*= false*/) } auto condition = - Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_INFIGHT, g_config[ConfigKeysInteger::PZ_LOCKED], 0); + Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_INFIGHT, getInteger(ConfigManager::PZ_LOCKED), 0); addCondition(condition); } bool Player::isAccountManager() const { - return g_config[ConfigKeysBoolean::ACCOUNT_MANAGER] && guid == ACCOUNT_MANAGER_PLAYER_ID; + return getBoolean(ConfigManager::ACCOUNT_MANAGER) && guid == ACCOUNT_MANAGER_PLAYER_ID; } void Player::removeList() @@ -2236,7 +2235,7 @@ ReturnValue Player::queryAdd(int32_t index, const Thing& thing, uint32_t count, } else if (slotPosition & SLOTP_TWO_HAND) { ret = RETURNVALUE_PUTTHISOBJECTINBOTHHANDS; } else if ((slotPosition & SLOTP_RIGHT) || (slotPosition & SLOTP_LEFT)) { - if (!g_config[ConfigKeysBoolean::CLASSIC_EQUIPMENT_SLOTS]) { + if (!getBoolean(ConfigManager::CLASSIC_EQUIPMENT_SLOTS)) { ret = RETURNVALUE_CANNOTBEDRESSED; } else { ret = RETURNVALUE_PUTTHISOBJECTINYOURHAND; @@ -2274,7 +2273,7 @@ ReturnValue Player::queryAdd(int32_t index, const Thing& thing, uint32_t count, case CONST_SLOT_RIGHT: { if (slotPosition & SLOTP_RIGHT) { - if (!g_config[ConfigKeysBoolean::CLASSIC_EQUIPMENT_SLOTS]) { + if (!getBoolean(ConfigManager::CLASSIC_EQUIPMENT_SLOTS)) { if (item->getWeaponType() != WEAPON_SHIELD) { ret = RETURNVALUE_CANNOTBEDRESSED; } else { @@ -2320,7 +2319,7 @@ ReturnValue Player::queryAdd(int32_t index, const Thing& thing, uint32_t count, case CONST_SLOT_LEFT: { if (slotPosition & SLOTP_LEFT) { - if (!g_config[ConfigKeysBoolean::CLASSIC_EQUIPMENT_SLOTS]) { + if (!getBoolean(ConfigManager::CLASSIC_EQUIPMENT_SLOTS)) { WeaponType_t type = item->getWeaponType(); if (type == WEAPON_NONE || type == WEAPON_SHIELD) { ret = RETURNVALUE_CANNOTBEDRESSED; @@ -2380,7 +2379,7 @@ ReturnValue Player::queryAdd(int32_t index, const Thing& thing, uint32_t count, } case CONST_SLOT_AMMO: { - if ((slotPosition & SLOTP_AMMO) || g_config[ConfigKeysBoolean::CLASSIC_EQUIPMENT_SLOTS]) { + if ((slotPosition & SLOTP_AMMO) || getBoolean(ConfigManager::CLASSIC_EQUIPMENT_SLOTS)) { ret = RETURNVALUE_NOERROR; } break; @@ -3132,7 +3131,7 @@ void Player::doAttacking(uint32_t) Item* tool = getWeapon(); const Weapon* weapon = g_weapons->getWeapon(tool); uint32_t delay = getAttackSpeed(); - const bool& classicSpeed = g_config[ConfigKeysBoolean::CLASSIC_ATTACK_SPEED]; + bool classicSpeed = getBoolean(ConfigManager::CLASSIC_ATTACK_SPEED); if (weapon) { if (!weapon->interruptSwing()) { @@ -3163,11 +3162,11 @@ void Player::doAttacking(uint32_t) uint64_t Player::getGainedExperience(Creature* attacker) const { - if (g_config[ConfigKeysBoolean::EXPERIENCE_FROM_PLAYERS]) { + if (getBoolean(ConfigManager::EXPERIENCE_FROM_PLAYERS)) { Player* attackerPlayer = attacker->getPlayer(); if (attackerPlayer && attackerPlayer != this && skillLoss && std::abs(static_cast(attackerPlayer->getLevel() - level)) <= - g_config[ConfigKeysInteger::EXP_FROM_PLAYERS_LEVEL_RANGE]) { + getInteger(ConfigManager::EXP_FROM_PLAYERS_LEVEL_RANGE)) { return std::max(0, std::floor(getLostExperience() * getDamageRatio(attacker) * 0.75)); } } @@ -3484,7 +3483,7 @@ bool Player::onKilledCreature(Creature* target, bool lastHit /* = true*/) if (lastHit && hasCondition(CONDITION_INFIGHT)) { pzLocked = true; auto condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_INFIGHT, - g_config[ConfigKeysInteger::WHITE_SKULL_TIME] * 1000, 0); + getInteger(ConfigManager::WHITE_SKULL_TIME) * 1000, 0); addCondition(condition); } } @@ -3767,15 +3766,14 @@ void Player::addUnjustifiedDead(const Player* attacked) sendTextMessage(MESSAGE_EVENT_ADVANCE, "Warning! The murder of " + attacked->getName() + " was not justified."); - skullTicks += g_config[ConfigKeysInteger::FRAG_TIME]; + skullTicks += getInteger(ConfigManager::FRAG_TIME); if (getSkull() != SKULL_BLACK) { - if (g_config[ConfigKeysInteger::KILLS_TO_BLACK] != 0 && - skullTicks > (g_config[ConfigKeysInteger::KILLS_TO_BLACK] - 1) * g_config[ConfigKeysInteger::FRAG_TIME]) { + if (getInteger(ConfigManager::KILLS_TO_BLACK) != 0 && + skullTicks > (getInteger(ConfigManager::KILLS_TO_BLACK) - 1) * getInteger(ConfigManager::FRAG_TIME)) { setSkull(SKULL_BLACK); - } else if (getSkull() != SKULL_RED && g_config[ConfigKeysInteger::KILLS_TO_RED] != 0 && - skullTicks > - (g_config[ConfigKeysInteger::KILLS_TO_RED] - 1) * g_config[ConfigKeysInteger::FRAG_TIME]) { + } else if (getSkull() != SKULL_RED && getInteger(ConfigManager::KILLS_TO_RED) != 0 && + skullTicks > (getInteger(ConfigManager::KILLS_TO_RED) - 1) * getInteger(ConfigManager::FRAG_TIME)) { setSkull(SKULL_RED); } } @@ -3803,7 +3801,7 @@ bool Player::isPromoted() const double Player::getLostPercent() const { - int64_t deathLosePercent = g_config[ConfigKeysInteger::DEATH_LOSE_PERCENT]; + int64_t deathLosePercent = getInteger(ConfigManager::DEATH_LOSE_PERCENT); if (deathLosePercent != -1) { if (isPromoted()) { deathLosePercent -= 3; @@ -3878,7 +3876,7 @@ bool Player::isInWarList(uint32_t guildId) const bool Player::isPremium() const { - if (g_config[ConfigKeysBoolean::FREE_PREMIUM] || hasFlag(PlayerFlag_IsAlwaysPremium)) { + if (getBoolean(ConfigManager::FREE_PREMIUM) || hasFlag(PlayerFlag_IsAlwaysPremium)) { return true; } @@ -4364,7 +4362,7 @@ size_t Player::getMaxVIPEntries() const return group->maxVipEntries; } - return g_config[isPremium() ? ConfigKeysInteger::VIP_PREMIUM_LIMIT : ConfigKeysInteger::VIP_FREE_LIMIT]; + return getInteger(isPremium() ? ConfigManager::VIP_PREMIUM_LIMIT : ConfigManager::VIP_FREE_LIMIT); } size_t Player::getMaxDepotItems() const @@ -4373,7 +4371,7 @@ size_t Player::getMaxDepotItems() const return group->maxDepotItems; } - return g_config[isPremium() ? ConfigKeysInteger::DEPOT_PREMIUM_LIMIT : ConfigKeysInteger::DEPOT_FREE_LIMIT]; + return getInteger(isPremium() ? ConfigManager::DEPOT_PREMIUM_LIMIT : ConfigManager::DEPOT_FREE_LIMIT); } std::forward_list Player::getMuteConditions() const diff --git a/src/protocolgame.cpp b/src/protocolgame.cpp index 8da218f..ee8c0a9 100644 --- a/src/protocolgame.cpp +++ b/src/protocolgame.cpp @@ -14,7 +14,6 @@ #include "player.h" #include "scheduler.h" -extern ConfigManager g_config; extern CreatureEvents* g_creatureEvents; extern Chat* g_chat; @@ -86,7 +85,7 @@ std::size_t clientLogin(const Player& player) cleanupList(priorityWaitList); cleanupList(waitList); - const uint32_t maxPlayers = static_cast(g_config[ConfigKeysInteger::MAX_PLAYERS]); + const uint32_t maxPlayers = static_cast(getInteger(ConfigManager::MAX_PLAYERS)); if (maxPlayers == 0 || (priorityWaitList.empty() && waitList.empty() && g_game.getPlayersOnline() < maxPlayers)) { return 0; } @@ -135,8 +134,8 @@ void ProtocolGame::login(uint32_t characterId, uint32_t accountId, OperatingSyst // dispatcher thread Player* foundPlayer = g_game.getPlayerByGUID(characterId); const bool isAccountManager = - g_config[ConfigKeysBoolean::ACCOUNT_MANAGER] && characterId == ACCOUNT_MANAGER_PLAYER_ID; - if (!foundPlayer || g_config[ConfigKeysBoolean::ALLOW_CLONES] || isAccountManager) { + getBoolean(ConfigManager::ACCOUNT_MANAGER) && characterId == ACCOUNT_MANAGER_PLAYER_ID; + if (!foundPlayer || getBoolean(ConfigManager::ALLOW_CLONES) || isAccountManager) { player = new Player(getThis()); player->setGUID(characterId); @@ -163,7 +162,7 @@ void ProtocolGame::login(uint32_t characterId, uint32_t accountId, OperatingSyst return; } - if (g_config[ConfigKeysBoolean::ONE_PLAYER_ON_ACCOUNT] && !isAccountManager && + if (getBoolean(ConfigManager::ONE_PLAYER_ON_ACCOUNT) && !isAccountManager && player->getAccountType() < ACCOUNT_TYPE_GAMEMASTER && g_game.getPlayerByAccount(player->getAccount())) { disconnectClient("You may only login with one character\nof your account at the same time."); return; @@ -227,7 +226,7 @@ void ProtocolGame::login(uint32_t characterId, uint32_t accountId, OperatingSyst player->lastLoginSaved = std::max(time(nullptr), player->lastLoginSaved + 1); acceptPackets = true; } else { - if (eventConnect != 0 || !g_config[ConfigKeysBoolean::REPLACE_KICK_ON_LOGIN]) { + if (eventConnect != 0 || !getBoolean(ConfigManager::REPLACE_KICK_ON_LOGIN)) { // Already trying to connect disconnectClient("You are already logged in."); return; @@ -347,7 +346,7 @@ void ProtocolGame::onRecvFirstMessage(NetworkMessage& msg) auto characterName = msg.getString(); auto password = msg.getString(); - const auto accountManager = g_config[ConfigKeysBoolean::ACCOUNT_MANAGER]; + bool accountManager = getBoolean(ConfigManager::ACCOUNT_MANAGER); if (accountManager && accountName.empty() && password.empty()) { accountName = ACCOUNT_MANAGER_ACCOUNT_NAME; password = ACCOUNT_MANAGER_ACCOUNT_PASSWORD; @@ -2332,7 +2331,7 @@ void ProtocolGame::sendOutfitWindow() protocolOutfits.emplace_back("Gamemaster", 75, 0); } - size_t maxProtocolOutfits = static_cast(g_config[ConfigKeysInteger::MAX_PROTOCOL_OUTFITS]); + size_t maxProtocolOutfits = static_cast(getInteger(ConfigManager::MAX_PROTOCOL_OUTFITS)); if (isOTCv8) { maxProtocolOutfits = std::numeric_limits::max(); } @@ -2704,7 +2703,7 @@ void ProtocolGame::parseExtendedOpcode(NetworkMessage& msg) void ProtocolGame::sendOTCv8Features() { - const auto& features = g_config.getOTCFeatures(); + const auto& features = ConfigManager::getOTCFeatures(); auto msg = getOutputBuffer(1024); msg->addByte(0x43); diff --git a/src/protocollogin.cpp b/src/protocollogin.cpp index 418f105..ba530dd 100644 --- a/src/protocollogin.cpp +++ b/src/protocollogin.cpp @@ -15,7 +15,6 @@ #include -extern ConfigManager g_config; extern Game g_game; void ProtocolLogin::disconnectClient(std::string_view message) @@ -37,7 +36,7 @@ void ProtocolLogin::getCharacterList(std::string_view accountName, std::string_v auto output = OutputMessagePool::getOutputMessage(); - auto motd = g_config[ConfigKeysString::MOTD]; + auto motd = getString(ConfigManager::MOTD); if (!motd.empty()) { // Add MOTD output->addByte(0x14); @@ -48,9 +47,9 @@ void ProtocolLogin::getCharacterList(std::string_view accountName, std::string_v output->addByte(0x64); uint8_t size = std::min(std::numeric_limits::max(), account.characters.size()); - auto IP = getIP(g_config[ConfigKeysString::IP]); - auto serverName = g_config[ConfigKeysString::SERVER_NAME]; - const auto& gamePort = g_config[ConfigKeysInteger::GAME_PORT]; + auto IP = getIP(getString(ConfigManager::IP)); + auto serverName = getString(ConfigManager::SERVER_NAME); + auto gamePort = getInteger(ConfigManager::GAME_PORT); output->addByte(size); for (uint8_t i = 0; i < size; i++) { output->addString(account.characters[i]); @@ -60,7 +59,7 @@ void ProtocolLogin::getCharacterList(std::string_view accountName, std::string_v } // Add premium days - if (g_config[ConfigKeysBoolean::FREE_PREMIUM]) { + if (getBoolean(ConfigManager::FREE_PREMIUM)) { output->add(0xFFFF); // client displays free premium } else { auto currentTime = time(nullptr); @@ -149,7 +148,7 @@ void ProtocolLogin::onRecvFirstMessage(NetworkMessage& msg) const bool accountNameEmpty = accountName.empty(); const bool passwordEmpty = password.empty(); - if (g_config[ConfigKeysBoolean::ACCOUNT_MANAGER] && accountNameEmpty && passwordEmpty) { + if (getBoolean(ConfigManager::ACCOUNT_MANAGER) && accountNameEmpty && passwordEmpty) { g_dispatcher.addTask([=, thisPtr = std::static_pointer_cast(shared_from_this())]() { thisPtr->getCharacterList(ACCOUNT_MANAGER_ACCOUNT_NAME, ACCOUNT_MANAGER_ACCOUNT_PASSWORD); }); diff --git a/src/protocolstatus.cpp b/src/protocolstatus.cpp index 952d7fa..99db884 100644 --- a/src/protocolstatus.cpp +++ b/src/protocolstatus.cpp @@ -9,7 +9,6 @@ #include "game.h" #include "outputmessage.h" -extern ConfigManager g_config; extern Game g_game; std::map ProtocolStatus::ipConnectMap; @@ -32,10 +31,10 @@ void ProtocolStatus::onRecvFirstMessage(NetworkMessage& msg) uint32_t ip = getIP(); if (ip != 0x0100007F) { std::string ipStr = convertIPToString(ip); - if (ipStr != g_config[ConfigKeysString::IP]) { + if (ipStr != getString(ConfigManager::IP)) { std::map::const_iterator it = ipConnectMap.find(ip); if (it != ipConnectMap.end() && - (OTSYS_TIME() < (it->second + g_config[ConfigKeysInteger::STATUSQUERY_TIMEOUT]))) { + (OTSYS_TIME() < (it->second + getInteger(ConfigManager::STATUSQUERY_TIMEOUT)))) { disconnect(); return; } @@ -92,22 +91,22 @@ void ProtocolStatus::sendStatusString() pugi::xml_node serverinfo = tsqp.append_child("serverinfo"); uint64_t uptime = (OTSYS_TIME() - ProtocolStatus::start) / 1000; serverinfo.append_attribute("uptime") = std::to_string(uptime).c_str(); - serverinfo.append_attribute("ip") = g_config[ConfigKeysString::IP].data(); - serverinfo.append_attribute("servername") = g_config[ConfigKeysString::SERVER_NAME].data(); - serverinfo.append_attribute("port") = std::to_string(g_config[ConfigKeysInteger::LOGIN_PORT]).data(); - serverinfo.append_attribute("location") = g_config[ConfigKeysString::LOCATION].data(); - serverinfo.append_attribute("url") = g_config[ConfigKeysString::URL].data(); + serverinfo.append_attribute("ip") = getString(ConfigManager::IP).data(); + serverinfo.append_attribute("servername") = getString(ConfigManager::SERVER_NAME).data(); + serverinfo.append_attribute("port") = std::to_string(getInteger(ConfigManager::LOGIN_PORT)).c_str(); + serverinfo.append_attribute("location") = getString(ConfigManager::LOCATION).data(); + serverinfo.append_attribute("url") = getString(ConfigManager::URL).data(); serverinfo.append_attribute("server") = STATUS_SERVER_NAME; serverinfo.append_attribute("version") = STATUS_SERVER_VERSION; serverinfo.append_attribute("client") = CLIENT_VERSION_STR; pugi::xml_node owner = tsqp.append_child("owner"); - owner.append_attribute("name") = g_config[ConfigKeysString::OWNER_NAME].data(); - owner.append_attribute("email") = g_config[ConfigKeysString::OWNER_EMAIL].data(); + owner.append_attribute("name") = getString(ConfigManager::OWNER_NAME).data(); + owner.append_attribute("email") = getString(ConfigManager::OWNER_EMAIL).data(); pugi::xml_node players = tsqp.append_child("players"); players.append_attribute("online") = std::to_string(g_game.getPlayersOnline()).c_str(); - players.append_attribute("max") = std::to_string(g_config[ConfigKeysInteger::MAX_PLAYERS]).c_str(); + players.append_attribute("max") = std::to_string(getInteger(ConfigManager::MAX_PLAYERS)).c_str(); players.append_attribute("peak") = std::to_string(g_game.getPlayersRecord()).c_str(); pugi::xml_node monsters = tsqp.append_child("monsters"); @@ -117,15 +116,15 @@ void ProtocolStatus::sendStatusString() npcs.append_attribute("total") = std::to_string(g_game.getNpcsOnline()).c_str(); pugi::xml_node rates = tsqp.append_child("rates"); - rates.append_attribute("experience") = std::to_string(g_config[ConfigKeysInteger::RATE_EXPERIENCE]).c_str(); - rates.append_attribute("skill") = std::to_string(g_config[ConfigKeysInteger::RATE_SKILL]).c_str(); - rates.append_attribute("loot") = std::to_string(g_config[ConfigKeysInteger::RATE_LOOT]).c_str(); - rates.append_attribute("magic") = std::to_string(g_config[ConfigKeysInteger::RATE_MAGIC]).c_str(); - rates.append_attribute("spawn") = std::to_string(g_config[ConfigKeysInteger::RATE_SPAWN]).c_str(); + rates.append_attribute("experience") = std::to_string(getInteger(ConfigManager::RATE_EXPERIENCE)).c_str(); + rates.append_attribute("skill") = std::to_string(getInteger(ConfigManager::RATE_SKILL)).c_str(); + rates.append_attribute("loot") = std::to_string(getInteger(ConfigManager::RATE_LOOT)).c_str(); + rates.append_attribute("magic") = std::to_string(getInteger(ConfigManager::RATE_MAGIC)).c_str(); + rates.append_attribute("spawn") = std::to_string(getInteger(ConfigManager::RATE_SPAWN)).c_str(); pugi::xml_node map = tsqp.append_child("map"); - map.append_attribute("name") = g_config[ConfigKeysString::MAP_NAME].data(); - map.append_attribute("author") = g_config[ConfigKeysString::MAP_AUTHOR].data(); + map.append_attribute("name") = getString(ConfigManager::MAP_NAME).data(); + map.append_attribute("author") = getString(ConfigManager::MAP_AUTHOR).data(); uint32_t mapWidth, mapHeight; g_game.getMapDimensions(mapWidth, mapHeight); @@ -133,7 +132,7 @@ void ProtocolStatus::sendStatusString() map.append_attribute("height") = std::to_string(mapHeight).c_str(); pugi::xml_node motd = tsqp.append_child("motd"); - motd.text() = g_config[ConfigKeysString::MOTD].data(); + motd.text() = getString(ConfigManager::MOTD).data(); std::ostringstream ss; doc.save(ss, "", pugi::format_raw); @@ -150,36 +149,36 @@ void ProtocolStatus::sendInfo(uint16_t requestedInfo, std::string_view character if (requestedInfo & REQUEST_BASIC_SERVER_INFO) { output->addByte(0x10); - output->addString(g_config[ConfigKeysString::SERVER_NAME]); - output->addString(g_config[ConfigKeysString::IP]); - output->addString(std::to_string(g_config[ConfigKeysInteger::LOGIN_PORT])); + output->addString(getString(ConfigManager::SERVER_NAME)); + output->addString(getString(ConfigManager::IP)); + output->addString(std::to_string(getInteger(ConfigManager::LOGIN_PORT))); } if (requestedInfo & REQUEST_OWNER_SERVER_INFO) { output->addByte(0x11); - output->addString(g_config[ConfigKeysString::OWNER_NAME]); - output->addString(g_config[ConfigKeysString::OWNER_EMAIL]); + output->addString(getString(ConfigManager::OWNER_NAME)); + output->addString(getString(ConfigManager::OWNER_EMAIL)); } if (requestedInfo & REQUEST_MISC_SERVER_INFO) { output->addByte(0x12); - output->addString(g_config[ConfigKeysString::MOTD]); - output->addString(g_config[ConfigKeysString::LOCATION]); - output->addString(g_config[ConfigKeysString::URL]); + output->addString(getString(ConfigManager::MOTD)); + output->addString(getString(ConfigManager::LOCATION)); + output->addString(getString(ConfigManager::URL)); output->add((OTSYS_TIME() - ProtocolStatus::start) / 1000); } if (requestedInfo & REQUEST_PLAYERS_INFO) { output->addByte(0x20); output->add(g_game.getPlayersOnline()); - output->add(g_config[ConfigKeysInteger::MAX_PLAYERS]); + output->add(getInteger(ConfigManager::MAX_PLAYERS)); output->add(g_game.getPlayersRecord()); } if (requestedInfo & REQUEST_MAP_INFO) { output->addByte(0x30); - output->addString(g_config[ConfigKeysString::MAP_NAME]); - output->addString(g_config[ConfigKeysString::MAP_AUTHOR]); + output->addString(getString(ConfigManager::MAP_NAME)); + output->addString(getString(ConfigManager::MAP_AUTHOR)); uint32_t mapWidth, mapHeight; g_game.getMapDimensions(mapWidth, mapHeight); output->add(static_cast(mapWidth)); diff --git a/src/raids.cpp b/src/raids.cpp index c8da8d2..cb7d675 100644 --- a/src/raids.cpp +++ b/src/raids.cpp @@ -12,7 +12,6 @@ #include "scheduler.h" extern Game g_game; -extern ConfigManager g_config; Raids::Raids() { scriptInterface.initState(); } diff --git a/src/script.cpp b/src/script.cpp index 78bd6af..6a2de4c 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -10,7 +10,6 @@ #include extern LuaEnvironment g_luaEnvironment; -extern ConfigManager g_config; Scripts::Scripts() : scriptInterface("Scripts Interface") { scriptInterface.initState(); } @@ -26,7 +25,7 @@ bool Scripts::loadScripts(const std::string& folderName, bool isLib, bool reload return false; } - const bool& scriptsConsoleLogs = g_config[ConfigKeysBoolean::SCRIPTS_CONSOLE_LOGS]; + bool scriptsConsoleLogs = getBoolean(ConfigManager::SCRIPTS_CONSOLE_LOGS); std::vector disabled = {}, loaded = {}, reloaded = {}; fs::recursive_directory_iterator endit; diff --git a/src/server.cpp b/src/server.cpp index 7ba4584..7941490 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -10,7 +10,6 @@ #include "outputmessage.h" #include "scheduler.h" -extern ConfigManager g_config; Ban g_bans; ServiceManager::~ServiceManager() { stop(); } @@ -142,11 +141,11 @@ void ServicePort::open(uint16_t port) pendingStart = false; try { - if (g_config[ConfigKeysBoolean::BIND_ONLY_GLOBAL_ADDRESS]) { + if (getBoolean(ConfigManager::BIND_ONLY_GLOBAL_ADDRESS)) { acceptor.reset(new boost::asio::ip::tcp::acceptor( io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::address(boost::asio::ip::address_v4::from_string( - std::string{g_config[ConfigKeysString::IP]})), + std::string{getString(ConfigManager::IP)})), serverPort))); } else { acceptor.reset(new boost::asio::ip::tcp::acceptor( diff --git a/src/signals.cpp b/src/signals.cpp index b9ca5e5..b3aeaaa 100644 --- a/src/signals.cpp +++ b/src/signals.cpp @@ -26,7 +26,6 @@ extern Scheduler g_scheduler; extern DatabaseTasks g_databaseTasks; extern Dispatcher g_dispatcher; -extern ConfigManager g_config; extern Actions* g_actions; extern Monsters g_monsters; extern TalkActions* g_talkActions; @@ -71,7 +70,7 @@ void sighupHandler() g_actions->reload(); std::cout << "Reloaded actions." << std::endl; - g_config.load(); + ConfigManager::load(); std::cout << "Reloaded config." << std::endl; g_creatureEvents->reload(); diff --git a/src/spawn.cpp b/src/spawn.cpp index 0df7134..e457bd2 100644 --- a/src/spawn.cpp +++ b/src/spawn.cpp @@ -12,7 +12,6 @@ #include "pugicast.h" #include "scheduler.h" -extern ConfigManager g_config; extern Monsters g_monsters; extern Game g_game; extern Events* g_events; @@ -371,7 +370,7 @@ void Spawn::checkSpawn() continue; } - if (++spawnCount >= g_config[ConfigKeysInteger::RATE_SPAWN]) { + if (++spawnCount >= getInteger(ConfigManager::RATE_SPAWN)) { break; } } diff --git a/src/spells.cpp b/src/spells.cpp index 6ed694d..50f7aaa 100644 --- a/src/spells.cpp +++ b/src/spells.cpp @@ -17,7 +17,6 @@ extern Game g_game; extern Spells* g_spells; extern Events* g_events; extern Monsters g_monsters; -extern ConfigManager g_config; extern LuaEnvironment g_luaEnvironment; Spells::Spells() { scriptInterface.initState(); } @@ -1079,7 +1078,7 @@ bool RuneSpell::executeUse(Player* player, Item* item, const Position&, Thing* t } } - if (hasCharges && item && g_config[ConfigKeysBoolean::REMOVE_RUNE_CHARGES]) { + if (hasCharges && item && getBoolean(ConfigManager::REMOVE_RUNE_CHARGES)) { int32_t newCount = std::max(0, item->getItemCount() - 1); g_game.transformItem(item, item->getID(), newCount); } diff --git a/src/tile.cpp b/src/tile.cpp index e42df7e..74bf986 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -17,7 +17,6 @@ extern Game g_game; extern MoveEvents* g_moveEvents; -extern ConfigManager g_config; StaticTile real_nullptr_tile(0xFFFF, 0xFFFF, 0xFF); Tile& Tile::nullptr_tile = real_nullptr_tile; @@ -367,7 +366,7 @@ void Tile::onAddTileItem(Item* item) spectator->onAddTileItem(this, cylinderMapPos); } - if ((!hasFlag(TILESTATE_PROTECTIONZONE) || g_config[ConfigKeysBoolean::CLEAN_PROTECTION_ZONES]) && + if ((!hasFlag(TILESTATE_PROTECTIONZONE) || getBoolean(ConfigManager::CLEAN_PROTECTION_ZONES)) && item->isCleanable()) { if (!dynamic_cast(this)) { g_game.addTileToClean(this); @@ -415,7 +414,7 @@ void Tile::onRemoveTileItem(const SpectatorVec& spectators, const std::vectoronRemoveTileItem(this, cylinderMapPos, iType, item); } - if (!hasFlag(TILESTATE_PROTECTIONZONE) || g_config[ConfigKeysBoolean::CLEAN_PROTECTION_ZONES]) { + if (!hasFlag(TILESTATE_PROTECTIONZONE) || getBoolean(ConfigManager::CLEAN_PROTECTION_ZONES)) { auto items = getItemList(); if (!items || items->empty()) { g_game.removeTileToClean(this); diff --git a/src/tools.cpp b/src/tools.cpp index f6d3b5d..d23e089 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -7,8 +7,6 @@ #include "configmanager.h" -extern ConfigManager g_config; - void printXMLError(std::string_view where, std::string_view fileName, const pugi::xml_parse_result& result) { std::cout << '[' << where << "] Failed to load " << fileName << ": " << result.description() << std::endl; diff --git a/src/vocation.h b/src/vocation.h index b464697..be2696b 100644 --- a/src/vocation.h +++ b/src/vocation.h @@ -4,6 +4,7 @@ #ifndef FS_VOCATION_H #define FS_VOCATION_H +#include "configmanager.h" #include "enums.h" #include "item.h" @@ -42,6 +43,14 @@ class Vocation bool allowsPvp() const { return allowPvp; } + bool getMagicShield() const + { + if (!getBoolean(ConfigManager::MANASHIELD_BREAKABLE)) { + return false; + } + return magicShield; + } + float meleeDamageMultiplier = 1.0f; float distDamageMultiplier = 1.0f; float defenseMultiplier = 1.0f; @@ -76,6 +85,8 @@ class Vocation uint8_t clientId = 0; bool allowPvp = true; + + bool magicShield = false; }; using VocationMap = std::map; diff --git a/src/weapons.cpp b/src/weapons.cpp index b6225c6..c36f9b0 100644 --- a/src/weapons.cpp +++ b/src/weapons.cpp @@ -13,7 +13,6 @@ extern Game g_game; extern Vocations g_vocations; -extern ConfigManager g_config; extern Weapons* g_weapons; Weapons::Weapons() { scriptInterface.initState(); } @@ -412,14 +411,14 @@ void Weapon::onUsedWeapon(Player* player, Item* item, Tile* destTile) const switch (action) { case WEAPONACTION_REMOVECOUNT: - if (g_config[ConfigKeysBoolean::REMOVE_WEAPON_AMMO]) { + if (getBoolean(ConfigManager::REMOVE_WEAPON_AMMO)) { Weapon::decrementItemCount(item); } break; case WEAPONACTION_REMOVECHARGE: { uint16_t charges = item->getCharges(); - if (charges != 0 && g_config[ConfigKeysBoolean::REMOVE_WEAPON_CHARGES]) { + if (charges != 0 && getBoolean(ConfigManager::REMOVE_WEAPON_CHARGES)) { g_game.transformItem(item, item->getID(), charges - 1); } break;