Merge remote-tracking branch 'origin/master' into 4.3.4

Conflicts:
	src/server/authserver/Main.cpp
	src/server/authserver/Realms/RealmList.cpp
	src/server/authserver/Realms/RealmList.h
	src/server/authserver/Server/AuthSession.cpp
	src/server/authserver/Server/AuthSocket.h
	src/server/authserver/Server/RealmAcceptor.h
	src/server/game/Accounts/AccountMgr.h
	src/server/game/Achievements/AchievementMgr.cpp
	src/server/game/Achievements/AchievementMgr.h
	src/server/game/Battlegrounds/ArenaTeamMgr.cpp
	src/server/game/Conditions/ConditionMgr.cpp
	src/server/game/DungeonFinding/LFGMgr.h
	src/server/game/Entities/Object/Object.h
	src/server/game/Entities/Player/Player.cpp
	src/server/game/Entities/Player/Player.h
	src/server/game/Entities/Unit/Unit.cpp
	src/server/game/Handlers/BattleGroundHandler.cpp
	src/server/game/Movement/Spline/MoveSplineFlag.h
	src/server/game/Quests/QuestDef.cpp
	src/server/game/Quests/QuestDef.h
	src/server/game/Server/WorldSession.cpp
	src/server/game/Server/WorldSession.h
	src/server/game/Server/WorldSocket.cpp
	src/server/game/Server/WorldSocket.h
	src/server/game/Spells/Spell.cpp
	src/server/scripts/Commands/cs_debug.cpp
	src/server/scripts/OutdoorPvP/OutdoorPvPEP.cpp
	src/server/scripts/Spells/spell_mage.cpp
	src/server/scripts/Spells/spell_rogue.cpp
	src/server/scripts/Spells/spell_shaman.cpp
	src/server/scripts/Spells/spell_warrior.cpp
	src/server/shared/Cryptography/BigNumber.h
	src/server/worldserver/RemoteAccess/RASocket.cpp
	src/server/worldserver/worldserver.conf.dist
This commit is contained in:
Shauren
2014-07-19 03:38:57 +02:00
1725 changed files with 4826 additions and 353949 deletions

View File

@@ -24,28 +24,26 @@
* authentication server
*/
#include <ace/Dev_Poll_Reactor.h>
#include <ace/TP_Reactor.h>
#include <ace/ACE.h>
#include <ace/Sig_Handler.h>
#include <cstdlib>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/program_options.hpp>
#include <iostream>
#include <openssl/opensslv.h>
#include <openssl/crypto.h>
#include "AsyncAcceptor.h"
#include "AuthSession.h"
#include "Common.h"
#include "Database/DatabaseEnv.h"
#include "Configuration/Config.h"
#include "Database/DatabaseEnv.h"
#include "Log.h"
#include "ProcessPriority.h"
#include "RealmList.h"
#include "SystemConfig.h"
#include "Util.h"
#include "SignalHandler.h"
#include "RealmList.h"
#include "RealmAcceptor.h"
#ifdef __linux__
#include <sched.h>
#include <sys/resource.h>
#define PROCESS_HIGH_PRIORITY -15 // [-20, 19], default is 0
#endif
using boost::asio::ip::tcp;
using namespace boost::program_options;
#ifndef _TRINITY_REALM_CONFIG
# define _TRINITY_REALM_CONFIG "authserver.conf"
@@ -53,77 +51,35 @@
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);
bool stopEvent = false; // Setting it to true stops the server
boost::asio::io_service _ioService;
boost::asio::deadline_timer _dbPingTimer(_ioService);
uint32 _dbPingInterval;
LoginDatabaseWorkerPool LoginDatabase;
LoginDatabaseWorkerPool LoginDatabase; // Accessor to the authserver database
/// Handle authserver's termination signals
class AuthServerSignalHandler : public Trinity::SignalHandler
int main(int argc, char** argv)
{
public:
virtual void HandleSignal(int sigNum)
{
switch (sigNum)
{
case SIGINT:
case SIGTERM:
stopEvent = true;
break;
}
}
};
/// Print out the usage string for this program on the console.
void usage(const char* prog)
{
TC_LOG_INFO("server.authserver", "Usage: \n %s [<options>]\n"
" -c config_file use config_file as configuration file\n\r",
prog);
}
/// Launch the auth server
extern int main(int argc, char** argv)
{
// Command line parsing to get the configuration file name
char const* configFile = _TRINITY_REALM_CONFIG;
int count = 1;
while (count < argc)
{
if (strcmp(argv[count], "-c") == 0)
{
if (++count >= argc)
{
printf("Runtime-Error: -c option requires an input argument\n");
usage(argv[0]);
return 1;
}
else
configFile = argv[count];
}
++count;
}
std::string configFile = _TRINITY_REALM_CONFIG;
auto vm = GetConsoleArguments(argc, argv, configFile);
// exit if help is enabled
if (vm.count("help"))
return 0;
if (!sConfigMgr->LoadInitial(configFile))
{
printf("Invalid or missing configuration file : %s\n", configFile);
printf("Invalid or missing configuration file : %s\n", configFile.c_str());
printf("Verify that the file exists and has \'[authserver]\' written in the top of the file!\n");
return 1;
}
TC_LOG_INFO("server.authserver", "%s (authserver)", _FULLVERSION);
TC_LOG_INFO("server.authserver", "<Ctrl-C> to stop.\n");
TC_LOG_INFO("server.authserver", "Using configuration file %s.", configFile);
TC_LOG_INFO("server.authserver", "%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
#if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL)
ACE_Reactor::instance(new ACE_Reactor(new ACE_Dev_Poll_Reactor(ACE::max_handles(), 1), 1), true);
#else
ACE_Reactor::instance(new ACE_Reactor(new ACE_TP_Reactor(), true), true);
#endif
TC_LOG_DEBUG("server.authserver", "Max allowed open files is %d", ACE::max_handles());
TC_LOG_INFO("server.authserver", "Using configuration file %s.", configFile.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);
// authserver PID file creation
std::string pidFile = sConfigMgr->GetStringDefault("PidFile", "");
@@ -143,139 +99,42 @@ extern int main(int argc, char** argv)
return 1;
// Get the list of realms for the server
sRealmList->Initialize(sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 20));
if (sRealmList->size() == 0)
sRealmList.Initialize(_ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 20));
if (sRealmList.size() == 0)
{
TC_LOG_ERROR("server.authserver", "No valid realms specified.");
return 1;
}
// Launch the listening network socket
RealmAcceptor<AuthSocket> acceptor;
RealmAcceptor<Battlenet::Socket> bnetacceptor;
int32 rmport = sConfigMgr->GetIntDefault("RealmServerPort", 3724);
if (rmport < 0 || rmport > 0xFFFF)
// Start the listening port (acceptor) for auth connections
int32 port = sConfigMgr->GetIntDefault("RealmServerPort", 3724);
if (port < 0 || port > 0xFFFF)
{
TC_LOG_ERROR("server.authserver", "Specified port out of allowed range (1-65535)");
return 1;
}
std::string bind_ip = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0");
std::string bindIp = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0");
AsyncAcceptor<AuthSession> authServer(_ioService, bindIp, port);
AsyncAcceptor<Battlenet::Socket> bnetServer(_ioService, bindIp, 1119);
ACE_INET_Addr bind_addr(uint16(rmport), bind_ip.c_str());
// Set signal handlers
boost::asio::signal_set signals(_ioService, SIGINT, SIGTERM);
signals.async_wait(SignalHandler);
if (acceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1)
{
TC_LOG_ERROR("server.authserver", "Auth server can not bind to %s:%d", bind_ip.c_str(), rmport);
return 1;
}
// Set process priority according to configuration settings
SetProcessPriority("server.authserver");
bind_addr.set_port_number(1119);
if (bnetacceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1)
{
TC_LOG_ERROR("server.authserver", "Auth server can not bind to %s:%d", bind_ip.c_str(), 1119);
return 1;
}
// Initialize the signal handlers
AuthServerSignalHandler SignalINT, SignalTERM;
// Register authservers's signal handlers
ACE_Sig_Handler Handler;
Handler.register_handler(SIGINT, &SignalINT);
Handler.register_handler(SIGTERM, &SignalTERM);
#if defined(_WIN32) || defined(__linux__)
///- Handle affinity for multiple processors and process priority
uint32 affinity = sConfigMgr->GetIntDefault("UseProcessors", 0);
bool highPriority = sConfigMgr->GetBoolDefault("ProcessPriority", false);
#ifdef _WIN32 // Windows
HANDLE hProcess = GetCurrentProcess();
if (affinity > 0)
{
ULONG_PTR appAff;
ULONG_PTR sysAff;
if (GetProcessAffinityMask(hProcess, &appAff, &sysAff))
{
// remove non accessible processors
ULONG_PTR currentAffinity = affinity & appAff;
if (!currentAffinity)
TC_LOG_ERROR("server.authserver", "Processors marked in UseProcessors bitmask (hex) %x are not accessible for the authserver. Accessible processors bitmask (hex): %x", affinity, appAff);
else if (SetProcessAffinityMask(hProcess, currentAffinity))
TC_LOG_INFO("server.authserver", "Using processors (bitmask, hex): %x", currentAffinity);
else
TC_LOG_ERROR("server.authserver", "Can't set used processors (hex): %x", currentAffinity);
}
}
if (highPriority)
{
if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
TC_LOG_INFO("server.authserver", "authserver process priority class set to HIGH");
else
TC_LOG_ERROR("server.authserver", "Can't set authserver process priority class.");
}
#else // Linux
if (affinity > 0)
{
cpu_set_t mask;
CPU_ZERO(&mask);
for (unsigned int i = 0; i < sizeof(affinity) * 8; ++i)
if (affinity & (1 << i))
CPU_SET(i, &mask);
if (sched_setaffinity(0, sizeof(mask), &mask))
TC_LOG_ERROR("server.authserver", "Can't set used processors (hex): %x, error: %s", affinity, strerror(errno));
else
{
CPU_ZERO(&mask);
sched_getaffinity(0, sizeof(mask), &mask);
TC_LOG_INFO("server.authserver", "Using processors (bitmask, hex): %lx", *(__cpu_mask*)(&mask));
}
}
if (highPriority)
{
if (setpriority(PRIO_PROCESS, 0, PROCESS_HIGH_PRIORITY))
TC_LOG_ERROR("server.authserver", "Can't set authserver process priority class, error: %s", strerror(errno));
else
TC_LOG_INFO("server.authserver", "authserver process priority class set to %i", getpriority(PRIO_PROCESS, 0));
}
#endif
#endif
// Enabled a timed callback for handling the database keep alive ping
_dbPingInterval = sConfigMgr->GetIntDefault("MaxPingTime", 30);
_dbPingTimer.expires_from_now(boost::posix_time::minutes(_dbPingInterval));
_dbPingTimer.async_wait(KeepDatabaseAliveHandler);
sBattlenetMgr->Load();
// maximum counter for next ping
uint32 numLoops = (sConfigMgr->GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000000 / 100000));
uint32 loopCounter = 0;
// Wait for termination signal
while (!stopEvent)
{
// dont move this outside the loop, the reactor will modify it
ACE_Time_Value interval(0, 100000);
if (ACE_Reactor::instance()->run_reactor_event_loop(interval) == -1)
break;
if ((++loopCounter) == numLoops)
{
loopCounter = 0;
TC_LOG_INFO("server.authserver", "Ping MySQL to keep connection alive");
LoginDatabase.KeepAlive();
}
}
// Start the io service worker loop
_ioService.run();
// Close the Database Pool and library
StopDB();
@@ -284,6 +143,7 @@ extern int main(int argc, char** argv)
return 0;
}
/// Initialize connection to the database
bool StartDB()
{
@@ -328,3 +188,53 @@ void StopDB()
LoginDatabase.Close();
MySQL::Library_End();
}
void SignalHandler(const boost::system::error_code& error, int signalNumber)
{
if (!error)
{
switch (signalNumber)
{
case SIGINT:
case SIGTERM:
_ioService.stop();
break;
}
}
}
void KeepDatabaseAliveHandler(const boost::system::error_code& error)
{
if (!error)
{
TC_LOG_INFO("server.authserver", "Ping MySQL to keep connection alive");
LoginDatabase.KeepAlive();
_dbPingTimer.expires_from_now(boost::posix_time::minutes(_dbPingInterval));
_dbPingTimer.async_wait(KeepDatabaseAliveHandler);
}
}
variables_map GetConsoleArguments(int argc, char** argv, std::string& configFile)
{
options_description all("Allowed options");
all.add_options()
("help,h", "print usage message")
("config,c", value<std::string>(&configFile)->default_value(_TRINITY_REALM_CONFIG), "use <arg> as configuration file")
;
variables_map variablesMap;
try
{
store(command_line_parser(argc, argv).options(all).allow_unregistered().run(), variablesMap);
notify(variablesMap);
}
catch (std::exception& e) {
std::cerr << e.what() << "\n";
}
if (variablesMap.count("help")) {
std::cout << all << "\n";
}
return variablesMap;
}