Core: Easy module conf creation & reload (#931)

* Change the read method of the config of the module.Developers can now easily read the config file in cmake.

e.g. AC_ADD_CONFIG_FILE("${CMAKE_CURRENT_LIST_DIR}/conf/my_first_module.conf.dist")

* Update Master.h

* Update cs_reload.cpp

Command: `.reload config` can now reload the config file of all modules #981
This commit is contained in:
ayase
2018-07-20 03:50:30 +08:00
committed by Barbz
parent 8b1f2ece8a
commit d29a1a3300
6 changed files with 85 additions and 0 deletions

View File

@@ -120,6 +120,8 @@ World::World()
m_CleaningFlags = 0;
m_configFileList = "";
memset(rate_values, 0, sizeof(rate_values));
memset(m_int_configs, 0, sizeof(m_int_configs));
memset(m_bool_configs, 0, sizeof(m_bool_configs));
@@ -414,6 +416,43 @@ bool World::RemoveQueuedPlayer(WorldSession* sess)
return found;
}
void World::LoadModuleConfigSettings()
{
Tokenizer configFileList(GetConfigFileList(), ',');
for (auto i = configFileList.begin(); i != configFileList.end(); i++)
{
std::string configFile = (*i) + std::string(".conf");
std::string conf_path = _CONF_DIR;
std::string cfg_file = conf_path + "/" + configFile;
#if PLATFORM == PLATFORM_WINDOWS
cfg_file = configFile;
#endif
std::string cfg_def_file = cfg_file + ".dist";
// Load .conf.dist config
if (!sConfigMgr->LoadMore(cfg_def_file.c_str()))
{
sLog->outString();
sLog->outError("Module config: Invalid or missing configuration dist file : %s", cfg_def_file.c_str());
sLog->outError("Module config: Verify that the file exists and has \'[worldserver]' written in the top of the file!");
sLog->outError("Module config: Use default settings!");
sLog->outString();
}
// Load .conf config
if (!sConfigMgr->LoadMore(cfg_file.c_str()))
{
sLog->outString();
sLog->outError("Module config: Invalid or missing configuration file : %s", cfg_file.c_str());
sLog->outError("Module config: Verify that the file exists and has \'[worldserver]' written in the top of the file!");
sLog->outError("Module config: Use default settings!");
sLog->outString();
}
}
}
/// Initialize config values
void World::LoadConfigSettings(bool reload)
{
@@ -426,6 +465,7 @@ void World::LoadConfigSettings(bool reload)
}
}
LoadModuleConfigSettings();
sScriptMgr->OnBeforeConfigLoad(reload);
// Reload log levels and filters

View File

@@ -642,6 +642,7 @@ class World
void SetInitialWorldSettings();
void LoadConfigSettings(bool reload = false);
void LoadModuleConfigSettings();
void SendWorldText(int32 string_id, ...);
void SendGlobalText(const char* text, WorldSession* self);
@@ -779,6 +780,9 @@ class World
std::string const& GetRealmName() const { return _realmName; } // pussywizard
void SetRealmName(std::string name) { _realmName = name; } // pussywizard
std::string GetConfigFileList() { return m_configFileList; }
void SetConfigFileList(std::string list) { m_configFileList = list; }
protected:
void _UpdateGameTime();
// callback for UpdateRealmCharacters
@@ -876,6 +880,8 @@ class World
void ProcessQueryCallbacks();
ACE_Future_Set<PreparedQueryResult> m_realmCharCallbacks;
std::string m_configFileList;
};
#define sWorld ACE_Singleton<World, ACE_Null_Mutex>::instance()