|
Project SkyFire Core
SkyFire 5.4.8 server core API documentation
|
Handler that can communicate over stream sockets. More...
#include <WorldSocket.h>
Public Types | |
| typedef std::unique_lock< LockType > | GuardType |
| 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 () |
| WorldSocket & | operator= (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< uint8 > | m_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 |
| WorldPacket * | m_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< WorldSocketHandle > | m_Socket |
| bool | m_Started |
| std::vector< uint8 > | m_WorldHeader |
| size_t | m_WorldHeaderRead |
| std::unique_ptr< Skyfire::Net::BoostAsioWriteQueue< WorldSocketHandle > > | m_WriteQueue |
Friends | |
| class | ReactorRunnable |
| class | WorldSocketMgr |
Handler that can communicate over stream sockets.
Definition at line 50 of file WorldSocket.h.
| typedef std::unique_lock<LockType> WorldSocket::GuardType |
Definition at line 61 of file WorldSocket.h.
| typedef Skyfire::Mutex WorldSocket::LockType |
Mutex type used for various synchronizations.
Definition at line 60 of file WorldSocket.h.
| WorldSocket::WorldSocket | ( | std::unique_ptr< WorldSocketHandle > | socket, |
| std::string | remoteAddress ) |
Definition at line 104 of file WorldSocket.cpp.
References SkyFire::Crypto::GetRandomBytes(), m_Address, m_Closed, m_CloseHandler, m_CloseNotified, m_HasLastPingTime, m_Header, m_HeaderRead, m_LastPingTime, m_OutBufferSize, m_OverSpeedPings, m_PendingOutput, m_RecvPctRead, m_RecvWPct, m_ReferenceCount, m_Seed, m_SessionState, m_Socket, m_Started, m_WorldHeader, m_WorldHeaderRead, and m_WriteQueue.
Referenced by operator=(), Start(), and WorldSocket().
| WorldSocket::~WorldSocket | ( | void | ) |
Definition at line 115 of file WorldSocket.cpp.
References CloseSocket(), m_RecvWPct, and sPacketLog.
|
privatedelete |
References WorldSocket().
| 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().
|
private |
Definition at line 372 of file WorldSocket.cpp.
References Skyfire::PacketLogServerSessionInfo::AccountId, Skyfire::PacketLogServerSessionInfo::CharacterName, WorldSession::GetAccountId(), WorldSession::GetPlayer(), WorldSession::GetVirtualRealmID(), m_Address, m_SessionState, Skyfire::PacketLogServerSessionInfo::RealmId, and Skyfire::PacketLogServerSessionInfo::RemoteAddress.
Referenced by LogPacketMarker(), ProcessIncoming(), RefreshPacketLogSessionInfo(), and SendPacket().
| 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().
| 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.
| 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().
|
private |
Helper functions for processing incoming data.
Definition at line 395 of file WorldSocket.cpp.
References ASSERT, clientOpcodeTable, AuthClientPktHeader::cmd, WorldClientPktHeader::cmd, PacketFilter::DropHighBytes(), WorldSession::GetAccountId(), Object::GetGUIDLow(), WorldObject::GetName(), WorldSession::GetPlayer(), m_Crypt, m_Header, m_HeaderRead, m_RecvPctRead, m_RecvWPct, m_SessionState, m_WorldHeader, m_WorldHeaderRead, SF_LOG_ERROR, AuthClientPktHeader::size, and WorldClientPktHeader::size.
Referenced by handle_input_missing_data().
|
private |
Definition at line 525 of file WorldSocket.cpp.
References ASSERT, handle_input_header(), handle_input_payload(), m_Crypt, m_Header, m_HeaderRead, m_RecvPctRead, m_RecvWPct, m_WorldHeader, m_WorldHeaderRead, and SF_LOG_ERROR.
Referenced by HandleAsyncRead().
|
private |
Definition at line 482 of file WorldSocket.cpp.
References ASSERT, m_Crypt, m_HeaderRead, m_RecvPctRead, m_RecvWPct, m_WorldHeaderRead, and ProcessIncoming().
Referenced by handle_input_missing_data().
|
private |
Definition at line 309 of file WorldSocket.cpp.
References CloseSocket(), handle_input_missing_data(), m_Closed, m_ReadBuffer, NotifyClosed(), SF_LOG_DEBUG, and StartAsyncRead().
Referenced by StartAsyncRead().
|
private |
Definition at line 348 of file WorldSocket.cpp.
References CloseSocket(), NotifyClosed(), and SF_LOG_DEBUG.
Referenced by QueueSerializedPacket().
|
private |
Called by ProcessIncoming() on CMSG_AUTH_SESSION.
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().
|
private |
Called by ProcessIncoming() on CMSG_PING.
Definition at line 1014 of file WorldSocket.cpp.
References CONFIG_MAX_OVERSPEED_PINGS, WorldSession::GetPlayerInfo(), GetRemoteAddress(), WorldSession::HasPermission(), m_HasLastPingTime, m_LastPingTime, m_OverSpeedPings, m_SessionState, rbac::RBAC_PERM_SKIP_CHECK_OVERSPEED_PING, WorldSession::ResetClientTimeDelay(), SendPacket(), WorldSession::SetLatency(), SF_LOG_ERROR, SMSG_PONG, and sWorld.
Referenced by ProcessIncoming().
|
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().
| 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.
| 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().
| bool WorldSocket::IsClosed | ( | void | ) | const |
|
private |
Definition at line 152 of file WorldSocket.cpp.
References m_Socket.
Referenced by QueueSerializedPacket(), and StartAsyncRead().
| 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.
|
private |
Definition at line 363 of file WorldSocket.cpp.
References m_CloseHandler, and m_CloseNotified.
Referenced by HandleAsyncRead(), HandleAsyncWrite(), QueueSerializedPacket(), Start(), and StartAsyncRead().
|
privatedelete |
References WorldSocket().
|
private |
process one incoming packet.
| new_pct | received packet, note that you need to delete it. |
Definition at line 629 of file WorldSocket.cpp.
References ASSERT, BuildPacketLogSessionInfo(), CLIENT_TO_SERVER, clientOpcodeTable, CMSG_AUTH_SESSION, CMSG_ENABLE_NAGLE, CMSG_KEEP_ALIVE, CMSG_LOG_DISCONNECT, CMSG_PING, WorldSession::GetAccountId(), WorldPacket::GetOpcode(), GetOpcodeNameForLogging(), WorldSession::GetPlayerInfo(), WorldPacket::GetReceivedOpcode(), GetRemoteAddress(), HandleAuthSession(), WorldSession::HandleEnableNagleAlgorithm(), HandlePing(), HandleSendAuthSession(), ByteBuffer::hexlike(), m_Closed, m_SessionState, MSG_VERIFY_CONNECTIVITY, NUM_OPCODES, WorldSession::QueuePacket(), WorldSession::ResetTimeOutTime(), ByteBuffer::rfinish(), SF_LOG_DEBUG, SF_LOG_ERROR, SF_LOG_TRACE, sPacketLog, sScriptMgr, OpcodeHandler::Status, and STATUS_UNHANDLED.
Referenced by handle_input_payload().
|
private |
Definition at line 275 of file WorldSocket.cpp.
References AddReference(), HandleAsyncWrite(), IsValidSocket(), m_WriteQueue, NotifyClosed(), and RemoveReference().
Referenced by SendPacket(), and Start().
| 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.
| 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().
|
private |
Definition at line 1088 of file WorldSocket.cpp.
References SendPacket(), SMSG_AUTH_RESPONSE, and ByteBuffer::WriteBit().
Referenced by HandleAuthSession().
| int WorldSocket::SendPacket | ( | const WorldPacket & | pct | ) |
Send A packet on the socket, this function is reentrant.
| pct | packet to send |
Definition at line 157 of file WorldSocket.cpp.
References BuildPacketLogSessionInfo(), ByteBuffer::contents(), ByteBuffer::empty(), ServerPktHeader::getHeaderLength(), WorldPacket::GetOpcode(), GetOpcodeNameForLogging(), WorldSession::GetPlayerInfo(), ServerPktHeader::header, m_Closed, m_Crypt, m_PendingOutput, m_SendLock, m_SessionState, m_Started, QueueSerializedPacket(), SERVER_TO_CLIENT, serverOpcodeTable, SF_LOG_TRACE, ByteBuffer::size(), sPacketLog, and sScriptMgr.
Referenced by HandlePing(), HandleSendAuthSession(), Initialize(), and SendAuthResponseError().
| 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().
|
private |
Definition at line 292 of file WorldSocket.cpp.
References AddReference(), HandleAsyncRead(), IsValidSocket(), m_Closed, m_ReadBuffer, m_Socket, NotifyClosed(), and RemoveReference().
Referenced by HandleAsyncRead(), and Start().
|
friend |
Definition at line 57 of file WorldSocket.h.
References ReactorRunnable.
Referenced by ReactorRunnable.
|
friend |
Definition at line 56 of file WorldSocket.h.
References WorldSocketMgr.
Referenced by WorldSocketMgr.
|
private |
Address of the remote peer.
Definition at line 138 of file WorldSocket.h.
Referenced by BuildPacketLogSessionInfo(), GetRemoteAddress(), and WorldSocket().
|
private |
Definition at line 172 of file WorldSocket.h.
Referenced by CloseSocket(), HandleAsyncRead(), IsClosed(), ProcessIncoming(), SendPacket(), Start(), StartAsyncRead(), and WorldSocket().
|
private |
Definition at line 170 of file WorldSocket.h.
Referenced by NotifyClosed(), Start(), and WorldSocket().
|
private |
Definition at line 173 of file WorldSocket.h.
Referenced by NotifyClosed(), and WorldSocket().
|
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().
|
private |
Definition at line 132 of file WorldSocket.h.
Referenced by HandlePing(), and WorldSocket().
|
private |
Definition at line 150 of file WorldSocket.h.
Referenced by handle_input_header(), handle_input_missing_data(), and WorldSocket().
|
private |
Definition at line 151 of file WorldSocket.h.
Referenced by handle_input_header(), handle_input_missing_data(), handle_input_payload(), and WorldSocket().
|
private |
Time in which the last ping was received.
Definition at line 131 of file WorldSocket.h.
Referenced by HandlePing(), and WorldSocket().
|
private |
Configured output buffer size retained for network option compatibility.
Definition at line 162 of file WorldSocket.h.
Referenced by WorldSocketMgr::OnSocketOpen(), and WorldSocket().
|
private |
Keep track of over-speed pings, to prevent ping flood.
Definition at line 135 of file WorldSocket.h.
Referenced by HandlePing(), and WorldSocket().
|
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().
|
private |
Definition at line 166 of file WorldSocket.h.
Referenced by HandleAsyncRead(), and StartAsyncRead().
|
private |
Definition at line 149 of file WorldSocket.h.
Referenced by handle_input_header(), handle_input_missing_data(), handle_input_payload(), and WorldSocket().
|
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().
|
private |
Definition at line 171 of file WorldSocket.h.
Referenced by AddReference(), RemoveReference(), and WorldSocket().
|
private |
Definition at line 165 of file WorldSocket.h.
Referenced by HandleAuthSession(), HandleSendAuthSession(), and WorldSocket().
|
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().
|
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().
|
private |
Definition at line 168 of file WorldSocket.h.
Referenced by CloseSocket(), IsValidSocket(), WorldSocketMgr::OnSocketOpen(), StartAsyncRead(), and WorldSocket().
|
private |
Definition at line 163 of file WorldSocket.h.
Referenced by SendPacket(), Start(), and WorldSocket().
|
private |
Definition at line 152 of file WorldSocket.h.
Referenced by handle_input_header(), handle_input_missing_data(), and WorldSocket().
|
private |
Definition at line 153 of file WorldSocket.h.
Referenced by handle_input_header(), handle_input_missing_data(), handle_input_payload(), and WorldSocket().
|
private |
Definition at line 169 of file WorldSocket.h.
Referenced by HasPendingOutput(), QueueSerializedPacket(), and WorldSocket().