Skip to content

Commit

Permalink
Various Cleanups (realmd/)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schmoozerd committed Jul 19, 2012
1 parent 7edba28 commit 1cf0d94
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 204 deletions.
2 changes: 1 addition & 1 deletion src/realmd/AuthCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ enum AuthResult
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
// client reject next login attempts after this error, so in code used WOW_FAIL_UNKNOWN_ACCOUNT for both cases
// client reject next login attempts after this error, so in code used WOW_FAIL_UNKNOWN_ACCOUNT for both cases
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.
Expand Down
144 changes: 72 additions & 72 deletions src/realmd/AuthSocket.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/realmd/AuthSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class AuthSocket: public BufferedSocket
void OnAccept();
void OnRead();
void SendProof(Sha1Hash sha);
void LoadRealmlist(ByteBuffer &pkt, uint32 acctid);
void LoadRealmlist(ByteBuffer& pkt, uint32 acctid);

bool _HandleLogonChallenge();
bool _HandleLogonProof();
Expand Down
76 changes: 38 additions & 38 deletions src/realmd/BufferedSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ BufferedSocket::BufferedSocket(void):
{
}

/*virtual*/ int BufferedSocket::open(void * arg)
/*virtual*/ int BufferedSocket::open(void* arg)
{
if(Base::open(arg) == -1)
if (Base::open(arg) == -1)
return -1;

ACE_INET_Addr addr;

if(peer().get_remote_addr(addr) == -1)
if (peer().get_remote_addr(addr) == -1)
return -1;

char address[1024];
Expand All @@ -71,21 +71,21 @@ size_t BufferedSocket::recv_len(void) const
return this->input_buffer_.length();
}

bool BufferedSocket::recv_soft(char *buf, size_t len)
bool BufferedSocket::recv_soft(char* buf, size_t len)
{
if(this->input_buffer_.length() < len)
if (this->input_buffer_.length() < len)
return false;

ACE_OS::memcpy(buf, this->input_buffer_.rd_ptr(), len);

return true;
}

bool BufferedSocket::recv(char *buf, size_t len)
bool BufferedSocket::recv(char* buf, size_t len)
{
bool ret = this->recv_soft(buf, len);

if(ret)
if (ret)
this->recv_skip(len);

return ret;
Expand All @@ -96,26 +96,26 @@ void BufferedSocket::recv_skip(size_t len)
this->input_buffer_.rd_ptr(len);
}

ssize_t BufferedSocket::noblk_send(ACE_Message_Block &message_block)
ssize_t BufferedSocket::noblk_send(ACE_Message_Block& message_block)
{
const size_t len = message_block.length();

if(len == 0)
if (len == 0)
return -1;

// Try to send the message directly.
ssize_t n = this->peer().send(message_block.rd_ptr(), len, MSG_NOSIGNAL);

if(n < 0)
if (n < 0)
{
if(errno == EWOULDBLOCK)
if (errno == EWOULDBLOCK)
// Blocking signal
return 0;
else
// Error
return -1;
}
else if(n == 0)
else if (n == 0)
{
// Can this happen ?
return -1;
Expand All @@ -125,35 +125,35 @@ ssize_t BufferedSocket::noblk_send(ACE_Message_Block &message_block)
return n;
}

bool BufferedSocket::send(const char *buf, size_t len)
bool BufferedSocket::send(const char* buf, size_t len)
{
if(buf == NULL || len == 0)
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);
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);
&db,
ACE_Message_Block::DONT_DELETE,
0);

message_block.wr_ptr(len);

if(this->msg_queue()->is_empty())
if (this->msg_queue()->is_empty())
{
// Try to send it directly.
ssize_t n = this->noblk_send(message_block);

if(n < 0)
if (n < 0)
return false;
else if(n == len)
else if (n == len)
return true;

// adjust how much bytes we sent
Expand All @@ -163,43 +163,43 @@ bool BufferedSocket::send(const char *buf, size_t len)
}

// enqueue the message, note: clone is needed cause we cant enqueue stuff on the stack
ACE_Message_Block *mb = message_block.clone();
ACE_Message_Block* mb = message_block.clone();

if(this->msg_queue()->enqueue_tail(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
if (this->msg_queue()->enqueue_tail(mb, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
{
mb->release();
return false;
}

// tell reactor to call handle_output() when we can send more data
if(this->reactor()->schedule_wakeup(this, ACE_Event_Handler::WRITE_MASK) == -1)
if (this->reactor()->schedule_wakeup(this, ACE_Event_Handler::WRITE_MASK) == -1)
return false;

return true;
}

/*virtual*/ int BufferedSocket::handle_output(ACE_HANDLE /*= ACE_INVALID_HANDLE*/)
{
ACE_Message_Block *mb = 0;
ACE_Message_Block* mb = 0;

if(this->msg_queue()->is_empty())
if (this->msg_queue()->is_empty())
{
// if no more data to send, then cancel notification
this->reactor()->cancel_wakeup(this, ACE_Event_Handler::WRITE_MASK);
return 0;
}

if(this->msg_queue()->dequeue_head(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
if (this->msg_queue()->dequeue_head(mb, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
return -1;

ssize_t n = this->noblk_send(*mb);

if(n < 0)
if (n < 0)
{
mb->release();
return -1;
}
else if(n == mb->length())
else if (n == mb->length())
{
mb->release();
return 1;
Expand All @@ -208,7 +208,7 @@ bool BufferedSocket::send(const char *buf, size_t len)
{
mb->rd_ptr(n);

if(this->msg_queue()->enqueue_head(mb, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1)
if (this->msg_queue()->enqueue_head(mb, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
{
mb->release();
return -1;
Expand All @@ -226,12 +226,12 @@ bool BufferedSocket::send(const char *buf, size_t len)

ssize_t n = this->peer().recv(this->input_buffer_.wr_ptr(), space);

if(n < 0)
if (n < 0)
{
// blocking signal or error
return errno == EWOULDBLOCK ? 0 : -1;
}
else if(n == 0)
else if (n == 0)
{
// EOF
return -1;
Expand Down
12 changes: 6 additions & 6 deletions src/realmd/BufferedSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@ class BufferedSocket: public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
virtual ~BufferedSocket(void);

size_t recv_len(void) const;
bool recv_soft(char *buf, size_t len);
bool recv(char *buf, size_t len);
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;

virtual int open(void *);
virtual int open(void*);

void close_connection(void);

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);
ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);

private:
ssize_t noblk_send(ACE_Message_Block &message_block);
ssize_t noblk_send(ACE_Message_Block& message_block);

private:
ACE_Message_Block input_buffer_;
Expand Down

0 comments on commit 1cf0d94

Please sign in to comment.