High-performance UDP client implementation using ASIO library. More...
#include <AsioClient.hpp>
Inheritance diagram for eng::AsioClient:
Collaboration diagram for eng::AsioClient:Public Member Functions | |
| AsioClient () | |
| Constructor. | |
| ~AsioClient () override | |
| Destructor. | |
| void | connect (const std::string &host, std::uint16_t port) override |
| Connect to game server. | |
| void | disconnect () override |
| Disconnect from server. | |
| void | update () override |
| Update client state (called each frame) | |
| const std::string | getName () const override |
| utl::PluginType | getType () const override |
| bool | isConnected () const override |
| Check if client is connected to server. | |
| ConnectionState | getConnectionState () const override |
| Get current connection state. | |
| std::uint32_t | getSessionId () const override |
| Get assigned session ID. | |
| std::uint16_t | getServerTickRate () const override |
| Get server tick rate. | |
| std::uint32_t | getLatency () const override |
| Get current latency to server. | |
| void | setPlayerName (const std::string &playerName) override |
| Set player name for connection. | |
| void | setClientCapabilities (std::uint32_t caps) override |
| Set client capability flags. | |
| void | processBusEvent () |
| Process events from event bus. | |
| void | sendToServer (const std::vector< std::uint8_t > &data, bool reliable=false) override |
| Send custom packet to server. | |
| const ConnectionStats & | getStats () const |
| Get connection statistics. | |
| void | requestLobbyList () |
| Request list of available lobbies from server. | |
| void | createLobby (rnp::PacketLobbyCreate lobbyCreate) |
| Create a new lobby on server. | |
| void | joinLobby (std::uint32_t lobbyId) |
| Join an existing lobby. | |
| void | leaveLobby () |
| Leave current lobby. | |
| void | requestStartGame (std::uint32_t lobbyId) |
| Request to start the game (host only) | |
| std::uint32_t | getCurrentLobbyId () const |
| Get current lobby ID. | |
| bool | isInLobby () const |
| Check if player is in a lobby. | |
| void | setOnLobbyListReceived (std::function< void(const std::vector< rnp::LobbyInfo > &)> callback) |
| Set callback for lobby list received. | |
| void | setOnLobbyCreated (std::function< void(std::uint32_t, bool, rnp::ErrorCode)> callback) |
| Set callback for lobby creation response. | |
| void | setOnLobbyJoined (std::function< void(std::uint32_t, bool, rnp::ErrorCode, const rnp::LobbyInfo *)> callback) |
| Set callback for lobby join response. | |
| void | setOnLobbyUpdated (std::function< void(const rnp::LobbyInfo &)> callback) |
| Set callback for lobby updates. | |
| void | setOnGameStart (std::function< void(std::uint32_t, std::uint32_t)> callback) |
| Set callback for game start notification. | |
Public Member Functions inherited from eng::INetworkClient | |
| virtual | ~INetworkClient ()=default |
| virtual void | connect (const std::string &host, uint16_t port)=0 |
Public Member Functions inherited from utl::IPlugin | |
| virtual | ~IPlugin ()=default |
Private Member Functions | |
| void | setupPacketHandlers () |
| Setup packet handlers for all RNP packet types. | |
| void | startReceive () |
| Start asynchronous receive operation. | |
| void | handleReceive (std::size_t bytesReceived) |
| Handle received packet data. | |
| void | networkThreadLoop () const |
| Main network thread loop. | |
| void | sendPacketImmediate (const std::vector< std::uint8_t > &data) |
| Send packet immediately via UDP socket. | |
| rnp::HandlerResult | handleConnectAccept (const rnp::PacketConnectAccept &packet, const rnp::PacketContext &context) |
| Handle CONNECT_ACCEPT packet. | |
| rnp::HandlerResult | handleDisconnect (const rnp::PacketDisconnect &packet, const rnp::PacketContext &context) |
| Handle DISCONNECT packet. | |
| rnp::HandlerResult | handlePong (const rnp::PacketPingPong &packet, const rnp::PacketContext &context) |
| Handle PONG packet. | |
| rnp::HandlerResult | handlePing (const rnp::PacketPingPong &packet, const rnp::PacketContext &context) |
| Handle PING packet. | |
| rnp::HandlerResult | handleWorldState (const rnp::PacketWorldState &packet, const rnp::PacketContext &context) const |
| Handle WORLD_STATE packet. | |
| rnp::HandlerResult | handleEntityEvent (const std::vector< rnp::EventRecord > &events, const rnp::PacketContext &context) const |
| Handle ENTITY_EVENT packet. | |
| rnp::HandlerResult | handleLobbyListResponse (const rnp::PacketLobbyListResponse &packet, const rnp::PacketContext &context) const |
| Handle LOBBY_LIST_RESPONSE packet. | |
| rnp::HandlerResult | handleLobbyCreateResponse (const rnp::PacketLobbyCreateResponse &packet, const rnp::PacketContext &context) |
| Handle LOBBY_CREATE_RESPONSE packet. | |
| rnp::HandlerResult | handleLobbyJoinResponse (const rnp::PacketLobbyJoinResponse &packet, const rnp::PacketContext &context) |
| Handle LOBBY_JOIN_RESPONSE packet. | |
| rnp::HandlerResult | handleLobbyUpdate (const rnp::PacketLobbyUpdate &packet, const rnp::PacketContext &context) const |
| Handle LOBBY_UPDATE packet. | |
| rnp::HandlerResult | handleGameStart (const rnp::PacketGameStart &packet, const rnp::PacketContext &context) const |
| Handle GAME_START packet. | |
| void | sendConnect () |
| Send CONNECT packet to initiate connection. | |
| void | sendDisconnect () |
| Send DISCONNECT packet to terminate connection. | |
| void | sendPing () |
| Send PING packet for latency measurement. | |
| void | sendPong (std::uint32_t nonce) |
| Send PONG response to server PING. | |
| void | processSendQueue () |
| Process outgoing packet queue. | |
| void | updateConnectionManagement () |
| Update connection management state. | |
Static Private Member Functions | |
| static rnp::HandlerResult | handleError (const rnp::PacketError &packet, const rnp::PacketContext &context) |
| Handle ERROR packet. | |
| static std::uint32_t | generatePingNonce () |
| Generate random ping nonce. | |
Private Attributes | |
| std::unique_ptr< asio::io_context > | m_ioContext |
| ASIO I/O context for async operations. | |
| std::unique_ptr< asio::ip::udp::socket > | m_socket |
| UDP socket for network communication. | |
| std::unique_ptr< std::thread > | m_networkThread |
| Dedicated network thread. | |
| std::string | m_serverHost |
| Server hostname or IP address. | |
| std::uint16_t | m_serverPort |
| Server port number. | |
| asio::ip::udp::endpoint | m_serverEndpoint |
| Resolved server endpoint. | |
| std::atomic< ConnectionState > | m_connectionState |
| Current connection state (atomic) | |
| std::uint32_t | m_sessionId |
| Assigned session ID from server. | |
| std::uint16_t | m_serverTickRate |
| Server tick rate in Hz. | |
| std::uint32_t | m_clientCaps |
| Client capability flags. | |
| std::string | m_playerName |
| Player display name. | |
| std::atomic< bool > | m_running |
| Network thread running state (atomic) | |
| std::unique_ptr< rnp::HandlerPacket > | m_packetHandler |
| RNP packet handler instance. | |
| std::queue< QueuedPacket > | m_sendQueue |
| Queue of packets waiting to be sent. | |
| std::mutex | m_sendQueueMutex |
| Mutex for send queue access. | |
| std::array< std::uint8_t, 1024 > | m_recvBuffer |
| Buffer for receiving UDP packets. | |
| asio::ip::udp::endpoint | m_senderEndpoint |
| Endpoint of last packet sender. | |
| std::uint32_t | m_lastPingNonce |
| Nonce of last PING sent. | |
| std::chrono::steady_clock::time_point | m_lastPingTime |
| Timestamp of last PING. | |
| std::uint32_t | m_latency |
| Round-trip time in milliseconds. | |
| std::chrono::milliseconds | m_pingInterval |
| Interval between pings (5000ms) | |
| std::chrono::steady_clock::time_point | m_lastServerResponse |
| Timestamp of last server packet. | |
| std::chrono::milliseconds | m_connectionTimeout |
| Timeout duration (15000ms) | |
| ConnectionStats | m_stats |
| Connection statistics. | |
| std::uint32_t | m_currentLobbyId |
| Current lobby ID, 0 if not in lobby. | |
| std::function< void(const std::vector< rnp::LobbyInfo > &)> | m_onLobbyListReceived |
| Lobby list callback. | |
| std::function< void(std::uint32_t, bool, rnp::ErrorCode)> | m_onLobbyCreated |
| Lobby created callback. | |
| std::function< void(std::uint32_t, bool, rnp::ErrorCode, const rnp::LobbyInfo *)> | m_onLobbyJoined |
| Lobby joined callback. | |
| std::function< void(const rnp::LobbyInfo &)> | m_onLobbyUpdated |
| Lobby updated callback. | |
| std::function< void(std::uint32_t, std::uint32_t)> | m_onGameStart |
| Game start callback. | |
| utl::EventBus & | m_eventBus |
| Event bus reference. | |
| std::uint32_t | m_componentId = utl::NETWORK_CLIENT |
| Component ID for event bus. | |
High-performance UDP client implementation using ASIO library.
This class provides a complete multiplayer game client implementation with:
The client runs its network operations on a separate thread and communicates with the game engine via an event bus system.
Definition at line 84 of file AsioClient.hpp.
| eng::AsioClient::AsioClient | ( | ) |
Constructor.
Definition at line 21 of file asioClient.cpp.
References eng::ConnectionStats::connectionTime, utl::INFO, utl::LOBBY_CREATE, utl::LOBBY_JOIN, utl::LOBBY_LEAVE, utl::LOBBY_LIST_REQUEST, utl::Logger::log(), m_componentId, m_eventBus, m_stats, utl::EventBus::registerComponent(), utl::REQUEST_CONNECT, utl::REQUEST_DISCONNECT, utl::SEND_ENTITY_EVENT, utl::SEND_PLAYER_INPUT, setupPacketHandlers(), and utl::EventBus::subscribe().
Here is the call graph for this function:
|
override |
Destructor.
Definition at line 46 of file asioClient.cpp.
References disconnect(), utl::INFO, and utl::Logger::log().
Here is the call graph for this function:
|
override |
Connect to game server.
| host | Server hostname or IP address |
| port | Server port number |
Definition at line 52 of file asioClient.cpp.
References eng::CONNECTING, eng::DISCONNECTED, utl::INFO, utl::Logger::log(), m_connectionState, m_ioContext, m_lastServerResponse, m_networkThread, m_running, m_serverEndpoint, m_serverHost, m_serverPort, m_socket, networkThreadLoop(), sendConnect(), startReceive(), and utl::WARNING.
Referenced by processBusEvent(), and sendConnect().
Here is the call graph for this function:
Here is the caller graph for this function:| void eng::AsioClient::createLobby | ( | rnp::PacketLobbyCreate | lobbyCreate | ) |
Create a new lobby on server.
| lobbyCreate | Lobby creation parameters (name, max players, game mode) |
Sends LOBBY_CREATE packet. Response handled via callback.
Definition at line 813 of file asioClient.cpp.
References eng::CONNECTED, rnp::PacketLobbyCreate::gameMode, rnp::Serializer::getData(), rnp::Serializer::getSize(), utl::INFO, rnp::PacketHeader::length, rnp::LOBBY_CREATE, rnp::PacketLobbyCreate::lobbyName, utl::Logger::log(), m_connectionState, m_currentLobbyId, m_sessionId, rnp::PacketLobbyCreate::maxPlayers, rnp::PacketLobbyCreate::nameLen, sendToServer(), rnp::Serializer::serializeHeader(), rnp::Serializer::serializeLobbyCreate(), rnp::PacketHeader::sessionId, rnp::PacketHeader::type, and utl::WARNING.
Referenced by processBusEvent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
Disconnect from server.
Sends DISCONNECT packet and closes connection
Implements eng::INetworkClient.
Definition at line 98 of file asioClient.cpp.
References eng::DISCONNECTED, eng::DISCONNECTING, utl::INFO, utl::Logger::log(), m_connectionState, m_ioContext, m_latency, m_networkThread, m_running, m_sendQueue, m_sendQueueMutex, m_serverTickRate, m_sessionId, m_socket, and sendDisconnect().
Referenced by processBusEvent(), sendDisconnect(), and ~AsioClient().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticprivate |
Generate random ping nonce.
Definition at line 651 of file asioClient.cpp.
Referenced by sendPing().
Here is the caller graph for this function:
|
nodiscardoverridevirtual |
Get current connection state.
Implements eng::INetworkClient.
Definition at line 174 of file asioClient.cpp.
References m_connectionState.
|
inline |
Get current lobby ID.
Definition at line 218 of file AsioClient.hpp.
References m_currentLobbyId.
|
nodiscardoverridevirtual |
Get current latency to server.
Implements eng::INetworkClient.
Definition at line 180 of file asioClient.cpp.
References m_latency.
|
inlinenodiscardoverridevirtual |
Implements utl::IPlugin.
Definition at line 116 of file AsioClient.hpp.
|
nodiscardoverridevirtual |
Get server tick rate.
Implements eng::INetworkClient.
Definition at line 178 of file asioClient.cpp.
References m_serverTickRate.
|
nodiscardoverridevirtual |
Get assigned session ID.
Implements eng::INetworkClient.
Definition at line 176 of file asioClient.cpp.
References m_sessionId.
|
inline |
Get connection statistics.
Definition at line 178 of file AsioClient.hpp.
References m_stats.
|
inlinenodiscardoverridevirtual |
Implements utl::IPlugin.
Definition at line 117 of file AsioClient.hpp.
References utl::NETWORK_CLIENT.
|
private |
Handle CONNECT_ACCEPT packet.
| packet | Connect accept packet |
| context | Packet context |
Definition at line 376 of file asioClient.cpp.
References eng::CONNECTED, utl::CONNECTION_ACCEPTED, rnp::Serializer::getData(), utl::INFO, utl::Logger::log(), m_componentId, m_connectionState, m_eventBus, m_serverTickRate, m_sessionId, utl::EventBus::publish(), utl::RENDERING_ENGINE, rnp::PacketConnectAccept::sessionId, rnp::SUCCESS, and rnp::PacketConnectAccept::tickRateHz.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle DISCONNECT packet.
| packet | Disconnect packet |
| context | Packet context |
Definition at line 393 of file asioClient.cpp.
References rnp::BANNED, rnp::CLIENT_REQUEST, eng::DISCONNECTED, utl::INFO, utl::Logger::log(), m_connectionState, m_sessionId, rnp::PROTOCOL_ERROR, rnp::PacketDisconnect::reasonCode, rnp::SERVER_FULL, rnp::SERVER_SHUTDOWN, rnp::SUCCESS, rnp::TIMEOUT, and rnp::UNSPECIFIED.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle ENTITY_EVENT packet.
| events | Vector of event records |
| context | Packet context |
Definition at line 777 of file asioClient.cpp.
References utl::ENTITY_EVENT_RECEIVED, utl::INFO, utl::Logger::log(), m_componentId, m_eventBus, utl::EventBus::publish(), and rnp::SUCCESS.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticprivate |
Handle ERROR packet.
| packet | Error packet |
| context | Packet context |
Definition at line 454 of file asioClient.cpp.
References rnp::PacketError::description, rnp::PacketError::errorCode, rnp::INTERNAL_ERROR, rnp::INVALID_PAYLOAD, utl::Logger::log(), rnp::RATE_LIMITED, rnp::SUCCESS, rnp::UNAUTHORIZED_SESSION, and utl::WARNING.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle GAME_START packet.
| packet | Game start packet |
| context | Packet context |
Definition at line 1046 of file asioClient.cpp.
References utl::Event::data, utl::GAME_START, utl::INFO, rnp::PacketGameStart::lobbyId, utl::Logger::log(), m_componentId, m_eventBus, m_onGameStart, utl::EventBus::publish(), rnp::PacketContext::sessionId, and rnp::SUCCESS.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle LOBBY_CREATE_RESPONSE packet.
| packet | Lobby create response packet |
| context | Packet context |
Definition at line 983 of file asioClient.cpp.
References rnp::PacketLobbyCreateResponse::errorCode, utl::INFO, utl::LOBBY_CREATE_RESPONSE, rnp::PacketLobbyCreateResponse::lobbyId, utl::Logger::log(), m_componentId, m_currentLobbyId, m_eventBus, m_onLobbyCreated, utl::EventBus::publish(), rnp::SUCCESS, and rnp::PacketLobbyCreateResponse::success.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle LOBBY_JOIN_RESPONSE packet.
| packet | Lobby join response packet |
| context | Packet context |
Definition at line 1005 of file asioClient.cpp.
References rnp::PacketLobbyJoinResponse::errorCode, utl::INFO, utl::LOBBY_JOIN_RESPONSE, rnp::PacketLobbyJoinResponse::lobbyId, rnp::PacketLobbyJoinResponse::lobbyInfo, utl::Logger::log(), m_componentId, m_currentLobbyId, m_eventBus, m_onLobbyJoined, utl::EventBus::publish(), rnp::SUCCESS, and rnp::PacketLobbyJoinResponse::success.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle LOBBY_LIST_RESPONSE packet.
| packet | Lobby list response packet |
| context | Packet context |
Definition at line 968 of file asioClient.cpp.
References utl::INFO, rnp::PacketLobbyListResponse::lobbies, utl::LOBBY_LIST_RESPONSE, rnp::PacketLobbyListResponse::lobbyCount, utl::Logger::log(), m_componentId, m_eventBus, m_onLobbyListReceived, utl::EventBus::publish(), and rnp::SUCCESS.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle LOBBY_UPDATE packet.
| packet | Lobby update packet |
| context | Packet context |
Definition at line 1029 of file asioClient.cpp.
References utl::INFO, utl::LOBBY_UPDATE, rnp::LobbyInfo::lobbyId, rnp::PacketLobbyUpdate::lobbyInfo, utl::Logger::log(), m_componentId, m_eventBus, m_onLobbyUpdated, utl::EventBus::publish(), and rnp::SUCCESS.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle PING packet.
| packet | Ping packet |
| context | Packet context |
Definition at line 447 of file asioClient.cpp.
References rnp::PacketPingPong::nonce, sendPong(), and rnp::SUCCESS.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle PONG packet.
| packet | Pong packet |
| context | Packet context |
Definition at line 432 of file asioClient.cpp.
References utl::INFO, utl::Logger::log(), m_lastPingNonce, m_lastPingTime, m_latency, rnp::PacketPingPong::nonce, and rnp::SUCCESS.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle received packet data.
| bytesReceived | Number of bytes received from server |
Deserializes and dispatches packet to appropriate handler
Definition at line 283 of file asioClient.cpp.
References eng::ConnectionStats::bytesTransferred, rnp::Serializer::deserializeHeader(), utl::Logger::log(), m_lastServerResponse, m_packetHandler, m_recvBuffer, m_senderEndpoint, m_stats, eng::ConnectionStats::packetsReceived, rnp::HandlerPacket::processPacket(), rnp::PacketContext::receiveTime, rnp::PacketContext::senderAddress, rnp::PacketContext::senderPort, rnp::PacketContext::sessionId, rnp::PacketHeader::sessionId, rnp::SUCCESS, and utl::WARNING.
Here is the call graph for this function:
|
private |
Handle WORLD_STATE packet.
| packet | World state packet |
| context | Packet context |
Definition at line 483 of file asioClient.cpp.
References rnp::PacketWorldState::entityCount, utl::INFO, utl::Logger::log(), m_componentId, m_eventBus, utl::EventBus::publish(), rnp::PacketWorldState::serverTick, rnp::SUCCESS, and utl::WORLD_STATE_RECEIVED.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
nodiscardoverridevirtual |
Check if client is connected to server.
Implements eng::INetworkClient.
Definition at line 172 of file asioClient.cpp.
References eng::CONNECTED, and m_connectionState.
|
inline |
Check if player is in a lobby.
Definition at line 224 of file AsioClient.hpp.
References m_currentLobbyId.
| void eng::AsioClient::joinLobby | ( | std::uint32_t | lobbyId | ) |
Join an existing lobby.
| lobbyId | Target lobby identifier |
Sends LOBBY_JOIN packet. Response handled via callback.
Definition at line 852 of file asioClient.cpp.
References eng::CONNECTED, rnp::Serializer::getData(), utl::INFO, rnp::PacketHeader::length, rnp::LOBBY_JOIN, rnp::PacketLobbyJoin::lobbyId, utl::Logger::log(), m_connectionState, m_currentLobbyId, m_sessionId, sendToServer(), rnp::Serializer::serializeHeader(), rnp::Serializer::serializeLobbyJoin(), rnp::PacketHeader::sessionId, rnp::PacketHeader::type, and utl::WARNING.
Referenced by processBusEvent().
Here is the call graph for this function:
Here is the caller graph for this function:| void eng::AsioClient::leaveLobby | ( | ) |
Leave current lobby.
Sends LOBBY_LEAVE packet and resets local lobby state
Definition at line 884 of file asioClient.cpp.
References eng::CONNECTED, rnp::Serializer::getData(), utl::INFO, rnp::PacketHeader::length, rnp::LOBBY_LEAVE, utl::Logger::log(), m_connectionState, m_currentLobbyId, m_sessionId, sendToServer(), rnp::Serializer::serializeHeader(), rnp::PacketHeader::sessionId, rnp::PacketHeader::type, and utl::WARNING.
Referenced by processBusEvent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Main network thread loop.
Runs the ASIO io_context and handles network events
Definition at line 324 of file asioClient.cpp.
References utl::INFO, utl::Logger::log(), m_ioContext, m_running, and utl::WARNING.
Referenced by connect().
Here is the call graph for this function:
Here is the caller graph for this function:| void eng::AsioClient::processBusEvent | ( | ) |
Process events from event bus.
Handles events from game engine
Definition at line 659 of file asioClient.cpp.
References connect(), eng::CONNECTED, utl::EventBus::consumeForTarget(), createLobby(), rnp::Serializer::deserializeLobbyCreate(), disconnect(), eng::DISCONNECTED, rnp::ENTITY_EVENT, rnp::PacketLobbyCreate::gameMode, rnp::Serializer::getData(), utl::INFO, joinLobby(), leaveLobby(), rnp::PacketHeader::length, utl::LOBBY_CREATE, utl::LOBBY_JOIN, utl::LOBBY_LEAVE, utl::LOBBY_LIST_REQUEST, rnp::PacketLobbyCreate::lobbyName, utl::Logger::log(), m_componentId, m_connectionState, m_eventBus, m_sessionId, rnp::PacketLobbyCreate::maxPlayers, rnp::PacketLobbyCreate::nameLen, rnp::Serializer::readString(), rnp::Serializer::readUInt32(), utl::REQUEST_CONNECT, utl::REQUEST_DISCONNECT, requestLobbyList(), requestStartGame(), utl::SEND_ENTITY_EVENT, utl::SEND_PLAYER_INPUT, sendToServer(), rnp::Serializer::serializeHeader(), rnp::PacketHeader::sessionId, setPlayerName(), rnp::PacketHeader::type, utl::WARNING, utl::WORLD_STATE_RECEIVED, and rnp::Serializer::writeBytes().
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Process outgoing packet queue.
Sends all queued packets via UDP socket
Definition at line 597 of file asioClient.cpp.
References eng::QueuedPacket::data, utl::INFO, utl::Logger::log(), m_sendQueue, m_sendQueueMutex, and sendPacketImmediate().
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:| void eng::AsioClient::requestLobbyList | ( | ) |
Request list of available lobbies from server.
Sends LOBBY_LIST_REQUEST packet
Definition at line 790 of file asioClient.cpp.
References eng::CONNECTED, rnp::Serializer::getData(), rnp::Serializer::getSize(), utl::INFO, rnp::PacketHeader::length, rnp::LOBBY_LIST_REQUEST, utl::Logger::log(), m_connectionState, m_sessionId, sendToServer(), rnp::Serializer::serializeHeader(), rnp::PacketHeader::sessionId, rnp::PacketHeader::type, and utl::WARNING.
Referenced by processBusEvent().
Here is the call graph for this function:
Here is the caller graph for this function:| void eng::AsioClient::requestStartGame | ( | std::uint32_t | lobbyId | ) |
Request to start the game (host only)
| lobbyId | Lobby ID to start |
Sends START_GAME_REQUEST packet. Only valid for lobby host.
Definition at line 914 of file asioClient.cpp.
References eng::CONNECTED, rnp::Serializer::getData(), utl::INFO, rnp::PacketHeader::length, rnp::PacketStartGameRequest::lobbyId, utl::Logger::log(), m_connectionState, m_sessionId, sendToServer(), rnp::Serializer::serializeHeader(), rnp::Serializer::serializeStartGameRequest(), rnp::PacketHeader::sessionId, rnp::START_GAME_REQUEST, rnp::PacketHeader::type, and utl::WARNING.
Referenced by processBusEvent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Send CONNECT packet to initiate connection.
Sends player name and client capabilities
Definition at line 497 of file asioClient.cpp.
References rnp::CONNECT, connect(), rnp::Serializer::getData(), utl::INFO, utl::Logger::log(), m_clientCaps, m_playerName, rnp::PacketConnect::nameLen, sendPacketImmediate(), rnp::Serializer::serializeConnect(), rnp::Serializer::serializeHeader(), and rnp::PacketHeader::type.
Referenced by connect(), and updateConnectionManagement().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Send DISCONNECT packet to terminate connection.
Includes disconnect reason code
Definition at line 522 of file asioClient.cpp.
References rnp::CLIENT_REQUEST, rnp::DISCONNECT, disconnect(), rnp::Serializer::getData(), utl::INFO, utl::Logger::log(), m_sessionId, rnp::PacketDisconnect::reasonCode, sendPacketImmediate(), rnp::Serializer::serializeDisconnect(), rnp::Serializer::serializeHeader(), and rnp::PacketHeader::type.
Referenced by disconnect().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Send packet immediately via UDP socket.
| data | Serialized packet data |
Bypasses send queue for immediate transmission
Definition at line 350 of file asioClient.cpp.
References eng::ConnectionStats::bytesTransferred, utl::INFO, utl::Logger::log(), m_serverEndpoint, m_socket, m_stats, eng::ConnectionStats::packetsSent, and utl::WARNING.
Referenced by processSendQueue(), sendConnect(), sendDisconnect(), sendPing(), and sendPong().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Send PING packet for latency measurement.
Generates and stores nonce for RTT calculation
Definition at line 545 of file asioClient.cpp.
References generatePingNonce(), rnp::Serializer::getData(), m_lastPingNonce, m_lastPingTime, m_sessionId, rnp::PacketPingPong::nonce, rnp::PING, sendPacketImmediate(), rnp::Serializer::serializeHeader(), rnp::Serializer::serializePingPong(), and rnp::PacketHeader::type.
Referenced by updateConnectionManagement().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Send PONG response to server PING.
| nonce | Ping nonce to echo back |
Definition at line 572 of file asioClient.cpp.
References rnp::Serializer::getData(), m_sessionId, rnp::PacketPingPong::nonce, rnp::PONG, sendPacketImmediate(), rnp::Serializer::serializeHeader(), rnp::Serializer::serializePingPong(), and rnp::PacketHeader::type.
Referenced by handlePing().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
Send custom packet to server.
| data | Serialized packet data |
| reliable | Whether packet requires reliable delivery (default: false) |
Implements eng::INetworkClient.
Definition at line 194 of file asioClient.cpp.
References eng::CONNECTED, utl::Logger::log(), m_connectionState, m_sendQueue, m_sendQueueMutex, and utl::WARNING.
Referenced by createLobby(), joinLobby(), leaveLobby(), processBusEvent(), requestLobbyList(), and requestStartGame().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
Set client capability flags.
| caps | Capability flags (reserved) |
Implements eng::INetworkClient.
Definition at line 188 of file asioClient.cpp.
References utl::INFO, utl::Logger::log(), and m_clientCaps.
Here is the call graph for this function:| void eng::AsioClient::setOnGameStart | ( | std::function< void(std::uint32_t, std::uint32_t)> | callback | ) |
Set callback for game start notification.
| callback | Function(lobbyId, sessionId) called when GAME_START is received |
Definition at line 963 of file asioClient.cpp.
References m_onGameStart.
| void eng::AsioClient::setOnLobbyCreated | ( | std::function< void(std::uint32_t, bool, rnp::ErrorCode)> | callback | ) |
Set callback for lobby creation response.
| callback | Function(lobbyId, success, errorCode) called when LOBBY_CREATE_RESPONSE is received |
Definition at line 947 of file asioClient.cpp.
References m_onLobbyCreated.
| void eng::AsioClient::setOnLobbyJoined | ( | std::function< void(std::uint32_t, bool, rnp::ErrorCode, const rnp::LobbyInfo *)> | callback | ) |
Set callback for lobby join response.
| callback | Function(lobbyId, success, errorCode, lobbyInfo*) called when LOBBY_JOIN_RESPONSE is received |
Definition at line 952 of file asioClient.cpp.
References m_onLobbyJoined.
| void eng::AsioClient::setOnLobbyListReceived | ( | std::function< void(const std::vector< rnp::LobbyInfo > &)> | callback | ) |
Set callback for lobby list received.
| callback | Function(vector<LobbyInfo>) called when LOBBY_LIST_RESPONSE is received |
Definition at line 942 of file asioClient.cpp.
References m_onLobbyListReceived.
| void eng::AsioClient::setOnLobbyUpdated | ( | std::function< void(const rnp::LobbyInfo &)> | callback | ) |
Set callback for lobby updates.
| callback | Function(LobbyInfo) called when LOBBY_UPDATE is received (player join/leave, status change) |
Definition at line 958 of file asioClient.cpp.
References m_onLobbyUpdated.
|
overridevirtual |
Set player name for connection.
| playerName | Display name |
Implements eng::INetworkClient.
Definition at line 182 of file asioClient.cpp.
References utl::INFO, utl::Logger::log(), and m_playerName.
Referenced by processBusEvent().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Setup packet handlers for all RNP packet types.
Registers callback functions for each packet type with the packet handler
Definition at line 206 of file asioClient.cpp.
References handleConnectAccept(), handleDisconnect(), handleEntityEvent(), handleError(), handleGameStart(), handleLobbyCreateResponse(), handleLobbyJoinResponse(), handleLobbyListResponse(), handleLobbyUpdate(), handlePing(), handlePong(), handleWorldState(), utl::INFO, utl::Logger::log(), m_packetHandler, rnp::HandlerPacket::onConnectAccept(), rnp::HandlerPacket::onDisconnect(), rnp::HandlerPacket::onEntityEvent(), rnp::HandlerPacket::onError(), rnp::HandlerPacket::onGameStart(), rnp::HandlerPacket::onLobbyCreateResponse(), rnp::HandlerPacket::onLobbyJoinResponse(), rnp::HandlerPacket::onLobbyListResponse(), rnp::HandlerPacket::onLobbyUpdate(), rnp::HandlerPacket::onPing(), rnp::HandlerPacket::onPong(), and rnp::HandlerPacket::onWorldState().
Referenced by AsioClient().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Start asynchronous receive operation.
Initiates async_receive_from on the UDP socket
Definition at line 264 of file asioClient.cpp.
References m_recvBuffer, m_running, m_senderEndpoint, and m_socket.
Referenced by connect().
Here is the caller graph for this function:
|
overridevirtual |
Update client state (called each frame)
Processes send queue, checks timeouts, sends pings
Implements eng::INetworkClient.
Definition at line 152 of file asioClient.cpp.
References eng::CONNECTED, m_connectionState, processBusEvent(), processSendQueue(), and updateConnectionManagement().
Here is the call graph for this function:
|
private |
Update connection management state.
Checks for timeouts and sends periodic pings
Definition at line 614 of file asioClient.cpp.
References eng::CONNECTED, eng::CONNECTING, eng::DISCONNECTED, utl::Logger::log(), m_connectionState, m_connectionTimeout, m_lastPingTime, m_lastServerResponse, m_pingInterval, m_sessionId, sendConnect(), sendPing(), and utl::WARNING.
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Client capability flags.
Definition at line 275 of file AsioClient.hpp.
Referenced by sendConnect(), and setClientCapabilities().
|
private |
Component ID for event bus.
Definition at line 317 of file AsioClient.hpp.
Referenced by AsioClient(), handleConnectAccept(), handleEntityEvent(), handleGameStart(), handleLobbyCreateResponse(), handleLobbyJoinResponse(), handleLobbyListResponse(), handleLobbyUpdate(), handleWorldState(), and processBusEvent().
|
private |
Current connection state (atomic)
Definition at line 272 of file AsioClient.hpp.
Referenced by connect(), createLobby(), disconnect(), getConnectionState(), handleConnectAccept(), handleDisconnect(), isConnected(), joinLobby(), leaveLobby(), processBusEvent(), requestLobbyList(), requestStartGame(), sendToServer(), update(), and updateConnectionManagement().
|
private |
Timeout duration (15000ms)
Definition at line 300 of file AsioClient.hpp.
Referenced by updateConnectionManagement().
|
private |
Current lobby ID, 0 if not in lobby.
Definition at line 306 of file AsioClient.hpp.
Referenced by createLobby(), getCurrentLobbyId(), handleLobbyCreateResponse(), handleLobbyJoinResponse(), isInLobby(), joinLobby(), and leaveLobby().
|
private |
Event bus reference.
Definition at line 316 of file AsioClient.hpp.
Referenced by AsioClient(), handleConnectAccept(), handleEntityEvent(), handleGameStart(), handleLobbyCreateResponse(), handleLobbyJoinResponse(), handleLobbyListResponse(), handleLobbyUpdate(), handleWorldState(), and processBusEvent().
|
private |
ASIO I/O context for async operations.
Definition at line 262 of file AsioClient.hpp.
Referenced by connect(), disconnect(), and networkThreadLoop().
|
private |
Nonce of last PING sent.
Definition at line 293 of file AsioClient.hpp.
Referenced by handlePong(), and sendPing().
|
private |
Timestamp of last PING.
Definition at line 294 of file AsioClient.hpp.
Referenced by handlePong(), sendPing(), and updateConnectionManagement().
|
private |
Timestamp of last server packet.
Definition at line 299 of file AsioClient.hpp.
Referenced by connect(), handleReceive(), and updateConnectionManagement().
|
private |
Round-trip time in milliseconds.
Definition at line 295 of file AsioClient.hpp.
Referenced by disconnect(), getLatency(), and handlePong().
|
private |
Dedicated network thread.
Definition at line 264 of file AsioClient.hpp.
Referenced by connect(), and disconnect().
|
private |
Game start callback.
Definition at line 314 of file AsioClient.hpp.
Referenced by handleGameStart(), and setOnGameStart().
|
private |
Lobby created callback.
Definition at line 310 of file AsioClient.hpp.
Referenced by handleLobbyCreateResponse(), and setOnLobbyCreated().
|
private |
Lobby joined callback.
Definition at line 312 of file AsioClient.hpp.
Referenced by handleLobbyJoinResponse(), and setOnLobbyJoined().
|
private |
Lobby list callback.
Definition at line 309 of file AsioClient.hpp.
Referenced by handleLobbyListResponse(), and setOnLobbyListReceived().
|
private |
Lobby updated callback.
Definition at line 313 of file AsioClient.hpp.
Referenced by handleLobbyUpdate(), and setOnLobbyUpdated().
|
private |
RNP packet handler instance.
Definition at line 284 of file AsioClient.hpp.
Referenced by handleReceive(), and setupPacketHandlers().
|
private |
Interval between pings (5000ms)
Definition at line 296 of file AsioClient.hpp.
Referenced by updateConnectionManagement().
|
private |
Player display name.
Definition at line 278 of file AsioClient.hpp.
Referenced by sendConnect(), and setPlayerName().
|
private |
Buffer for receiving UDP packets.
Definition at line 289 of file AsioClient.hpp.
Referenced by handleReceive(), and startReceive().
|
private |
Network thread running state (atomic)
Definition at line 281 of file AsioClient.hpp.
Referenced by connect(), disconnect(), networkThreadLoop(), and startReceive().
|
private |
Endpoint of last packet sender.
Definition at line 290 of file AsioClient.hpp.
Referenced by handleReceive(), and startReceive().
|
private |
Queue of packets waiting to be sent.
Definition at line 285 of file AsioClient.hpp.
Referenced by disconnect(), processSendQueue(), and sendToServer().
|
private |
Mutex for send queue access.
Definition at line 286 of file AsioClient.hpp.
Referenced by disconnect(), processSendQueue(), and sendToServer().
|
private |
Resolved server endpoint.
Definition at line 269 of file AsioClient.hpp.
Referenced by connect(), and sendPacketImmediate().
|
private |
Server hostname or IP address.
Definition at line 267 of file AsioClient.hpp.
Referenced by connect().
|
private |
|
private |
Server tick rate in Hz.
Definition at line 274 of file AsioClient.hpp.
Referenced by disconnect(), getServerTickRate(), and handleConnectAccept().
|
private |
Assigned session ID from server.
Definition at line 273 of file AsioClient.hpp.
Referenced by createLobby(), disconnect(), getSessionId(), handleConnectAccept(), handleDisconnect(), joinLobby(), leaveLobby(), processBusEvent(), requestLobbyList(), requestStartGame(), sendDisconnect(), sendPing(), sendPong(), and updateConnectionManagement().
|
private |
UDP socket for network communication.
Definition at line 263 of file AsioClient.hpp.
Referenced by connect(), disconnect(), sendPacketImmediate(), and startReceive().
|
private |
Connection statistics.
Definition at line 303 of file AsioClient.hpp.
Referenced by AsioClient(), getStats(), handleReceive(), and sendPacketImmediate().