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:
1 parent
dd745ef326
commit
60c6d462e4
11 files changed
+299
-474
No files matched your search
@@ -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