SuperTuxKart
Loading...
Searching...
No Matches
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.
 
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.
 
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.
 
uint32_t getHostId () const
 Returns the host id of this peer.
 
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
 
const SocketAddressgetAddress () const
 
void setAlwaysSpectate (AlwaysSpectateMode mode)
 
bool alwaysSpectate () const
 
void resetAlwaysSpectateFull ()
 

Protected Attributes

ENetPeer * m_enet_peer
 Pointer to the corresponding ENet peer data structure.
 
ENetAddress m_address
 
std::atomic_bool m_validated
 True if this peer is validated by server.
 
std::atomic_bool m_waiting_for_game
 True if this peer is waiting for game.
 
std::atomic_bool m_spectator
 
std::atomic_bool m_disconnected
 
std::atomic_bool m_warned_for_high_ping
 
std::atomic< uint8_t > m_always_spectate
 
uint32_t m_host_id
 Host id of this peer.
 
std::unique_ptr< SocketAddressm_socket_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::set< std::string > m_client_capabilities
 List of client capabilities set when connecting it, to determine features available in same version.
 
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

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

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