63 std::array<std::shared_ptr<Trinity::Net::SocketConnectionInitializer>, 3> initializers =
65 std::make_shared<Trinity::Net::IpBanCheckConnectionInitializer<WorldSocket>>(
this),
66 std::make_shared<WorldSocketProtocolInitializer>(
this),
67 std::make_shared<Trinity::Net::ReadConnectionInitializer<WorldSocket>>(
this),
102 if (!queued->
empty())
115 if (!BaseSocket::Update())
220 TC_LOG_ERROR(
"network",
"WorldSocket::ReadHeaderHandler(): client {} sent malformed packet (size: {}, cmd: {})",
225 header->
size -=
sizeof(header->
cmd);
331 if (sessionGuard.try_lock())
355 TC_LOG_ERROR(
"network",
"WorldSocket::ReadDataHandler: client {} sent CMSG_KEEP_ALIVE without being authenticated",
GetRemoteIpAddress().to_string());
358 packetToQueue =
new WorldPacket(std::move(packet), std::chrono::steady_clock::now());
362 packetToQueue =
new WorldPacket(std::move(packet));
372 TC_LOG_ERROR(
"network.opcode",
"ProcessIncoming: Client not authed opcode = {}",
uint32(opcode));
373 delete packetToQueue;
381 delete packetToQueue;
425 std::shared_ptr<AuthSession> authSession = std::make_shared<AuthSession>();
428 recvPacket >> authSession->Build;
429 recvPacket >> authSession->LoginServerID;
430 recvPacket >> authSession->Account;
431 recvPacket >> authSession->LoginServerType;
432 recvPacket.
read(authSession->LocalChallenge);
433 recvPacket >> authSession->RegionID;
434 recvPacket >> authSession->BattlegroupID;
435 recvPacket >> authSession->RealmID;
436 recvPacket >> authSession->DosResponse;
437 recvPacket.
read(authSession->Digest);
438 authSession->AddonInfo.resize(recvPacket.
size() - recvPacket.
rpos());
439 recvPacket.
read(authSession->AddonInfo.contents(), authSession->AddonInfo.size());
444 stmt->
setString(1, authSession->Account);
448 HandleAuthSessionCallback(std::move(authSession), std::move(result));
459 TC_LOG_ERROR(
"network",
"WorldSocket::HandleAuthSession: Sent Auth Response (unknown account).");
476 stmt->
setString(1, authSession->Account);
496 TC_LOG_ERROR(
"network",
"WorldSocket::HandleAuthSession: Client {} requested connecting with realm id {} but this realm has id {} set in config.",
507 TC_LOG_ERROR(
"network",
"WorldSocket::HandleAuthSession: Client {} attempted to log in using invalid client OS ({}).", address, account.
OS);
513 uint8 t[4] = { 0x00,0x00,0x00,0x00 };
523 if (sha.
GetDigest() != authSession->Digest)
526 TC_LOG_ERROR(
"network",
"WorldSocket::HandleAuthSession: Authentication failed for account: {} ('{}') address: {}", account.
Id, authSession->Account, address);
537 if (account.
LastIP != address)
540 TC_LOG_DEBUG(
"network",
"WorldSocket::HandleAuthSession: Sent Auth Response (Account IP differs. Original IP: {}, new IP: {}).", account.
LastIP, address);
552 TC_LOG_DEBUG(
"network",
"WorldSocket::HandleAuthSession: Sent Auth Response (Account country differs. Original country: {}, new country: {}).", account.
LockCountry,
_ipCountry);
575 TC_LOG_ERROR(
"network",
"WorldSocket::HandleAuthSession: Sent Auth Response (Account banned).");
583 TC_LOG_DEBUG(
"network",
"Allowed Level: {} Player Level {}", allowedAccountType, account.
Security);
587 TC_LOG_DEBUG(
"network",
"WorldSocket::HandleAuthSession: User tries to login but his security level is not enough");
593 TC_LOG_DEBUG(
"network",
"WorldSocket::HandleAuthSession: Client '{}' authenticated successfully from {}.", authSession->Account, address);
601 stmt->
setString(1, authSession->Account);
611 static_pointer_cast<WorldSocket>(shared_from_this()), account.
Security, account.
Expansion, mutetime,
635 packet <<
uint8(code);
642 using namespace std::chrono;
649 recvPacket >> latency;
657 steady_clock::time_point now = steady_clock::now();
663 if (diff < seconds(27))
675 TC_LOG_ERROR(
"network",
"WorldSocket::HandlePing: {} kicked for over-speed pings (address: {})",
693 TC_LOG_ERROR(
"network",
"WorldSocket::HandlePing: peer sent CMSG_PING, but is not authenticated or got recently kicked, address = {}",
GetRemoteIpAddress().to_string());
constexpr size_t SESSION_KEY_LENGTH
std::array< uint8, SESSION_KEY_LENGTH > SessionKey
void EndianConvertReverse(T &)
void EndianConvert(T &val)
std::shared_ptr< PreparedResultSet > PreparedQueryResult
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
std::chrono::minutes Minutes
Minutes shorthand typedef.
#define TC_LOG_DEBUG(filterType__,...)
#define TC_LOG_TRACE(filterType__,...)
#define TC_LOG_ERROR(filterType__,...)
@ LOGIN_UPD_MUTE_TIME_LOGIN
@ LOGIN_UPD_LAST_ATTEMPT_IP
@ LOGIN_SEL_ACCOUNT_INFO_BY_NAME
Role Based Access Control related classes definition.
@ REALM_LIST_REALM_NOT_FOUND
T & AddCallback(T &&query)
void ProcessReadyCallbacks()
std::array< uint8, 4 > LocalChallenge
Trinity::Crypto::SHA1::Digest Digest
bool NeedsEncryption() const
Class used to access individual fields of database query result.
std::string GetString() const
std::vector< uint8 > GetBinary() const
void Resize(size_type bytes)
size_type GetRemainingSpace() const
void ReadCompleted(size_type bytes)
size_type GetActiveSize() const
void Write(void const *data, std::size_t size)
void setUInt32(uint8 index, uint32 value)
void setInt64(uint8 index, int64 value)
void setInt32(uint8 index, int32 value)
void setString(uint8 index, std::string const &value)
QueryCallback && WithPreparedCallback(std::function< void(PreparedQueryResult)> &&callback)
std::array< uint8, DIGEST_LENGTH > Digest
void UpdateData(uint8 const *data, size_t len)
Digest const & GetDigest() const
uint16 GetRemotePort() const
boost::asio::ip::address const & GetRemoteIpAddress() const
void AsyncRead(Callback &&callback)
void QueuePacket(MessageBuffer &&buffer)
void DelayedCloseSocket()
Marks the socket for closing after write buffer becomes empty.
MessageBuffer & GetReadBuffer()
bool IsInitialized() const
void EncryptSend(uint8 *data, size_t len)
void Init(SessionKey const &K)
void DecryptRecv(uint8 *data, size_t len)
std::array< uint8, 4 > Challenge
WorldPacket const * Write() override
std::array< uint32, 8 > DosChallenge
Player session in the World.
void InitWarden(SessionKey const &k, std::string const &os)
rbac::RBACData * GetRBACData() const
void ReadAddonsInfo(ByteBuffer &data)
void QueuePacket(WorldPacket *new_packet)
Add an incoming packet to the queue.
std::string GetPlayerInfo() const
QueryCallback LoadPermissionsAsync()
bool HasPermission(uint32 permissionId)
void ResetTimeOutTime(bool onlyActive)
void SetLatency(uint32 latency)
MessageBuffer _headerBuffer
void LogOpcodeText(OpcodeClient opcode, std::unique_lock< std::mutex > const &guard) const
void QueueQuery(QueryCallback &&queryCallback)
void HandleAuthSession(WorldPacket &recvPacket)
bool HandlePing(WorldPacket &recvPacket)
void LoadSessionPermissionsCallback(PreparedQueryResult result)
MessageBuffer _packetBuffer
QueryCallbackProcessor _queryProcessor
WorldPacketCrypt _authCrypt
std::array< uint8, 4 > _serverChallenge
std::size_t _sendBufferSize
std::array< uint8, 32 > _dosChallenge
Trinity::Net::SocketReadCallbackResult ReadHandler() override
WorldSocket(Trinity::Net::IoContextTcpSocket &&socket)
WorldSession * _worldSession
void SendPacket(WorldPacket const &packet)
MPSCQueue< EncryptablePacket, &EncryptablePacket::SocketQueueLink > _bufferQueue
void SendPacketAndLogOpcode(WorldPacket const &packet)
sends and logs network.opcode without accessing WorldSession
void HandleAuthSessionCallback(std::shared_ptr< AuthSession > authSession, PreparedQueryResult result)
std::mutex _worldSessionLock
ReadDataHandlerResult ReadDataHandler()
void SendAuthResponseError(uint8 code)
void LoadFromDBCallback(PreparedQueryResult result)
std::string GetOpcodeNameForLogging(Opcodes opcode)
Lookup opcode name for human understandable logging.
@ CONFIG_MAX_OVERSPEED_PINGS
@ CONFIG_ALLOW_LOGGING_IP_ADDRESSES_IN_DATABASE
std::array< uint8, S > GetRandomBytes()
boost::asio::basic_stream_socket< boost::asio::ip::tcp, boost::asio::io_context::executor_type > IoContextTcpSocket
@ RBAC_PERM_SKIP_CHECK_OVERSPEED_PING
AccountInfo(Field const *fields)
static std::shared_ptr< SocketConnectionInitializer > & SetupChain(std::span< std::shared_ptr< SocketConnectionInitializer > > initializers)
std::shared_ptr< SocketConnectionInitializer > next
WorldSocketProtocolInitializer(WorldSocket *socket)