[svn] Merge from Mangos:
3c7ac5bd3e20c33a22ac57c5c3bac23a0798dc9e 2008-10-23 19:06:27 Some endianess related fixes and cleanups. By VladimirMangos. --HG-- branch : trunk
This commit is contained in:
@@ -48,12 +48,18 @@ namespace ByteConverter
|
||||
|
||||
#if TRINITY_ENDIAN == TRINITY_BIGENDIAN
|
||||
template<typename T> inline void EndianConvert(T& val) { ByteConverter::apply<T>(&val); }
|
||||
template<typename T> inline void EndianConvertReverse(T&) { }
|
||||
#else
|
||||
template<typename T> inline void EndianConvert(T&) { }
|
||||
template<typename T> inline void EndianConvertReverse(T& val) { ByteConverter::apply<T>(&val); }
|
||||
#endif
|
||||
|
||||
template<typename T> inline void EndianConvert(T*) { }
|
||||
template<typename T> void EndianConvert(T*); // will generate link error
|
||||
template<typename T> void EndianConvertReverse(T*); // will generate link error
|
||||
|
||||
inline void EndianConvert(uint8&) { }
|
||||
inline void EndianConvert( int8&) { }
|
||||
inline void EndianConvertReverse(uint8&) { }
|
||||
inline void EndianConvertReverse( int8&) { }
|
||||
|
||||
#endif
|
||||
|
||||
+6
-5
@@ -230,7 +230,7 @@ World::AddSession_ (WorldSession* s)
|
||||
packet << uint32 (0); // unknown random value...
|
||||
packet << uint8 (0);
|
||||
packet << uint32 (0);
|
||||
packet << uint8 (s->Expansion () ? 1 : 0); // 0 - normal, 1 - TBC, must be set in database manually for each account
|
||||
packet << uint8 (s->Expansion()); // 0 - normal, 1 - TBC, must be set in database manually for each account
|
||||
s->SendPacket (&packet);
|
||||
|
||||
UpdateMaxSessionCounters ();
|
||||
@@ -2304,7 +2304,7 @@ BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, std::string dura
|
||||
if(!resultAccounts)
|
||||
{
|
||||
if(mode==BAN_IP)
|
||||
return BAN_SUCCESS;
|
||||
return BAN_SUCCESS; // ip correctly banned but nobody affected (yet)
|
||||
else
|
||||
return BAN_NOTFOUND; // Nobody to ban
|
||||
}
|
||||
@@ -2342,13 +2342,13 @@ bool World::RemoveBanAccount(BanMode mode, std::string nameOrIP)
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32 account=0;
|
||||
uint32 account = 0;
|
||||
if (mode == BAN_ACCOUNT)
|
||||
account = accmgr.GetId (nameOrIP);
|
||||
else if (mode == BAN_CHARACTER)
|
||||
account = objmgr.GetPlayerAccountIdByPlayerName (nameOrIP);
|
||||
|
||||
if(!account)
|
||||
if (!account)
|
||||
return false;
|
||||
|
||||
//NO SQL injection as account is uint32
|
||||
@@ -2433,7 +2433,7 @@ void World::ShutdownMsg(bool show, Player* player)
|
||||
uint32 msgid = (m_ShutdownMask & SHUTDOWN_MASK_RESTART) ? SERVER_MSG_RESTART_TIME : SERVER_MSG_SHUTDOWN_TIME;
|
||||
|
||||
SendServerMessage(msgid,str.c_str(),player);
|
||||
outstring_log("Server will %s in %s", (m_ShutdownMask & SHUTDOWN_MASK_RESTART ? "restart" : "shutdown"), str.c_str());
|
||||
DEBUG_LOG("Server is %s in %s",(m_ShutdownMask & SHUTDOWN_MASK_RESTART ? "restart" : "shuttingdown"),str.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2507,6 +2507,7 @@ void World::ProcessCliCommands()
|
||||
return;
|
||||
|
||||
CliCommandHolder::Print* zprint;
|
||||
|
||||
while (!cliCmdQueue.empty())
|
||||
{
|
||||
sLog.outDebug("CLI command under processing...");
|
||||
|
||||
@@ -61,8 +61,8 @@ _logoutTime(0), m_playerLoading(false), m_playerLogout(false), m_playerRecentlyL
|
||||
WorldSession::~WorldSession()
|
||||
{
|
||||
///- unload player if not unloaded
|
||||
if(_player)
|
||||
LogoutPlayer(true);
|
||||
if (_player)
|
||||
LogoutPlayer (true);
|
||||
|
||||
/// - If have unclosed socket, close it
|
||||
if (m_Socket)
|
||||
@@ -75,10 +75,9 @@ WorldSession::~WorldSession()
|
||||
///- empty incoming packet queue
|
||||
while(!_recvQueue.empty())
|
||||
{
|
||||
WorldPacket *packet = _recvQueue.next();
|
||||
WorldPacket *packet = _recvQueue.next ();
|
||||
delete packet;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void WorldSession::SizeError(WorldPacket const& packet, uint32 size) const
|
||||
@@ -133,7 +132,7 @@ void WorldSession::SendPacket(WorldPacket const* packet)
|
||||
sendLastPacketBytes = packet->wpos(); // wpos is real written size
|
||||
}
|
||||
|
||||
#endif // !TRINITY_DEBUG
|
||||
#endif // !MANGOS_DEBUG
|
||||
|
||||
if (m_Socket->SendPacket (*packet) == -1)
|
||||
m_Socket->CloseSocket ();
|
||||
@@ -284,7 +283,7 @@ void WorldSession::LogoutPlayer(bool Save)
|
||||
|
||||
// give honor to all attackers from set like group case
|
||||
for(std::set<Player*>::const_iterator itr = aset.begin(); itr != aset.end(); ++itr)
|
||||
(*itr)->RewardHonor(_player, aset.size(), -1, true);
|
||||
(*itr)->RewardHonor(_player,aset.size());
|
||||
|
||||
// give bg rewards and update counters like kill by first from attackers
|
||||
// this can't be called for all attackers.
|
||||
@@ -521,7 +520,3 @@ void WorldSession::SendAuthWaitQue(uint32 position)
|
||||
SendPacket(&packet);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+108
-152
@@ -1,22 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
|
||||
*
|
||||
* Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
* Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
|
||||
*
|
||||
* Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <ace/Message_Block.h>
|
||||
#include <ace/OS_NS_string.h>
|
||||
@@ -54,14 +54,14 @@
|
||||
|
||||
struct ServerPktHeader
|
||||
{
|
||||
ACE_UINT16 size;
|
||||
ACE_UINT16 cmd;
|
||||
uint16 size;
|
||||
uint16 cmd;
|
||||
};
|
||||
|
||||
struct ClientPktHeader
|
||||
{
|
||||
ACE_UINT16 size;
|
||||
ACE_UINT32 cmd;
|
||||
uint16 size;
|
||||
uint32 cmd;
|
||||
};
|
||||
|
||||
#if defined( __GNUC__ )
|
||||
@@ -83,7 +83,7 @@ m_Seed (static_cast<uint32> (rand32 ())),
|
||||
m_OverSpeedPings (0),
|
||||
m_LastPingTime (ACE_Time_Value::zero)
|
||||
{
|
||||
this->reference_counting_policy ().value (ACE_Event_Handler::Reference_Counting_Policy::ENABLED);
|
||||
reference_counting_policy ().value (ACE_Event_Handler::Reference_Counting_Policy::ENABLED);
|
||||
}
|
||||
|
||||
WorldSocket::~WorldSocket (void)
|
||||
@@ -94,33 +94,31 @@ WorldSocket::~WorldSocket (void)
|
||||
if (m_OutBuffer)
|
||||
m_OutBuffer->release ();
|
||||
|
||||
this->closing_ = true;
|
||||
closing_ = true;
|
||||
|
||||
this->peer ().close ();
|
||||
peer ().close ();
|
||||
|
||||
WorldPacket* pct;
|
||||
while (m_PacketQueue.dequeue_head (pct) == 0)
|
||||
delete pct;
|
||||
}
|
||||
|
||||
bool
|
||||
WorldSocket::IsClosed (void) const
|
||||
bool WorldSocket::IsClosed (void) const
|
||||
{
|
||||
return this->closing_;
|
||||
return closing_;
|
||||
}
|
||||
|
||||
void
|
||||
WorldSocket::CloseSocket (void)
|
||||
void WorldSocket::CloseSocket (void)
|
||||
{
|
||||
{
|
||||
ACE_GUARD (LockType, Guard, m_OutBufferLock);
|
||||
|
||||
if (this->closing_)
|
||||
if (closing_)
|
||||
return;
|
||||
|
||||
this->closing_ = true;
|
||||
closing_ = true;
|
||||
|
||||
this->peer ().close_writer ();
|
||||
peer ().close_writer ();
|
||||
}
|
||||
|
||||
{
|
||||
@@ -128,21 +126,18 @@ WorldSocket::CloseSocket (void)
|
||||
|
||||
m_Session = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const std::string&
|
||||
WorldSocket::GetRemoteAddress (void) const
|
||||
const std::string& WorldSocket::GetRemoteAddress (void) const
|
||||
{
|
||||
return m_Address;
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::SendPacket (const WorldPacket& pct)
|
||||
int WorldSocket::SendPacket (const WorldPacket& pct)
|
||||
{
|
||||
ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
|
||||
|
||||
if (this->closing_)
|
||||
if (closing_)
|
||||
return -1;
|
||||
|
||||
// Dump outgoing packet.
|
||||
@@ -158,7 +153,7 @@ WorldSocket::SendPacket (const WorldPacket& pct)
|
||||
while (p < pct.size ())
|
||||
{
|
||||
for (uint32 j = 0; j < 16 && p < pct.size (); j++)
|
||||
sWorldLog.Log ("%.2X ", const_cast<WorldPacket&> (pct)[p++]);
|
||||
sWorldLog.Log ("%.2X ", const_cast<WorldPacket&>(pct)[p++]);
|
||||
|
||||
sWorldLog.Log ("\n");
|
||||
}
|
||||
@@ -185,20 +180,17 @@ WorldSocket::SendPacket (const WorldPacket& pct)
|
||||
return 0;
|
||||
}
|
||||
|
||||
long
|
||||
WorldSocket::AddReference (void)
|
||||
long WorldSocket::AddReference (void)
|
||||
{
|
||||
return static_cast<long> (this->add_reference ());
|
||||
return static_cast<long> (add_reference ());
|
||||
}
|
||||
|
||||
long
|
||||
WorldSocket::RemoveReference (void)
|
||||
long WorldSocket::RemoveReference (void)
|
||||
{
|
||||
return static_cast<long> (this->remove_reference ());
|
||||
return static_cast<long> (remove_reference ());
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::open (void *a)
|
||||
int WorldSocket::open (void *a)
|
||||
{
|
||||
ACE_UNUSED_ARG (a);
|
||||
|
||||
@@ -220,7 +212,7 @@ WorldSocket::open (void *a)
|
||||
// Store peer address.
|
||||
ACE_INET_Addr remote_addr;
|
||||
|
||||
if (this->peer ().get_remote_addr (remote_addr) == -1)
|
||||
if (peer ().get_remote_addr (remote_addr) == -1)
|
||||
{
|
||||
sLog.outError ("WorldSocket::open: peer ().get_remote_addr errno = %s", ACE_OS::strerror (errno));
|
||||
return -1;
|
||||
@@ -236,51 +228,47 @@ WorldSocket::open (void *a)
|
||||
return -1;
|
||||
|
||||
// Register with ACE Reactor
|
||||
if (this->reactor ()->register_handler
|
||||
(this,
|
||||
ACE_Event_Handler::READ_MASK | ACE_Event_Handler::WRITE_MASK) == -1)
|
||||
if (reactor ()->register_handler(this, ACE_Event_Handler::READ_MASK | ACE_Event_Handler::WRITE_MASK) == -1)
|
||||
{
|
||||
sLog.outError ("WorldSocket::open: unable to register client handler errno = %s", ACE_OS::strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
// reactor takes care of the socket from now on
|
||||
this->remove_reference ();
|
||||
remove_reference ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::close (int)
|
||||
int WorldSocket::close (int)
|
||||
{
|
||||
this->shutdown ();
|
||||
shutdown ();
|
||||
|
||||
this->closing_ = true;
|
||||
closing_ = true;
|
||||
|
||||
this->remove_reference ();
|
||||
remove_reference ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::handle_input (ACE_HANDLE)
|
||||
int WorldSocket::handle_input (ACE_HANDLE)
|
||||
{
|
||||
if (this->closing_)
|
||||
if (closing_)
|
||||
return -1;
|
||||
|
||||
switch (this->handle_input_missing_data ())
|
||||
switch (handle_input_missing_data ())
|
||||
{
|
||||
case -1 :
|
||||
{
|
||||
if ((errno == EWOULDBLOCK) ||
|
||||
(errno == EAGAIN))
|
||||
{
|
||||
//return 0;
|
||||
return this->Update (); // interesting line ,isnt it ?
|
||||
return Update (); // interesting line ,isnt it ?
|
||||
}
|
||||
|
||||
DEBUG_LOG ("WorldSocket::handle_input: Peer error closing connection errno = %s", ACE_OS::strerror (errno));
|
||||
|
||||
errno = ECONNRESET;
|
||||
return -1;
|
||||
}
|
||||
case 0:
|
||||
@@ -288,35 +276,33 @@ WorldSocket::handle_input (ACE_HANDLE)
|
||||
DEBUG_LOG ("WorldSocket::handle_input: Peer has closed connection\n");
|
||||
|
||||
errno = ECONNRESET;
|
||||
|
||||
return -1;
|
||||
}
|
||||
case 1:
|
||||
return 1;
|
||||
default:
|
||||
return Update (); // another interesting line ;)
|
||||
}
|
||||
|
||||
//return 0;
|
||||
return this->Update (); // another interesting line ;)
|
||||
ACE_NOTREACHED(return -1);
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::handle_output (ACE_HANDLE)
|
||||
int WorldSocket::handle_output (ACE_HANDLE)
|
||||
{
|
||||
ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
|
||||
|
||||
if (this->closing_)
|
||||
if (closing_)
|
||||
return -1;
|
||||
|
||||
const size_t send_len = m_OutBuffer->length ();
|
||||
|
||||
if (send_len == 0)
|
||||
return this->cancel_wakeup_output (Guard);
|
||||
return cancel_wakeup_output (Guard);
|
||||
|
||||
// TODO SO_NOSIGPIPE on platforms that support it
|
||||
#ifdef MSG_NOSIGNAL
|
||||
ssize_t n = this->peer ().send (m_OutBuffer->rd_ptr (), send_len, MSG_NOSIGNAL);
|
||||
ssize_t n = peer ().send (m_OutBuffer->rd_ptr (), send_len, MSG_NOSIGNAL);
|
||||
#else
|
||||
ssize_t n = this->peer ().send (m_OutBuffer->rd_ptr (), send_len);
|
||||
ssize_t n = peer ().send (m_OutBuffer->rd_ptr (), send_len);
|
||||
#endif // MSG_NOSIGNAL
|
||||
|
||||
if (n == 0)
|
||||
@@ -324,7 +310,7 @@ WorldSocket::handle_output (ACE_HANDLE)
|
||||
else if (n == -1)
|
||||
{
|
||||
if (errno == EWOULDBLOCK || errno == EAGAIN)
|
||||
return this->schedule_wakeup_output (Guard);
|
||||
return schedule_wakeup_output (Guard);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -335,32 +321,31 @@ WorldSocket::handle_output (ACE_HANDLE)
|
||||
// move the data to the base of the buffer
|
||||
m_OutBuffer->crunch ();
|
||||
|
||||
return this->schedule_wakeup_output (Guard);
|
||||
return schedule_wakeup_output (Guard);
|
||||
}
|
||||
else //now n == send_len
|
||||
{
|
||||
m_OutBuffer->reset ();
|
||||
|
||||
if (!iFlushPacketQueue ())
|
||||
return this->cancel_wakeup_output (Guard);
|
||||
return cancel_wakeup_output (Guard);
|
||||
else
|
||||
return this->schedule_wakeup_output (Guard);
|
||||
return schedule_wakeup_output (Guard);
|
||||
}
|
||||
|
||||
ACE_NOTREACHED (return 0);
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::handle_close (ACE_HANDLE h, ACE_Reactor_Mask)
|
||||
int WorldSocket::handle_close (ACE_HANDLE h, ACE_Reactor_Mask)
|
||||
{
|
||||
// Critical section
|
||||
{
|
||||
ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
|
||||
|
||||
this->closing_ = true;
|
||||
closing_ = true;
|
||||
|
||||
if (h == ACE_INVALID_HANDLE)
|
||||
this->peer ().close_writer ();
|
||||
peer ().close_writer ();
|
||||
}
|
||||
|
||||
// Critical section
|
||||
@@ -373,49 +358,35 @@ WorldSocket::handle_close (ACE_HANDLE h, ACE_Reactor_Mask)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::Update (void)
|
||||
int WorldSocket::Update (void)
|
||||
{
|
||||
if (this->closing_)
|
||||
if (closing_)
|
||||
return -1;
|
||||
|
||||
if (m_OutActive || m_OutBuffer->length () == 0)
|
||||
return 0;
|
||||
|
||||
return this->handle_output (this->get_handle ());
|
||||
return handle_output (get_handle ());
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::handle_input_header (void)
|
||||
int WorldSocket::handle_input_header (void)
|
||||
{
|
||||
ACE_ASSERT (m_RecvWPct == NULL);
|
||||
|
||||
if (m_Header.length () != sizeof (ClientPktHeader))
|
||||
{
|
||||
sLog.outError ("WorldSocket::handle_input_header: internal error: invalid header");
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
ACE_ASSERT (m_Header.length () == sizeof (ClientPktHeader));
|
||||
|
||||
m_Crypt.DecryptRecv ((ACE_UINT8*) m_Header.rd_ptr (), sizeof (ClientPktHeader));
|
||||
|
||||
ClientPktHeader& header = *((ClientPktHeader*) m_Header.rd_ptr ());
|
||||
|
||||
header.size = ACE_NTOHS (header.size);
|
||||
EndianConvertReverse(header.size);
|
||||
EndianConvert(header.cmd);
|
||||
|
||||
#if ACE_BYTE_ORDER == ACE_BIG_ENDIAN
|
||||
header.cmd = ACE_SWAP_LONG (header.cmd)
|
||||
#endif // ACE_BIG_ENDIAN
|
||||
|
||||
if ((header.size < 4) ||
|
||||
(header.size > 10240) ||
|
||||
(header.cmd <= 0) ||
|
||||
(header.cmd > 10240)
|
||||
)
|
||||
if ((header.size < 4) || (header.size > 10240) ||
|
||||
(header.cmd < 0) || (header.cmd > 10240) )
|
||||
{
|
||||
sLog.outError ("WorldSocket::handle_input_header: client sent mailformed packet size = %d , cmd = %d",
|
||||
header.size,
|
||||
header.cmd);
|
||||
header.size, header.cmd);
|
||||
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
@@ -425,22 +396,20 @@ WorldSocket::handle_input_header (void)
|
||||
|
||||
ACE_NEW_RETURN (m_RecvWPct, WorldPacket ((uint16) header.cmd, header.size), -1);
|
||||
|
||||
if (header.size > 0)
|
||||
if(header.size > 0)
|
||||
{
|
||||
m_RecvWPct->resize (header.size);
|
||||
m_RecvPct.base ((char*) m_RecvWPct->contents (), m_RecvWPct->size ());
|
||||
}
|
||||
else
|
||||
{
|
||||
ACE_ASSERT (m_RecvPct.space () == 0);
|
||||
ACE_ASSERT(m_RecvPct.space() == 0);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::handle_input_payload (void)
|
||||
int WorldSocket::handle_input_payload (void)
|
||||
{
|
||||
// set errno properly here on error !!!
|
||||
// now have a header and payload
|
||||
@@ -449,7 +418,7 @@ WorldSocket::handle_input_payload (void)
|
||||
ACE_ASSERT (m_Header.space () == 0);
|
||||
ACE_ASSERT (m_RecvWPct != NULL);
|
||||
|
||||
const int ret = this->ProcessIncoming (m_RecvWPct);
|
||||
const int ret = ProcessIncoming (m_RecvWPct);
|
||||
|
||||
m_RecvPct.base (NULL, 0);
|
||||
m_RecvPct.reset ();
|
||||
@@ -463,12 +432,11 @@ WorldSocket::handle_input_payload (void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::handle_input_missing_data (void)
|
||||
int WorldSocket::handle_input_missing_data (void)
|
||||
{
|
||||
char buf [1024];
|
||||
|
||||
ACE_Data_Block db (sizeof (buf),
|
||||
ACE_Data_Block db ( sizeof (buf),
|
||||
ACE_Message_Block::MB_DATA,
|
||||
buf,
|
||||
0,
|
||||
@@ -476,13 +444,13 @@ WorldSocket::handle_input_missing_data (void)
|
||||
ACE_Message_Block::DONT_DELETE,
|
||||
0);
|
||||
|
||||
ACE_Message_Block message_block (&db,
|
||||
ACE_Message_Block message_block(&db,
|
||||
ACE_Message_Block::DONT_DELETE,
|
||||
0);
|
||||
|
||||
const size_t recv_size = message_block.space ();
|
||||
|
||||
const ssize_t n = this->peer ().recv (message_block.wr_ptr (),
|
||||
const ssize_t n = peer ().recv (message_block.wr_ptr (),
|
||||
recv_size);
|
||||
|
||||
if (n <= 0)
|
||||
@@ -508,7 +476,7 @@ WorldSocket::handle_input_missing_data (void)
|
||||
}
|
||||
|
||||
//we just recieved nice new header
|
||||
if (this->handle_input_header () == -1)
|
||||
if (handle_input_header () == -1)
|
||||
{
|
||||
ACE_ASSERT ((errno != EWOULDBLOCK) && (errno != EAGAIN));
|
||||
return -1;
|
||||
@@ -543,7 +511,7 @@ WorldSocket::handle_input_missing_data (void)
|
||||
}
|
||||
|
||||
//just recieved fresh new payload
|
||||
if (this->handle_input_payload () == -1)
|
||||
if (handle_input_payload () == -1)
|
||||
{
|
||||
ACE_ASSERT ((errno != EWOULDBLOCK) && (errno != EAGAIN));
|
||||
return -1;
|
||||
@@ -553,8 +521,7 @@ WorldSocket::handle_input_missing_data (void)
|
||||
return n == recv_size ? 1 : 2;
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::cancel_wakeup_output (GuardType& g)
|
||||
int WorldSocket::cancel_wakeup_output (GuardType& g)
|
||||
{
|
||||
if (!m_OutActive)
|
||||
return 0;
|
||||
@@ -563,7 +530,7 @@ WorldSocket::cancel_wakeup_output (GuardType& g)
|
||||
|
||||
g.release ();
|
||||
|
||||
if (this->reactor ()->cancel_wakeup
|
||||
if (reactor ()->cancel_wakeup
|
||||
(this, ACE_Event_Handler::WRITE_MASK) == -1)
|
||||
{
|
||||
// would be good to store errno from reactor with errno guard
|
||||
@@ -574,8 +541,7 @@ WorldSocket::cancel_wakeup_output (GuardType& g)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::schedule_wakeup_output (GuardType& g)
|
||||
int WorldSocket::schedule_wakeup_output (GuardType& g)
|
||||
{
|
||||
if (m_OutActive)
|
||||
return 0;
|
||||
@@ -584,7 +550,7 @@ WorldSocket::schedule_wakeup_output (GuardType& g)
|
||||
|
||||
g.release ();
|
||||
|
||||
if (this->reactor ()->schedule_wakeup
|
||||
if (reactor ()->schedule_wakeup
|
||||
(this, ACE_Event_Handler::WRITE_MASK) == -1)
|
||||
{
|
||||
sLog.outError ("WorldSocket::schedule_wakeup_output");
|
||||
@@ -594,8 +560,7 @@ WorldSocket::schedule_wakeup_output (GuardType& g)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::ProcessIncoming (WorldPacket* new_pct)
|
||||
int WorldSocket::ProcessIncoming (WorldPacket* new_pct)
|
||||
{
|
||||
ACE_ASSERT (new_pct);
|
||||
|
||||
@@ -604,7 +569,7 @@ WorldSocket::ProcessIncoming (WorldPacket* new_pct)
|
||||
|
||||
const ACE_UINT16 opcode = new_pct->GetOpcode ();
|
||||
|
||||
if (this->closing_)
|
||||
if (closing_)
|
||||
return -1;
|
||||
|
||||
// dump recieved packet
|
||||
@@ -670,9 +635,9 @@ WorldSocket::ProcessIncoming (WorldPacket* new_pct)
|
||||
ACE_NOTREACHED (return 0);
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||
int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||
{
|
||||
// NOTE: ATM the socket is singlethreaded, have this in mind ...
|
||||
uint8 digest[20];
|
||||
uint32 clientSeed;
|
||||
uint32 unk2;
|
||||
@@ -778,8 +743,7 @@ WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||
const char* vStr = v.AsHexStr (); //Must be freed by OPENSSL_free()
|
||||
const char* vold = fields[6].GetString ();
|
||||
|
||||
DEBUG_LOG ("WorldSocket::HandleAuthSession: "
|
||||
"(s,v) check s: %s v_old: %s v_new: %s",
|
||||
DEBUG_LOG ("WorldSocket::HandleAuthSession: (s,v) check s: %s v_old: %s v_new: %s",
|
||||
sStr,
|
||||
vold,
|
||||
vStr);
|
||||
@@ -852,7 +816,7 @@ WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||
|
||||
delete banresult;
|
||||
|
||||
sLog.outBasic ("WorldSocket::HandleAuthSession: Sent Auth Response (Account banned).");
|
||||
sLog.outError ("WorldSocket::HandleAuthSession: Sent Auth Response (Account banned).");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -890,11 +854,11 @@ WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||
|
||||
SendPacket (packet);
|
||||
|
||||
sLog.outBasic ("WorldSocket::HandleAuthSession: Sent Auth Response (authentification failed).");
|
||||
sLog.outError ("WorldSocket::HandleAuthSession: Sent Auth Response (authentification failed).");
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string address = this->GetRemoteAddress ();
|
||||
std::string address = GetRemoteAddress ();
|
||||
|
||||
DEBUG_LOG ("WorldSocket::HandleAuthSession: Client '%s' authenticated successfully from %s.",
|
||||
account.c_str (),
|
||||
@@ -910,8 +874,7 @@ WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||
address.c_str (),
|
||||
safe_account.c_str ());
|
||||
|
||||
// TODO protect here probably ?
|
||||
// Althought atm the socket is singlethreaded
|
||||
// NOTE ATM the socket is singlethreaded, have this in mind ...
|
||||
ACE_NEW_RETURN (m_Session, WorldSession (id, this, security, expansion, mutetime, locale), -1);
|
||||
|
||||
m_Crypt.SetKey (&K);
|
||||
@@ -920,8 +883,7 @@ WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||
// In case needed sometime the second arg is in microseconds 1 000 000 = 1 sec
|
||||
ACE_OS::sleep (ACE_Time_Value (0, 10000));
|
||||
|
||||
// TODO error handling
|
||||
sWorld.AddSession (this->m_Session);
|
||||
sWorld.AddSession (m_Session);
|
||||
|
||||
// Create and send the Addon packet
|
||||
if (sAddOnHandler.BuildAddonPacket (&recvPacket, &SendAddonPacked))
|
||||
@@ -930,8 +892,7 @@ WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::HandlePing (WorldPacket& recvPacket)
|
||||
int WorldSocket::HandlePing (WorldPacket& recvPacket)
|
||||
{
|
||||
uint32 ping;
|
||||
uint32 latency;
|
||||
@@ -990,18 +951,17 @@ WorldSocket::HandlePing (WorldPacket& recvPacket)
|
||||
sLog.outError ("WorldSocket::HandlePing: peer sent CMSG_PING, "
|
||||
"but is not authenticated or got recently kicked,"
|
||||
" adress = %s",
|
||||
this->GetRemoteAddress ().c_str ());
|
||||
GetRemoteAddress ().c_str ());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
WorldPacket packet (SMSG_PONG, 4);
|
||||
packet << ping;
|
||||
return this->SendPacket (packet);
|
||||
return SendPacket (packet);
|
||||
}
|
||||
|
||||
int
|
||||
WorldSocket::iSendPacket (const WorldPacket& pct)
|
||||
int WorldSocket::iSendPacket (const WorldPacket& pct)
|
||||
{
|
||||
if (m_OutBuffer->space () < pct.size () + sizeof (ServerPktHeader))
|
||||
{
|
||||
@@ -1012,13 +972,10 @@ WorldSocket::iSendPacket (const WorldPacket& pct)
|
||||
ServerPktHeader header;
|
||||
|
||||
header.cmd = pct.GetOpcode ();
|
||||
|
||||
#if ACE_BYTE_ORDER == ACE_BIG_ENDIAN
|
||||
header.cmd = ACE_SWAP_WORD (header.cmd)
|
||||
#endif
|
||||
EndianConvert(header.cmd);
|
||||
|
||||
header.size = (uint16) pct.size () + 2;
|
||||
header.size = ACE_HTONS (header.size);
|
||||
EndianConvertReverse(header.size);
|
||||
|
||||
m_Crypt.EncryptSend ((uint8*) & header, sizeof (header));
|
||||
|
||||
@@ -1032,8 +989,7 @@ WorldSocket::iSendPacket (const WorldPacket& pct)
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool
|
||||
WorldSocket::iFlushPacketQueue ()
|
||||
bool WorldSocket::iFlushPacketQueue ()
|
||||
{
|
||||
WorldPacket *pct;
|
||||
bool haveone = false;
|
||||
|
||||
@@ -90,7 +90,7 @@ typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> WorldHandler;
|
||||
*/
|
||||
class WorldSocket : protected WorldHandler
|
||||
{
|
||||
public:
|
||||
public:
|
||||
/// Declare some friends
|
||||
friend class ACE_Acceptor< WorldSocket, ACE_SOCK_ACCEPTOR >;
|
||||
friend class WorldSocketMgr;
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
/// Remove refference to this object.
|
||||
long RemoveReference (void);
|
||||
|
||||
protected:
|
||||
protected:
|
||||
/// things called by ACE framework.
|
||||
WorldSocket (void);
|
||||
virtual ~WorldSocket (void);
|
||||
@@ -150,7 +150,7 @@ protected:
|
||||
/// Called by WorldSocketMgr/ReactorRunnable.
|
||||
int Update (void);
|
||||
|
||||
private:
|
||||
private:
|
||||
/// Helper functions for processing incoming data.
|
||||
int handle_input_header (void);
|
||||
int handle_input_payload (void);
|
||||
@@ -181,7 +181,7 @@ private:
|
||||
/// to mark the socket for output ).
|
||||
bool iFlushPacketQueue ();
|
||||
|
||||
private:
|
||||
private:
|
||||
/// Time in which the last ping was received
|
||||
ACE_Time_Value m_LastPingTime;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user