r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
eng::AsioClient Class Referencefinal

Network implementation with asio for client. More...

#include <AsioClient.hpp>

+ Inheritance diagram for eng::AsioClient:
+ Collaboration diagram for eng::AsioClient:

Public Types

using PacketHandler = std::function<void(const rnp::PacketHeader &, const std::vector<uint8_t> &)>
 
- Public Types inherited from eng::INetworkClient
using PacketHandler = std::function<void(const rnp::PacketHeader &, const std::vector<uint8_t> &)>
 

Public Member Functions

 AsioClient ()
 
 ~AsioClient () override=default
 
 AsioClient (const AsioClient &)=delete
 
 AsioClient (AsioClient &&)=delete
 
AsioClientoperator= (const AsioClient &)=delete
 
AsioClientoperator= (AsioClient &&)=delete
 
const std::string getName () const override
 
utl::PluginType getType () const override
 
void connect (const std::string &host, uint16_t port) override
 
void disconnect () override
 
void sendConnect (const std::string &playerName)
 
void sendConnectWithCaps (const std::string &playerName, std::uint32_t clientCaps)
 
void sendDisconnect ()
 
void sendDisconnect (rnp::DisconnectReason reason)
 
void sendPlayerInput (uint8_t direction, uint8_t shooting)
 
void sendPlayerInputAsEvent (std::uint16_t playerId, uint8_t direction, uint8_t shooting, uint32_t clientTimeMs)
 
void sendPing ()
 
void sendPing (std::uint32_t nonce, std::uint32_t sendTimeMs)
 
void sendAck (std::uint32_t cumulative, std::uint32_t ackBits)
 
void setPacketHandler (rnp::PacketType type, PacketHandler handler)
 
void setEventsHandler (std::function< void(const std::vector< rnp::EventRecord > &)> handler)
 
std::uint32_t getSessionId () const
 
std::uint16_t getServerTickRate () const
 
- Public Member Functions inherited from eng::INetworkClient
virtual ~INetworkClient ()=default
 
- Public Member Functions inherited from utl::IPlugin
virtual ~IPlugin ()=default
 

Private Member Functions

void startReceive ()
 
void handleReceive (const asio::error_code &error, std::size_t bytesTransferred)
 
void handleSend (const asio::error_code &error, std::size_t bytesTransferred)
 
void processPacket (const std::vector< uint8_t > &data)
 
void processEvents (const std::vector< uint8_t > &payload)
 
void handleConnectAccept (const std::vector< uint8_t > &payload)
 
void handleReliablePacket (const rnp::PacketHeader &header)
 
void processAck (const std::vector< uint8_t > &payload)
 
void processWorldState (const std::vector< uint8_t > &payload)
 
void processEntityEvent (const std::vector< uint8_t > &payload)
 
void retransmitReliable ()
 

Private Attributes

asio::io_context m_ioContext
 
asio::ip::udp::socket m_socket
 
asio::ip::udp::endpoint m_serverEndpoint
 
std::array< uint8_t, rnp::MAX_PAYLOAD+16 > m_recvBuffer
 
std::unique_ptr< asio::executor_work_guard< asio::io_context::executor_type > > m_workGuard
 
std::thread m_ioThread
 
std::unordered_map< rnp::PacketType, PacketHandlerm_packetHandlers
 
std::function< void(const std::vector< rnp::EventRecord > &)> m_eventsHandler
 
uint32_t m_sequenceNumber = 0
 
bool m_connected = false
 
std::uint32_t m_sessionId = 0
 
std::uint16_t m_serverTickRate = 0
 
std::uint16_t m_serverMtu = 0
 
std::uint32_t m_serverCaps = 0
 
std::uint32_t m_clientCaps = 0
 
std::unordered_map< std::uint32_t, std::vector< uint8_t > > m_pendingReliable
 
std::uint32_t m_lastAckSent = 0
 

Detailed Description

Network implementation with asio for client.

Definition at line 30 of file AsioClient.hpp.

Member Typedef Documentation

◆ PacketHandler

using eng::AsioClient::PacketHandler = std::function<void(const rnp::PacketHeader &, const std::vector<uint8_t> &)>

Definition at line 33 of file AsioClient.hpp.

Constructor & Destructor Documentation

◆ AsioClient() [1/3]

eng::AsioClient::AsioClient ( )

Definition at line 10 of file asioClient.cpp.

◆ ~AsioClient()

eng::AsioClient::~AsioClient ( )
overridedefault

◆ AsioClient() [2/3]

eng::AsioClient::AsioClient ( const AsioClient & )
delete

◆ AsioClient() [3/3]

eng::AsioClient::AsioClient ( AsioClient && )
delete

Member Function Documentation

◆ connect()

void eng::AsioClient::connect ( const std::string & host,
uint16_t port )
overridevirtual

Implements eng::INetworkClient.

Definition at line 12 of file asioClient.cpp.

◆ disconnect()

void eng::AsioClient::disconnect ( )
overridevirtual

Implements eng::INetworkClient.

Definition at line 47 of file asioClient.cpp.

◆ getName()

const std::string eng::AsioClient::getName ( ) const
inlinenodiscardoverridevirtual

Implements utl::IPlugin.

Definition at line 43 of file AsioClient.hpp.

◆ getServerTickRate()

std::uint16_t eng::AsioClient::getServerTickRate ( ) const
inlinevirtual

Implements eng::INetworkClient.

Definition at line 65 of file AsioClient.hpp.

References m_serverTickRate.

◆ getSessionId()

std::uint32_t eng::AsioClient::getSessionId ( ) const
inlinevirtual

Implements eng::INetworkClient.

Definition at line 64 of file AsioClient.hpp.

References m_sessionId.

◆ getType()

utl::PluginType eng::AsioClient::getType ( ) const
inlinenodiscardoverridevirtual

Implements utl::IPlugin.

Definition at line 44 of file AsioClient.hpp.

References utl::NETWORK_CLIENT.

◆ handleConnectAccept()

void eng::AsioClient::handleConnectAccept ( const std::vector< uint8_t > & payload)
private

Definition at line 286 of file asioClient.cpp.

◆ handleReceive()

void eng::AsioClient::handleReceive ( const asio::error_code & error,
std::size_t bytesTransferred )
private

Definition at line 428 of file asioClient.cpp.

◆ handleReliablePacket()

void eng::AsioClient::handleReliablePacket ( const rnp::PacketHeader & header)
private

Definition at line 312 of file asioClient.cpp.

◆ handleSend()

void eng::AsioClient::handleSend ( const asio::error_code & error,
std::size_t bytesTransferred )
private

Definition at line 443 of file asioClient.cpp.

◆ operator=() [1/2]

AsioClient & eng::AsioClient::operator= ( AsioClient && )
delete

◆ operator=() [2/2]

AsioClient & eng::AsioClient::operator= ( const AsioClient & )
delete

◆ processAck()

void eng::AsioClient::processAck ( const std::vector< uint8_t > & payload)
private

Definition at line 318 of file asioClient.cpp.

◆ processEntityEvent()

void eng::AsioClient::processEntityEvent ( const std::vector< uint8_t > & payload)
private

Definition at line 368 of file asioClient.cpp.

References rnp::deserializeEvents().

+ Here is the call graph for this function:

◆ processEvents()

void eng::AsioClient::processEvents ( const std::vector< uint8_t > & payload)
private

◆ processPacket()

void eng::AsioClient::processPacket ( const std::vector< uint8_t > & data)
private

◆ processWorldState()

void eng::AsioClient::processWorldState ( const std::vector< uint8_t > & payload)
private

Definition at line 348 of file asioClient.cpp.

◆ retransmitReliable()

void eng::AsioClient::retransmitReliable ( )
private

Definition at line 409 of file asioClient.cpp.

◆ sendAck()

void eng::AsioClient::sendAck ( std::uint32_t cumulative,
std::uint32_t ackBits )
virtual

◆ sendConnect()

void eng::AsioClient::sendConnect ( const std::string & playerName)
virtual

Implements eng::INetworkClient.

Definition at line 76 of file asioClient.cpp.

◆ sendConnectWithCaps()

void eng::AsioClient::sendConnectWithCaps ( const std::string & playerName,
std::uint32_t clientCaps )
virtual

◆ sendDisconnect() [1/2]

void eng::AsioClient::sendDisconnect ( )
virtual

Implements eng::INetworkClient.

Definition at line 110 of file asioClient.cpp.

References rnp::CLIENT_REQUEST.

◆ sendDisconnect() [2/2]

void eng::AsioClient::sendDisconnect ( rnp::DisconnectReason reason)
virtual

◆ sendPing() [1/2]

void eng::AsioClient::sendPing ( )
virtual

◆ sendPing() [2/2]

void eng::AsioClient::sendPing ( std::uint32_t nonce,
std::uint32_t sendTimeMs )
virtual

◆ sendPlayerInput()

void eng::AsioClient::sendPlayerInput ( uint8_t direction,
uint8_t shooting )
virtual

◆ sendPlayerInputAsEvent()

void eng::AsioClient::sendPlayerInputAsEvent ( std::uint16_t playerId,
uint8_t direction,
uint8_t shooting,
uint32_t clientTimeMs )
virtual

◆ setEventsHandler()

void eng::AsioClient::setEventsHandler ( std::function< void(const std::vector< rnp::EventRecord > &)> handler)
virtual

Implements eng::INetworkClient.

Definition at line 281 of file asioClient.cpp.

◆ setPacketHandler()

void eng::AsioClient::setPacketHandler ( rnp::PacketType type,
PacketHandler handler )
virtual

Implements eng::INetworkClient.

Definition at line 276 of file asioClient.cpp.

◆ startReceive()

void eng::AsioClient::startReceive ( )
private

Definition at line 421 of file asioClient.cpp.

Member Data Documentation

◆ m_clientCaps

std::uint32_t eng::AsioClient::m_clientCaps = 0
private

Definition at line 95 of file AsioClient.hpp.

◆ m_connected

bool eng::AsioClient::m_connected = false
private

Definition at line 90 of file AsioClient.hpp.

◆ m_eventsHandler

std::function<void(const std::vector<rnp::EventRecord> &)> eng::AsioClient::m_eventsHandler
private

Definition at line 88 of file AsioClient.hpp.

◆ m_ioContext

asio::io_context eng::AsioClient::m_ioContext
private

Definition at line 80 of file AsioClient.hpp.

◆ m_ioThread

std::thread eng::AsioClient::m_ioThread
private

Definition at line 86 of file AsioClient.hpp.

◆ m_lastAckSent

std::uint32_t eng::AsioClient::m_lastAckSent = 0
private

Definition at line 97 of file AsioClient.hpp.

◆ m_packetHandlers

std::unordered_map<rnp::PacketType, PacketHandler> eng::AsioClient::m_packetHandlers
private

Definition at line 87 of file AsioClient.hpp.

◆ m_pendingReliable

std::unordered_map<std::uint32_t, std::vector<uint8_t> > eng::AsioClient::m_pendingReliable
private

Definition at line 96 of file AsioClient.hpp.

◆ m_recvBuffer

std::array<uint8_t, rnp::MAX_PAYLOAD + 16> eng::AsioClient::m_recvBuffer
private

Definition at line 83 of file AsioClient.hpp.

◆ m_sequenceNumber

uint32_t eng::AsioClient::m_sequenceNumber = 0
private

Definition at line 89 of file AsioClient.hpp.

◆ m_serverCaps

std::uint32_t eng::AsioClient::m_serverCaps = 0
private

Definition at line 94 of file AsioClient.hpp.

◆ m_serverEndpoint

asio::ip::udp::endpoint eng::AsioClient::m_serverEndpoint
private

Definition at line 82 of file AsioClient.hpp.

◆ m_serverMtu

std::uint16_t eng::AsioClient::m_serverMtu = 0
private

Definition at line 93 of file AsioClient.hpp.

◆ m_serverTickRate

std::uint16_t eng::AsioClient::m_serverTickRate = 0
private

Definition at line 92 of file AsioClient.hpp.

Referenced by getServerTickRate().

◆ m_sessionId

std::uint32_t eng::AsioClient::m_sessionId = 0
private

Definition at line 91 of file AsioClient.hpp.

Referenced by getSessionId().

◆ m_socket

asio::ip::udp::socket eng::AsioClient::m_socket
private

Definition at line 81 of file AsioClient.hpp.

◆ m_workGuard

std::unique_ptr<asio::executor_work_guard<asio::io_context::executor_type> > eng::AsioClient::m_workGuard
private

Definition at line 85 of file AsioClient.hpp.


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