mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-22 10:05:32 +01:00
*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget --HG-- branch : trunk
This commit is contained in:
@@ -17,15 +17,12 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/// \addtogroup realmd Realm Daemon
|
||||
/// @{
|
||||
/// \file
|
||||
|
||||
#include "Common.h"
|
||||
#include "Database/DatabaseEnv.h"
|
||||
#include "RealmList.h"
|
||||
|
||||
#include "Config/ConfigEnv.h"
|
||||
#include "Log.h"
|
||||
#include "sockets/ListenSocket.h"
|
||||
@@ -34,17 +31,14 @@
|
||||
#include "Util.h"
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
// Format is YYYYMMDDRR where RR is the change in the conf file
|
||||
// for that day.
|
||||
#ifndef _REALMDCONFVERSION
|
||||
# define _REALMDCONFVERSION 2009081701
|
||||
#endif
|
||||
|
||||
#ifndef _TRINITY_REALM_CONFIG
|
||||
# define _TRINITY_REALM_CONFIG "TrinityRealm.conf"
|
||||
#endif //_TRINITY_REALM_CONFIG
|
||||
|
||||
#ifdef WIN32
|
||||
#include "ServiceWin32.h"
|
||||
char serviceName[] = "TrinityRealm";
|
||||
@@ -58,16 +52,12 @@ char serviceDescription[] = "Massive Network Game Object Server";
|
||||
*/
|
||||
int m_ServiceStatus = -1;
|
||||
#endif
|
||||
|
||||
bool StartDB();
|
||||
void UnhookSignals();
|
||||
void HookSignals();
|
||||
|
||||
bool stopEvent = false; ///< Setting it to true stops the server
|
||||
RealmList m_realmList; ///< Holds the list of realms for this server
|
||||
|
||||
DatabaseType loginDatabase; ///< Accessor to the realm server database
|
||||
|
||||
/// Print out the usage string for this program on the console.
|
||||
void usage(const char *prog)
|
||||
{
|
||||
@@ -81,7 +71,6 @@ void usage(const char *prog)
|
||||
#endif
|
||||
,prog);
|
||||
}
|
||||
|
||||
/// Launch the realm server
|
||||
extern int main(int argc, char **argv)
|
||||
{
|
||||
@@ -102,7 +91,6 @@ extern int main(int argc, char **argv)
|
||||
else
|
||||
cfg_file = argv[c];
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
////////////
|
||||
//Services//
|
||||
@@ -142,18 +130,15 @@ extern int main(int argc, char **argv)
|
||||
#endif
|
||||
++c;
|
||||
}
|
||||
|
||||
if (!sConfig.SetSource(cfg_file))
|
||||
{
|
||||
sLog.outError("Could not find configuration file %s.", cfg_file);
|
||||
return 1;
|
||||
}
|
||||
sLog.Initialize();
|
||||
|
||||
sLog.outString("%s (realm-daemon)", _FULLVERSION);
|
||||
sLog.outString("<Ctrl-C> to stop.\n");
|
||||
sLog.outString("Using configuration file %s.", cfg_file);
|
||||
|
||||
///- Check the version of the configuration file
|
||||
uint32 confVersion = sConfig.GetIntDefault("ConfVersion", 0);
|
||||
if (confVersion < _REALMDCONFVERSION)
|
||||
@@ -164,10 +149,8 @@ extern int main(int argc, char **argv)
|
||||
sLog.outError(" strange behavior.");
|
||||
sLog.outError("*****************************************************************************");
|
||||
clock_t pause = 3000 + clock();
|
||||
|
||||
while (pause > clock()) {}
|
||||
}
|
||||
|
||||
sLog.outDetail("%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
|
||||
if (SSLeay() < 0x009080bfL)
|
||||
{
|
||||
@@ -177,7 +160,6 @@ extern int main(int argc, char **argv)
|
||||
while (pause > clock()) {}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// realmd PID file creation
|
||||
std::string pidfile = sConfig.GetStringDefault("PidFile", "");
|
||||
if (!pidfile.empty())
|
||||
@@ -188,14 +170,11 @@ extern int main(int argc, char **argv)
|
||||
sLog.outError("Cannot create PID file %s.\n", pidfile.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
sLog.outString("Daemon PID: %u\n", pid);
|
||||
}
|
||||
|
||||
///- Initialize the database connection
|
||||
if (!StartDB())
|
||||
return 1;
|
||||
|
||||
///- Initialize the log database
|
||||
if (sConfig.GetBoolDefault("EnableLogDB", false))
|
||||
{
|
||||
@@ -211,7 +190,6 @@ extern int main(int argc, char **argv)
|
||||
sLog.SetLogDB(false);
|
||||
sLog.SetRealmID(0);
|
||||
}
|
||||
|
||||
///- Get the list of realms for the server
|
||||
m_realmList.Initialize(sConfig.GetIntDefault("RealmsStateUpdateDelay", 20));
|
||||
if (m_realmList.size() == 0)
|
||||
@@ -219,11 +197,9 @@ extern int main(int argc, char **argv)
|
||||
sLog.outError("No valid realms specified.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
///- Launch the listening network socket
|
||||
port_t rmport = sConfig.GetIntDefault("RealmServerPort", DEFAULT_REALMSERVER_PORT);
|
||||
std::string bind_ip = sConfig.GetStringDefault("BindIP", "0.0.0.0");
|
||||
|
||||
SocketHandler h;
|
||||
ListenSocket<AuthSocket> authListenSocket(h);
|
||||
if (authListenSocket.Bind(bind_ip.c_str(),rmport))
|
||||
@@ -231,27 +207,21 @@ extern int main(int argc, char **argv)
|
||||
sLog.outError("Trinity realm can not bind to %s:%d",bind_ip.c_str(), rmport);
|
||||
return 1;
|
||||
}
|
||||
|
||||
h.Add(&authListenSocket);
|
||||
|
||||
///- Catch termination signals
|
||||
HookSignals();
|
||||
|
||||
///- Handle affinity for multiple processors and process priority on Windows
|
||||
#ifdef WIN32
|
||||
{
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
|
||||
uint32 Aff = sConfig.GetIntDefault("UseProcessors", 0);
|
||||
if (Aff > 0)
|
||||
{
|
||||
ULONG_PTR appAff;
|
||||
ULONG_PTR sysAff;
|
||||
|
||||
if (GetProcessAffinityMask(hProcess,&appAff,&sysAff))
|
||||
{
|
||||
ULONG_PTR curAff = Aff & appAff; // remove non accessible processors
|
||||
|
||||
if (!curAff)
|
||||
{
|
||||
sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for realmd. Accessible processors bitmask (hex): %x",Aff,appAff);
|
||||
@@ -266,9 +236,7 @@ extern int main(int argc, char **argv)
|
||||
}
|
||||
sLog.outString();
|
||||
}
|
||||
|
||||
bool Prio = sConfig.GetBoolDefault("ProcessPriority", false);
|
||||
|
||||
if (Prio)
|
||||
{
|
||||
if (SetPriorityClass(hProcess,HIGH_PRIORITY_CLASS))
|
||||
@@ -279,11 +247,9 @@ extern int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// maximum counter for next ping
|
||||
uint32 numLoops = (sConfig.GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000000 / 100000));
|
||||
uint32 loopCounter = 0;
|
||||
|
||||
// possibly enable db logging; avoid massive startup spam by doing it here.
|
||||
if (sLog.GetLogDBLater())
|
||||
{
|
||||
@@ -297,13 +263,10 @@ extern int main(int argc, char **argv)
|
||||
sLog.SetLogDB(false);
|
||||
sLog.SetLogDBLater(false);
|
||||
}
|
||||
|
||||
///- Wait for termination signal
|
||||
while (!stopEvent)
|
||||
{
|
||||
|
||||
h.Select(0, 100000);
|
||||
|
||||
if ((++loopCounter) == numLoops)
|
||||
{
|
||||
loopCounter = 0;
|
||||
@@ -315,18 +278,14 @@ extern int main(int argc, char **argv)
|
||||
while (m_ServiceStatus == 2) Sleep(1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
///- Wait for the delay thread to exit
|
||||
loginDatabase.ThreadEnd();
|
||||
loginDatabase.HaltDelayThread();
|
||||
|
||||
///- Remove signal handling before leaving
|
||||
UnhookSignals();
|
||||
|
||||
sLog.outString("Halting process...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Handle termination signals
|
||||
/** Put the global variable stopEvent to 'true' if a termination signal is caught **/
|
||||
void OnSignal(int s)
|
||||
@@ -344,10 +303,8 @@ void OnSignal(int s)
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
signal(s, OnSignal);
|
||||
}
|
||||
|
||||
/// Initialize connection to the database
|
||||
bool StartDB()
|
||||
{
|
||||
@@ -357,17 +314,14 @@ bool StartDB()
|
||||
sLog.outError("Database not specified");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!loginDatabase.Initialize(dbstring.c_str()))
|
||||
{
|
||||
sLog.outError("Cannot connect to database");
|
||||
return false;
|
||||
}
|
||||
loginDatabase.ThreadStart();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Define hook 'OnSignal' for all termination signals
|
||||
void HookSignals()
|
||||
{
|
||||
@@ -378,7 +332,6 @@ void HookSignals()
|
||||
signal(SIGBREAK, OnSignal);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Unhook the signals before leaving
|
||||
void UnhookSignals()
|
||||
{
|
||||
@@ -389,5 +342,4 @@ void UnhookSignals()
|
||||
signal(SIGBREAK, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
Reference in New Issue
Block a user