FastEngine 0.9.3
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>

Public Member Functions

 Client (Latency_ms CTOSLatency, Latency_ms STOCLatency)
 Constructor with default latencies.
 
void setSkey (Skey key)
 Set the session key for this client.
 
Skey getSkey () const
 Get the session key for this client.
 
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.
 
Latency_ms getLastPacketElapsedTime () const
 Get the delta time between the last sent packet and the current time.
 
void clearPackets ()
 Clear the packet queue.
 
void pushPacket (TransmissionPacketPtr pck)
 Add a TransmissionPacket to the queue.
 
TransmissionPacketPtr popPacket ()
 Pop a packet from the queue.
 
bool isPendingPacketsEmpty () const
 Check if the packet queue is empty.
 
ProtocolPacket::Realm getCurrentRealm () const
 
std::chrono::milliseconds getLastRealmChangeElapsedTime () const
 
void setCurrentRealm (ProtocolPacket::Realm realm)
 
ProtocolPacket::Realm advanceCurrentRealm ()
 
ProtocolPacket::CountId getCurrentPacketCountId () const
 
ProtocolPacket::CountId advanceCurrentPacketCountId ()
 
void setCurrentPacketCountId (ProtocolPacket::CountId countId)
 
ProtocolPacket::CountId getClientPacketCountId () const
 
ProtocolPacket::CountId advanceClientPacketCountId ()
 
void setClientPacketCountId (ProtocolPacket::CountId countId)
 
PacketReorderergetPacketReorderer ()
 
PacketReorderer const & getPacketReorderer () const
 
void clearLostPacketCount ()
 
uint32_t advanceLostPacketCount ()
 
void setLostPacketThreshold (uint32_t threshold)
 
uint32_t getLostPacketThreshold () const
 
uint32_t getLostPacketCount () const
 

Static Public Member Functions

static Skey GenerateSkey ()
 Generate a new random session key.
 
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.
 

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()

static 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

◆ GenerateSkey()

static Skey fge::net::Client::GenerateSkey ( )
static

Generate a new random session key.

Returns
The generated session key

◆ 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()

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

Get a timestamp of the current time.

Returns
The timestamp

◆ getLastPacketElapsedTime()

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

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

◆ getSkey()

Skey fge::net::Client::getSkey ( ) const

Get the session key for this client.

Returns
The session key

◆ getSTOCLatency_ms()

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

Get the "Server To Client" latency.

Returns
Latency in milliseconds

◆ getTimestamp_ms()

static 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()

TransmissionPacketPtr 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 ( TransmissionPacketPtr pck)

Add a TransmissionPacket 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

◆ setSkey()

void fge::net::Client::setSkey ( Skey key)

Set the session key for this client.

Parameters
keyThe session key

◆ 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.


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