|
20 | 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21 | 21 | */
|
22 | 22 |
|
| 23 | +#include "WorldSocket.h" |
| 24 | +#include "WorldSocketMgr.h" |
| 25 | +#include "WorldSession.h" |
| 26 | + |
23 | 27 | #include "Auth/AuthCrypt.h"
|
24 | 28 | #include "World.h"
|
25 | 29 | #include "AccountMgr.h"
|
26 | 30 | #include "SharedDefines.h"
|
27 |
| -#include "WorldSession.h" |
28 |
| -#include "WorldSocket.h" |
29 |
| - |
30 |
| -#include <memory> |
31 | 31 | #include "AddonHandler.h"
|
32 | 32 | #include "Opcodes.h"
|
33 | 33 | #include "Crypto/Hash/SHA1.h"
|
34 | 34 | #include "Database/SqlPreparedStatement.h"
|
35 | 35 | #include "Database/DatabaseEnv.h"
|
36 | 36 | #include "DBCStores.h"
|
| 37 | +#include "Config/Config.h" |
| 38 | + |
37 | 39 | #include "IO/Networking/DNS.h"
|
38 |
| -#include "WorldSocketMgr.h" |
| 40 | +#include "IO/Timer/AsyncSystemTimer.h" |
| 41 | + |
| 42 | +#include <memory> |
39 | 43 |
|
40 | 44 | #if defined( __GNUC__ )
|
41 | 45 | #pragma pack(1)
|
@@ -78,6 +82,11 @@ WorldSocket::~WorldSocket()
|
78 | 82 | {
|
79 | 83 | CloseSocket();
|
80 | 84 | sLog.Out(LOG_NETWORK, LOG_LVL_BASIC, "[%s] Connection closed", GetRemoteIpString().c_str());
|
| 85 | + |
| 86 | + if (m_sessionNoAuthTimeout) |
| 87 | + { |
| 88 | + m_sessionNoAuthTimeout->Cancel(); |
| 89 | + } |
81 | 90 | }
|
82 | 91 |
|
83 | 92 | void WorldSocket::DoRecvIncomingData()
|
@@ -412,6 +421,14 @@ WorldSocket::HandlerResult WorldSocket::_HandleAuthSession(WorldPacket& recvPack
|
412 | 421 | return HandlerResult::Fail;
|
413 | 422 | }
|
414 | 423 |
|
| 424 | + |
| 425 | + // ===== Auth was successful ===== |
| 426 | + if (this->m_sessionNoAuthTimeout) |
| 427 | + { |
| 428 | + this->m_sessionNoAuthTimeout->Cancel(); |
| 429 | + this->m_sessionNoAuthTimeout = nullptr; |
| 430 | + } |
| 431 | + |
415 | 432 | m_Session = new WorldSession(accountId, this->shared_from_this(), security, mutetime, locale);
|
416 | 433 |
|
417 | 434 | m_Crypt.SetKey(K.AsByteArray());
|
@@ -595,6 +612,17 @@ void WorldSocket::HandleResultOfAsyncWrite(IO::NetworkError const& error, std::s
|
595 | 612 |
|
596 | 613 | void WorldSocket::Start()
|
597 | 614 | {
|
| 615 | + // Start auto timeout loop |
| 616 | + if (int secs = sConfig.GetIntDefault("Network.TimeoutSecsIfNoAuth", 10)) |
| 617 | + { |
| 618 | + m_sessionNoAuthTimeout = sAsyncSystemTimer.ScheduleFunctionOnce(std::chrono::seconds(secs), [this]() |
| 619 | + { |
| 620 | + sLog.Out(LOG_NETWORK, LOG_LVL_DETAIL, "[%s] Connection has reached TimeoutSecsIfNoAuth. Closing socket...", this->GetRemoteIpString().c_str()); |
| 621 | + // It's correct that we capture _this_ and not a shared_ptr, since the timer will be canceled in destructor |
| 622 | + this->CloseSocket(); |
| 623 | + }); |
| 624 | + } |
| 625 | + |
598 | 626 | SendInitialPacketAndStartRecvLoop();
|
599 | 627 | }
|
600 | 628 |
|
|
0 commit comments