Skip to content

Commit 7f01436

Browse files
committed
Disconnect idle connections that don't login.
1 parent b2e78c0 commit 7f01436

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/framework/Network/MangosSocket.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ class MangosSocket : public WorldHandler
121121
virtual int close(int);
122122

123123
// Get address of connected peer.
124-
const std::string& GetRemoteAddress () const { return m_address; }
124+
std::string const& GetRemoteAddress () const { return m_address; }
125125

126126
// Send A packet on the socket, this function is reentrant.
127127
// @param pct packet to send
128128
// @return -1 of failure
129-
int SendPacket (const WorldPacket& pct);
129+
int SendPacket (WorldPacket const& pct);
130130

131131
// Add reference to this object.
132132
long AddReference() { return static_cast<long>(add_reference()); }
@@ -179,7 +179,10 @@ class MangosSocket : public WorldHandler
179179
// to mark the socket for output ).
180180
bool iFlushPacketQueue ();
181181

182-
// Time in which the last ping was received
182+
// Time at which the socket was created.
183+
ACE_Time_Value m_createTime;
184+
185+
// Time at which the last ping was received.
183186
ACE_Time_Value m_lastPingTime;
184187

185188
// Keep track of over-speed pings ,to prevent ping flood.

src/framework/Network/MangosSocketImpl.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
template <typename SessionType, typename SocketName, typename Crypt>
2525
MangosSocket<SessionType, SocketName, Crypt>::MangosSocket() :
2626
WorldHandler(),
27+
m_createTime(ACE_OS::gettimeofday()),
2728
m_lastPingTime(ACE_Time_Value::zero),
2829
m_overSpeedPings(0),
2930
m_session(0),
@@ -77,7 +78,7 @@ void MangosSocket<SessionType, SocketName, Crypt>::CloseSocket(void)
7778
}
7879

7980
template <typename SessionType, typename SocketName, typename Crypt>
80-
int MangosSocket<SessionType, SocketName, Crypt>::SendPacket(const WorldPacket& pct)
81+
int MangosSocket<SessionType, SocketName, Crypt>::SendPacket(WorldPacket const& pct)
8182
{
8283
GuardType lock(m_outBufferLock);
8384

@@ -283,6 +284,13 @@ int MangosSocket<SessionType, SocketName, Crypt>::Update(void)
283284
{
284285
if (closing_)
285286
return -1;
287+
288+
if (!m_session && m_isServerSocket && ((ACE_OS::gettimeofday() - m_createTime) > ACE_Time_Value(10)))
289+
{
290+
sLog.Out(LOG_BASIC, LOG_LVL_DETAIL, "Disconnecting idle connection from %s.", m_address.c_str());
291+
CloseSocket();
292+
return -1;
293+
}
286294

287295
if (m_outActive || m_outBuffer->length() == 0)
288296
return 0;

0 commit comments

Comments
 (0)