mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-24 14:16:31 +00:00
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:
@@ -19,3 +19,11 @@ MACRO(AC_ADD_SCRIPT_LOADER script_dec include)
|
||||
endif()
|
||||
endif()
|
||||
ENDMACRO()
|
||||
|
||||
#
|
||||
#AC_ADD_CONFIG_FILE
|
||||
#
|
||||
MACRO(AC_ADD_CONFIG_FILE configFilePath)
|
||||
CU_GET_GLOBAL("MODULE_CONFIG_FILE_LIST")
|
||||
CU_ADD_GLOBAL("MODULE_CONFIG_FILE_LIST" "${configFilePath}")
|
||||
ENDMACRO()
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -315,6 +315,7 @@ public:
|
||||
{
|
||||
sLog->outString("Re-Loading config settings...");
|
||||
sWorld->LoadConfigSettings(true);
|
||||
sWorld->LoadModuleConfigSettings();//reload modules config setting
|
||||
sMapMgr->InitializeVisibilityDistanceInfo();
|
||||
handler->SendGlobalGMSysMessage("World config settings reloaded.");
|
||||
return true;
|
||||
|
||||
@@ -213,4 +213,31 @@ if( USE_COREPCH )
|
||||
add_cxx_pch(worldserver ${worldserver_PCH_HDR} ${worldserver_PCH_SRC})
|
||||
endif()
|
||||
|
||||
# handle config file
|
||||
CU_GET_GLOBAL("MODULE_CONFIG_FILE_LIST")
|
||||
FOREACH(configFile ${MODULE_CONFIG_FILE_LIST})
|
||||
if( WIN32 )
|
||||
if ( MSVC )
|
||||
add_custom_command(TARGET worldserver
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${configFile}" ${CMAKE_BINARY_DIR}/bin/$(ConfigurationName)/
|
||||
)
|
||||
elseif ( MINGW )
|
||||
add_custom_command(TARGET worldserver
|
||||
POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${configFile}" ${CMAKE_BINARY_DIR}/bin/
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
install(FILES "${configFile}" DESTINATION ${CONF_DIR})
|
||||
ENDFOREACH()
|
||||
|
||||
CU_GET_GLOBAL("MODULE_CONFIG_FILE_LIST")
|
||||
FOREACH(configFile ${MODULE_CONFIG_FILE_LIST})
|
||||
get_filename_component(file_name ${configFile} NAME_WE)
|
||||
set(CONFIG_LIST ${CONFIG_LIST}${file_name},)
|
||||
ENDFOREACH()
|
||||
add_definitions(-DCONFIG_FILE_LIST="\\"${CONFIG_LIST}\\"")
|
||||
# end handle config file
|
||||
|
||||
CU_RUN_HOOK("AFTER_WORLDSERVER_CMAKE")
|
||||
|
||||
@@ -153,6 +153,9 @@ int Master::Run()
|
||||
// set server offline (not connectable)
|
||||
LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = (flag & ~%u) | %u WHERE id = '%d'", REALM_FLAG_OFFLINE, REALM_FLAG_INVALID, realmID);
|
||||
|
||||
//set module config file list
|
||||
sWorld->SetConfigFileList(CONFIG_FILE_LIST);
|
||||
|
||||
///- Initialize the World
|
||||
sWorld->SetInitialWorldSettings();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user