FastEngine 0.9.4
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
fge::net::ProtocolPacket Class Reference

A special inheritance of Packet with a predefined communication protocol. More...

#include <C_protocol.hpp>

Inheritance diagram for fge::net::ProtocolPacket:
fge::net::Packet

Classes

struct  Header
struct  Option

Public Types

enum class  Options { UPDATE_TIMESTAMP , UPDATE_FULL_TIMESTAMP , UPDATE_CORRECTION_LATENCY }
 Options to pass to the network thread when sending a packet. More...
using IdType = uint16_t
using RealmType = uint16_t
using CounterType = uint16_t

Public Member Functions

 ProtocolPacket (Packet const &pck, Identity const &id, std::size_t fluxIndex=0, std::size_t fluxLifetime=0)
 ProtocolPacket (Packet &&pck, Identity const &id, std::size_t fluxIndex=0, std::size_t fluxLifetime=0)
 ProtocolPacket (IdType header, RealmType realmId=0, CounterType countId=0, CounterType lastCountId=0)
 ProtocolPacket (Packet const &r)
 ProtocolPacket (Packet &&r) noexcept
 ProtocolPacket (ProtocolPacket const &r)
 ProtocolPacket (ProtocolPacket &&r) noexcept
Packetpacket () noexcept
Packet const & packet () const noexcept
bool haveCorrectHeader () const
bool haveCorrectHeaderSize () const
std::optional< IdType > retrieveHeaderId () const
std::optional< IdType > retrieveFlags () const
std::optional< IdType > retrieveFullHeaderId () const
std::optional< RealmType > retrieveRealm () const
std::optional< CounterType > retrieveCounter () const
std::optional< CounterType > retrieveLastCounter () const
std::optional< HeaderretrieveHeader () const
bool isFragmented () const
ProtocolPacketsetHeader (Header const &header)
ProtocolPacketsetHeaderId (IdType id)
ProtocolPacketsetFlags (IdType flags)
ProtocolPacketaddFlags (IdType flags)
ProtocolPacketremoveFlags (IdType flags)
bool checkFlags (IdType flags) const
ProtocolPacketdoNotDiscard ()
ProtocolPacketdoNotReorder ()
ProtocolPacketdoNotFragment ()
ProtocolPacketsetRealm (RealmType realm)
ProtocolPacketsetCounter (CounterType counter)
ProtocolPacketsetLastReorderedPacketCounter (CounterType counter)
void setTimestamp (Timestamp timestamp)
Timestamp getTimeStamp () const
Identity const & getIdentity () const
std::vector< Option > const & options () const
std::vector< Option > & options ()
bool compress (Compressor &compressor)
bool decompress (Compressor &compressor)
void markForEncryption ()
void unmarkForEncryption ()
bool isMarkedForEncryption () const
void markAsLocallyReordered ()
void unmarkAsLocallyReordered ()
bool isMarkedAsLocallyReordered () const
void markAsCached ()
void unmarkAsCached ()
bool isMarkedAsCached () const
void applyOptions (Client const &client)
 Apply packet options to the packet.
void applyOptions ()
 Apply packet options to the packet.
bool checkFluxLifetime (std::size_t fluxSize)
 Check if the flux lifetime is reached.
std::size_t getFluxIndex () const
std::size_t bumpFluxIndex (std::size_t fluxSize)
std::vector< std::unique_ptr< ProtocolPacket > > fragment (uint16_t mtu) const
void clear ()
void flush ()
void reserve (std::size_t reserveSize)
Packetappend (std::size_t size)
Packetappend (void const *data, std::size_t size)
Packetpack (void const *data, std::size_t size)
bool pack (std::size_t pos, void const *data, std::size_t size)
bool write (std::size_t pos, void const *data, std::size_t size)
Packet const & read (void *buff, std::size_t size) const
bool read (std::size_t pos, void *buff, std::size_t size) const
Packet const & unpack (void *buff, std::size_t size) const
bool unpack (std::size_t pos, void *buff, std::size_t size) const
Packetshrink (std::size_t size)
bool erase (std::size_t pos, std::size_t size)
Packet const & skip (std::size_t size) const
void setReadPos (std::size_t pos) const
std::size_t getReadPos () const
bool isExtractable (std::size_t size) const
uint8_t const * getData (std::size_t pos) const
uint8_t * getData (std::size_t pos)
uint8_t const * getData () const
uint8_t * getData ()
std::size_t getDataSize () const
uint32_t getLength () const
void invalidate () const
void setValidity (bool validity) const
bool isValid () const
 operator bool () const
bool endReached () const
std::vector< uint8_t > const & getTransmitCache () const
std::size_t getTransmitPos () const
bool isTransmitCacheValid () const
void invalidateTransmitCache ()
Packetoperator<< (bool data)
Packetoperator<< (int8_t data)
Packetoperator<< (int16_t data)
Packetoperator<< (int32_t data)
Packetoperator<< (int64_t data)
Packetoperator<< (uint8_t data)
Packetoperator<< (uint16_t data)
Packetoperator<< (uint32_t data)
Packetoperator<< (uint64_t data)
Packetoperator<< (float data)
Packetoperator<< (double data)
Packetoperator<< (long double data)
Packetoperator<< (std::string_view const &data)
Packetoperator<< (char const *data)
Packetoperator<< (std::string const &data)
Packetoperator<< (tiny_utf8::string const &data)
Packetoperator<< (wchar_t const *data)
Packetoperator<< (std::wstring const &data)
template<typename T>
Packetoperator<< (std::forward_list< T > const &data)
template<typename T>
Packetoperator<< (std::list< T > const &data)
template<typename T>
Packetoperator<< (std::vector< T > const &data)
template<typename T>
Packetoperator<< (fge::Vector2< T > const &data)
template<typename T>
Packetoperator<< (fge::Vector3< T > const &data)
template<typename T>
Packetoperator<< (fge::Matrix< T > const &data)
Packetoperator<< (fge::Color const &data)
template<class TEnum, typename = std::enable_if_t<std::is_enum_v<TEnum>>>
Packetoperator<< (TEnum const &data)
template<class TData>
Packetoperator<< (std::unique_ptr< TData > const &data)
template<typename T>
fge::net::Packetoperator<< (std::forward_list< T > const &data)
template<typename T>
fge::net::Packetoperator<< (std::list< T > const &data)
template<typename T>
fge::net::Packetoperator<< (std::vector< T > const &data)
template<typename T>
fge::net::Packetoperator<< (fge::Vector2< T > const &data)
template<typename T>
fge::net::Packetoperator<< (fge::Vector3< T > const &data)
template<typename T>
fge::net::Packetoperator<< (fge::Matrix< T > const &data)
template<class TEnum, typename>
fge::net::Packetoperator<< (TEnum const &data)
template<class TData>
fge::net::Packetoperator<< (std::unique_ptr< TData > const &data)
Packet const & operator>> (bool &data) const
Packet const & operator>> (int8_t &data) const
Packet const & operator>> (int16_t &data) const
Packet const & operator>> (int32_t &data) const
Packet const & operator>> (int64_t &data) const
Packet const & operator>> (uint8_t &data) const
Packet const & operator>> (uint16_t &data) const
Packet const & operator>> (uint32_t &data) const
Packet const & operator>> (uint64_t &data) const
Packet const & operator>> (float &data) const
Packet const & operator>> (double &data) const
Packet const & operator>> (long double &data) const
Packet const & operator>> (char *data) const
Packet const & operator>> (std::string &data) const
Packet const & operator>> (tiny_utf8::string &data) const
Packet const & operator>> (wchar_t *data) const
Packet const & operator>> (std::wstring &data) const
template<typename T>
Packet const & operator>> (std::forward_list< T > &data) const
template<typename T>
Packet const & operator>> (std::list< T > &data) const
template<typename T>
Packet const & operator>> (std::vector< T > &data) const
template<typename T>
Packet const & operator>> (fge::Vector2< T > &data) const
template<typename T>
Packet const & operator>> (fge::Vector3< T > &data) const
template<typename T>
Packet const & operator>> (fge::Matrix< T > &data) const
Packet const & operator>> (fge::Color &data) const
template<class TEnum, typename = std::enable_if_t<std::is_enum_v<TEnum>>>
Packet const & operator>> (TEnum &data) const
template<class TData>
Packet const & operator>> (std::unique_ptr< TData > &data) const
template<typename T>
fge::net::Packet const & operator>> (std::forward_list< T > &data) const
template<typename T>
fge::net::Packet const & operator>> (std::list< T > &data) const
template<typename T>
fge::net::Packet const & operator>> (std::vector< T > &data) const
template<typename T>
fge::net::Packet const & operator>> (fge::Vector2< T > &data) const
template<typename T>
fge::net::Packet const & operator>> (fge::Vector3< T > &data) const
template<typename T>
fge::net::Packet const & operator>> (fge::Matrix< T > &data) const
template<class TEnum, typename>
fge::net::Packet const & operator>> (TEnum &data) const
template<class TData>
fge::net::Packet const & operator>> (std::unique_ptr< TData > &data) const
bool operator== (Packet const &right) const =delete
bool operator!= (Packet const &right) const =delete
virtual bool onSend (std::size_t offset)
virtual void onReceive (std::span< uint8_t const > const &data)

Static Public Attributes

static constexpr std::size_t HeaderSize = sizeof(IdType) + sizeof(RealmType) + sizeof(CounterType) * 2
static constexpr std::size_t IdPosition = 0
static constexpr std::size_t RealmPosition = sizeof(IdType)
static constexpr std::size_t CounterPosition = sizeof(IdType) + sizeof(RealmType)
static constexpr std::size_t LastCounterPosition = sizeof(IdType) + sizeof(RealmType) + sizeof(CounterType)

Protected Attributes

std::vector< uint8_t > _g_transmitCache
std::size_t _g_transmitPos
bool _g_transmitCacheValid

Detailed Description

A special inheritance of Packet with a predefined communication protocol.

This class is used to handle the communication between the server and the client by storing a packet with its identity and timestamp. This also add some data used internally by the server in order to handle multiple received packets.

When transmitting a packet, the server will apply some options to the packet when sending it.

Warning
When the packet is pushed via Client::pushPacket or ClientList::sendToAll, the user must not modify the packet/options anymore causing undefined behavior.

Member Enumeration Documentation

◆ Options

Options to pass to the network thread when sending a packet.

Enumerator
UPDATE_TIMESTAMP 

The timestamp of the packet will be updated when sending.

UPDATE_FULL_TIMESTAMP 

The full timestamp of the packet will be updated when sending.

UPDATE_CORRECTION_LATENCY 

The latency of the packet will be updated with the corrector latency from the Client.

Member Function Documentation

◆ applyOptions() [1/2]

void fge::net::ProtocolPacket::applyOptions ( )

Apply packet options to the packet.

Same as applyOptions(Client const& client) but without the client parameter. UPDATE_CORRECTION_LATENCY will throw.

◆ applyOptions() [2/2]

void fge::net::ProtocolPacket::applyOptions ( Client const & client)

Apply packet options to the packet.

See also
Options
Parameters
clientThe client to apply the options

◆ checkFluxLifetime()

bool fge::net::ProtocolPacket::checkFluxLifetime ( std::size_t fluxSize)
inlinenodiscard

Check if the flux lifetime is reached.

Increment the flux lifetime and return false if the lifetime is greater or equal to fluxSize. Otherwise, increment the flux index and return true. The flux index is incremented by 1 and modulo fluxSize.

Parameters
fluxSizeThe number of fluxes
Returns
true if lifetime is not reached, false otherwise

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