TrinityCore
Loading...
Searching...
No Matches
WorldSocket Class Referencefinal

#include <WorldSocket.h>

+ Inheritance diagram for WorldSocket:

Public Member Functions

 WorldSocket (Trinity::Net::IoContextTcpSocket &&socket)
 
 ~WorldSocket ()
 
 WorldSocket (WorldSocket const &right)=delete
 
 WorldSocket (WorldSocket &&right)=delete
 
WorldSocket & operator= (WorldSocket const &right)=delete
 
WorldSocket & operator= (WorldSocket &&right)=delete
 
void Start () override
 
bool Update () override
 
void SendPacket (WorldPacket const &packet)
 
ConnectionType GetConnectionType () const
 
void SendAuthResponseError (uint32 code)
 
void SetWorldSession (WorldSession *session)
 
void SetSendBufferSize (std::size_t sendBufferSize)
 
void OnClose () override
 
Trinity::Net::SocketReadCallbackResult ReadHandler () override
 
void QueueQuery (QueryCallback &&queryCallback)
 
void SendAuthSession ()
 
bool InitializeCompression ()
 
- Public Member Functions inherited from Trinity::Net::Socket< Stream >
template<typename... Args>
 Socket (IoContextTcpSocket &&socket, Args &&... args)
 
template<typename... Args>
 Socket (Asio::IoContext &context, Args &&... args)
 
 Socket (Socket const &other)=delete
 
 Socket (Socket &&other)=delete
 
Socket & operator= (Socket const &other)=delete
 
Socket & operator= (Socket &&other)=delete
 
virtual ~Socket ()
 
template<BOOST_ASIO_COMPLETION_TOKEN_FOR(void(boost::system::error_code, boost::asio::ip::tcp::endpoint)) Callback>
decltype(auto) Connect (boost::asio::ip::tcp::endpoint const &endpoint, Callback &&callback)
 
template<BOOST_ASIO_COMPLETION_TOKEN_FOR(void(boost::system::error_code, boost::asio::ip::tcp::endpoint)) Callback>
decltype(auto) Connect (std::vector< boost::asio::ip::tcp::endpoint > const &endpoints, Callback &&callback)
 
boost::asio::ip::address const & GetRemoteIpAddress () const
 
uint16 GetRemotePort () const
 
void SetRemoteEndpoint (boost::asio::ip::tcp::endpoint const &endpoint)
 
template<invocable_r< SocketReadCallbackResult > Callback>
void AsyncRead (Callback &&callback)
 
void QueuePacket (MessageBuffer &&buffer)
 
bool IsOpen () const
 
void CloseSocket ()
 
void DelayedCloseSocket ()
 Marks the socket for closing after write buffer becomes empty.
 
MessageBuffer & GetReadBuffer ()
 
Stream & underlying_stream ()
 

Protected Types

enum class  ReadDataHandlerResult { Ok = 0 , Error = 1 , WaitingForQuery = 2 }
 

Protected Member Functions

bool ReadHeaderHandler ()
 
ReadDataHandlerResult ReadDataHandler ()
 
- Protected Member Functions inherited from Trinity::Net::Socket< Stream >
bool AsyncProcessQueue ()
 
void SetNoDelay (bool enable)
 

Private Types

using BaseSocket = Socket
 

Private Member Functions

void LogOpcodeText (OpcodeClient opcode) const
 writes network.opcode log
 
void LogOpcodeText (OpcodeClient opcode, std::scoped_lock< std::mutex > const &guard) const
 
void SendPacketAndLogOpcode (WorldPacket const &packet)
 sends and logs network.opcode without accessing WorldSession
 
void WritePacketToBuffer (EncryptablePacket const &packet, MessageBuffer &buffer)
 
uint32 CompressPacket (uint8 *buffer, WorldPacket const &packet)
 
ReadDataHandlerResult HandleAuthSession (WorldPacket &&packet)
 
void HandleAuthSessionCallback (WorldPackets::Auth::AuthSession const *authSession, JSON::RealmList::RealmJoinTicket *joinTicket, PreparedResultSet const *result)
 
ReadDataHandlerResult HandleAuthContinuedSession (WorldPacket &&packet)
 
void HandleAuthContinuedSessionCallback (WorldPackets::Auth::AuthContinuedSession const *authSession, PreparedResultSet const *result)
 
void LoadSessionPermissionsCallback (PreparedQueryResult result)
 
ReadDataHandlerResult HandleKeepAlive ()
 
ReadDataHandlerResult HandleLogDisconnect (WorldPacket &&packet) const
 
ReadDataHandlerResult HandleConnectToFailed (WorldPacket &&packet)
 
ReadDataHandlerResult HandlePing (WorldPacket &&packet)
 
ReadDataHandlerResult HandleEnterEncryptedModeAck ()
 

Private Attributes

ConnectionType _type
 
uint64 _key
 
std::array< uint8, 32 > _serverChallenge
 
WorldPacketCrypt _authCrypt
 
SessionKey _sessionKey
 
std::array< uint8, 32 > _encryptKey
 
TimePoint _lastPingTime
 
uint32 _overSpeedPings
 
std::mutex _worldSessionLock
 
WorldSession * _worldSession
 
bool _authed
 
bool _canRequestHotfixes
 
MessageBuffer _headerBuffer
 
MessageBuffer _packetBuffer
 
MPSCQueue< EncryptablePacket, &EncryptablePacket::SocketQueueLink > _bufferQueue
 
std::size_t _sendBufferSize
 
z_stream * _compressionStream
 
QueryCallbackProcessor _queryProcessor
 
std::string _ipCountry
 

Static Private Attributes

static uint32 const MinSizeForCompression = 0x400
 
static std::array< uint8, 32 > const AuthCheckSeed
 
static std::array< uint8, 32 > const SessionKeySeed
 
static std::array< uint8, 32 > const ContinuedSessionSeed
 
static std::array< uint8, 32 > const EncryptionKeySeed
 

Detailed Description

Definition at line 83 of file WorldSocket.h.

Member Typedef Documentation

◆ BaseSocket

Definition at line 92 of file WorldSocket.h.

Member Enumeration Documentation

◆ ReadDataHandlerResult

enum class WorldSocket::ReadDataHandlerResult
strongprotected
Enumerator
Ok 
Error 
WaitingForQuery 

Definition at line 125 of file WorldSocket.h.

Constructor & Destructor Documentation

◆ WorldSocket() [1/3]

WorldSocket::WorldSocket ( Trinity::Net::IoContextTcpSocket &&  socket)
explicit

Definition at line 65 of file WorldSocket.cpp.

◆ ~WorldSocket()

WorldSocket::~WorldSocket ( )

Definition at line 71 of file WorldSocket.cpp.

References _compressionStream.

◆ WorldSocket() [2/3]

WorldSocket::WorldSocket ( WorldSocket const &  right)
delete

◆ WorldSocket() [3/3]

WorldSocket::WorldSocket ( WorldSocket &&  right)
delete

Member Function Documentation

◆ CompressPacket()

uint32 WorldSocket::CompressPacket ( uint8 *  buffer,
WorldPacket const &  packet 
)
private

◆ GetConnectionType()

ConnectionType WorldSocket::GetConnectionType ( ) const
inline

Definition at line 108 of file WorldSocket.h.

Referenced by ReadDataHandler(), and SendPacket().

◆ HandleAuthContinuedSession()

◆ HandleAuthContinuedSessionCallback()

◆ HandleAuthSession()

◆ HandleAuthSessionCallback()

void WorldSocket::HandleAuthSessionCallback ( WorldPackets::Auth::AuthSession const *  authSession,
JSON::RealmList::RealmJoinTicket *  joinTicket,
PreparedResultSet const *  result 
)
private
  • Re-check ip locking (same check as in auth).

Negative mutetime indicates amount of seconds to be muted effective on next login - which is now.

Definition at line 651 of file WorldSocket.cpp.

References _authed, _encryptKey, _ipCountry, _serverChallenge, _sessionKey, _worldSession, ClientBuild::VariantId::Arch, Trinity::Net::Socket< Stream >::AsyncRead(), AuthCheckSeed, ClientBuild::Info::AuthKeys, AccountInfo::BattleNet, AccountInfo::Build, CONFIG_ALLOW_LOGGING_IP_ADDRESSES_IN_DATABASE, Trinity::Net::Socket< Stream >::DelayedCloseSocket(), WorldPackets::Auth::AuthSession::Digest, AccountInfo::Email, EncryptionKeySeed, ERROR_BAD_VERSION, ERROR_DENIED, ERROR_GAME_ACCOUNT_BANNED, ERROR_RISK_ACCOUNT_LOCKED, ERROR_SERVER_IS_PRIVATE, AccountInfo::Expansion, Trinity::Impl::GenericHash< HashCreator, DigestLength >::Finalize(), Trinity::Impl::GenericHMAC< HashCreator, DigestLength >::Finalize(), AccountInfo::Game, SessionKeyGenerator< Hash >::Generate(), ClientBuild::GetBuildInfo(), Trinity::Impl::GenericHash< HashCreator, DigestLength >::GetDigest(), Trinity::Impl::GenericHMAC< HashCreator, DigestLength >::GetDigest(), GameTime::GetGameTime(), Trinity::Net::Socket< Stream >::GetRemoteIpAddress(), AccountInfo::Id, AccountInfo::IsBanned, AccountInfo::IsLockedToIP, AccountInfo::IsRecruiter, AccountInfo::KeyData, AccountInfo::LastIP, WorldSession::LoadPermissionsAsync(), WorldPackets::Auth::AuthSession::LocalChallenge, AccountInfo::Locale, AccountInfo::LockCountry, LOGIN_UPD_ACCOUNT_INFO_CONTINUED_SESSION, LOGIN_UPD_LAST_ATTEMPT_IP, LOGIN_UPD_LAST_IP, LOGIN_UPD_MUTE_TIME_LOGIN, LoginDatabase, AccountInfo::MuteTime, AccountInfo::OS, ClientBuild::VariantId::Platform, QueueQuery(), WorldPackets::Auth::AuthSession::RealmID, AccountInfo::Recruiter, SEC_PLAYER, AccountInfo::Security, SendAuthResponseError(), SessionKeySeed, PreparedStatementBase::setBinary(), PreparedStatementBase::setInt64(), PreparedStatementBase::setString(), PreparedStatementBase::setUInt32(), sIPLocation, Trinity::Net::InvokeReadHandlerCallback< SocketType >::Socket, sRealmList, sScriptMgr, sWorld, TC_LOG_DEBUG, TC_LOG_ERROR, AccountInfo::TimezoneOffset, ClientBuild::VariantId::Type, Trinity::Impl::GenericHash< HashCreator, DigestLength >::UpdateData(), Trinity::Impl::GenericHMAC< HashCreator, DigestLength >::UpdateData(), ClientBuild::AuthKey::Variant, and QueryCallback::WithPreparedCallback().

◆ HandleConnectToFailed()

◆ HandleEnterEncryptedModeAck()

◆ HandleKeepAlive()

◆ HandleLogDisconnect()

◆ HandlePing()

◆ InitializeCompression()

bool WorldSocket::InitializeCompression ( )

◆ LoadSessionPermissionsCallback()

void WorldSocket::LoadSessionPermissionsCallback ( PreparedQueryResult  result)
private

◆ LogOpcodeText() [1/2]

◆ LogOpcodeText() [2/2]

void WorldSocket::LogOpcodeText ( OpcodeClient  opcode,
std::scoped_lock< std::mutex > const &  guard 
) const
private

◆ OnClose()

void WorldSocket::OnClose ( )
overridevirtual

Reimplemented from Trinity::Net::Socket< Stream >.

Definition at line 258 of file WorldSocket.cpp.

References _worldSession, and _worldSessionLock.

◆ operator=() [1/2]

WorldSocket & WorldSocket::operator= ( WorldSocket &&  right)
delete

◆ operator=() [2/2]

WorldSocket & WorldSocket::operator= ( WorldSocket const &  right)
delete

◆ QueueQuery()

void WorldSocket::QueueQuery ( QueryCallback &&  queryCallback)

◆ ReadDataHandler()

◆ ReadHandler()

◆ ReadHeaderHandler()

◆ SendAuthResponseError()

◆ SendAuthSession()

◆ SendPacket()

◆ SendPacketAndLogOpcode()

void WorldSocket::SendPacketAndLogOpcode ( WorldPacket const &  packet)
private

◆ SetSendBufferSize()

void WorldSocket::SetSendBufferSize ( std::size_t  sendBufferSize)
inline

Definition at line 112 of file WorldSocket.h.

◆ SetWorldSession()

void WorldSocket::SetWorldSession ( WorldSession *  session)

Definition at line 329 of file WorldSocket.cpp.

References _authed, _worldSession, and _worldSessionLock.

◆ Start()

void WorldSocket::Start ( )
overridevirtual

◆ Update()

◆ WritePacketToBuffer()

Member Data Documentation

◆ _authCrypt

WorldPacketCrypt WorldSocket::_authCrypt
private

◆ _authed

bool WorldSocket::_authed
private

◆ _bufferQueue

MPSCQueue<EncryptablePacket, &EncryptablePacket::SocketQueueLink> WorldSocket::_bufferQueue
private

Definition at line 171 of file WorldSocket.h.

Referenced by SendPacket(), and Update().

◆ _canRequestHotfixes

bool WorldSocket::_canRequestHotfixes
private

Definition at line 167 of file WorldSocket.h.

Referenced by ReadDataHandler(), and ReadHeaderHandler().

◆ _compressionStream

z_stream* WorldSocket::_compressionStream
private

Definition at line 174 of file WorldSocket.h.

Referenced by CompressPacket(), InitializeCompression(), Update(), and ~WorldSocket().

◆ _encryptKey

std::array<uint8, 32> WorldSocket::_encryptKey
private

◆ _headerBuffer

MessageBuffer WorldSocket::_headerBuffer
private

Definition at line 169 of file WorldSocket.h.

Referenced by ReadDataHandler(), ReadHandler(), and ReadHeaderHandler().

◆ _ipCountry

std::string WorldSocket::_ipCountry
private

Definition at line 177 of file WorldSocket.h.

Referenced by HandleAuthSessionCallback().

◆ _key

uint64 WorldSocket::_key
private

◆ _lastPingTime

TimePoint WorldSocket::_lastPingTime
private

Definition at line 161 of file WorldSocket.h.

Referenced by HandlePing().

◆ _overSpeedPings

uint32 WorldSocket::_overSpeedPings
private

Definition at line 162 of file WorldSocket.h.

Referenced by HandlePing().

◆ _packetBuffer

MessageBuffer WorldSocket::_packetBuffer
private

Definition at line 170 of file WorldSocket.h.

Referenced by ReadDataHandler(), ReadHandler(), and ReadHeaderHandler().

◆ _queryProcessor

QueryCallbackProcessor WorldSocket::_queryProcessor
private

Definition at line 176 of file WorldSocket.h.

Referenced by QueueQuery(), and Update().

◆ _sendBufferSize

std::size_t WorldSocket::_sendBufferSize
private

Definition at line 172 of file WorldSocket.h.

Referenced by Update().

◆ _serverChallenge

std::array<uint8, 32> WorldSocket::_serverChallenge
private

◆ _sessionKey

SessionKey WorldSocket::_sessionKey
private

Definition at line 158 of file WorldSocket.h.

Referenced by HandleAuthContinuedSessionCallback(), and HandleAuthSessionCallback().

◆ _type

ConnectionType WorldSocket::_type
private

Definition at line 153 of file WorldSocket.h.

Referenced by HandleAuthContinuedSession(), and HandleEnterEncryptedModeAck().

◆ _worldSession

◆ _worldSessionLock

std::mutex WorldSocket::_worldSessionLock
private

◆ AuthCheckSeed

std::array< uint8, 32 > const WorldSocket::AuthCheckSeed
staticprivate
Initial value:
= { 0xDE, 0x3A, 0x2A, 0x8E, 0x6B, 0x89, 0x52, 0x66, 0x88, 0x9D, 0x7E, 0x7A, 0x77, 0x1D, 0x5D, 0x1F,
0x4E, 0xD9, 0x0C, 0x23, 0x9B, 0xCD, 0x0E, 0xDC, 0xD2, 0xE8, 0x04, 0x3A, 0x68, 0x64, 0xC7, 0xB0 }

Definition at line 56 of file WorldSocket.h.

Referenced by HandleAuthSessionCallback().

◆ ContinuedSessionSeed

std::array< uint8, 32 > const WorldSocket::ContinuedSessionSeed
staticprivate
Initial value:
= { 0x56, 0x5C, 0x61, 0x9C, 0x48, 0x3A, 0x52, 0x1F, 0x61, 0x5D, 0x05, 0x49, 0xB2, 0x9A, 0x39, 0xBF,
0x4B, 0x97, 0xB0, 0x1B, 0xF9, 0x6C, 0xDE, 0xD6, 0x80, 0x1D, 0xAB, 0x26, 0x02, 0xA9, 0x9B, 0x9D }

Definition at line 60 of file WorldSocket.h.

Referenced by HandleAuthContinuedSessionCallback().

◆ EncryptionKeySeed

std::array< uint8, 32 > const WorldSocket::EncryptionKeySeed
staticprivate
Initial value:
= { 0x71, 0xC9, 0xED, 0x5A, 0xA7, 0x0E, 0x4D, 0xFF, 0x4C, 0x36, 0xA6, 0x5A, 0x3E, 0x46, 0x8A, 0x4A,
0x5D, 0xA1, 0x48, 0xC8, 0x30, 0x47, 0x4A, 0xDE, 0xF6, 0x0D, 0x6C, 0xBE, 0x6F, 0xE4, 0x55, 0x73 }

Definition at line 62 of file WorldSocket.h.

Referenced by HandleAuthContinuedSessionCallback(), and HandleAuthSessionCallback().

◆ MinSizeForCompression

uint32 const WorldSocket::MinSizeForCompression = 0x400
staticprivate

Definition at line 85 of file WorldSocket.h.

Referenced by Update(), and WritePacketToBuffer().

◆ SessionKeySeed

std::array< uint8, 32 > const WorldSocket::SessionKeySeed
staticprivate
Initial value:
= { 0xE8, 0x1E, 0x8B, 0x59, 0x27, 0x62, 0x1E, 0xAA, 0x86, 0x15, 0x18, 0xEA, 0xC0, 0xBF, 0x66, 0x8C,
0x6D, 0xBF, 0x83, 0x93, 0xBC, 0xAA, 0x80, 0x52, 0x5B, 0x1E, 0xDC, 0x23, 0xA0, 0x12, 0xB7, 0x50 }

Definition at line 58 of file WorldSocket.h.

Referenced by HandleAuthSessionCallback().


The documentation for this class was generated from the following files: