16#define ASIO_STANDALONE
43 [[nodiscard]]
const std::string
getName()
const override {
return "Network_Asio_Client"; }
46 void connect(
const std::string &host, uint16_t port)
override;
55 uint32_t clientTimeMs);
57 void sendPing(std::uint32_t nonce, std::uint32_t sendTimeMs);
58 void sendAck(std::uint32_t cumulative, std::uint32_t ackBits);
62 void setEventsHandler(std::function<
void(
const std::vector<rnp::EventRecord> &)> handler);
69 void handleReceive(
const asio::error_code &error, std::size_t bytesTransferred);
70 void handleSend(
const asio::error_code &error, std::size_t bytesTransferred);
75 void processAck(
const std::vector<uint8_t> &payload);
85 std::unique_ptr<asio::executor_work_guard<asio::io_context::executor_type>>
m_workGuard;
This file contains the client network interface.
This file contains the network protocol.
Network implementation with asio for client.
std::uint32_t m_serverCaps
void processPacket(const std::vector< uint8_t > &data)
void handleReliablePacket(const rnp::PacketHeader &header)
void handleReceive(const asio::error_code &error, std::size_t bytesTransferred)
std::uint16_t m_serverTickRate
void connect(const std::string &host, uint16_t port) override
void sendPlayerInput(uint8_t direction, uint8_t shooting)
std::unordered_map< std::uint32_t, std::vector< uint8_t > > m_pendingReliable
std::uint32_t m_clientCaps
void sendConnect(const std::string &playerName)
void processWorldState(const std::vector< uint8_t > &payload)
void sendPlayerInputAsEvent(std::uint16_t playerId, uint8_t direction, uint8_t shooting, uint32_t clientTimeMs)
std::unordered_map< rnp::PacketType, PacketHandler > m_packetHandlers
std::uint32_t m_sessionId
std::array< uint8_t, rnp::MAX_PAYLOAD+16 > m_recvBuffer
void disconnect() override
void processEvents(const std::vector< uint8_t > &payload)
void handleSend(const asio::error_code &error, std::size_t bytesTransferred)
AsioClient(AsioClient &&)=delete
void processAck(const std::vector< uint8_t > &payload)
std::unique_ptr< asio::executor_work_guard< asio::io_context::executor_type > > m_workGuard
std::function< void(const rnp::PacketHeader &, const std::vector< uint8_t > &)> PacketHandler
std::uint32_t m_lastAckSent
void processEntityEvent(const std::vector< uint8_t > &payload)
std::function< void(const std::vector< rnp::EventRecord > &)> m_eventsHandler
std::uint32_t getSessionId() const
uint32_t m_sequenceNumber
AsioClient & operator=(AsioClient &&)=delete
void setEventsHandler(std::function< void(const std::vector< rnp::EventRecord > &)> handler)
void setPacketHandler(rnp::PacketType type, PacketHandler handler)
AsioClient & operator=(const AsioClient &)=delete
void retransmitReliable()
const std::string getName() const override
AsioClient(const AsioClient &)=delete
void sendAck(std::uint32_t cumulative, std::uint32_t ackBits)
asio::ip::udp::endpoint m_serverEndpoint
utl::PluginType getType() const override
std::uint16_t getServerTickRate() const
~AsioClient() override=default
std::uint16_t m_serverMtu
void sendConnectWithCaps(const std::string &playerName, std::uint32_t clientCaps)
asio::ip::udp::socket m_socket
void handleConnectAccept(const std::vector< uint8_t > &payload)
asio::io_context m_ioContext
Interface for the client network.
DisconnectReason
Disconnect reason codes.
PacketType
Packet types according to RNP specification.