[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
|
#if TRINITY_ENDIAN == TRINITY_BIGENDIAN
|
||||||
template<typename T> inline void EndianConvert(T& val) { ByteConverter::apply<T>(&val); }
|
template<typename T> inline void EndianConvert(T& val) { ByteConverter::apply<T>(&val); }
|
||||||
|
template<typename T> inline void EndianConvertReverse(T&) { }
|
||||||
#else
|
#else
|
||||||
template<typename T> inline void EndianConvert(T&) { }
|
template<typename T> inline void EndianConvert(T&) { }
|
||||||
|
template<typename T> inline void EndianConvertReverse(T& val) { ByteConverter::apply<T>(&val); }
|
||||||
#endif
|
#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(uint8&) { }
|
||||||
inline void EndianConvert( int8&) { }
|
inline void EndianConvert( int8&) { }
|
||||||
|
inline void EndianConvertReverse(uint8&) { }
|
||||||
|
inline void EndianConvertReverse( int8&) { }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+4
-3
@@ -230,7 +230,7 @@ World::AddSession_ (WorldSession* s)
|
|||||||
packet << uint32 (0); // unknown random value...
|
packet << uint32 (0); // unknown random value...
|
||||||
packet << uint8 (0);
|
packet << uint8 (0);
|
||||||
packet << uint32 (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);
|
s->SendPacket (&packet);
|
||||||
|
|
||||||
UpdateMaxSessionCounters ();
|
UpdateMaxSessionCounters ();
|
||||||
@@ -2304,7 +2304,7 @@ BanReturn World::BanAccount(BanMode mode, std::string nameOrIP, std::string dura
|
|||||||
if(!resultAccounts)
|
if(!resultAccounts)
|
||||||
{
|
{
|
||||||
if(mode==BAN_IP)
|
if(mode==BAN_IP)
|
||||||
return BAN_SUCCESS;
|
return BAN_SUCCESS; // ip correctly banned but nobody affected (yet)
|
||||||
else
|
else
|
||||||
return BAN_NOTFOUND; // Nobody to ban
|
return BAN_NOTFOUND; // Nobody to ban
|
||||||
}
|
}
|
||||||
@@ -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;
|
uint32 msgid = (m_ShutdownMask & SHUTDOWN_MASK_RESTART) ? SERVER_MSG_RESTART_TIME : SERVER_MSG_SHUTDOWN_TIME;
|
||||||
|
|
||||||
SendServerMessage(msgid,str.c_str(),player);
|
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;
|
return;
|
||||||
|
|
||||||
CliCommandHolder::Print* zprint;
|
CliCommandHolder::Print* zprint;
|
||||||
|
|
||||||
while (!cliCmdQueue.empty())
|
while (!cliCmdQueue.empty())
|
||||||
{
|
{
|
||||||
sLog.outDebug("CLI command under processing...");
|
sLog.outDebug("CLI command under processing...");
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ WorldSession::~WorldSession()
|
|||||||
WorldPacket *packet = _recvQueue.next ();
|
WorldPacket *packet = _recvQueue.next ();
|
||||||
delete packet;
|
delete packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldSession::SizeError(WorldPacket const& packet, uint32 size) const
|
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
|
sendLastPacketBytes = packet->wpos(); // wpos is real written size
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // !TRINITY_DEBUG
|
#endif // !MANGOS_DEBUG
|
||||||
|
|
||||||
if (m_Socket->SendPacket (*packet) == -1)
|
if (m_Socket->SendPacket (*packet) == -1)
|
||||||
m_Socket->CloseSocket ();
|
m_Socket->CloseSocket ();
|
||||||
@@ -284,7 +283,7 @@ void WorldSession::LogoutPlayer(bool Save)
|
|||||||
|
|
||||||
// give honor to all attackers from set like group case
|
// give honor to all attackers from set like group case
|
||||||
for(std::set<Player*>::const_iterator itr = aset.begin(); itr != aset.end(); ++itr)
|
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
|
// give bg rewards and update counters like kill by first from attackers
|
||||||
// this can't be called for all attackers.
|
// this can't be called for all attackers.
|
||||||
@@ -521,7 +520,3 @@ void WorldSession::SendAuthWaitQue(uint32 position)
|
|||||||
SendPacket(&packet);
|
SendPacket(&packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+85
-129
@@ -54,14 +54,14 @@
|
|||||||
|
|
||||||
struct ServerPktHeader
|
struct ServerPktHeader
|
||||||
{
|
{
|
||||||
ACE_UINT16 size;
|
uint16 size;
|
||||||
ACE_UINT16 cmd;
|
uint16 cmd;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ClientPktHeader
|
struct ClientPktHeader
|
||||||
{
|
{
|
||||||
ACE_UINT16 size;
|
uint16 size;
|
||||||
ACE_UINT32 cmd;
|
uint32 cmd;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined( __GNUC__ )
|
#if defined( __GNUC__ )
|
||||||
@@ -83,7 +83,7 @@ m_Seed (static_cast<uint32> (rand32 ())),
|
|||||||
m_OverSpeedPings (0),
|
m_OverSpeedPings (0),
|
||||||
m_LastPingTime (ACE_Time_Value::zero)
|
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)
|
WorldSocket::~WorldSocket (void)
|
||||||
@@ -94,33 +94,31 @@ WorldSocket::~WorldSocket (void)
|
|||||||
if (m_OutBuffer)
|
if (m_OutBuffer)
|
||||||
m_OutBuffer->release ();
|
m_OutBuffer->release ();
|
||||||
|
|
||||||
this->closing_ = true;
|
closing_ = true;
|
||||||
|
|
||||||
this->peer ().close ();
|
peer ().close ();
|
||||||
|
|
||||||
WorldPacket* pct;
|
WorldPacket* pct;
|
||||||
while (m_PacketQueue.dequeue_head (pct) == 0)
|
while (m_PacketQueue.dequeue_head (pct) == 0)
|
||||||
delete pct;
|
delete pct;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool WorldSocket::IsClosed (void) const
|
||||||
WorldSocket::IsClosed (void) const
|
|
||||||
{
|
{
|
||||||
return this->closing_;
|
return closing_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void WorldSocket::CloseSocket (void)
|
||||||
WorldSocket::CloseSocket (void)
|
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
ACE_GUARD (LockType, Guard, m_OutBufferLock);
|
ACE_GUARD (LockType, Guard, m_OutBufferLock);
|
||||||
|
|
||||||
if (this->closing_)
|
if (closing_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this->closing_ = true;
|
closing_ = true;
|
||||||
|
|
||||||
this->peer ().close_writer ();
|
peer ().close_writer ();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -128,21 +126,18 @@ WorldSocket::CloseSocket (void)
|
|||||||
|
|
||||||
m_Session = NULL;
|
m_Session = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string&
|
const std::string& WorldSocket::GetRemoteAddress (void) const
|
||||||
WorldSocket::GetRemoteAddress (void) const
|
|
||||||
{
|
{
|
||||||
return m_Address;
|
return m_Address;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::SendPacket (const WorldPacket& pct)
|
||||||
WorldSocket::SendPacket (const WorldPacket& pct)
|
|
||||||
{
|
{
|
||||||
ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
|
ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
|
||||||
|
|
||||||
if (this->closing_)
|
if (closing_)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Dump outgoing packet.
|
// Dump outgoing packet.
|
||||||
@@ -185,20 +180,17 @@ WorldSocket::SendPacket (const WorldPacket& pct)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
long WorldSocket::AddReference (void)
|
||||||
WorldSocket::AddReference (void)
|
|
||||||
{
|
{
|
||||||
return static_cast<long> (this->add_reference ());
|
return static_cast<long> (add_reference ());
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
long WorldSocket::RemoveReference (void)
|
||||||
WorldSocket::RemoveReference (void)
|
|
||||||
{
|
{
|
||||||
return static_cast<long> (this->remove_reference ());
|
return static_cast<long> (remove_reference ());
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::open (void *a)
|
||||||
WorldSocket::open (void *a)
|
|
||||||
{
|
{
|
||||||
ACE_UNUSED_ARG (a);
|
ACE_UNUSED_ARG (a);
|
||||||
|
|
||||||
@@ -220,7 +212,7 @@ WorldSocket::open (void *a)
|
|||||||
// Store peer address.
|
// Store peer address.
|
||||||
ACE_INET_Addr remote_addr;
|
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));
|
sLog.outError ("WorldSocket::open: peer ().get_remote_addr errno = %s", ACE_OS::strerror (errno));
|
||||||
return -1;
|
return -1;
|
||||||
@@ -236,51 +228,47 @@ WorldSocket::open (void *a)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Register with ACE Reactor
|
// Register with ACE Reactor
|
||||||
if (this->reactor ()->register_handler
|
if (reactor ()->register_handler(this, ACE_Event_Handler::READ_MASK | ACE_Event_Handler::WRITE_MASK) == -1)
|
||||||
(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));
|
sLog.outError ("WorldSocket::open: unable to register client handler errno = %s", ACE_OS::strerror (errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reactor takes care of the socket from now on
|
// reactor takes care of the socket from now on
|
||||||
this->remove_reference ();
|
remove_reference ();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::close (int)
|
||||||
WorldSocket::close (int)
|
|
||||||
{
|
{
|
||||||
this->shutdown ();
|
shutdown ();
|
||||||
|
|
||||||
this->closing_ = true;
|
closing_ = true;
|
||||||
|
|
||||||
this->remove_reference ();
|
remove_reference ();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::handle_input (ACE_HANDLE)
|
||||||
WorldSocket::handle_input (ACE_HANDLE)
|
|
||||||
{
|
{
|
||||||
if (this->closing_)
|
if (closing_)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
switch (this->handle_input_missing_data ())
|
switch (handle_input_missing_data ())
|
||||||
{
|
{
|
||||||
case -1 :
|
case -1 :
|
||||||
{
|
{
|
||||||
if ((errno == EWOULDBLOCK) ||
|
if ((errno == EWOULDBLOCK) ||
|
||||||
(errno == EAGAIN))
|
(errno == EAGAIN))
|
||||||
{
|
{
|
||||||
//return 0;
|
return Update (); // interesting line ,isnt it ?
|
||||||
return this->Update (); // interesting line ,isnt it ?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_LOG ("WorldSocket::handle_input: Peer error closing connection errno = %s", ACE_OS::strerror (errno));
|
DEBUG_LOG ("WorldSocket::handle_input: Peer error closing connection errno = %s", ACE_OS::strerror (errno));
|
||||||
|
|
||||||
|
errno = ECONNRESET;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
case 0:
|
case 0:
|
||||||
@@ -288,35 +276,33 @@ WorldSocket::handle_input (ACE_HANDLE)
|
|||||||
DEBUG_LOG ("WorldSocket::handle_input: Peer has closed connection\n");
|
DEBUG_LOG ("WorldSocket::handle_input: Peer has closed connection\n");
|
||||||
|
|
||||||
errno = ECONNRESET;
|
errno = ECONNRESET;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
return 1;
|
return 1;
|
||||||
|
default:
|
||||||
|
return Update (); // another interesting line ;)
|
||||||
}
|
}
|
||||||
|
|
||||||
//return 0;
|
ACE_NOTREACHED(return -1);
|
||||||
return this->Update (); // another interesting line ;)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::handle_output (ACE_HANDLE)
|
||||||
WorldSocket::handle_output (ACE_HANDLE)
|
|
||||||
{
|
{
|
||||||
ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
|
ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
|
||||||
|
|
||||||
if (this->closing_)
|
if (closing_)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
const size_t send_len = m_OutBuffer->length ();
|
const size_t send_len = m_OutBuffer->length ();
|
||||||
|
|
||||||
if (send_len == 0)
|
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
|
#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
|
#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
|
#endif // MSG_NOSIGNAL
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
@@ -324,7 +310,7 @@ WorldSocket::handle_output (ACE_HANDLE)
|
|||||||
else if (n == -1)
|
else if (n == -1)
|
||||||
{
|
{
|
||||||
if (errno == EWOULDBLOCK || errno == EAGAIN)
|
if (errno == EWOULDBLOCK || errno == EAGAIN)
|
||||||
return this->schedule_wakeup_output (Guard);
|
return schedule_wakeup_output (Guard);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -335,32 +321,31 @@ WorldSocket::handle_output (ACE_HANDLE)
|
|||||||
// move the data to the base of the buffer
|
// move the data to the base of the buffer
|
||||||
m_OutBuffer->crunch ();
|
m_OutBuffer->crunch ();
|
||||||
|
|
||||||
return this->schedule_wakeup_output (Guard);
|
return schedule_wakeup_output (Guard);
|
||||||
}
|
}
|
||||||
else //now n == send_len
|
else //now n == send_len
|
||||||
{
|
{
|
||||||
m_OutBuffer->reset ();
|
m_OutBuffer->reset ();
|
||||||
|
|
||||||
if (!iFlushPacketQueue ())
|
if (!iFlushPacketQueue ())
|
||||||
return this->cancel_wakeup_output (Guard);
|
return cancel_wakeup_output (Guard);
|
||||||
else
|
else
|
||||||
return this->schedule_wakeup_output (Guard);
|
return schedule_wakeup_output (Guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
ACE_NOTREACHED (return 0);
|
ACE_NOTREACHED (return 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::handle_close (ACE_HANDLE h, ACE_Reactor_Mask)
|
||||||
WorldSocket::handle_close (ACE_HANDLE h, ACE_Reactor_Mask)
|
|
||||||
{
|
{
|
||||||
// Critical section
|
// Critical section
|
||||||
{
|
{
|
||||||
ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
|
ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
|
||||||
|
|
||||||
this->closing_ = true;
|
closing_ = true;
|
||||||
|
|
||||||
if (h == ACE_INVALID_HANDLE)
|
if (h == ACE_INVALID_HANDLE)
|
||||||
this->peer ().close_writer ();
|
peer ().close_writer ();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Critical section
|
// Critical section
|
||||||
@@ -373,49 +358,35 @@ WorldSocket::handle_close (ACE_HANDLE h, ACE_Reactor_Mask)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::Update (void)
|
||||||
WorldSocket::Update (void)
|
|
||||||
{
|
{
|
||||||
if (this->closing_)
|
if (closing_)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (m_OutActive || m_OutBuffer->length () == 0)
|
if (m_OutActive || m_OutBuffer->length () == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return this->handle_output (this->get_handle ());
|
return handle_output (get_handle ());
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::handle_input_header (void)
|
||||||
WorldSocket::handle_input_header (void)
|
|
||||||
{
|
{
|
||||||
ACE_ASSERT (m_RecvWPct == NULL);
|
ACE_ASSERT (m_RecvWPct == NULL);
|
||||||
|
|
||||||
if (m_Header.length () != sizeof (ClientPktHeader))
|
ACE_ASSERT (m_Header.length () == sizeof (ClientPktHeader));
|
||||||
{
|
|
||||||
sLog.outError ("WorldSocket::handle_input_header: internal error: invalid header");
|
|
||||||
errno = EINVAL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_Crypt.DecryptRecv ((ACE_UINT8*) m_Header.rd_ptr (), sizeof (ClientPktHeader));
|
m_Crypt.DecryptRecv ((ACE_UINT8*) m_Header.rd_ptr (), sizeof (ClientPktHeader));
|
||||||
|
|
||||||
ClientPktHeader& header = *((ClientPktHeader*) m_Header.rd_ptr ());
|
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
|
if ((header.size < 4) || (header.size > 10240) ||
|
||||||
header.cmd = ACE_SWAP_LONG (header.cmd)
|
(header.cmd < 0) || (header.cmd > 10240) )
|
||||||
#endif // ACE_BIG_ENDIAN
|
|
||||||
|
|
||||||
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",
|
sLog.outError ("WorldSocket::handle_input_header: client sent mailformed packet size = %d , cmd = %d",
|
||||||
header.size,
|
header.size, header.cmd);
|
||||||
header.cmd);
|
|
||||||
|
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
@@ -435,12 +406,10 @@ WorldSocket::handle_input_header (void)
|
|||||||
ACE_ASSERT(m_RecvPct.space() == 0);
|
ACE_ASSERT(m_RecvPct.space() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::handle_input_payload (void)
|
||||||
WorldSocket::handle_input_payload (void)
|
|
||||||
{
|
{
|
||||||
// set errno properly here on error !!!
|
// set errno properly here on error !!!
|
||||||
// now have a header and payload
|
// now have a header and payload
|
||||||
@@ -449,7 +418,7 @@ WorldSocket::handle_input_payload (void)
|
|||||||
ACE_ASSERT (m_Header.space () == 0);
|
ACE_ASSERT (m_Header.space () == 0);
|
||||||
ACE_ASSERT (m_RecvWPct != NULL);
|
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.base (NULL, 0);
|
||||||
m_RecvPct.reset ();
|
m_RecvPct.reset ();
|
||||||
@@ -463,8 +432,7 @@ WorldSocket::handle_input_payload (void)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::handle_input_missing_data (void)
|
||||||
WorldSocket::handle_input_missing_data (void)
|
|
||||||
{
|
{
|
||||||
char buf [1024];
|
char buf [1024];
|
||||||
|
|
||||||
@@ -482,7 +450,7 @@ WorldSocket::handle_input_missing_data (void)
|
|||||||
|
|
||||||
const size_t recv_size = message_block.space ();
|
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);
|
recv_size);
|
||||||
|
|
||||||
if (n <= 0)
|
if (n <= 0)
|
||||||
@@ -508,7 +476,7 @@ WorldSocket::handle_input_missing_data (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//we just recieved nice new header
|
//we just recieved nice new header
|
||||||
if (this->handle_input_header () == -1)
|
if (handle_input_header () == -1)
|
||||||
{
|
{
|
||||||
ACE_ASSERT ((errno != EWOULDBLOCK) && (errno != EAGAIN));
|
ACE_ASSERT ((errno != EWOULDBLOCK) && (errno != EAGAIN));
|
||||||
return -1;
|
return -1;
|
||||||
@@ -543,7 +511,7 @@ WorldSocket::handle_input_missing_data (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//just recieved fresh new payload
|
//just recieved fresh new payload
|
||||||
if (this->handle_input_payload () == -1)
|
if (handle_input_payload () == -1)
|
||||||
{
|
{
|
||||||
ACE_ASSERT ((errno != EWOULDBLOCK) && (errno != EAGAIN));
|
ACE_ASSERT ((errno != EWOULDBLOCK) && (errno != EAGAIN));
|
||||||
return -1;
|
return -1;
|
||||||
@@ -553,8 +521,7 @@ WorldSocket::handle_input_missing_data (void)
|
|||||||
return n == recv_size ? 1 : 2;
|
return n == recv_size ? 1 : 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::cancel_wakeup_output (GuardType& g)
|
||||||
WorldSocket::cancel_wakeup_output (GuardType& g)
|
|
||||||
{
|
{
|
||||||
if (!m_OutActive)
|
if (!m_OutActive)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -563,7 +530,7 @@ WorldSocket::cancel_wakeup_output (GuardType& g)
|
|||||||
|
|
||||||
g.release ();
|
g.release ();
|
||||||
|
|
||||||
if (this->reactor ()->cancel_wakeup
|
if (reactor ()->cancel_wakeup
|
||||||
(this, ACE_Event_Handler::WRITE_MASK) == -1)
|
(this, ACE_Event_Handler::WRITE_MASK) == -1)
|
||||||
{
|
{
|
||||||
// would be good to store errno from reactor with errno guard
|
// would be good to store errno from reactor with errno guard
|
||||||
@@ -574,8 +541,7 @@ WorldSocket::cancel_wakeup_output (GuardType& g)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::schedule_wakeup_output (GuardType& g)
|
||||||
WorldSocket::schedule_wakeup_output (GuardType& g)
|
|
||||||
{
|
{
|
||||||
if (m_OutActive)
|
if (m_OutActive)
|
||||||
return 0;
|
return 0;
|
||||||
@@ -584,7 +550,7 @@ WorldSocket::schedule_wakeup_output (GuardType& g)
|
|||||||
|
|
||||||
g.release ();
|
g.release ();
|
||||||
|
|
||||||
if (this->reactor ()->schedule_wakeup
|
if (reactor ()->schedule_wakeup
|
||||||
(this, ACE_Event_Handler::WRITE_MASK) == -1)
|
(this, ACE_Event_Handler::WRITE_MASK) == -1)
|
||||||
{
|
{
|
||||||
sLog.outError ("WorldSocket::schedule_wakeup_output");
|
sLog.outError ("WorldSocket::schedule_wakeup_output");
|
||||||
@@ -594,8 +560,7 @@ WorldSocket::schedule_wakeup_output (GuardType& g)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::ProcessIncoming (WorldPacket* new_pct)
|
||||||
WorldSocket::ProcessIncoming (WorldPacket* new_pct)
|
|
||||||
{
|
{
|
||||||
ACE_ASSERT (new_pct);
|
ACE_ASSERT (new_pct);
|
||||||
|
|
||||||
@@ -604,7 +569,7 @@ WorldSocket::ProcessIncoming (WorldPacket* new_pct)
|
|||||||
|
|
||||||
const ACE_UINT16 opcode = new_pct->GetOpcode ();
|
const ACE_UINT16 opcode = new_pct->GetOpcode ();
|
||||||
|
|
||||||
if (this->closing_)
|
if (closing_)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// dump recieved packet
|
// dump recieved packet
|
||||||
@@ -670,9 +635,9 @@ WorldSocket::ProcessIncoming (WorldPacket* new_pct)
|
|||||||
ACE_NOTREACHED (return 0);
|
ACE_NOTREACHED (return 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
||||||
WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
|
||||||
{
|
{
|
||||||
|
// NOTE: ATM the socket is singlethreaded, have this in mind ...
|
||||||
uint8 digest[20];
|
uint8 digest[20];
|
||||||
uint32 clientSeed;
|
uint32 clientSeed;
|
||||||
uint32 unk2;
|
uint32 unk2;
|
||||||
@@ -778,8 +743,7 @@ WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
|||||||
const char* vStr = v.AsHexStr (); //Must be freed by OPENSSL_free()
|
const char* vStr = v.AsHexStr (); //Must be freed by OPENSSL_free()
|
||||||
const char* vold = fields[6].GetString ();
|
const char* vold = fields[6].GetString ();
|
||||||
|
|
||||||
DEBUG_LOG ("WorldSocket::HandleAuthSession: "
|
DEBUG_LOG ("WorldSocket::HandleAuthSession: (s,v) check s: %s v_old: %s v_new: %s",
|
||||||
"(s,v) check s: %s v_old: %s v_new: %s",
|
|
||||||
sStr,
|
sStr,
|
||||||
vold,
|
vold,
|
||||||
vStr);
|
vStr);
|
||||||
@@ -852,7 +816,7 @@ WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
|||||||
|
|
||||||
delete banresult;
|
delete banresult;
|
||||||
|
|
||||||
sLog.outBasic ("WorldSocket::HandleAuthSession: Sent Auth Response (Account banned).");
|
sLog.outError ("WorldSocket::HandleAuthSession: Sent Auth Response (Account banned).");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -890,11 +854,11 @@ WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
|||||||
|
|
||||||
SendPacket (packet);
|
SendPacket (packet);
|
||||||
|
|
||||||
sLog.outBasic ("WorldSocket::HandleAuthSession: Sent Auth Response (authentification failed).");
|
sLog.outError ("WorldSocket::HandleAuthSession: Sent Auth Response (authentification failed).");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string address = this->GetRemoteAddress ();
|
std::string address = GetRemoteAddress ();
|
||||||
|
|
||||||
DEBUG_LOG ("WorldSocket::HandleAuthSession: Client '%s' authenticated successfully from %s.",
|
DEBUG_LOG ("WorldSocket::HandleAuthSession: Client '%s' authenticated successfully from %s.",
|
||||||
account.c_str (),
|
account.c_str (),
|
||||||
@@ -910,8 +874,7 @@ WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
|||||||
address.c_str (),
|
address.c_str (),
|
||||||
safe_account.c_str ());
|
safe_account.c_str ());
|
||||||
|
|
||||||
// TODO protect here probably ?
|
// NOTE ATM the socket is singlethreaded, have this in mind ...
|
||||||
// Althought atm the socket is singlethreaded
|
|
||||||
ACE_NEW_RETURN (m_Session, WorldSession (id, this, security, expansion, mutetime, locale), -1);
|
ACE_NEW_RETURN (m_Session, WorldSession (id, this, security, expansion, mutetime, locale), -1);
|
||||||
|
|
||||||
m_Crypt.SetKey (&K);
|
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
|
// In case needed sometime the second arg is in microseconds 1 000 000 = 1 sec
|
||||||
ACE_OS::sleep (ACE_Time_Value (0, 10000));
|
ACE_OS::sleep (ACE_Time_Value (0, 10000));
|
||||||
|
|
||||||
// TODO error handling
|
sWorld.AddSession (m_Session);
|
||||||
sWorld.AddSession (this->m_Session);
|
|
||||||
|
|
||||||
// Create and send the Addon packet
|
// Create and send the Addon packet
|
||||||
if (sAddOnHandler.BuildAddonPacket (&recvPacket, &SendAddonPacked))
|
if (sAddOnHandler.BuildAddonPacket (&recvPacket, &SendAddonPacked))
|
||||||
@@ -930,8 +892,7 @@ WorldSocket::HandleAuthSession (WorldPacket& recvPacket)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::HandlePing (WorldPacket& recvPacket)
|
||||||
WorldSocket::HandlePing (WorldPacket& recvPacket)
|
|
||||||
{
|
{
|
||||||
uint32 ping;
|
uint32 ping;
|
||||||
uint32 latency;
|
uint32 latency;
|
||||||
@@ -990,18 +951,17 @@ WorldSocket::HandlePing (WorldPacket& recvPacket)
|
|||||||
sLog.outError ("WorldSocket::HandlePing: peer sent CMSG_PING, "
|
sLog.outError ("WorldSocket::HandlePing: peer sent CMSG_PING, "
|
||||||
"but is not authenticated or got recently kicked,"
|
"but is not authenticated or got recently kicked,"
|
||||||
" adress = %s",
|
" adress = %s",
|
||||||
this->GetRemoteAddress ().c_str ());
|
GetRemoteAddress ().c_str ());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WorldPacket packet (SMSG_PONG, 4);
|
WorldPacket packet (SMSG_PONG, 4);
|
||||||
packet << ping;
|
packet << ping;
|
||||||
return this->SendPacket (packet);
|
return SendPacket (packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int WorldSocket::iSendPacket (const WorldPacket& pct)
|
||||||
WorldSocket::iSendPacket (const WorldPacket& pct)
|
|
||||||
{
|
{
|
||||||
if (m_OutBuffer->space () < pct.size () + sizeof (ServerPktHeader))
|
if (m_OutBuffer->space () < pct.size () + sizeof (ServerPktHeader))
|
||||||
{
|
{
|
||||||
@@ -1012,13 +972,10 @@ WorldSocket::iSendPacket (const WorldPacket& pct)
|
|||||||
ServerPktHeader header;
|
ServerPktHeader header;
|
||||||
|
|
||||||
header.cmd = pct.GetOpcode ();
|
header.cmd = pct.GetOpcode ();
|
||||||
|
EndianConvert(header.cmd);
|
||||||
#if ACE_BYTE_ORDER == ACE_BIG_ENDIAN
|
|
||||||
header.cmd = ACE_SWAP_WORD (header.cmd)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
header.size = (uint16) pct.size () + 2;
|
header.size = (uint16) pct.size () + 2;
|
||||||
header.size = ACE_HTONS (header.size);
|
EndianConvertReverse(header.size);
|
||||||
|
|
||||||
m_Crypt.EncryptSend ((uint8*) & header, sizeof (header));
|
m_Crypt.EncryptSend ((uint8*) & header, sizeof (header));
|
||||||
|
|
||||||
@@ -1032,8 +989,7 @@ WorldSocket::iSendPacket (const WorldPacket& pct)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool WorldSocket::iFlushPacketQueue ()
|
||||||
WorldSocket::iFlushPacketQueue ()
|
|
||||||
{
|
{
|
||||||
WorldPacket *pct;
|
WorldPacket *pct;
|
||||||
bool haveone = false;
|
bool haveone = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user