diff --git a/src/common/Configuration/Config.cpp b/src/common/Configuration/Config.cpp index ddaab7dee61..888aa6ecef3 100644 --- a/src/common/Configuration/Config.cpp +++ b/src/common/Configuration/Config.cpp @@ -25,11 +25,13 @@ using namespace boost::property_tree; -bool ConfigMgr::LoadInitial(std::string const& file, std::string& error) +bool ConfigMgr::LoadInitial(std::string const& file, std::vector args, + std::string& error) { std::lock_guard lock(_configLock); _filename = file; + _args = args; try { @@ -65,7 +67,7 @@ ConfigMgr* ConfigMgr::instance() bool ConfigMgr::Reload(std::string& error) { - return LoadInitial(_filename, error); + return LoadInitial(_filename, std::move(_args), error); } template diff --git a/src/common/Configuration/Config.h b/src/common/Configuration/Config.h index 10113cd88d3..573bc7b4a15 100644 --- a/src/common/Configuration/Config.h +++ b/src/common/Configuration/Config.h @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -35,7 +36,8 @@ class TC_COMMON_API ConfigMgr public: /// Method used only for loading main configuration files (authserver.conf and worldserver.conf) - bool LoadInitial(std::string const& file, std::string& error); + bool LoadInitial(std::string const& file, std::vector args, + std::string& error); static ConfigMgr* instance(); @@ -47,10 +49,12 @@ public: float GetFloatDefault(std::string const& name, float def) const; std::string const& GetFilename(); + std::vector const& GetArguments() const { return _args; } std::list GetKeysByString(std::string const& name); private: std::string _filename; + std::vector _args; boost::property_tree::ptree _config; std::mutex _configLock; diff --git a/src/common/Cryptography/Authentication/WorldPacketCrypt.h b/src/common/Cryptography/Authentication/WorldPacketCrypt.h index 0e94abd376c..e9e6bda9135 100644 --- a/src/common/Cryptography/Authentication/WorldPacketCrypt.h +++ b/src/common/Cryptography/Authentication/WorldPacketCrypt.h @@ -23,7 +23,7 @@ class BigNumber; -class WorldPacketCrypt : public PacketCrypt +class TC_COMMON_API WorldPacketCrypt : public PacketCrypt { public: WorldPacketCrypt(); diff --git a/src/common/Define.h b/src/common/Define.h index d3348a08640..4eb9362e07c 100644 --- a/src/common/Define.h +++ b/src/common/Define.h @@ -128,6 +128,12 @@ # define TC_SHARED_API TC_API_IMPORT #endif +#ifdef TRINITY_API_EXPORT_IPC +# define TC_IPC_API TC_API_EXPORT +#else +# define TC_IPC_API TC_API_IMPORT +#endif + #ifdef TRINITY_API_EXPORT_GAME # define TC_GAME_API TC_API_EXPORT #else diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp index a53187ad737..1392900fb9a 100644 --- a/src/server/authserver/Main.cpp +++ b/src/server/authserver/Main.cpp @@ -36,12 +36,14 @@ #include "GitRevision.h" #include "Util.h" #include +#include #include #include #include using boost::asio::ip::tcp; using namespace boost::program_options; +namespace fs = boost::filesystem; #ifndef _TRINITY_REALM_CONFIG # define _TRINITY_REALM_CONFIG "authserver.conf" @@ -69,7 +71,7 @@ void StopDB(); void SignalHandler(const boost::system::error_code& error, int signalNumber); void KeepDatabaseAliveHandler(const boost::system::error_code& error); void BanExpiryHandler(boost::system::error_code const& error); -variables_map GetConsoleArguments(int argc, char** argv, std::string& configFile, std::string& configService); +variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, std::string& configService); boost::asio::io_service* _ioService; boost::asio::deadline_timer* _dbPingTimer; @@ -81,7 +83,7 @@ int main(int argc, char** argv) { signal(SIGABRT, &Trinity::AbortHandler); - std::string configFile = _TRINITY_REALM_CONFIG; + auto configFile = fs::absolute(_TRINITY_REALM_CONFIG); std::string configService; auto vm = GetConsoleArguments(argc, argv, configFile, configService); // exit if help or version is enabled @@ -98,7 +100,9 @@ int main(int argc, char** argv) #endif std::string configError; - if (!sConfigMgr->LoadInitial(configFile, configError)) + if (!sConfigMgr->LoadInitial(configFile.generic_string(), + std::vector(argv, argv + argc), + configError)) { printf("Error in config file: %s\n", configError.c_str()); return 1; @@ -109,7 +113,7 @@ int main(int argc, char** argv) TC_LOG_INFO("server.authserver", "%s (authserver)", GitRevision::GetFullVersion()); TC_LOG_INFO("server.authserver", " to stop.\n"); - TC_LOG_INFO("server.authserver", "Using configuration file %s.", configFile.c_str()); + TC_LOG_INFO("server.authserver", "Using configuration file %s.", sConfigMgr->GetFilename().c_str()); TC_LOG_INFO("server.authserver", "Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION)); TC_LOG_INFO("server.authserver", "Using Boost version: %i.%i.%i", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100); @@ -286,13 +290,14 @@ void ServiceStatusWatcher(boost::system::error_code const& error) } #endif -variables_map GetConsoleArguments(int argc, char** argv, std::string& configFile, std::string& configService) +variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, std::string& configService) { options_description all("Allowed options"); all.add_options() ("help,h", "print usage message") ("version,v", "print version build info") - ("config,c", value(&configFile)->default_value(_TRINITY_REALM_CONFIG), "use as configuration file") + ("config,c", value(&configFile)->default_value(fs::absolute(_TRINITY_REALM_CONFIG)), + "use as configuration file") ; #if PLATFORM == PLATFORM_WINDOWS options_description win("Windows platform specific options"); diff --git a/src/server/bnetserver/Main.cpp b/src/server/bnetserver/Main.cpp index 58a28dcaefe..6f6b792f91b 100644 --- a/src/server/bnetserver/Main.cpp +++ b/src/server/bnetserver/Main.cpp @@ -40,12 +40,14 @@ #include #include #include +#include #include #include #include using boost::asio::ip::tcp; using namespace boost::program_options; +namespace fs = boost::filesystem; #ifndef _TRINITY_BNET_CONFIG # define _TRINITY_BNET_CONFIG "bnetserver.conf" @@ -72,7 +74,7 @@ bool StartDB(); void StopDB(); void SignalHandler(const boost::system::error_code& error, int signalNumber); void KeepDatabaseAliveHandler(const boost::system::error_code& error); -variables_map GetConsoleArguments(int argc, char** argv, std::string& configFile); +variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile); boost::asio::io_service _ioService; boost::asio::deadline_timer _dbPingTimer(_ioService); @@ -80,14 +82,16 @@ uint32 _dbPingInterval; int main(int argc, char** argv) { - std::string configFile = _TRINITY_BNET_CONFIG; + auto configFile = fs::absolute(_TRINITY_BNET_CONFIG); auto vm = GetConsoleArguments(argc, argv, configFile); // exit if help is enabled if (vm.count("help")) return 0; std::string configError; - if (!sConfigMgr->LoadInitial(configFile, configError)) + if (!sConfigMgr->LoadInitial(configFile.generic_string(), + std::vector(argv, argv + argc), + configError)) { printf("Error in config file: %s\n", configError.c_str()); return 1; @@ -95,7 +99,7 @@ int main(int argc, char** argv) TC_LOG_INFO("server.bnetserver", "%s (bnetserver)", GitRevision::GetFullVersion()); TC_LOG_INFO("server.bnetserver", " to stop.\n"); - TC_LOG_INFO("server.bnetserver", "Using configuration file %s.", configFile.c_str()); + TC_LOG_INFO("server.bnetserver", "Using configuration file %s.", sConfigMgr->GetFilename().c_str()); TC_LOG_INFO("server.bnetserver", "Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION)); TC_LOG_INFO("server.bnetserver", "Using Boost version: %i.%i.%i", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100); @@ -217,12 +221,13 @@ void KeepDatabaseAliveHandler(const boost::system::error_code& error) } } -variables_map GetConsoleArguments(int argc, char** argv, std::string& configFile) +variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile) { options_description all("Allowed options"); all.add_options() ("help,h", "print usage message") - ("config,c", value(&configFile)->default_value(_TRINITY_BNET_CONFIG), "use as configuration file") + ("config,c", value(&configFile)->default_value(fs::absolute(_TRINITY_BNET_CONFIG)), + "use as configuration file") ; variables_map variablesMap; try diff --git a/src/server/game/Accounts/BattlenetAccountMgr.h b/src/server/game/Accounts/BattlenetAccountMgr.h index 402b7f8fbca..d849a36a413 100644 --- a/src/server/game/Accounts/BattlenetAccountMgr.h +++ b/src/server/game/Accounts/BattlenetAccountMgr.h @@ -29,13 +29,13 @@ namespace Battlenet { namespace AccountMgr { - AccountOpResult CreateBattlenetAccount(std::string email, std::string password); - AccountOpResult ChangePassword(uint32 accountId, std::string newPassword); - bool CheckPassword(uint32 accountId, std::string password); + TC_GAME_API AccountOpResult CreateBattlenetAccount(std::string email, std::string password); + TC_GAME_API AccountOpResult ChangePassword(uint32 accountId, std::string newPassword); + TC_GAME_API bool CheckPassword(uint32 accountId, std::string password); - uint32 GetId(std::string const& username); - bool GetName(uint32 accountId, std::string& name); - uint32 GetIdByGameAccount(uint32 gameAccountId); + TC_GAME_API uint32 GetId(std::string const& username); + TC_GAME_API bool GetName(uint32 accountId, std::string& name); + TC_GAME_API uint32 GetIdByGameAccount(uint32 gameAccountId); std::string CalculateShaPassHash(std::string const& name, std::string const& password); } diff --git a/src/server/game/DataStores/DBCStores.h b/src/server/game/DataStores/DBCStores.h index 9a165c4c239..ffb6711ea91 100644 --- a/src/server/game/DataStores/DBCStores.h +++ b/src/server/game/DataStores/DBCStores.h @@ -80,7 +80,7 @@ TC_GAME_API LFGDungeonEntry const* GetLFGDungeon(uint32 mapId, Difficulty diffic uint32 GetDefaultMapLight(uint32 mapId); -std::set const& GetPhasesForGroup(uint32 group); +TC_GAME_API std::set const& GetPhasesForGroup(uint32 group); typedef std::unordered_multimap SkillRaceClassInfoMap; typedef std::pair SkillRaceClassInfoBounds; diff --git a/src/server/game/DataStores/M2Stores.h b/src/server/game/DataStores/M2Stores.h index 298deb00b26..e8da9ac01e5 100644 --- a/src/server/game/DataStores/M2Stores.h +++ b/src/server/game/DataStores/M2Stores.h @@ -29,7 +29,7 @@ struct FlyByCamera typedef std::vector FlyByCameraCollection; -extern std::unordered_map sFlyByCameraStore; +TC_GAME_API extern std::unordered_map sFlyByCameraStore; void LoadM2Cameras(std::string const& dataPath); diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index 05ecedd14c7..4d9b716760e 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -92,7 +92,7 @@ class ZoneScript; typedef TC_GAME_API std::unordered_map UpdateDataMapType; -class Object +class TC_GAME_API Object { public: virtual ~Object(); diff --git a/src/server/game/Server/BattlenetServerManager.h b/src/server/game/Server/BattlenetServerManager.h index 3892ac5040f..5760ddce845 100644 --- a/src/server/game/Server/BattlenetServerManager.h +++ b/src/server/game/Server/BattlenetServerManager.h @@ -31,7 +31,7 @@ namespace IPC { namespace BattlenetComm { - class ServerManager + class TC_GAME_API ServerManager { ServerManager() : _socket(nullptr) { } diff --git a/src/server/ipc/CMakeLists.txt b/src/server/ipc/CMakeLists.txt index a52f77cff31..883fea1caf9 100644 --- a/src/server/ipc/CMakeLists.txt +++ b/src/server/ipc/CMakeLists.txt @@ -14,11 +14,17 @@ CollectSourceFiles( GroupSources(${CMAKE_CURRENT_SOURCE_DIR}) +add_definitions(-DTRINITY_API_EXPORT_IPC) + add_library(ipc ${PRIVATE_SOURCES}) +CollectIncludeDirectories( + ${CMAKE_CURRENT_SOURCE_DIR} + PUBLIC_INCLUDES) + target_include_directories(ipc PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR} + ${PUBLIC_INCLUDES} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) @@ -32,3 +38,14 @@ set_target_properties(ipc FOLDER "server") +if( BUILD_SHARED_LIBS ) + if( UNIX ) + install(TARGETS ipc + LIBRARY + DESTINATION lib) + elseif( WIN32 ) + install(TARGETS ipc + RUNTIME + DESTINATION "${CMAKE_INSTALL_PREFIX}") + endif() +endif() diff --git a/src/server/ipc/Commands.h b/src/server/ipc/Commands.h index 618e8ca0509..c8b0f792505 100644 --- a/src/server/ipc/Commands.h +++ b/src/server/ipc/Commands.h @@ -67,14 +67,14 @@ namespace zmqpp class message; } -zmqpp::message& operator>>(zmqpp::message& msg, IPC::Header& header); -zmqpp::message& operator>>(zmqpp::message& msg, Battlenet::RealmHandle& realm); -zmqpp::message& operator>>(zmqpp::message& msg, IPC::BattlenetComm::Header& header); -zmqpp::message& operator>>(zmqpp::message& msg, IPC::BattlenetComm::ToonHandle& toonHandle); +TC_IPC_API zmqpp::message& operator>>(zmqpp::message& msg, IPC::Header& header); +TC_IPC_API zmqpp::message& operator>>(zmqpp::message& msg, Battlenet::RealmHandle& realm); +TC_IPC_API zmqpp::message& operator>>(zmqpp::message& msg, IPC::BattlenetComm::Header& header); +TC_IPC_API zmqpp::message& operator>>(zmqpp::message& msg, IPC::BattlenetComm::ToonHandle& toonHandle); -zmqpp::message& operator<<(zmqpp::message& msg, IPC::Header const& header); -zmqpp::message& operator<<(zmqpp::message& msg, Battlenet::RealmHandle const& realm); -zmqpp::message& operator<<(zmqpp::message& msg, IPC::BattlenetComm::Header const& header); -zmqpp::message& operator<<(zmqpp::message& msg, IPC::BattlenetComm::ToonHandle const& toonHandle); +TC_IPC_API zmqpp::message& operator<<(zmqpp::message& msg, IPC::Header const& header); +TC_IPC_API zmqpp::message& operator<<(zmqpp::message& msg, Battlenet::RealmHandle const& realm); +TC_IPC_API zmqpp::message& operator<<(zmqpp::message& msg, IPC::BattlenetComm::Header const& header); +TC_IPC_API zmqpp::message& operator<<(zmqpp::message& msg, IPC::BattlenetComm::ToonHandle const& toonHandle); #endif // _COMMANDS_H diff --git a/src/server/ipc/ZMQTask.h b/src/server/ipc/ZMQTask.h index 6a90fd4d1ff..4a442211d46 100644 --- a/src/server/ipc/ZMQTask.h +++ b/src/server/ipc/ZMQTask.h @@ -27,7 +27,7 @@ This class serves as a base for all long running tasks It is set up to terminate its running task upon receiving "kill" command */ -class ZMQTask +class TC_IPC_API ZMQTask { public: ZMQTask(); diff --git a/src/server/ipc/ZmqContext.cpp b/src/server/ipc/ZmqContext.cpp index bc062de8e88..a3517d971e5 100644 --- a/src/server/ipc/ZmqContext.cpp +++ b/src/server/ipc/ZmqContext.cpp @@ -25,6 +25,12 @@ ZmqContext::~ZmqContext() { } +ZmqContext* ZmqContext::Instance() +{ + static ZmqContext instance; + return &instance; +} + zmqpp::socket* ZmqContext::CreateNewSocket(zmqpp::socket_type type) { std::unique_lock lock(_mutex); diff --git a/src/server/ipc/ZmqContext.h b/src/server/ipc/ZmqContext.h index a762a08fe14..0f0fba75294 100644 --- a/src/server/ipc/ZmqContext.h +++ b/src/server/ipc/ZmqContext.h @@ -18,22 +18,19 @@ #ifndef __ZMQCONTEX_H #define __ZMQCONTEX_H +#include "Common.h" #include #include /* * We need to serialize access to zmq context otherwise stuff blows up. */ -class ZmqContext +class TC_IPC_API ZmqContext { public: - ~ZmqContext(); + static ZmqContext* Instance(); - static ZmqContext* Instance() - { - static ZmqContext instance; - return &instance; - } + ~ZmqContext(); zmqpp::socket* CreateNewSocket(zmqpp::socket_type); void Initialize(); diff --git a/src/server/ipc/ZmqListener.h b/src/server/ipc/ZmqListener.h index b7eaa8f48a3..6ee41a7eab0 100644 --- a/src/server/ipc/ZmqListener.h +++ b/src/server/ipc/ZmqListener.h @@ -21,7 +21,7 @@ #include "ZMQTask.h" #include -class ZmqListener : public ZMQTask +class TC_IPC_API ZmqListener : public ZMQTask { /* * Read broadcasts from remote PUB socket, and forward them to diff --git a/src/server/ipc/ZmqMux.h b/src/server/ipc/ZmqMux.h index 2ff2d97d4aa..bcea3c97ec5 100644 --- a/src/server/ipc/ZmqMux.h +++ b/src/server/ipc/ZmqMux.h @@ -26,7 +26,7 @@ * Multiplexes zmq messages from many threads, * and then passes them to another socket. */ -class ZmqMux : public ZMQTask +class TC_IPC_API ZmqMux : public ZMQTask { public: ZmqMux(std::string from, std::string to); diff --git a/src/server/ipc/ZmqWorker.h b/src/server/ipc/ZmqWorker.h index 21d2d95ac18..1b4b31bbaf9 100644 --- a/src/server/ipc/ZmqWorker.h +++ b/src/server/ipc/ZmqWorker.h @@ -21,7 +21,7 @@ #include "ZMQTask.h" #include -class ZmqWorker : public ZMQTask +class TC_IPC_API ZmqWorker : public ZMQTask { public: ZmqWorker(std::string const& taskUri, std::string const& resUri); diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h index 349d4808ee7..24877a92810 100644 --- a/src/server/shared/Packets/ByteBuffer.h +++ b/src/server/shared/Packets/ByteBuffer.h @@ -51,7 +51,7 @@ public: ~ByteBufferPositionException() throw() { } }; -class ByteBufferSourceException : public ByteBufferException +class TC_SHARED_API ByteBufferSourceException : public ByteBufferException { public: ByteBufferSourceException(size_t pos, size_t size, size_t valueSize); diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index 120c8d7b3bb..f32bb8906fa 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -51,9 +51,11 @@ #include #include #include +#include #include using namespace boost::program_options; +namespace fs = boost::filesystem; #ifndef _TRINITY_CORE_CONFIG #define _TRINITY_CORE_CONFIG "worldserver.conf" @@ -91,14 +93,14 @@ void ClearOnlineAccounts(); void ShutdownCLIThread(std::thread* cliThread); void ShutdownThreadPool(std::vector& threadPool); bool LoadRealmInfo(); -variables_map GetConsoleArguments(int argc, char** argv, std::string& cfg_file, std::string& cfg_service); +variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, std::string& cfg_service); /// Launch the Trinity server extern int main(int argc, char** argv) { signal(SIGABRT, &Trinity::AbortHandler); - std::string configFile = _TRINITY_CORE_CONFIG; + auto configFile = fs::absolute(_TRINITY_CORE_CONFIG); std::string configService; auto vm = GetConsoleArguments(argc, argv, configFile, configService); @@ -116,7 +118,9 @@ extern int main(int argc, char** argv) #endif std::string configError; - if (!sConfigMgr->LoadInitial(configFile, configError)) + if (!sConfigMgr->LoadInitial(configFile.generic_string(), + std::vector(argv, argv + argc), + configError)) { printf("Error in config file: %s\n", configError.c_str()); return 1; @@ -137,7 +141,7 @@ extern int main(int argc, char** argv) TC_LOG_INFO("server.worldserver", " \\/_/\\/_/ \\/_/\\/_/\\/_/\\/_/\\/__/ `/___/> \\"); TC_LOG_INFO("server.worldserver", " C O R E /\\___/"); TC_LOG_INFO("server.worldserver", "http://TrinityCore.org \\/__/\n"); - TC_LOG_INFO("server.worldserver", "Using configuration file %s.", configFile.c_str()); + TC_LOG_INFO("server.worldserver", "Using configuration file %s.", sConfigMgr->GetFilename().c_str()); TC_LOG_INFO("server.worldserver", "Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION)); TC_LOG_INFO("server.worldserver", "Using Boost version: %i.%i.%i", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100); @@ -590,7 +594,7 @@ void ClearOnlineAccounts() /// @} -variables_map GetConsoleArguments(int argc, char** argv, std::string& configFile, std::string& configService) +variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, std::string& configService) { // Silences warning about configService not be used if the OS is not Windows (void)configService; @@ -599,7 +603,8 @@ variables_map GetConsoleArguments(int argc, char** argv, std::string& configFile all.add_options() ("help,h", "print usage message") ("version,v", "print version build info") - ("config,c", value(&configFile)->default_value(_TRINITY_CORE_CONFIG), "use as configuration file") + ("config,c", value(&configFile)->default_value(fs::absolute(_TRINITY_CORE_CONFIG)), + "use as configuration file") ; #ifdef _WIN32 options_description win("Windows platform specific options");