12#ifndef SF_WORLDSOCKET_H
13#define SF_WORLDSOCKET_H
20#include <boost/asio/ip/tcp.hpp>
21#include <boost/system/error_code.hpp>
37 template<
class AsyncWriteStream>
46struct PacketLogServerSessionInfo;
53 WorldSocket(std::unique_ptr<WorldSocketHandle> socket, std::string remoteAddress);
125 void HandleAsyncRead(boost::system::error_code
const& error,
size_t transferredBytes);
126 void HandleAsyncWrite(boost::system::error_code
const& error,
size_t transferredBytes);
169 std::unique_ptr<Skyfire::Net::BoostAsioWriteQueue<WorldSocketHandle>>
m_WriteQueue;
Player session in the World.
size_t m_OutBufferSize
Configured output buffer size retained for network option compatibility.
bool IsClosed(void) const
Check if socket is closed.
WorldSocket(std::unique_ptr< WorldSocketHandle > socket, std::string remoteAddress)
void HandleAsyncWrite(boost::system::error_code const &error, size_t transferredBytes)
long RemoveReference(void)
Remove reference to this object.
std::unique_ptr< WorldSocketHandle > m_Socket
std::atomic< bool > m_CloseNotified
std::vector< uint8 > m_WorldHeader
friend class WorldSocketMgr
void SendAuthResponseError(ResponseCodes code)
WorldPacket * m_RecvWPct
here are stored the fragments of the received data
std::atomic< long > m_ReferenceCount
Skyfire::Mutex LockType
Mutex type used for various synchronizations.
WorldSocketSessionState m_SessionState
Session to which received packets are routed.
long AddReference(void)
Add reference to this object.
std::chrono::steady_clock::time_point m_LastPingTime
Time in which the last ping was received.
friend class ReactorRunnable
int ProcessIncoming(WorldPacket *new_pct)
WorldSocket & operator=(WorldSocket const &right)=delete
AuthCrypt m_Crypt
Class used for managing encryption of the headers.
std::unique_ptr< Skyfire::Net::BoostAsioWriteQueue< WorldSocketHandle > > m_WriteQueue
int HandleSendAuthSession()
Called by MSG_VERIFY_CONNECTIVITY_RESPONSE.
uint32 m_OverSpeedPings
Keep track of over-speed pings, to prevent ping flood.
LockType m_SendLock
Mutex for protecting packet serialization and pre-start output.
void RefreshPacketLogSessionInfo()
Refreshes packet log metadata after a session gains character context.
int handle_input_header(void)
Helper functions for processing incoming data.
bool HasPendingOutput(void) const
Returns true when outgoing data is waiting to be flushed.
void Start(std::function< void(WorldSocket *)> closeHandler)
Starts asynchronous socket processing.
int HandleAuthSession(WorldPacket &recvPacket)
Called by ProcessIncoming() on CMSG_AUTH_SESSION.
void CloseSocket(void)
Close the socket.
void HandleAsyncRead(boost::system::error_code const &error, size_t transferredBytes)
void DetachSession(WorldSession *session)
Detaches the owning world session when the session is being removed.
int handle_input_payload(void)
std::atomic< bool > m_Closed
std::vector< uint8 > m_Header
std::unique_lock< LockType > GuardType
int Initialize(void)
Called after socket accept and manager setup.
const std::string & GetRemoteAddress(void) const
Get address of connected peer.
int HandlePing(WorldPacket &recvPacket)
Called by ProcessIncoming() on CMSG_PING.
Skyfire::PacketLogServerSessionInfo BuildPacketLogSessionInfo() const
bool IsValidSocket(void) const
void LogPacketMarker(std::string const &marker)
Writes a readable marker into the per-session packet log.
std::function< void(WorldSocket *)> m_CloseHandler
WorldSocket(WorldSocket const &right)=delete
std::array< uint8, 4 > m_Seed
std::deque< std::vector< char > > m_PendingOutput
Queue used before the socket manager starts asynchronous processing.
std::array< char, 4096 > m_ReadBuffer
void QueueSerializedPacket(std::vector< char > data)
std::string m_Address
Address of the remote peer.
int SendPacket(const WorldPacket &pct)
int handle_input_missing_data(char const *data, size_t length)
boost::asio::ip::tcp::socket WorldSocketHandle