Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
WorldSocket Class Reference

Handler that can communicate over stream sockets. More...

#include <WorldSocket.h>

Collaboration diagram for WorldSocket:

Public Types

typedef std::unique_lock< LockTypeGuardType
typedef Skyfire::Mutex LockType
 Mutex type used for various synchronizations.

Public Member Functions

long AddReference (void)
 Add reference to this object.
void CloseSocket (void)
 Close the socket.
void DetachSession (WorldSession *session)
 Detaches the owning world session when the session is being removed.
const std::string & GetRemoteAddress (void) const
 Get address of connected peer.
bool HasPendingOutput (void) const
 Returns true when outgoing data is waiting to be flushed.
int Initialize (void)
 Called after socket accept and manager setup.
bool IsClosed (void) const
 Check if socket is closed.
void LogPacketMarker (std::string const &marker)
 Writes a readable marker into the per-session packet log.
void RefreshPacketLogSessionInfo ()
 Refreshes packet log metadata after a session gains character context.
long RemoveReference (void)
 Remove reference to this object.
int SendPacket (const WorldPacket &pct)
void Start (std::function< void(WorldSocket *)> closeHandler)
 Starts asynchronous socket processing.
 WorldSocket (std::unique_ptr< WorldSocketHandle > socket, std::string remoteAddress)
 ~WorldSocket (void)

Private Member Functions

Skyfire::PacketLogServerSessionInfo BuildPacketLogSessionInfo () const
int handle_input_header (void)
 Helper functions for processing incoming data.
int handle_input_missing_data (char const *data, size_t length)
int handle_input_payload (void)
void HandleAsyncRead (boost::system::error_code const &error, size_t transferredBytes)
void HandleAsyncWrite (boost::system::error_code const &error, size_t transferredBytes)
int HandleAuthSession (WorldPacket &recvPacket)
 Called by ProcessIncoming() on CMSG_AUTH_SESSION.
int HandlePing (WorldPacket &recvPacket)
 Called by ProcessIncoming() on CMSG_PING.
int HandleSendAuthSession ()
 Called by MSG_VERIFY_CONNECTIVITY_RESPONSE.
bool IsValidSocket (void) const
void NotifyClosed ()
WorldSocketoperator= (WorldSocket const &right)=delete
int ProcessIncoming (WorldPacket *new_pct)
void QueueSerializedPacket (std::vector< char > data)
void SendAuthResponseError (ResponseCodes code)
void StartAsyncRead ()
 WorldSocket (WorldSocket const &right)=delete

Private Attributes

std::string m_Address
 Address of the remote peer.
std::atomic< bool > m_Closed
std::function< void(WorldSocket *)> m_CloseHandler
std::atomic< bool > m_CloseNotified
AuthCrypt m_Crypt
 Class used for managing encryption of the headers.
bool m_HasLastPingTime
std::vector< uint8m_Header
size_t m_HeaderRead
std::chrono::steady_clock::time_point m_LastPingTime
 Time in which the last ping was received.
size_t m_OutBufferSize
 Configured output buffer size retained for network option compatibility.
uint32 m_OverSpeedPings
 Keep track of over-speed pings, to prevent ping flood.
std::deque< std::vector< char > > m_PendingOutput
 Queue used before the socket manager starts asynchronous processing.
std::array< char, 4096 > m_ReadBuffer
size_t m_RecvPctRead
WorldPacketm_RecvWPct
 here are stored the fragments of the received data
std::atomic< long > m_ReferenceCount
std::array< uint8, 4 > m_Seed
LockType m_SendLock
 Mutex for protecting packet serialization and pre-start output.
WorldSocketSessionState m_SessionState
 Session to which received packets are routed.
std::unique_ptr< WorldSocketHandlem_Socket
bool m_Started
std::vector< uint8m_WorldHeader
size_t m_WorldHeaderRead
std::unique_ptr< Skyfire::Net::BoostAsioWriteQueue< WorldSocketHandle > > m_WriteQueue

Friends

class ReactorRunnable
class WorldSocketMgr

Detailed Description

Handler that can communicate over stream sockets.

Definition at line 50 of file WorldSocket.h.

Member Typedef Documentation

◆ GuardType

typedef std::unique_lock<LockType> WorldSocket::GuardType

Definition at line 61 of file WorldSocket.h.

◆ LockType

Mutex type used for various synchronizations.

Definition at line 60 of file WorldSocket.h.

Constructor & Destructor Documentation

◆ WorldSocket() [1/2]

◆ ~WorldSocket()

WorldSocket::~WorldSocket ( void )

Definition at line 115 of file WorldSocket.cpp.

References CloseSocket(), m_RecvWPct, and sPacketLog.

◆ WorldSocket() [2/2]

WorldSocket::WorldSocket ( WorldSocket const & right)
privatedelete

References WorldSocket().

Member Function Documentation

◆ AddReference()

long WorldSocket::AddReference ( void )

Add reference to this object.

Definition at line 219 of file WorldSocket.cpp.

References m_ReferenceCount.

Referenced by ReactorRunnable::AddSocket(), QueueSerializedPacket(), StartAsyncRead(), and WorldSession::WorldSession().

◆ BuildPacketLogSessionInfo()

◆ CloseSocket()

void WorldSocket::CloseSocket ( void )

Close the socket.

Definition at line 127 of file WorldSocket.cpp.

References Skyfire::Net::CloseTcpSocket(), m_Closed, m_PendingOutput, m_SendLock, and m_Socket.

Referenced by HandleAsyncRead(), HandleAsyncWrite(), and ~WorldSocket().

◆ DetachSession()

void WorldSocket::DetachSession ( WorldSession * session)

Detaches the owning world session when the session is being removed.

Definition at line 270 of file WorldSocket.cpp.

References m_SessionState.

◆ GetRemoteAddress()

const std::string & WorldSocket::GetRemoteAddress ( void ) const

Get address of connected peer.

Definition at line 141 of file WorldSocket.cpp.

References m_Address.

Referenced by HandleAuthSession(), HandlePing(), ProcessIncoming(), and WorldSession::WorldSession().

◆ handle_input_header()

◆ handle_input_missing_data()

int WorldSocket::handle_input_missing_data ( char const * data,
size_t length )
private

◆ handle_input_payload()

int WorldSocket::handle_input_payload ( void )
private

◆ HandleAsyncRead()

void WorldSocket::HandleAsyncRead ( boost::system::error_code const & error,
size_t transferredBytes )
private

◆ HandleAsyncWrite()

void WorldSocket::HandleAsyncWrite ( boost::system::error_code const & error,
size_t transferredBytes )
private

Definition at line 348 of file WorldSocket.cpp.

References CloseSocket(), NotifyClosed(), and SF_LOG_DEBUG.

Referenced by QueueSerializedPacket().

◆ HandleAuthSession()

int WorldSocket::HandleAuthSession ( WorldPacket & recvPacket)
private

Called by ProcessIncoming() on CMSG_AUTH_SESSION.

  • Re-check ip locking (same check as in realmd).

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

Definition at line 769 of file WorldSocket.cpp.

References AUTH_BANNED, AUTH_FAILED, AUTH_REJECT, AUTH_UNAVAILABLE, AUTH_UNKNOWN_ACCOUNT, CONFIG_EXPANSION, CONFIG_SESSION_ADD_DELAY, CONFIG_WARDEN_ENABLED, ByteBuffer::contents(), SkyFire::Impl::GenericHash< HashCreator, DigestLength >::Finalize(), Field::GetBinary(), Field::GetBool(), SkyFire::Impl::GenericHash< HashCreator, DigestLength >::GetDigest(), Field::GetInt64(), GetRemoteAddress(), Field::GetString(), Field::GetUInt32(), Field::GetUInt8(), WorldSession::InitWarden(), llabs, WorldSession::LoadGlobalAccountData(), WorldSession::LoadPermissions(), WorldSession::LoadTutorialsData(), LOCALE_enUS, LOGIN_GET_GMLEVEL_BY_REALMID, LOGIN_SEL_ACCOUNT_INFO_BY_NAME, LOGIN_SEL_ACCOUNT_RECRUITER, LOGIN_SEL_BANS, LOGIN_UPD_LAST_IP, LOGIN_UPD_MUTE_TIME_LOGIN, LoginDatabase, m_Crypt, m_Seed, m_SessionState, ByteBuffer::read(), ByteBuffer::read_skip(), WorldSession::ReadAddonsInfo(), ByteBuffer::ReadBit(), ByteBuffer::ReadBits(), ByteBuffer::ReadString(), ByteBuffer::resize(), SEC_PLAYER, SendAuthResponseError(), SESSION_KEY_LENGTH, PreparedStatement::setInt32(), PreparedStatement::setInt64(), PreparedStatement::setString(), PreparedStatement::setUInt32(), WorldSession::SetVirtualRealmID(), SF_LOG_DEBUG, SF_LOG_ERROR, SF_LOG_INFO, Skyfire::SleepForMicroseconds(), sWorld, TOTAL_LOCALES, and SkyFire::Impl::GenericHash< HashCreator, DigestLength >::UpdateData().

Referenced by ProcessIncoming().

◆ HandlePing()

◆ HandleSendAuthSession()

int WorldSocket::HandleSendAuthSession ( )
private

Called by MSG_VERIFY_CONNECTIVITY_RESPONSE.

Definition at line 756 of file WorldSocket.cpp.

References ByteBuffer::append(), SkyFire::Crypto::GetRandomBytes(), m_Seed, SendPacket(), and SMSG_AUTH_CHALLENGE.

Referenced by ProcessIncoming().

◆ HasPendingOutput()

bool WorldSocket::HasPendingOutput ( void ) const

Returns true when outgoing data is waiting to be flushed.

Definition at line 146 of file WorldSocket.cpp.

References m_PendingOutput, m_SendLock, and m_WriteQueue.

◆ Initialize()

int WorldSocket::Initialize ( void )

Called after socket accept and manager setup.

Definition at line 233 of file WorldSocket.cpp.

References MSG_VERIFY_CONNECTIVITY, and SendPacket().

Referenced by WorldSocketMgr::OnSocketOpen().

◆ IsClosed()

bool WorldSocket::IsClosed ( void ) const

Check if socket is closed.

Definition at line 122 of file WorldSocket.cpp.

References m_Closed.

◆ IsValidSocket()

bool WorldSocket::IsValidSocket ( void ) const
private

Definition at line 152 of file WorldSocket.cpp.

References m_Socket.

Referenced by QueueSerializedPacket(), and StartAsyncRead().

◆ LogPacketMarker()

void WorldSocket::LogPacketMarker ( std::string const & marker)

Writes a readable marker into the per-session packet log.

Definition at line 208 of file WorldSocket.cpp.

References BuildPacketLogSessionInfo(), and sPacketLog.

◆ NotifyClosed()

void WorldSocket::NotifyClosed ( )
private

◆ operator=()

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

References WorldSocket().

◆ ProcessIncoming()

◆ QueueSerializedPacket()

void WorldSocket::QueueSerializedPacket ( std::vector< char > data)
private

◆ RefreshPacketLogSessionInfo()

void WorldSocket::RefreshPacketLogSessionInfo ( )

Refreshes packet log metadata after a session gains character context.

Definition at line 214 of file WorldSocket.cpp.

References BuildPacketLogSessionInfo(), and sPacketLog.

◆ RemoveReference()

long WorldSocket::RemoveReference ( void )

Remove reference to this object.

Definition at line 224 of file WorldSocket.cpp.

References m_ReferenceCount.

Referenced by ReactorRunnable::AddSocket(), QueueSerializedPacket(), ReactorRunnable::SocketClosed(), and StartAsyncRead().

◆ SendAuthResponseError()

void WorldSocket::SendAuthResponseError ( ResponseCodes code)
private

Definition at line 1088 of file WorldSocket.cpp.

References SendPacket(), SMSG_AUTH_RESPONSE, and ByteBuffer::WriteBit().

Referenced by HandleAuthSession().

◆ SendPacket()

◆ Start()

void WorldSocket::Start ( std::function< void(WorldSocket *)> closeHandler)

Starts asynchronous socket processing.

Definition at line 246 of file WorldSocket.cpp.

References m_Closed, m_CloseHandler, m_PendingOutput, m_SendLock, m_Started, NotifyClosed(), QueueSerializedPacket(), StartAsyncRead(), and WorldSocket().

Referenced by ReactorRunnable::AddSocket().

◆ StartAsyncRead()

void WorldSocket::StartAsyncRead ( )
private

◆ ReactorRunnable

friend class ReactorRunnable
friend

Definition at line 57 of file WorldSocket.h.

References ReactorRunnable.

Referenced by ReactorRunnable.

◆ WorldSocketMgr

friend class WorldSocketMgr
friend

Definition at line 56 of file WorldSocket.h.

References WorldSocketMgr.

Referenced by WorldSocketMgr.

Member Data Documentation

◆ m_Address

std::string WorldSocket::m_Address
private

Address of the remote peer.

Definition at line 138 of file WorldSocket.h.

Referenced by BuildPacketLogSessionInfo(), GetRemoteAddress(), and WorldSocket().

◆ m_Closed

std::atomic<bool> WorldSocket::m_Closed
private

◆ m_CloseHandler

std::function<void(WorldSocket*)> WorldSocket::m_CloseHandler
private

Definition at line 170 of file WorldSocket.h.

Referenced by NotifyClosed(), Start(), and WorldSocket().

◆ m_CloseNotified

std::atomic<bool> WorldSocket::m_CloseNotified
private

Definition at line 173 of file WorldSocket.h.

Referenced by NotifyClosed(), and WorldSocket().

◆ m_Crypt

AuthCrypt WorldSocket::m_Crypt
private

Class used for managing encryption of the headers.

Definition at line 141 of file WorldSocket.h.

Referenced by handle_input_header(), handle_input_missing_data(), handle_input_payload(), HandleAuthSession(), and SendPacket().

◆ m_HasLastPingTime

bool WorldSocket::m_HasLastPingTime
private

Definition at line 132 of file WorldSocket.h.

Referenced by HandlePing(), and WorldSocket().

◆ m_Header

std::vector<uint8> WorldSocket::m_Header
private

Definition at line 150 of file WorldSocket.h.

Referenced by handle_input_header(), handle_input_missing_data(), and WorldSocket().

◆ m_HeaderRead

size_t WorldSocket::m_HeaderRead
private

◆ m_LastPingTime

std::chrono::steady_clock::time_point WorldSocket::m_LastPingTime
private

Time in which the last ping was received.

Definition at line 131 of file WorldSocket.h.

Referenced by HandlePing(), and WorldSocket().

◆ m_OutBufferSize

size_t WorldSocket::m_OutBufferSize
private

Configured output buffer size retained for network option compatibility.

Definition at line 162 of file WorldSocket.h.

Referenced by WorldSocketMgr::OnSocketOpen(), and WorldSocket().

◆ m_OverSpeedPings

uint32 WorldSocket::m_OverSpeedPings
private

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

Definition at line 135 of file WorldSocket.h.

Referenced by HandlePing(), and WorldSocket().

◆ m_PendingOutput

std::deque<std::vector<char> > WorldSocket::m_PendingOutput
private

Queue used before the socket manager starts asynchronous processing.

Definition at line 159 of file WorldSocket.h.

Referenced by CloseSocket(), HasPendingOutput(), SendPacket(), Start(), and WorldSocket().

◆ m_ReadBuffer

std::array<char, 4096> WorldSocket::m_ReadBuffer
private

Definition at line 166 of file WorldSocket.h.

Referenced by HandleAsyncRead(), and StartAsyncRead().

◆ m_RecvPctRead

size_t WorldSocket::m_RecvPctRead
private

◆ m_RecvWPct

WorldPacket* WorldSocket::m_RecvWPct
private

here are stored the fragments of the received data

Definition at line 147 of file WorldSocket.h.

Referenced by handle_input_header(), handle_input_missing_data(), handle_input_payload(), WorldSocket(), and ~WorldSocket().

◆ m_ReferenceCount

std::atomic<long> WorldSocket::m_ReferenceCount
private

Definition at line 171 of file WorldSocket.h.

Referenced by AddReference(), RemoveReference(), and WorldSocket().

◆ m_Seed

std::array<uint8, 4> WorldSocket::m_Seed
private

Definition at line 165 of file WorldSocket.h.

Referenced by HandleAuthSession(), HandleSendAuthSession(), and WorldSocket().

◆ m_SendLock

LockType WorldSocket::m_SendLock
mutableprivate

Mutex for protecting packet serialization and pre-start output.

Definition at line 156 of file WorldSocket.h.

Referenced by CloseSocket(), HasPendingOutput(), SendPacket(), and Start().

◆ m_SessionState

WorldSocketSessionState WorldSocket::m_SessionState
private

Session to which received packets are routed.

Definition at line 144 of file WorldSocket.h.

Referenced by BuildPacketLogSessionInfo(), DetachSession(), handle_input_header(), HandleAuthSession(), HandlePing(), ProcessIncoming(), SendPacket(), and WorldSocket().

◆ m_Socket

std::unique_ptr<WorldSocketHandle> WorldSocket::m_Socket
private

◆ m_Started

bool WorldSocket::m_Started
private

Definition at line 163 of file WorldSocket.h.

Referenced by SendPacket(), Start(), and WorldSocket().

◆ m_WorldHeader

std::vector<uint8> WorldSocket::m_WorldHeader
private

Definition at line 152 of file WorldSocket.h.

Referenced by handle_input_header(), handle_input_missing_data(), and WorldSocket().

◆ m_WorldHeaderRead

size_t WorldSocket::m_WorldHeaderRead
private

◆ m_WriteQueue

std::unique_ptr<Skyfire::Net::BoostAsioWriteQueue<WorldSocketHandle> > WorldSocket::m_WriteQueue
private

Definition at line 169 of file WorldSocket.h.

Referenced by HasPendingOutput(), QueueSerializedPacket(), and WorldSocket().


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