This commit is contained in:
Aokromes
2016-08-14 10:17:14 +02:00
21 changed files with 100 additions and 53 deletions

View File

@@ -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<std::string> args,
std::string& error)
{
std::lock_guard<std::mutex> 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<class T>

View File

@@ -23,6 +23,7 @@
#include <string>
#include <list>
#include <vector>
#include <mutex>
#include <boost/property_tree/ptree.hpp>
@@ -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<std::string> 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<std::string> const& GetArguments() const { return _args; }
std::list<std::string> GetKeysByString(std::string const& name);
private:
std::string _filename;
std::vector<std::string> _args;
boost::property_tree::ptree _config;
std::mutex _configLock;

View File

@@ -23,7 +23,7 @@
class BigNumber;
class WorldPacketCrypt : public PacketCrypt
class TC_COMMON_API WorldPacketCrypt : public PacketCrypt
{
public:
WorldPacketCrypt();

View File

@@ -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

View File

@@ -36,12 +36,14 @@
#include "GitRevision.h"
#include "Util.h"
#include <iostream>
#include <boost/filesystem/path.hpp>
#include <boost/program_options.hpp>
#include <openssl/opensslv.h>
#include <openssl/crypto.h>
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<std::string>(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", "<Ctrl-C> 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<std::string>(&configFile)->default_value(_TRINITY_REALM_CONFIG), "use <arg> as configuration file")
("config,c", value<fs::path>(&configFile)->default_value(fs::absolute(_TRINITY_REALM_CONFIG)),
"use <arg> as configuration file")
;
#if PLATFORM == PLATFORM_WINDOWS
options_description win("Windows platform specific options");

View File

@@ -40,12 +40,14 @@
#include <cstdlib>
#include <iostream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/program_options.hpp>
#include <openssl/opensslv.h>
#include <openssl/crypto.h>
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<std::string>(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", "<Ctrl-C> 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<std::string>(&configFile)->default_value(_TRINITY_BNET_CONFIG), "use <arg> as configuration file")
("config,c", value<fs::path>(&configFile)->default_value(fs::absolute(_TRINITY_BNET_CONFIG)),
"use <arg> as configuration file")
;
variables_map variablesMap;
try

View File

@@ -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);
}

View File

@@ -80,7 +80,7 @@ TC_GAME_API LFGDungeonEntry const* GetLFGDungeon(uint32 mapId, Difficulty diffic
uint32 GetDefaultMapLight(uint32 mapId);
std::set<uint32> const& GetPhasesForGroup(uint32 group);
TC_GAME_API std::set<uint32> const& GetPhasesForGroup(uint32 group);
typedef std::unordered_multimap<uint32, SkillRaceClassInfoEntry const*> SkillRaceClassInfoMap;
typedef std::pair<SkillRaceClassInfoMap::iterator, SkillRaceClassInfoMap::iterator> SkillRaceClassInfoBounds;

View File

@@ -29,7 +29,7 @@ struct FlyByCamera
typedef std::vector<FlyByCamera> FlyByCameraCollection;
extern std::unordered_map<uint32, FlyByCameraCollection> sFlyByCameraStore;
TC_GAME_API extern std::unordered_map<uint32, FlyByCameraCollection> sFlyByCameraStore;
void LoadM2Cameras(std::string const& dataPath);

View File

@@ -92,7 +92,7 @@ class ZoneScript;
typedef TC_GAME_API std::unordered_map<Player*, UpdateData> UpdateDataMapType;
class Object
class TC_GAME_API Object
{
public:
virtual ~Object();

View File

@@ -31,7 +31,7 @@ namespace IPC
{
namespace BattlenetComm
{
class ServerManager
class TC_GAME_API ServerManager
{
ServerManager() : _socket(nullptr) { }

View File

@@ -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()

View File

@@ -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

View File

@@ -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();

View File

@@ -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<std::mutex> lock(_mutex);

View File

@@ -18,22 +18,19 @@
#ifndef __ZMQCONTEX_H
#define __ZMQCONTEX_H
#include "Common.h"
#include <zmqpp/zmqpp.hpp>
#include <mutex>
/*
* 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();

View File

@@ -21,7 +21,7 @@
#include "ZMQTask.h"
#include <zmqpp/zmqpp.hpp>
class ZmqListener : public ZMQTask
class TC_IPC_API ZmqListener : public ZMQTask
{
/*
* Read broadcasts from remote PUB socket, and forward them to

View File

@@ -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);

View File

@@ -21,7 +21,7 @@
#include "ZMQTask.h"
#include <zmqpp/zmqpp.hpp>
class ZmqWorker : public ZMQTask
class TC_IPC_API ZmqWorker : public ZMQTask
{
public:
ZmqWorker(std::string const& taskUri, std::string const& resUri);

View File

@@ -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);

View File

@@ -51,9 +51,11 @@
#include <openssl/crypto.h>
#include <boost/asio/io_service.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/program_options.hpp>
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<std::thread>& 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<std::string>(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<std::string>(&configFile)->default_value(_TRINITY_CORE_CONFIG), "use <arg> as configuration file")
("config,c", value<fs::path>(&configFile)->default_value(fs::absolute(_TRINITY_CORE_CONFIG)),
"use <arg> as configuration file")
;
#ifdef _WIN32
options_description win("Windows platform specific options");