SuperTuxKart
Public Member Functions | Protected Attributes | List of all members
STKPeer Class Reference

Represents a peer. This class is used to interface the ENetPeer structure. More...

#include <stk_peer.hpp>

Inheritance diagram for STKPeer:
Inheritance graph
[legend]

Public Member Functions

 STKPeer (ENetPeer *enet_peer, STKHost *host, uint32_t host_id)
 Constructor for an empty peer.
 
void sendPacket (NetworkString *data, bool reliable=true, bool encrypted=true)
 Sends a packet to this host. More...
 
void disconnect ()
 
void kick ()
 Kick this peer (used by server).
 
void reset ()
 Forcefully disconnects a peer (used by server).
 
bool isConnected () const
 Returns if the peer is connected or not.
 
const TransportAddressgetAddress () const
 
const std::string & getIPV6Address () const
 
std::string getRealAddress () const
 
bool isSamePeer (const STKPeer *peer) const
 Returns if this STKPeer is the same as the given peer.
 
bool isSamePeer (const ENetPeer *peer) const
 Returns if this STKPeer is the same as the given peer.
 
std::vector< std::shared_ptr< NetworkPlayerProfile > > & getPlayerProfiles ()
 
bool hasPlayerProfiles () const
 
void cleanPlayerProfiles ()
 
void addPlayer (std::shared_ptr< NetworkPlayerProfile > p)
 
void setValidated (bool val)
 
bool isValidated () const
 Returns if the client is validated by server. More...
 
uint32_t getHostId () const
 Returns the host id of this peer. More...
 
float getConnectedTime () const
 
void setAvailableKartsTracks (std::set< std::string > &k, std::set< std::string > &t)
 
void eraseServerKarts (const std::set< std::string > &server_karts, std::set< std::string > &karts_erase) const
 
void eraseServerTracks (const std::set< std::string > &server_tracks, std::set< std::string > &tracks_erase) const
 
std::pair< std::set< std::string >, std::set< std::string > > getClientAssets () const
 
void setPingInterval (uint32_t interval)
 
uint32_t getPing ()
 Returns the ping to this peer from host, it waits for 3 seconds for a stable ping returned by enet measured in ms.
 
Crypto * getCrypto () const
 
void setCrypto (std::unique_ptr< Crypto > &&c)
 
uint32_t getAveragePing () const
 
ENetPeer * getENetPeer () const
 
void setWaitingForGame (bool val)
 
bool isWaitingForGame () const
 
void setSpectator (bool val)
 
bool isSpectator () const
 
bool isDisconnected () const
 
void setDisconnected (bool val)
 
bool hasWarnedForHighPing () const
 
void setWarnedForHighPing (bool val)
 
void clearAvailableKartIDs ()
 
void addAvailableKartID (unsigned id)
 
bool availableKartID (unsigned id)
 
const std::set< unsigned > & getAvailableKartIDs () const
 
void setUserVersion (const std::string &uv)
 
const std::string & getUserVersion () const
 
void updateLastActivity ()
 
int idleForSeconds () const
 
void setClientCapabilities (std::set< std::string > &caps)
 
const std::set< std::string > & getClientCapabilities () const
 
bool isAIPeer () const
 
void setPacketLoss (int loss)
 
int getPacketLoss () const
 
const std::array< int, AS_TOTAL > & getAddonsScores () const
 
void setAddonsScores (const std::array< int, AS_TOTAL > &scores)
 
void updateLastMessage ()
 
int64_t getLastMessage () const
 
void updateConsecutiveMessages (bool too_fast)
 
int getConsecutiveMessages () const
 

Protected Attributes

ENetPeer * m_enet_peer
 Pointer to the corresponding ENet peer data structure. More...
 
std::atomic_bool m_validated
 True if this peer is validated by server. More...
 
std::atomic_bool m_waiting_for_game
 True if this peer is waiting for game. More...
 
std::atomic_bool m_spectator
 
std::atomic_bool m_disconnected
 
std::atomic_bool m_warned_for_high_ping
 
uint32_t m_host_id
 Host id of this peer. More...
 
TransportAddress m_peer_address
 
STKHostm_host
 
std::vector< std::shared_ptr< NetworkPlayerProfile > > m_players
 
uint64_t m_connected_time
 
std::atomic< int64_t > m_last_activity
 
std::atomic< int64_t > m_last_message
 
int m_consecutive_messages
 
std::pair< std::set< std::string >, std::set< std::string > > m_available_kts
 Available karts and tracks from this peer.
 
std::unique_ptr< Crypto > m_crypto
 
std::deque< uint32_t > m_previous_pings
 
std::atomic< uint32_t > m_average_ping
 
std::atomic< int > m_packet_loss
 
std::set< unsigned > m_available_kart_ids
 
std::string m_user_version
 
std::string m_ipv6_address
 
std::set< std::string > m_client_capabilities
 List of client capabilities set when connecting it, to determine features available in same version. More...
 
std::array< int, AS_TOTAL > m_addons_scores
 

Detailed Description

Represents a peer. This class is used to interface the ENetPeer structure.

Member Function Documentation

◆ getHostId()

uint32_t STKPeer::getHostId ( ) const
inline

Returns the host id of this peer.

◆ isValidated()

bool STKPeer::isValidated ( ) const
inline

Returns if the client is validated by server.

◆ sendPacket()

void STKPeer::sendPacket ( NetworkString data,
bool  reliable = true,
bool  encrypted = true 
)

Sends a packet to this host.

Parameters
dataThe data to send.
reliableIf the data is sent reliable or not.
encryptedIf the data is sent encrypted or not.

Member Data Documentation

◆ m_client_capabilities

std::set<std::string> STKPeer::m_client_capabilities
protected

List of client capabilities set when connecting it, to determine features available in same version.

◆ m_enet_peer

ENetPeer* STKPeer::m_enet_peer
protected

Pointer to the corresponding ENet peer data structure.

◆ m_host_id

uint32_t STKPeer::m_host_id
protected

Host id of this peer.

◆ m_validated

std::atomic_bool STKPeer::m_validated
protected

True if this peer is validated by server.

◆ m_waiting_for_game

std::atomic_bool STKPeer::m_waiting_for_game
protected

True if this peer is waiting for game.


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