mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-22 18:15:31 +01:00
Core/Authserver: Significant cleanup in preparation for a rewrite.
Dropped support for running as a service on windows; it may be back in some form later. Otherwise there should be no functional changes. --HG-- branch : trunk
This commit is contained in:
@@ -2,32 +2,30 @@
|
||||
|
||||
namespace AuthHelper
|
||||
{
|
||||
bool IsPreBCAcceptedClientBuild(int build)
|
||||
{
|
||||
int accepted_versions[] = PRE_BC_ACCEPTED_CLIENT_BUILD;
|
||||
|
||||
bool IsPreBCAcceptedClientBuild(int build)
|
||||
{
|
||||
int accepted_versions[] = PRE_BC_ACCEPTED_CLIENT_BUILD;
|
||||
for (int i = 0; accepted_versions[i]; ++i)
|
||||
if (build == accepted_versions[i])
|
||||
return true;
|
||||
|
||||
for (int i = 0; accepted_versions[i]; ++i)
|
||||
if (build == accepted_versions[i])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool IsPostBCAcceptedClientBuild(int build)
|
||||
{
|
||||
int accepted_versions[] = POST_BC_ACCEPTED_CLIENT_BUILD;
|
||||
|
||||
bool IsPostBCAcceptedClientBuild(int build)
|
||||
{
|
||||
int accepted_versions[] = POST_BC_ACCEPTED_CLIENT_BUILD;
|
||||
for (int i = 0; accepted_versions[i]; ++i)
|
||||
if (build == accepted_versions[i])
|
||||
return true;
|
||||
|
||||
for (int i = 0; accepted_versions[i]; ++i)
|
||||
if (build == accepted_versions[i])
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsAcceptedClientBuild(int build)
|
||||
{
|
||||
return (IsPostBCAcceptedClientBuild(build) || IsPreBCAcceptedClientBuild(build));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsAcceptedClientBuild(int build)
|
||||
{
|
||||
return (IsPostBCAcceptedClientBuild(build) || IsPreBCAcceptedClientBuild(build));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -16,76 +16,64 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
\ingroup realmd
|
||||
*/
|
||||
|
||||
#ifndef _AUTHCODES_H
|
||||
#define _AUTHCODES_H
|
||||
|
||||
enum AuthResult
|
||||
{
|
||||
WOW_SUCCESS = 0x00,
|
||||
WOW_FAIL_UNKNOWN0 = 0x01, ///< ? Unable to connect
|
||||
WOW_FAIL_UNKNOWN1 = 0x02, ///< ? Unable to connect
|
||||
WOW_FAIL_BANNED = 0x03, ///< This <game> account has been closed and is no longer available for use. Please go to <site>/banned.html for further information.
|
||||
WOW_FAIL_UNKNOWN_ACCOUNT = 0x04, ///< The information you have entered is not valid. Please check the spelling of the account name and password. If you need help in retrieving a lost or stolen password, see <site> for more information
|
||||
WOW_FAIL_INCORRECT_PASSWORD = 0x05, ///< The information you have entered is not valid. Please check the spelling of the account name and password. If you need help in retrieving a lost or stolen password, see <site> for more information
|
||||
WOW_FAIL_ALREADY_ONLINE = 0x06, ///< This account is already logged into <game>. Please check the spelling and try again.
|
||||
WOW_FAIL_NO_TIME = 0x07, ///< You have used up your prepaid time for this account. Please purchase more to continue playing
|
||||
WOW_FAIL_DB_BUSY = 0x08, ///< Could not log in to <game> at this time. Please try again later.
|
||||
WOW_FAIL_VERSION_INVALID = 0x09, ///< Unable to validate game version. This may be caused by file corruption or interference of another program. Please visit <site> for more information and possible solutions to this issue.
|
||||
WOW_FAIL_VERSION_UPDATE = 0x0A, ///< Downloading
|
||||
WOW_FAIL_INVALID_SERVER = 0x0B, ///< Unable to connect
|
||||
WOW_FAIL_SUSPENDED = 0x0C, ///< This <game> account has been temporarily suspended. Please go to <site>/banned.html for further information
|
||||
WOW_FAIL_FAIL_NOACCESS = 0x0D, ///< Unable to connect
|
||||
WOW_SUCCESS_SURVEY = 0x0E, ///< Connected.
|
||||
WOW_FAIL_PARENTCONTROL = 0x0F, ///< Access to this account has been blocked by parental controls. Your settings may be changed in your account preferences at <site>
|
||||
WOW_FAIL_LOCKED_ENFORCED = 0x10, ///< You have applied a lock to your account. You can change your locked status by calling your account lock phone number.
|
||||
WOW_FAIL_TRIAL_ENDED = 0x11, ///< Your trial subscription has expired. Please visit <site> to upgrade your account.
|
||||
WOW_FAIL_USE_BATTLENET = 0x12, ///< WOW_FAIL_OTHER This account is now attached to a Battle.net account. Please login with your Battle.net account email address and password.
|
||||
WOW_SUCCESS = 0x00,
|
||||
WOW_FAIL_BANNED = 0x03,
|
||||
WOW_FAIL_UNKNOWN_ACCOUNT = 0x04,
|
||||
WOW_FAIL_INCORRECT_PASSWORD = 0x05,
|
||||
WOW_FAIL_ALREADY_ONLINE = 0x06,
|
||||
WOW_FAIL_NO_TIME = 0x07,
|
||||
WOW_FAIL_DB_BUSY = 0x08,
|
||||
WOW_FAIL_VERSION_INVALID = 0x09,
|
||||
WOW_FAIL_VERSION_UPDATE = 0x0A,
|
||||
WOW_FAIL_SUSPENDED = 0x0C,
|
||||
WOW_SUCCESS_SURVEY = 0x0E,
|
||||
WOW_FAIL_PARENTCONTROL = 0x0F,
|
||||
WOW_FAIL_LOCKED_ENFORCED = 0x10,
|
||||
WOW_FAIL_TRIAL_ENDED = 0x11,
|
||||
WOW_FAIL_USE_BATTLENET = 0x12,
|
||||
WOW_FAIL_TOO_FAST = 0x16,
|
||||
WOW_FAIL_CHARGEBACK = 0x17,
|
||||
WOW_FAIL_GAME_ACCOUNT_LOCKED = 0x18,
|
||||
WOW_FAIL_INTERNET_GAME_ROOM_WITHOUT_BNET = 0x19,
|
||||
WOW_FAIL_UNLOCKABLE_LOCK = 0x20,
|
||||
WOW_FAIL_DISCONNECTED = 0xFF,
|
||||
};
|
||||
|
||||
enum LoginResult
|
||||
{
|
||||
LOGIN_OK = 0x00,
|
||||
LOGIN_FAILED = 0x01,
|
||||
LOGIN_FAILED2 = 0x02,
|
||||
LOGIN_BANNED = 0x03,
|
||||
LOGIN_UNKNOWN_ACCOUNT = 0x04,
|
||||
LOGIN_UNKNOWN_ACCOUNT3 = 0x05,
|
||||
LOGIN_ALREADYONLINE = 0x06,
|
||||
LOGIN_NOTIME = 0x07,
|
||||
LOGIN_DBBUSY = 0x08,
|
||||
LOGIN_BADVERSION = 0x09,
|
||||
LOGIN_DOWNLOAD_FILE = 0x0A,
|
||||
LOGIN_FAILED3 = 0x0B,
|
||||
LOGIN_SUSPENDED = 0x0C,
|
||||
LOGIN_FAILED4 = 0x0D,
|
||||
LOGIN_CONNECTED = 0x0E,
|
||||
LOGIN_PARENTALCONTROL = 0x0F,
|
||||
LOGIN_LOCKED_ENFORCED = 0x10,
|
||||
LOGIN_OK = 0x00,
|
||||
LOGIN_FAILED = 0x01,
|
||||
LOGIN_FAILED2 = 0x02,
|
||||
LOGIN_BANNED = 0x03,
|
||||
LOGIN_UNKNOWN_ACCOUNT = 0x04,
|
||||
LOGIN_UNKNOWN_ACCOUNT3 = 0x05,
|
||||
LOGIN_ALREADYONLINE = 0x06,
|
||||
LOGIN_NOTIME = 0x07,
|
||||
LOGIN_DBBUSY = 0x08,
|
||||
LOGIN_BADVERSION = 0x09,
|
||||
LOGIN_DOWNLOAD_FILE = 0x0A,
|
||||
LOGIN_FAILED3 = 0x0B,
|
||||
LOGIN_SUSPENDED = 0x0C,
|
||||
LOGIN_FAILED4 = 0x0D,
|
||||
LOGIN_CONNECTED = 0x0E,
|
||||
LOGIN_PARENTALCONTROL = 0x0F,
|
||||
LOGIN_LOCKED_ENFORCED = 0x10,
|
||||
};
|
||||
|
||||
//multirealm supported versions:
|
||||
//1.12.1 build 5875
|
||||
//1.12.2 build 6005
|
||||
//2.4.3 build 8606
|
||||
//3.1.3 build 9947
|
||||
//3.1.3 build 10146 Chinese build
|
||||
//3.2.2a build 10505
|
||||
//3.3.0 build 10571
|
||||
//3.3.0a build 11159
|
||||
//3.3.2 build 11403
|
||||
//3.3.3a build 11723
|
||||
//3.3.5a build 12340
|
||||
#define POST_BC_ACCEPTED_CLIENT_BUILD {12340, 11723, 11403, 11159, 10571, 10505, 10146, 9947, 8606, 0}
|
||||
#define PRE_BC_ACCEPTED_CLIENT_BUILD {5875, 6005, 0}
|
||||
|
||||
#define POST_BC_ACCEPTED_CLIENT_BUILD {12340, 11723, 11403, 11159, 10571, 10505, 10146, 9947, 8606, 0}
|
||||
#define PRE_BC_ACCEPTED_CLIENT_BUILD {5875, 6005, 0}
|
||||
|
||||
#define POST_BC_EXP_FLAG 0x2
|
||||
#define PRE_BC_EXP_FLAG 0x1
|
||||
#define NO_VALID_EXP_FLAG 0x0
|
||||
enum ExpansionFlags
|
||||
{
|
||||
POST_BC_EXP_FLAG = 0x2,
|
||||
PRE_BC_EXP_FLAG = 0x1,
|
||||
NO_VALID_EXP_FLAG = 0x0
|
||||
};
|
||||
|
||||
namespace AuthHelper
|
||||
{
|
||||
|
||||
@@ -16,13 +16,15 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/// \addtogroup realmd Realm Daemon
|
||||
/// @{
|
||||
/// \file
|
||||
#include <ace/Dev_Poll_Reactor.h>
|
||||
#include <ace/TP_Reactor.h>
|
||||
#include <ace/ACE.h>
|
||||
#include <ace/Sig_Handler.h>
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
#include "Common.h"
|
||||
#include "Database/DatabaseEnv.h"
|
||||
|
||||
#include "Configuration/Config.h"
|
||||
#include "Log.h"
|
||||
#include "SystemConfig.h"
|
||||
@@ -31,84 +33,50 @@
|
||||
#include "RealmList.h"
|
||||
#include "RealmAcceptor.h"
|
||||
|
||||
#include <ace/Dev_Poll_Reactor.h>
|
||||
#include <ace/TP_Reactor.h>
|
||||
#include <ace/ACE.h>
|
||||
#include <ace/Sig_Handler.h>
|
||||
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
#ifndef _TRINITY_REALM_CONFIG
|
||||
# define _TRINITY_REALM_CONFIG "authserver.conf"
|
||||
#endif //_TRINITY_REALM_CONFIG
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "ServiceWin32.h"
|
||||
char serviceName[] = "TrinityRealm";
|
||||
char serviceLongName[] = "Trinity realm service";
|
||||
char serviceDescription[] = "Massive Network Game Object Server";
|
||||
/*
|
||||
* -1 - not in service mode
|
||||
* 0 - stopped
|
||||
* 1 - running
|
||||
* 2 - paused
|
||||
*/
|
||||
int m_ServiceStatus = -1;
|
||||
#endif
|
||||
|
||||
bool StartDB();
|
||||
|
||||
bool stopEvent = false; ///< Setting it to true stops the server
|
||||
bool stopEvent = false; // Setting it to true stops the server
|
||||
|
||||
LoginDatabaseWorkerPool LoginDatabase; ///< Accessor to the realm server database
|
||||
LoginDatabaseWorkerPool LoginDatabase; // Accessor to the realm server database
|
||||
|
||||
/// Handle realmd's termination signals
|
||||
// Handle realmd's termination signals
|
||||
class RealmdSignalHandler : public Trinity::SignalHandler
|
||||
{
|
||||
public:
|
||||
virtual void HandleSignal(int SigNum)
|
||||
public:
|
||||
virtual void HandleSignal(int SigNum)
|
||||
{
|
||||
switch (SigNum)
|
||||
{
|
||||
switch (SigNum)
|
||||
{
|
||||
case SIGINT:
|
||||
case SIGTERM:
|
||||
stopEvent = true;
|
||||
break;
|
||||
#ifdef _WIN32
|
||||
case SIGBREAK:
|
||||
if (m_ServiceStatus != 1)
|
||||
stopEvent = true;
|
||||
break;
|
||||
#endif /* _WIN32 */
|
||||
}
|
||||
case SIGINT:
|
||||
case SIGTERM:
|
||||
stopEvent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/// Print out the usage string for this program on the console.
|
||||
void usage(const char *prog)
|
||||
{
|
||||
sLog->outString("Usage: \n %s [<options>]\n"
|
||||
" -c config_file use config_file as configuration file\n\r"
|
||||
#ifdef _WIN32
|
||||
" Running as service functions:\n\r"
|
||||
" --service run as service\n\r"
|
||||
" -s install install service\n\r"
|
||||
" -s uninstall uninstall service\n\r"
|
||||
#endif
|
||||
,prog);
|
||||
" -c config_file use config_file as configuration file\n\r",
|
||||
prog);
|
||||
}
|
||||
|
||||
/// Launch the realm server
|
||||
// Launch the realm server
|
||||
extern int main(int argc, char **argv)
|
||||
{
|
||||
sLog->SetLogDB(false);
|
||||
///- Command line parsing to get the configuration file name
|
||||
char const* cfg_file = _TRINITY_REALM_CONFIG;
|
||||
int c=1;
|
||||
// Command line parsing to get the configuration file name
|
||||
char const *cfg_file = _TRINITY_REALM_CONFIG;
|
||||
int c = 1;
|
||||
while(c < argc)
|
||||
{
|
||||
if (strcmp(argv[c],"-c") == 0)
|
||||
if (strcmp(argv[c], "-c") == 0)
|
||||
{
|
||||
if (++c >= argc)
|
||||
{
|
||||
@@ -119,44 +87,6 @@ extern int main(int argc, char **argv)
|
||||
else
|
||||
cfg_file = argv[c];
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
////////////
|
||||
//Services//
|
||||
////////////
|
||||
if (strcmp(argv[c],"-s") == 0)
|
||||
{
|
||||
if (++c >= argc)
|
||||
{
|
||||
sLog->outError("Runtime-Error: -s option requires an input argument");
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
if (strcmp(argv[c],"install") == 0)
|
||||
{
|
||||
if (WinServiceInstall())
|
||||
sLog->outString("Installing service");
|
||||
return 1;
|
||||
}
|
||||
else if (strcmp(argv[c],"uninstall") == 0)
|
||||
{
|
||||
if (WinServiceUninstall())
|
||||
sLog->outString("Uninstalling service");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sLog->outError("Runtime-Error: unsupported option %s",argv[c]);
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (strcmp(argv[c],"--service") == 0)
|
||||
{
|
||||
WinServiceRun();
|
||||
}
|
||||
////
|
||||
#endif
|
||||
++c;
|
||||
}
|
||||
|
||||
@@ -182,7 +112,7 @@ extern int main(int argc, char **argv)
|
||||
|
||||
sLog->outBasic("Max allowed open files is %d", ACE::max_handles());
|
||||
|
||||
/// realmd PID file creation
|
||||
// realmd PID file creation
|
||||
std::string pidfile = sConfig->GetStringDefault("PidFile", "");
|
||||
if (!pidfile.empty())
|
||||
{
|
||||
@@ -196,16 +126,16 @@ extern int main(int argc, char **argv)
|
||||
sLog->outString("Daemon PID: %u\n", pid);
|
||||
}
|
||||
|
||||
///- Initialize the database connection
|
||||
// Initialize the database connection
|
||||
if (!StartDB())
|
||||
return 1;
|
||||
|
||||
///- Initialize the log database
|
||||
// Initialize the log database
|
||||
sLog->SetLogDBLater(sConfig->GetBoolDefault("EnableLogDB", false)); // set var to enable DB logging once startup finished.
|
||||
sLog->SetLogDB(false);
|
||||
sLog->SetRealmID(0); // ensure we've set realm to 0 (realmd realmid)
|
||||
|
||||
///- Get the list of realms for the server
|
||||
// Get the list of realms for the server
|
||||
sRealmList->Initialize(sConfig->GetIntDefault("RealmsStateUpdateDelay", 20));
|
||||
if (sRealmList->size() == 0)
|
||||
{
|
||||
@@ -213,7 +143,7 @@ extern int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
///- Launch the listening network socket
|
||||
// Launch the listening network socket
|
||||
RealmAcceptor acceptor;
|
||||
|
||||
uint16 rmport = sConfig->GetIntDefault("RealmServerPort", 3724);
|
||||
@@ -229,20 +159,14 @@ extern int main(int argc, char **argv)
|
||||
|
||||
// Initialise the signal handlers
|
||||
RealmdSignalHandler SignalINT, SignalTERM;
|
||||
#ifdef _WIN32
|
||||
RealmdSignalHandler SignalBREAK;
|
||||
#endif /* _WIN32 */
|
||||
|
||||
// Register realmd's signal handlers
|
||||
ACE_Sig_Handler Handler;
|
||||
Handler.register_handler(SIGINT, &SignalINT);
|
||||
Handler.register_handler(SIGTERM, &SignalTERM);
|
||||
#ifdef _WIN32
|
||||
Handler.register_handler(SIGBREAK, &SignalBREAK);
|
||||
#endif /* _WIN32 */
|
||||
|
||||
///- Handle affinity for multiple processors and process priority on Windows
|
||||
#ifdef _WIN32
|
||||
#ifdef _WIN32
|
||||
{
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
|
||||
@@ -257,16 +181,11 @@ extern int main(int argc, char **argv)
|
||||
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);
|
||||
}
|
||||
sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for realmd. Accessible processors bitmask (hex): %x", Aff, appAff);
|
||||
else if (SetProcessAffinityMask(hProcess,curAff))
|
||||
sLog.outString("Using processors (bitmask, hex): %x", curAff);
|
||||
else
|
||||
{
|
||||
if (SetProcessAffinityMask(hProcess,curAff))
|
||||
sLog->outString("Using processors (bitmask, hex): %x", curAff);
|
||||
else
|
||||
sLog->outError("Can't set used processors (hex): %x", curAff);
|
||||
}
|
||||
sLog.outError("Can't set used processors (hex): %x", curAff);
|
||||
}
|
||||
sLog->outString();
|
||||
}
|
||||
@@ -275,14 +194,14 @@ extern int main(int argc, char **argv)
|
||||
|
||||
if (Prio)
|
||||
{
|
||||
if (SetPriorityClass(hProcess,HIGH_PRIORITY_CLASS))
|
||||
if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
|
||||
sLog->outString("TrinityRealm process priority class set to HIGH");
|
||||
else
|
||||
sLog->outError("Can't set realmd process priority class.");
|
||||
sLog->outString();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// maximum counter for next ping
|
||||
uint32 numLoops = (sConfig->GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000000 / 100000));
|
||||
@@ -299,7 +218,7 @@ extern int main(int argc, char **argv)
|
||||
else
|
||||
sLog->SetLogDB(false);
|
||||
|
||||
///- Wait for termination signal
|
||||
// Wait for termination signal
|
||||
while (!stopEvent)
|
||||
{
|
||||
// dont move this outside the loop, the reactor will modify it
|
||||
@@ -314,20 +233,16 @@ extern int main(int argc, char **argv)
|
||||
sLog->outDetail("Ping MySQL to keep connection alive");
|
||||
LoginDatabase.KeepAlive();
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (m_ServiceStatus == 0) stopEvent = true;
|
||||
while (m_ServiceStatus == 2) Sleep(1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
///- Close the Database Pool
|
||||
// Close the Database Pool
|
||||
LoginDatabase.Close();
|
||||
|
||||
sLog->outString("Halting process...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Initialize connection to the database
|
||||
// Initialize connection to the database
|
||||
bool StartDB()
|
||||
{
|
||||
std::string dbstring = sConfig->GetStringDefault("LoginDatabaseInfo", "");
|
||||
@@ -351,7 +266,7 @@ bool StartDB()
|
||||
synch_threads = 1;
|
||||
}
|
||||
|
||||
/// NOTE: While authserver is singlethreaded you should keep synch_threads == 1. Increasing it is just silly since only 1 will be used ever.
|
||||
// NOTE: While authserver is singlethreaded you should keep synch_threads == 1. Increasing it is just silly since only 1 will be used ever.
|
||||
if (!LoginDatabase.Open(dbstring.c_str(), worker_threads, synch_threads))
|
||||
{
|
||||
sLog->outError("Cannot connect to database");
|
||||
@@ -360,5 +275,3 @@ bool StartDB()
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
@@ -4,4 +4,3 @@
|
||||
#include "RealmList.h"
|
||||
#include "RealmSocket.h"
|
||||
#include "Common.h"
|
||||
|
||||
|
||||
@@ -16,44 +16,38 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
\ingroup realmd
|
||||
*/
|
||||
|
||||
#include "Common.h"
|
||||
#include "RealmList.h"
|
||||
#include "Database/DatabaseEnv.h"
|
||||
|
||||
RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL))
|
||||
{
|
||||
}
|
||||
RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL)) { }
|
||||
|
||||
/// Load the realm list from the database
|
||||
// Load the realm list from the database
|
||||
void RealmList::Initialize(uint32 updateInterval)
|
||||
{
|
||||
m_UpdateInterval = updateInterval;
|
||||
|
||||
///- Get the content of the realmlist table in the database
|
||||
// Get the content of the realmlist table in the database
|
||||
UpdateRealms(true);
|
||||
}
|
||||
|
||||
void RealmList::UpdateRealm(uint32 ID, const std::string& name, const std::string& address, uint32 port, uint8 icon, uint8 color, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, uint32 build)
|
||||
{
|
||||
///- Create new if not exist or update existed
|
||||
// Create new if not exist or update existed
|
||||
Realm& realm = m_realms[name];
|
||||
|
||||
realm.m_ID = ID;
|
||||
realm.name = name;
|
||||
realm.icon = icon;
|
||||
realm.color = color;
|
||||
realm.timezone = timezone;
|
||||
realm.m_ID = ID;
|
||||
realm.name = name;
|
||||
realm.icon = icon;
|
||||
realm.color = color;
|
||||
realm.timezone = timezone;
|
||||
realm.allowedSecurityLevel = allowedSecurityLevel;
|
||||
realm.populationLevel = popu;
|
||||
realm.populationLevel = popu;
|
||||
|
||||
///- Append port to IP address.
|
||||
// Append port to IP address.
|
||||
std::ostringstream ss;
|
||||
ss << address << ":" << port;
|
||||
realm.address = ss.str();
|
||||
realm.address = ss.str();
|
||||
realm.gamebuild = build;
|
||||
}
|
||||
|
||||
@@ -69,22 +63,22 @@ void RealmList::UpdateIfNeed()
|
||||
m_realms.clear();
|
||||
|
||||
// Get the content of the realmlist table in the database
|
||||
UpdateRealms(false);
|
||||
UpdateRealms();
|
||||
}
|
||||
|
||||
void RealmList::UpdateRealms(bool init)
|
||||
{
|
||||
sLog->outDetail("Updating Realm List...");
|
||||
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_REALMLIST);
|
||||
PreparedStatement *stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_REALMLIST);
|
||||
PreparedQueryResult result = LoginDatabase.Query(stmt);
|
||||
|
||||
///- Circle through results and add them to the realm map
|
||||
// Circle through results and add them to the realm map
|
||||
if (result)
|
||||
{
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
Field *fields = result->Fetch();
|
||||
uint32 realmId = fields[0].GetUInt32();
|
||||
const std::string& name = fields[1].GetString();
|
||||
const std::string& address = fields[2].GetString();
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/// \addtogroup realmd
|
||||
/// @{
|
||||
/// \file
|
||||
|
||||
#ifndef _REALMLIST_H
|
||||
#define _REALMLIST_H
|
||||
|
||||
@@ -27,7 +23,7 @@
|
||||
#include <ace/Null_Mutex.h>
|
||||
#include "Common.h"
|
||||
|
||||
/// Storage object for a realm
|
||||
// Storage object for a realm
|
||||
struct Realm
|
||||
{
|
||||
std::string address;
|
||||
@@ -44,31 +40,30 @@ struct Realm
|
||||
/// Storage object for the list of realms on the server
|
||||
class RealmList
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, Realm> RealmMap;
|
||||
public:
|
||||
typedef std::map<std::string, Realm> RealmMap;
|
||||
|
||||
RealmList();
|
||||
~RealmList() {}
|
||||
RealmList();
|
||||
~RealmList() {}
|
||||
|
||||
void Initialize(uint32 updateInterval);
|
||||
void Initialize(uint32 updateInterval);
|
||||
|
||||
void UpdateIfNeed();
|
||||
void UpdateIfNeed();
|
||||
|
||||
void AddRealm(Realm NewRealm) {m_realms[NewRealm.name] = NewRealm;}
|
||||
void AddRealm(Realm NewRealm) {m_realms[NewRealm.name] = NewRealm;}
|
||||
|
||||
RealmMap::const_iterator begin() const { return m_realms.begin(); }
|
||||
RealmMap::const_iterator end() const { return m_realms.end(); }
|
||||
uint32 size() const { return m_realms.size(); }
|
||||
private:
|
||||
void UpdateRealms(bool init);
|
||||
void UpdateRealm(uint32 ID, const std::string& name, const std::string& address, uint32 port, uint8 icon, uint8 color, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, uint32 build);
|
||||
RealmMap::const_iterator begin() const { return m_realms.begin(); }
|
||||
RealmMap::const_iterator end() const { return m_realms.end(); }
|
||||
uint32 size() const { return m_realms.size(); }
|
||||
|
||||
RealmMap m_realms; ///< Internal map of realms
|
||||
uint32 m_UpdateInterval;
|
||||
time_t m_NextUpdateTime;
|
||||
private:
|
||||
void UpdateRealms(bool init=false);
|
||||
void UpdateRealm(uint32 ID, const std::string& name, const std::string& address, uint32 port, uint8 icon, uint8 color, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, uint32 build);
|
||||
|
||||
RealmMap m_realms;
|
||||
uint32 m_UpdateInterval;
|
||||
time_t m_NextUpdateTime;
|
||||
};
|
||||
|
||||
#define sRealmList ACE_Singleton<RealmList, ACE_Null_Mutex>::instance()
|
||||
|
||||
#endif
|
||||
/// @}
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
\ingroup realmd
|
||||
*/
|
||||
#include <openssl/md5.h>
|
||||
|
||||
#include "Common.h"
|
||||
#include "Database/DatabaseEnv.h"
|
||||
@@ -28,28 +26,27 @@
|
||||
#include "RealmList.h"
|
||||
#include "AuthSocket.h"
|
||||
#include "AuthCodes.h"
|
||||
#include <openssl/md5.h>
|
||||
#include "SHA1.h"
|
||||
|
||||
#define ChunkSize 2048
|
||||
|
||||
enum eAuthCmd
|
||||
{
|
||||
AUTH_LOGON_CHALLENGE = 0x00,
|
||||
AUTH_LOGON_PROOF = 0x01,
|
||||
AUTH_RECONNECT_CHALLENGE = 0x02,
|
||||
AUTH_RECONNECT_PROOF = 0x03,
|
||||
REALM_LIST = 0x10,
|
||||
XFER_INITIATE = 0x30,
|
||||
XFER_DATA = 0x31,
|
||||
XFER_ACCEPT = 0x32,
|
||||
XFER_RESUME = 0x33,
|
||||
XFER_CANCEL = 0x34
|
||||
AUTH_LOGON_CHALLENGE = 0x00,
|
||||
AUTH_LOGON_PROOF = 0x01,
|
||||
AUTH_RECONNECT_CHALLENGE = 0x02,
|
||||
AUTH_RECONNECT_PROOF = 0x03,
|
||||
REALM_LIST = 0x10,
|
||||
XFER_INITIATE = 0x30,
|
||||
XFER_DATA = 0x31,
|
||||
XFER_ACCEPT = 0x32,
|
||||
XFER_RESUME = 0x33,
|
||||
XFER_CANCEL = 0x34
|
||||
};
|
||||
|
||||
enum eStatus
|
||||
{
|
||||
STATUS_CONNECTED = 0,
|
||||
STATUS_CONNECTED = 0,
|
||||
STATUS_AUTHED
|
||||
};
|
||||
|
||||
@@ -149,12 +146,12 @@ typedef struct AuthHandler
|
||||
// Launch a thread to transfer a patch to the client
|
||||
class PatcherRunnable: public ACE_Based::Runnable
|
||||
{
|
||||
public:
|
||||
PatcherRunnable(class AuthSocket *);
|
||||
void run();
|
||||
public:
|
||||
PatcherRunnable(class AuthSocket *);
|
||||
void run();
|
||||
|
||||
private:
|
||||
AuthSocket * mySocket;
|
||||
private:
|
||||
AuthSocket * mySocket;
|
||||
};
|
||||
|
||||
typedef struct PATCH_INFO
|
||||
@@ -165,18 +162,18 @@ typedef struct PATCH_INFO
|
||||
// Caches MD5 hash of client patches present on the server
|
||||
class Patcher
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, PATCH_INFO*> Patches;
|
||||
~Patcher();
|
||||
Patcher();
|
||||
Patches::const_iterator begin() const { return _patches.begin(); }
|
||||
Patches::const_iterator end() const { return _patches.end(); }
|
||||
void LoadPatchMD5(char*);
|
||||
bool GetHash(char * pat,uint8 mymd5[16]);
|
||||
public:
|
||||
typedef std::map<std::string, PATCH_INFO*> Patches;
|
||||
~Patcher();
|
||||
Patcher();
|
||||
Patches::const_iterator begin() const { return _patches.begin(); }
|
||||
Patches::const_iterator end() const { return _patches.end(); }
|
||||
void LoadPatchMD5(char*);
|
||||
bool GetHash(char * pat,uint8 mymd5[16]);
|
||||
|
||||
private:
|
||||
void LoadPatchesInfo();
|
||||
Patches _patches;
|
||||
private:
|
||||
void LoadPatchesInfo();
|
||||
Patches _patches;
|
||||
};
|
||||
|
||||
const AuthHandler table[] =
|
||||
@@ -191,7 +188,7 @@ const AuthHandler table[] =
|
||||
{ XFER_CANCEL, STATUS_CONNECTED, &AuthSocket::_HandleXferCancel }
|
||||
};
|
||||
|
||||
#define AUTH_TOTAL_COMMANDS sizeof(table)/sizeof(AuthHandler)
|
||||
#define AUTH_TOTAL_COMMANDS 8
|
||||
|
||||
// Holds the MD5 hash of client patches present on the server
|
||||
Patcher PatchesCache;
|
||||
@@ -233,9 +230,7 @@ void AuthSocket::OnRead()
|
||||
// Circle through known commands and call the correct command handler
|
||||
for (i = 0; i < AUTH_TOTAL_COMMANDS; ++i)
|
||||
{
|
||||
if ((uint8)table[i].cmd == _cmd &&
|
||||
(table[i].status == STATUS_CONNECTED ||
|
||||
(_authed && table[i].status == STATUS_AUTHED)))
|
||||
if ((uint8)table[i].cmd == _cmd && (table[i].status == STATUS_CONNECTED || (_authed && table[i].status == STATUS_AUTHED)))
|
||||
{
|
||||
sLog->outStaticDebug("[Auth] got data for cmd %u recv length %u", (uint32)_cmd, (uint32)socket().recv_len());
|
||||
|
||||
@@ -281,6 +276,7 @@ void AuthSocket::_SetVSFields(const std::string& rI)
|
||||
BigNumber x;
|
||||
x.SetBinary(sha.GetDigest(), sha.GetLength());
|
||||
v = g.ModExp(x, N);
|
||||
|
||||
// No SQL injection (username escaped)
|
||||
const char *v_hex, *s_hex;
|
||||
v_hex = v.AsHexStr();
|
||||
@@ -483,9 +479,7 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||
for (int i = 0; i < 4; ++i)
|
||||
_localizationName[i] = ch->country[4-i-1];
|
||||
|
||||
sLog->outBasic("[AuthChallenge] account %s is using '%c%c%c%c' locale (%u)",
|
||||
_login.c_str (), ch->country[3], ch->country[2], ch->country[1], ch->country[0], GetLocaleByName(_localizationName)
|
||||
);
|
||||
sLog->outBasic("[AuthChallenge] account %s is using '%c%c%c%c' locale (%u)", _login.c_str (), ch->country[3], ch->country[2], ch->country[1], ch->country[0], GetLocaleByName(_localizationName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -599,9 +593,9 @@ bool AuthSocket::_HandleLogonProof()
|
||||
|
||||
// Update the sessionkey, last_ip, last login time and reset number of failed logins in the account table for this account
|
||||
// No SQL injection (escaped user name) and IP address as received by socket
|
||||
const char* K_hex = K.AsHexStr();
|
||||
const char *K_hex = K.AsHexStr();
|
||||
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SET_LOGONPROOF);
|
||||
PreparedStatement *stmt = LoginDatabase.GetPreparedStatement(LOGIN_SET_LOGONPROOF);
|
||||
stmt->setString(0, K_hex);
|
||||
stmt->setString(1, socket().get_remote_address().c_str());
|
||||
stmt->setUInt32(2, GetLocaleByName(_localizationName));
|
||||
@@ -640,10 +634,10 @@ bool AuthSocket::_HandleLogonProof()
|
||||
}
|
||||
else
|
||||
{
|
||||
char data[4]= { AUTH_LOGON_PROOF, WOW_FAIL_UNKNOWN_ACCOUNT, 3, 0};
|
||||
uint8 data[4]= { AUTH_LOGON_PROOF, WOW_FAIL_UNKNOWN_ACCOUNT, 3, 0 };
|
||||
socket().send(data, sizeof(data));
|
||||
|
||||
sLog->outBasic("[AuthChallenge] account %s tried to login with wrong password!",_login.c_str ());
|
||||
sLog->outBasic("[AuthChallenge] account %s tried to login with wrong password!", _login.c_str());
|
||||
|
||||
uint32 MaxWrongPassCount = sConfig->GetIntDefault("WrongPass.MaxCount", 0);
|
||||
if (MaxWrongPassCount > 0)
|
||||
@@ -683,8 +677,7 @@ bool AuthSocket::_HandleLogonProof()
|
||||
stmt->setUInt32(1, WrongPassBanTime);
|
||||
LoginDatabase.Execute(stmt);
|
||||
|
||||
sLog->outBasic("[AuthChallenge] IP %s got banned for '%u' seconds because account %s failed to authenticate '%u' times",
|
||||
socket().get_remote_address().c_str(), WrongPassBanTime, _login.c_str(), failed_logins);
|
||||
sLog->outBasic("[AuthChallenge] IP %s got banned for '%u' seconds because account %s failed to authenticate '%u' times", socket().get_remote_address().c_str(), WrongPassBanTime, _login.c_str(), failed_logins);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -864,7 +857,7 @@ bool AuthSocket::_HandleRealmList()
|
||||
pkt << i->second.populationLevel;
|
||||
pkt << AmountOfCharacters;
|
||||
pkt << i->second.timezone; // realm category
|
||||
if ( _expversion & POST_BC_EXP_FLAG ) // 2.x and 3.x clients
|
||||
if (_expversion & POST_BC_EXP_FLAG) // 2.x and 3.x clients
|
||||
pkt << (uint8)0x2C; // unk, may be realm number/id?
|
||||
else
|
||||
pkt << (uint8)0x0; // 1.12.1 and 1.12.2 clients
|
||||
@@ -969,9 +962,8 @@ void PatcherRunnable::run() {}
|
||||
#include <errno.h>
|
||||
void Patcher::LoadPatchesInfo()
|
||||
{
|
||||
DIR * dirp;
|
||||
//int errno;
|
||||
struct dirent * dp;
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
dirp = opendir("./patches/");
|
||||
|
||||
if (!dirp)
|
||||
@@ -983,8 +975,10 @@ void Patcher::LoadPatchesInfo()
|
||||
if ((dp = readdir(dirp)) != NULL)
|
||||
{
|
||||
int l = strlen(dp->d_name);
|
||||
|
||||
if (l < 8)
|
||||
continue;
|
||||
|
||||
if (!memcmp(&dp->d_name[l - 4], ".mpq", 4))
|
||||
LoadPatchMD5(dp->d_name);
|
||||
}
|
||||
@@ -1002,19 +996,16 @@ void Patcher::LoadPatchesInfo()
|
||||
if (dirp)
|
||||
closedir(dirp);
|
||||
}
|
||||
|
||||
#else
|
||||
void Patcher::LoadPatchesInfo()
|
||||
{
|
||||
WIN32_FIND_DATA fil;
|
||||
HANDLE hFil=FindFirstFile("./patches/*.mpq", &fil);
|
||||
HANDLE hFil = FindFirstFile("./patches/*.mpq", &fil);
|
||||
if (hFil == INVALID_HANDLE_VALUE)
|
||||
return; // no patches were found
|
||||
|
||||
do
|
||||
{
|
||||
LoadPatchMD5(fil.cFileName);
|
||||
}
|
||||
while (FindNextFile(hFil, &fil));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -16,79 +16,74 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/// \addtogroup realmd
|
||||
/// @{
|
||||
/// \file
|
||||
|
||||
#ifndef _AUTHSOCKET_H
|
||||
#define _AUTHSOCKET_H
|
||||
|
||||
#include "Common.h"
|
||||
#include "BigNumber.h"
|
||||
|
||||
#include "RealmSocket.h"
|
||||
|
||||
enum RealmFlags
|
||||
{
|
||||
REALM_FLAG_NONE = 0x00,
|
||||
REALM_FLAG_INVALID = 0x01,
|
||||
REALM_FLAG_OFFLINE = 0x02,
|
||||
REALM_FLAG_SPECIFYBUILD = 0x04, // client will show realm version in RealmList screen in form "RealmName (major.minor.revision.build)"
|
||||
REALM_FLAG_UNK1 = 0x08,
|
||||
REALM_FLAG_UNK2 = 0x10,
|
||||
REALM_FLAG_RECOMMENDED = 0x20, // client checks pop == 600f
|
||||
REALM_FLAG_NEW = 0x40, // client checks pop == 200f
|
||||
REALM_FLAG_FULL = 0x80 // client checks pop == 400f
|
||||
REALM_FLAG_NONE = 0x00,
|
||||
REALM_FLAG_INVALID = 0x01,
|
||||
REALM_FLAG_OFFLINE = 0x02,
|
||||
REALM_FLAG_SPECIFYBUILD = 0x04,
|
||||
REALM_FLAG_UNK1 = 0x08,
|
||||
REALM_FLAG_UNK2 = 0x10,
|
||||
REALM_FLAG_RECOMMENDED = 0x20,
|
||||
REALM_FLAG_NEW = 0x40,
|
||||
REALM_FLAG_FULL = 0x80
|
||||
};
|
||||
|
||||
/// Handle login commands
|
||||
// Handle login commands
|
||||
class AuthSocket: public RealmSocket::Session
|
||||
{
|
||||
public:
|
||||
const static int s_BYTE_SIZE = 32;
|
||||
public:
|
||||
const static int s_BYTE_SIZE = 32;
|
||||
|
||||
AuthSocket(RealmSocket& socket);
|
||||
virtual ~AuthSocket(void);
|
||||
AuthSocket(RealmSocket& socket);
|
||||
virtual ~AuthSocket(void);
|
||||
|
||||
virtual void OnRead(void);
|
||||
virtual void OnAccept(void);
|
||||
virtual void OnClose(void);
|
||||
virtual void OnRead(void);
|
||||
virtual void OnAccept(void);
|
||||
virtual void OnClose(void);
|
||||
|
||||
bool _HandleLogonChallenge();
|
||||
bool _HandleLogonProof();
|
||||
bool _HandleReconnectChallenge();
|
||||
bool _HandleReconnectProof();
|
||||
bool _HandleRealmList();
|
||||
//data transfer handle for patch
|
||||
bool _HandleLogonChallenge();
|
||||
bool _HandleLogonProof();
|
||||
bool _HandleReconnectChallenge();
|
||||
bool _HandleReconnectProof();
|
||||
bool _HandleRealmList();
|
||||
|
||||
bool _HandleXferResume();
|
||||
bool _HandleXferCancel();
|
||||
bool _HandleXferAccept();
|
||||
//data transfer handle for patch
|
||||
bool _HandleXferResume();
|
||||
bool _HandleXferCancel();
|
||||
bool _HandleXferAccept();
|
||||
|
||||
void _SetVSFields(const std::string& rI);
|
||||
void _SetVSFields(const std::string& rI);
|
||||
|
||||
FILE *pPatch;
|
||||
ACE_Thread_Mutex patcherLock;
|
||||
FILE *pPatch;
|
||||
ACE_Thread_Mutex patcherLock;
|
||||
|
||||
private:
|
||||
RealmSocket& socket_;
|
||||
RealmSocket& socket(void) { return socket_; }
|
||||
private:
|
||||
RealmSocket& socket_;
|
||||
RealmSocket& socket(void) { return socket_; }
|
||||
|
||||
BigNumber N, s, g, v;
|
||||
BigNumber b, B;
|
||||
BigNumber K;
|
||||
BigNumber _reconnectProof;
|
||||
BigNumber N, s, g, v;
|
||||
BigNumber b, B;
|
||||
BigNumber K;
|
||||
BigNumber _reconnectProof;
|
||||
|
||||
bool _authed;
|
||||
bool _authed;
|
||||
|
||||
std::string _login;
|
||||
std::string _login;
|
||||
|
||||
// Since GetLocaleByName() is _NOT_ bijective, we have to store the locale as a string. Otherwise we can't differ
|
||||
// between enUS and enGB, which is important for the patch system
|
||||
std::string _localizationName;
|
||||
uint16 _build;
|
||||
uint8 _expversion;
|
||||
AccountTypes _accountSecurityLevel;
|
||||
// Since GetLocaleByName() is _NOT_ bijective, we have to store the locale as a string. Otherwise we can't differ
|
||||
// between enUS and enGB, which is important for the patch system
|
||||
std::string _localizationName;
|
||||
uint16 _build;
|
||||
uint8 _expversion;
|
||||
AccountTypes _accountSecurityLevel;
|
||||
};
|
||||
|
||||
#endif
|
||||
/// @}
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
\ingroup realmd
|
||||
*/
|
||||
|
||||
#ifndef __REALMACCEPTOR_H__
|
||||
#define __REALMACCEPTOR_H__
|
||||
|
||||
@@ -31,20 +27,20 @@
|
||||
|
||||
class RealmAcceptor : public ACE_Acceptor<RealmSocket, ACE_SOCK_Acceptor>
|
||||
{
|
||||
public:
|
||||
RealmAcceptor(void) { }
|
||||
virtual ~RealmAcceptor(void) { }
|
||||
public:
|
||||
RealmAcceptor(void) { }
|
||||
virtual ~RealmAcceptor(void) { }
|
||||
|
||||
protected:
|
||||
virtual int make_svc_handler(RealmSocket *&sh)
|
||||
{
|
||||
if (sh == 0)
|
||||
ACE_NEW_RETURN(sh, RealmSocket, -1);
|
||||
protected:
|
||||
virtual int make_svc_handler(RealmSocket *&sh)
|
||||
{
|
||||
if (sh == 0)
|
||||
ACE_NEW_RETURN(sh, RealmSocket, -1);
|
||||
|
||||
sh->reactor(reactor());
|
||||
sh->set_session(new AuthSocket(*sh));
|
||||
return 0;
|
||||
}
|
||||
sh->reactor(reactor());
|
||||
sh->set_session(new AuthSocket(*sh));
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* __REALMACCEPTOR_H__ */
|
||||
#endif
|
||||
|
||||
@@ -16,41 +16,27 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
\ingroup realmd
|
||||
*/
|
||||
|
||||
#include "RealmSocket.h"
|
||||
|
||||
#include "Log.h"
|
||||
|
||||
#include <ace/OS_NS_string.h>
|
||||
#include <ace/INET_Addr.h>
|
||||
#include <ace/SString.h>
|
||||
|
||||
#include "RealmSocket.h"
|
||||
#include "Log.h"
|
||||
|
||||
#ifndef MSG_NOSIGNAL
|
||||
#define MSG_NOSIGNAL 0
|
||||
#endif
|
||||
|
||||
RealmSocket::Session::Session(void)
|
||||
RealmSocket::Session::Session(void) {}
|
||||
|
||||
RealmSocket::Session::~Session(void) { }
|
||||
|
||||
RealmSocket::RealmSocket(void) : input_buffer_(4096), session_(NULL), remote_address_()
|
||||
{
|
||||
}
|
||||
|
||||
RealmSocket::Session::~Session(void)
|
||||
{
|
||||
}
|
||||
|
||||
RealmSocket::RealmSocket(void):
|
||||
input_buffer_(4096),
|
||||
session_(NULL),
|
||||
remote_address_()
|
||||
{
|
||||
reference_counting_policy().value(
|
||||
ACE_Event_Handler::Reference_Counting_Policy::ENABLED);
|
||||
|
||||
msg_queue()->high_water_mark(8*1024*1024);
|
||||
msg_queue()->low_water_mark(8*1024*1024);
|
||||
reference_counting_policy().value(ACE_Event_Handler::Reference_Counting_Policy::ENABLED);
|
||||
|
||||
msg_queue()->high_water_mark(8 * 1024 * 1024);
|
||||
msg_queue()->low_water_mark(8 * 1024 * 1024);
|
||||
}
|
||||
|
||||
RealmSocket::~RealmSocket(void)
|
||||
@@ -71,9 +57,9 @@ int RealmSocket::open(void * arg)
|
||||
{
|
||||
ACE_INET_Addr addr;
|
||||
|
||||
if (peer ().get_remote_addr (addr) == -1)
|
||||
if (peer().get_remote_addr(addr) == -1)
|
||||
{
|
||||
sLog->outError ("RealmSocket::open: peer ().get_remote_addr errno = %s", ACE_OS::strerror (errno));
|
||||
sLog->outError("Error %s while opening realm socket!", ACE_OS::strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -83,10 +69,8 @@ int RealmSocket::open(void * arg)
|
||||
if (Base::open(arg) == -1)
|
||||
return -1;
|
||||
|
||||
if (session_ != NULL)
|
||||
{
|
||||
if (session_)
|
||||
session_->OnAccept();
|
||||
}
|
||||
|
||||
// reactor takes care of the socket from now on
|
||||
remove_reference();
|
||||
@@ -152,11 +136,9 @@ ssize_t RealmSocket::noblk_send(ACE_Message_Block &message_block)
|
||||
|
||||
if (n < 0)
|
||||
{
|
||||
if (errno == EWOULDBLOCK)
|
||||
// Blocking signal
|
||||
if (errno == EWOULDBLOCK) // Blocking signal
|
||||
return 0;
|
||||
else
|
||||
// Error happened
|
||||
else // Error happened
|
||||
return -1;
|
||||
}
|
||||
else if (n == 0)
|
||||
@@ -174,19 +156,8 @@ bool RealmSocket::send(const char *buf, size_t len)
|
||||
if (buf == NULL || len == 0)
|
||||
return true;
|
||||
|
||||
ACE_Data_Block db(
|
||||
len,
|
||||
ACE_Message_Block::MB_DATA,
|
||||
(const char*)buf,
|
||||
0,
|
||||
0,
|
||||
ACE_Message_Block::DONT_DELETE,
|
||||
0);
|
||||
|
||||
ACE_Message_Block message_block(
|
||||
&db,
|
||||
ACE_Message_Block::DONT_DELETE,
|
||||
0);
|
||||
ACE_Data_Block db(len, ACE_Message_Block::MB_DATA, (const char*)buf, 0, 0, ACE_Message_Block::DONT_DELETE, 0);
|
||||
ACE_Message_Block message_block(&db, ACE_Message_Block::DONT_DELETE, 0);
|
||||
|
||||
message_block.wr_ptr(len);
|
||||
|
||||
@@ -197,6 +168,7 @@ bool RealmSocket::send(const char *buf, size_t len)
|
||||
|
||||
if (n < 0)
|
||||
return false;
|
||||
|
||||
size_t un = size_t(n);
|
||||
if (un == len)
|
||||
return true;
|
||||
@@ -207,7 +179,7 @@ bool RealmSocket::send(const char *buf, size_t len)
|
||||
|
||||
ACE_Message_Block *mb = message_block.clone();
|
||||
|
||||
if (msg_queue()->enqueue_tail(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
|
||||
if (msg_queue()->enqueue_tail(mb, (ACE_Time_Value *)(&ACE_Time_Value::zero)) == -1)
|
||||
{
|
||||
mb->release();
|
||||
return false;
|
||||
@@ -219,7 +191,7 @@ bool RealmSocket::send(const char *buf, size_t len)
|
||||
return true;
|
||||
}
|
||||
|
||||
int RealmSocket::handle_output(ACE_HANDLE /*= ACE_INVALID_HANDLE*/)
|
||||
int RealmSocket::handle_output(ACE_HANDLE)
|
||||
{
|
||||
if (closing_)
|
||||
return -1;
|
||||
@@ -232,7 +204,7 @@ int RealmSocket::handle_output(ACE_HANDLE /*= ACE_INVALID_HANDLE*/)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (msg_queue()->dequeue_head(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
|
||||
if (msg_queue()->dequeue_head(mb, (ACE_Time_Value *)(&ACE_Time_Value::zero)) == -1)
|
||||
return -1;
|
||||
|
||||
ssize_t n = noblk_send(*mb);
|
||||
@@ -263,24 +235,21 @@ int RealmSocket::handle_output(ACE_HANDLE /*= ACE_INVALID_HANDLE*/)
|
||||
ACE_NOTREACHED(return -1);
|
||||
}
|
||||
|
||||
int RealmSocket::handle_close(ACE_HANDLE h, ACE_Reactor_Mask /*m*/)
|
||||
int RealmSocket::handle_close(ACE_HANDLE h, ACE_Reactor_Mask)
|
||||
{
|
||||
// As opposed to WorldSocket::handle_close, we don't need locks here.
|
||||
|
||||
closing_ = true;
|
||||
|
||||
if (h == ACE_INVALID_HANDLE)
|
||||
peer ().close_writer ();
|
||||
peer().close_writer();
|
||||
|
||||
if (session_ != NULL)
|
||||
{
|
||||
if (session_)
|
||||
session_->OnClose();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RealmSocket::handle_input(ACE_HANDLE /*= ACE_INVALID_HANDLE*/)
|
||||
int RealmSocket::handle_input(ACE_HANDLE)
|
||||
{
|
||||
if (closing_)
|
||||
return -1;
|
||||
@@ -290,21 +259,15 @@ int RealmSocket::handle_input(ACE_HANDLE /*= ACE_INVALID_HANDLE*/)
|
||||
ssize_t n = peer().recv(input_buffer_.wr_ptr(), space);
|
||||
|
||||
if (n < 0)
|
||||
{
|
||||
return errno == EWOULDBLOCK ? 0 : -1;
|
||||
}
|
||||
else if (n == 0)
|
||||
{
|
||||
// EOF
|
||||
else if (n == 0) // EOF
|
||||
return -1;
|
||||
}
|
||||
|
||||
input_buffer_.wr_ptr((size_t)n);
|
||||
|
||||
if (session_ != NULL)
|
||||
{
|
||||
session_->OnRead();
|
||||
|
||||
input_buffer_.crunch();
|
||||
}
|
||||
|
||||
@@ -320,4 +283,3 @@ void RealmSocket::set_session(Session* session)
|
||||
|
||||
session_ = session;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** \file
|
||||
\ingroup realmd
|
||||
*/
|
||||
|
||||
#ifndef __REALMSOCKET_H__
|
||||
#define __REALMSOCKET_H__
|
||||
|
||||
@@ -31,52 +27,50 @@
|
||||
|
||||
class RealmSocket : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
|
||||
{
|
||||
private:
|
||||
typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> Base;
|
||||
private:
|
||||
typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> Base;
|
||||
|
||||
public:
|
||||
class Session
|
||||
{
|
||||
public:
|
||||
class Session
|
||||
{
|
||||
public:
|
||||
Session(void);
|
||||
virtual ~Session(void);
|
||||
Session(void);
|
||||
virtual ~Session(void);
|
||||
|
||||
virtual void OnRead(void) = 0;
|
||||
virtual void OnAccept(void) = 0;
|
||||
virtual void OnClose(void) = 0;
|
||||
};
|
||||
virtual void OnRead(void) = 0;
|
||||
virtual void OnAccept(void) = 0;
|
||||
virtual void OnClose(void) = 0;
|
||||
};
|
||||
|
||||
RealmSocket(void);
|
||||
virtual ~RealmSocket(void);
|
||||
RealmSocket(void);
|
||||
virtual ~RealmSocket(void);
|
||||
|
||||
size_t recv_len(void) const;
|
||||
bool recv_soft(char *buf, size_t len);
|
||||
bool recv(char *buf, size_t len);
|
||||
void recv_skip(size_t len);
|
||||
size_t recv_len(void) const;
|
||||
bool recv_soft(char *buf, size_t len);
|
||||
bool recv(char *buf, size_t len);
|
||||
void recv_skip(size_t len);
|
||||
|
||||
bool send(const char *buf, size_t len);
|
||||
bool send(const char *buf, size_t len);
|
||||
|
||||
const std::string& get_remote_address(void) const;
|
||||
const std::string& get_remote_address(void) const;
|
||||
|
||||
virtual int open(void *);
|
||||
virtual int open(void *);
|
||||
|
||||
virtual int close(int);
|
||||
virtual int close(int);
|
||||
|
||||
virtual int handle_input(ACE_HANDLE = ACE_INVALID_HANDLE);
|
||||
virtual int handle_output(ACE_HANDLE = ACE_INVALID_HANDLE);
|
||||
virtual int handle_input(ACE_HANDLE = ACE_INVALID_HANDLE);
|
||||
virtual int handle_output(ACE_HANDLE = ACE_INVALID_HANDLE);
|
||||
|
||||
virtual int handle_close(ACE_HANDLE = ACE_INVALID_HANDLE,
|
||||
ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
|
||||
virtual int handle_close(ACE_HANDLE = ACE_INVALID_HANDLE, ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
|
||||
|
||||
void set_session(Session* session);
|
||||
void set_session(Session* session);
|
||||
|
||||
private:
|
||||
ssize_t noblk_send(ACE_Message_Block &message_block);
|
||||
private:
|
||||
ssize_t noblk_send(ACE_Message_Block &message_block);
|
||||
|
||||
private:
|
||||
ACE_Message_Block input_buffer_;
|
||||
Session* session_;
|
||||
std::string remote_address_;
|
||||
ACE_Message_Block input_buffer_;
|
||||
Session *session_;
|
||||
std::string remote_address_;
|
||||
};
|
||||
|
||||
#endif /* __REALMSOCKET_H__ */
|
||||
|
||||
Reference in New Issue
Block a user