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

Class that represent the identity of a client. More...

#include <C_client.hpp>

Classes

struct  CryptInfo

Public Member Functions

 Client (Latency_ms CTOSLatency, Latency_ms STOCLatency)
 Constructor with default latencies.
void setCTOSLatency_ms (Latency_ms latency)
 Set the "Client To Server" latency.
void setSTOCLatency_ms (Latency_ms latency)
 Set the "Server To Client" latency.
Latency_ms getCTOSLatency_ms () const
 Get the "Client To Server" latency.
Latency_ms getSTOCLatency_ms () const
 Get the "Server To Client" latency.
Latency_ms getPing_ms () const
 Compute the ping.
void setCorrectorTimestamp (Timestamp timestamp)
 Set the corrector timestamp.
std::optional< TimestampgetCorrectorTimestamp () const
 Get the corrector timestamp.
std::optional< Latency_msgetCorrectorLatency () const
 Compute the corrector latency.
void resetLastPacketTimePoint ()
 Reset the time point for limiting the packets sending frequency.
std::chrono::milliseconds getLastPacketElapsedTime () const
 Get the delta time between the last sent packet and the current time.
Latency_ms getLastPacketLatency () const
void clearPackets ()
 Clear the packet queue.
void pushPacket (TransmitPacketPtr pck)
 Add a Packet to the queue.
void pushForcedFrontPacket (TransmitPacketPtr pck)
TransmitPacketPtr popPacket ()
 Pop a packet from the queue.
bool isPendingPacketsEmpty () const
 Check if the packet queue is empty.
void disconnect (bool pushDisconnectPacket=true)
ProtocolPacket::RealmType getCurrentRealm () const
std::chrono::milliseconds getLastRealmChangeElapsedTime () const
void setCurrentRealm (ProtocolPacket::RealmType realm)
ProtocolPacket::RealmType advanceCurrentRealm ()
ProtocolPacket::CounterType getCurrentPacketCounter () const
ProtocolPacket::CounterType advanceCurrentPacketCounter ()
void setCurrentPacketCounter (ProtocolPacket::CounterType counter)
ProtocolPacket::CounterType getClientPacketCounter () const
ProtocolPacket::CounterType advanceClientPacketCounter ()
void setClientPacketCounter (ProtocolPacket::CounterType counter)
void resetLastReorderedPacketCounter ()
ProtocolPacket::CounterType getLastReorderedPacketCounter () const
PacketReorderergetPacketReorderer ()
PacketReorderer const & getPacketReorderer () const
DataLockPair< PacketCache *, std::recursive_mutex > getPacketCache ()
DataLockPair< PacketCache const *, std::recursive_mutex > getPacketCache () const
void acknowledgeReception (ReceivedPacketPtr const &packet)
std::vector< PacketCache::Label > const & getAcknowledgedList () const
void clearAcknowledgedList ()
void clearLostPacketCount ()
uint32_t advanceLostPacketCount ()
void setLostPacketThreshold (uint32_t threshold)
uint32_t getLostPacketThreshold () const
uint32_t getLostPacketCount () const
ClientStatus const & getStatus () const
ClientStatusgetStatus ()
CryptInfo const & getCryptInfo () const
CryptInfogetCryptInfo ()
uint16_t getMTU () const
void setMTU (uint16_t mtu)
void setPacketReturnRate (std::chrono::milliseconds rate)
std::chrono::milliseconds getPacketReturnRate () const

Static Public Member Functions

static Timestamp getTimestamp_ms ()
 Get a modulated timestamp of the current time.
static Timestamp getTimestamp_ms (FullTimestamp fullTimestamp)
static FullTimestamp getFullTimestamp_ms ()
 Get a timestamp of the current time.
static Latency_ms computeLatency_ms (Timestamp const &sentTimestamp, Timestamp const &receivedTimestamp)
 Compute the latency for the client->server / server->client with the given timestamps.

Public Attributes

CallbackHandler< Client & > _onThresholdLostPacket
Event _event
 Optional client-side event that can be synchronized with the server.
PropertyList _data
 Some user-defined client properties.
OneWayLatencyPlanner _latencyPlanner
 A latency planner that will help latency calculation.
bool _mtuFinalizedFlag {false}
 A flag that indicate if the MTU has been finalized from the remote side.

Detailed Description

Class that represent the identity of a client.

Constructor & Destructor Documentation

◆ Client()

fge::net::Client::Client ( Latency_ms CTOSLatency,
Latency_ms STOCLatency )
explicit

Constructor with default latencies.

Parameters
CTOSLatencyThe "Client To Server" latency
STOCLatencyThe "Server To Client" latency

Member Function Documentation

◆ clearPackets()

void fge::net::Client::clearPackets ( )

Clear the packet queue.

◆ computeLatency_ms()

Latency_ms fge::net::Client::computeLatency_ms ( Timestamp const & sentTimestamp,
Timestamp const & receivedTimestamp )
static

Compute the latency for the client->server / server->client with the given timestamps.

Parameters
sentTimestampThe timestamp that have been sent
receivedTimestampThe received timestamp
Returns
Latency in milliseconds

◆ getCorrectorLatency()

std::optional< Latency_ms > fge::net::Client::getCorrectorLatency ( ) const

Compute the corrector latency.

The corrector latency is simply the time between the set timestamp and the timestamp now.

This is useful in order to compute more precise latency between client/server

Returns
The corrector latency

◆ getCorrectorTimestamp()

std::optional< Timestamp > fge::net::Client::getCorrectorTimestamp ( ) const

Get the corrector timestamp.

When the getCorrectorLatency method is called, it will clear the corrector timestamp and std::nullopt will be returned.

See also
getCorrectorLatency
Returns
The corrector timestamp

◆ getCTOSLatency_ms()

Latency_ms fge::net::Client::getCTOSLatency_ms ( ) const

Get the "Client To Server" latency.

Returns
Latency in milliseconds

◆ getFullTimestamp_ms()

FullTimestamp fge::net::Client::getFullTimestamp_ms ( )
static

Get a timestamp of the current time.

Returns
The timestamp

◆ getLastPacketElapsedTime()

std::chrono::milliseconds fge::net::Client::getLastPacketElapsedTime ( ) const
nodiscard

Get the delta time between the last sent packet and the current time.

Returns
The delta time in milliseconds

◆ getPing_ms()

Latency_ms fge::net::Client::getPing_ms ( ) const

Compute the ping.

The ping is simply the CTOS + STOC latencies.

Returns
Pin in milliseconds

◆ getSTOCLatency_ms()

Latency_ms fge::net::Client::getSTOCLatency_ms ( ) const

Get the "Server To Client" latency.

Returns
Latency in milliseconds

◆ getTimestamp_ms()

Timestamp fge::net::Client::getTimestamp_ms ( )
static

Get a modulated timestamp of the current time.

Returns
The modulated timestamp

◆ isPendingPacketsEmpty()

bool fge::net::Client::isPendingPacketsEmpty ( ) const

Check if the packet queue is empty.

Returns
True if the queue is empty, false otherwise

◆ popPacket()

TransmitPacketPtr fge::net::Client::popPacket ( )

Pop a packet from the queue.

Returns
The popped packet or nullptr if the queue is empty

◆ pushPacket()

void fge::net::Client::pushPacket ( TransmitPacketPtr pck)

Add a Packet to the queue.

The packet will be sent when the network thread is ready to send it. The network thread is ready to send a packet when the time interval between the last sent packet is greater than the latency of the server->client.

The current realm will be set and the current countId will be incremented and set to the packet.

  • on the client side, advanceClientPacketCountId() will be called
  • on the server side, advanceCurrentPacketCountId() will be called
Parameters
pckThe packet to send with eventual options

◆ resetLastPacketTimePoint()

void fge::net::Client::resetLastPacketTimePoint ( )

Reset the time point for limiting the packets sending frequency.

This function is generally automatically called by the network thread.

◆ setCorrectorTimestamp()

void fge::net::Client::setCorrectorTimestamp ( Timestamp timestamp)

Set the corrector timestamp.

A corrector timestamp is generally set with the timestamp of a received packet.

See also
getCorrectorLatency
Parameters
timestampThe corrector timestamp

◆ setCTOSLatency_ms()

void fge::net::Client::setCTOSLatency_ms ( Latency_ms latency)

Set the "Client To Server" latency.

Parameters
latencyLatency in milliseconds

◆ setSTOCLatency_ms()

void fge::net::Client::setSTOCLatency_ms ( Latency_ms latency)

Set the "Server To Client" latency.

Parameters
latencyLatency in milliseconds

Member Data Documentation

◆ _data

PropertyList fge::net::Client::_data

Some user-defined client properties.

◆ _event

Event fge::net::Client::_event

Optional client-side event that can be synchronized with the server.

◆ _latencyPlanner

OneWayLatencyPlanner fge::net::Client::_latencyPlanner

A latency planner that will help latency calculation.

◆ _mtuFinalizedFlag

bool fge::net::Client::_mtuFinalizedFlag {false}

A flag that indicate if the MTU has been finalized from the remote side.


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