|
26 | 26 | #include "CryptoRandom.h" |
27 | 27 | #include "DatabaseEnv.h" |
28 | 28 | #include "IPLocation.h" |
| 29 | +#include "IoContext.h" |
29 | 30 | #include "Log.h" |
30 | 31 | #include "RealmList.h" |
31 | 32 | #include "SecretMgr.h" |
@@ -199,6 +200,7 @@ void AccountInfo::LoadResult(Field* fields) |
199 | 200 | } |
200 | 201 |
|
201 | 202 | AuthSession::AuthSession(tcp::socket&& socket) : Socket(std::move(socket)), |
| 203 | + _timeout(*underlying_stream().get_executor().target<boost::asio::io_context::executor_type>()), |
202 | 204 | _status(STATUS_CHALLENGE), _locale(LOCALE_enUS), _os(0), _build(0), _expversion(0), _timezoneOffset(0min) |
203 | 205 | { |
204 | 206 | } |
@@ -250,6 +252,7 @@ void AuthSession::CheckIpCallback(PreparedQueryResult result) |
250 | 252 | } |
251 | 253 |
|
252 | 254 | AsyncRead(); |
| 255 | + SetTimeout(); |
253 | 256 | } |
254 | 257 |
|
255 | 258 | void AuthSession::ReadHandler() |
@@ -290,6 +293,7 @@ void AuthSession::ReadHandler() |
290 | 293 | } |
291 | 294 |
|
292 | 295 | packet.ReadCompleted(size); |
| 296 | + SetTimeout(); |
293 | 297 | } |
294 | 298 |
|
295 | 299 | AsyncRead(); |
@@ -898,3 +902,34 @@ bool AuthSession::VerifyVersion(std::span<uint8 const> a, Trinity::Crypto::SHA1: |
898 | 902 |
|
899 | 903 | return versionProof == version.GetDigest(); |
900 | 904 | } |
| 905 | + |
| 906 | +void AuthSession::SetTimeout() |
| 907 | +{ |
| 908 | + _timeout.cancel(); |
| 909 | + |
| 910 | + switch (_status) |
| 911 | + { |
| 912 | + case STATUS_AUTHED: |
| 913 | + case STATUS_WAITING_FOR_REALM_LIST: |
| 914 | + _timeout.expires_after(1min); |
| 915 | + break; |
| 916 | + case STATUS_XFER: |
| 917 | + return; |
| 918 | + default: |
| 919 | + _timeout.expires_after(10s); |
| 920 | + break; |
| 921 | + } |
| 922 | + |
| 923 | + _timeout.async_wait([selfRef = weak_from_this()](boost::system::error_code const& error) |
| 924 | + { |
| 925 | + std::shared_ptr<AuthSession> self = selfRef.lock(); |
| 926 | + if (!self) |
| 927 | + return; |
| 928 | + |
| 929 | + if (error == boost::asio::error::operation_aborted) |
| 930 | + return; |
| 931 | + |
| 932 | + TC_LOG_DEBUG("server.authserver", "{}:{} session timed out.", self->GetRemoteIpAddress().to_string(), self->GetRemotePort()); |
| 933 | + self->CloseSocket(); |
| 934 | + }); |
| 935 | +} |
0 commit comments