PGE API 0.4
PR00F's Game Engine full documentation
Loading...
Searching...
No Matches
PgeGnsClient Class Referencefinal

Client Wrapper for GameNetworkingSockets library. More...

Detailed Description

Client Wrapper for GameNetworkingSockets library.

Definition at line 29 of file PgeGnsClient.h.

#include <PgeGnsClient.h>

+ Inheritance diagram for PgeGnsClient:

Public Member Functions

virtual ~PgeGnsClient ()
 
virtual bool destroy () override
 Calls disconnectClient() and PgeGnsWrapper::destroy().
 
bool connectToServer (const std::string &sServerAddress, const std::string &sAppVersion="")
 Sets up GameNetworkingSockets client connection to a GameNetworkingSockets server instance.
 
bool disconnectClient (const std::string &sExtraDebugText="")
 Disconnects the client from the server.
 
bool isConnected () const
 Gets if we are logically connected to a server.
 
const HSteamNetConnection & getConnectionHandle () const
 
const HSteamNetConnection & getConnectionHandleServerSide () const
 
const char * getServerAddress () const
 
void sendToServer (const pge_network::PgePacket &pkt)
 
const SteamNetConnectionRealTimeStatus_t & getRealTimeStatus (bool bForceUpdate)
 
std::string getDetailedConnectionStatus () const
 
- Public Member Functions inherited from PgeGnsWrapper
virtual ~PgeGnsWrapper ()
 
bool init ()
 Initializes the GameNetworkingSockets library.
 
bool isInitialized () const
 Gets the state of initialization of the GameNetworkingSockets library.
 
bool pollIncomingMessages ()
 Moves incoming SteamNetworkingMessages from GameNetworkingSockets layer to m_queuePackets as PgePackets.
 
void pollConnectionStateChanges ()
 
std::size_t getPacketQueueSize () const
 
pge_network::PgePacket popFrontPacket () noexcept(false)
 
std::set< pge_network::PgePktId > & getAllowListedPgeMessages ()
 
std::set< pge_network::MsgApp::TMsgId > & getAllowListedAppMessages ()
 
uint32_t getRxPacketCount () const
 
uint32_t getTxPacketCount () const
 
uint32_t getInjectPacketCount () const
 
uint32_t getRxPacketPerSecondCount () const
 
uint32_t getTxPacketPerSecondCount () const
 
uint32_t getInjectPacketPerSecondCount () const
 
const std::map< pge_network::MsgApp::TMsgId, uint32_t > & getRxMsgCount () const
 
const std::map< pge_network::MsgApp::TMsgId, uint32_t > & getTxMsgCount () const
 
const std::map< pge_network::MsgApp::TMsgId, uint32_t > & getInjectMsgCount () const
 
std::map< pge_network::MsgApp::TMsgId, std::string > & getMsgAppId2StringMap ()
 
uint32_t getRxByteCount () const
 
uint32_t getTxByteCount () const
 
uint32_t getInjectByteCount () const
 

Static Public Member Functions

static PgeGnsClientcreateAndGet (PGEcfgProfiles &cfgProfiles)
 Creates and gets the singleton implementation instance.
 

Protected Member Functions

virtual bool pgeMessageIsHandledAtGnsLevel (const pge_network::PgePacket &pktReceivedFromServer)
 
virtual int receiveMessages (ISteamNetworkingMessage **pIncomingMsg, int nIncomingMsgArraySize) const override
 
virtual bool validateSteamNetworkingMessage (const HSteamNetConnection &connHandle) const override
 
virtual void updateIncomingPgePacket (pge_network::PgePacket &pkt, const HSteamNetConnection &connHandle) const override
 
virtual void onSteamNetConnectionStatusChanged (SteamNetConnectionStatusChangedCallback_t *pInfo) override
 
- Protected Member Functions inherited from PgeGnsWrapper
 PgeGnsWrapper (PGEcfgProfiles &cfgProfiles)
 
 PgeGnsWrapper (const PgeGnsWrapper &)
 
PgeGnsWrapperoperator= (const PgeGnsWrapper &)
 
std::string getStringByMsgAppId (const pge_network::MsgApp::TMsgId &id) const
 
std::string getDetailedConnectionStatus (const HSteamNetConnection &connHandle) const
 
void logDetailedConnectionStatus (const HSteamNetConnection &connHandle) const
 

Private Member Functions

 PgeGnsClient (PGEcfgProfiles &cfgProfiles)
 
 PgeGnsClient (const PgeGnsClient &)
 
PgeGnsClientoperator= (const PgeGnsClient &)
 

Private Attributes

SteamNetworkingIPAddr m_addrServer
 
char m_szAddr [SteamNetworkingIPAddr::k_cchMaxString]
 
HSteamNetConnection m_hConnection
 
HSteamNetConnection m_hConnectionServerSide
 
SteamNetConnectionRealTimeStatus_t m_connRtStatus
 

Additional Inherited Members

- Static Public Attributes inherited from PgeGnsWrapper
static const uint16 DEFAULT_SERVER_PORT = 27020
 
- Static Protected Member Functions inherited from PgeGnsWrapper
static void steamNetConnectionStatusChangedCallback (SteamNetConnectionStatusChangedCallback_t *pInfo)
 
- Protected Attributes inherited from PgeGnsWrapper
PGEcfgProfilesm_cfgProfiles
 
ISteamNetworkingSockets * m_pInterface
 
std::deque< pge_network::PgePacketm_queuePackets
 
std::set< pge_network::PgePktIdm_allowListedPgeMessages
 
std::set< pge_network::MsgApp::TMsgIdm_allowListedAppMessages
 
uint32_t m_nRxPktCount
 
uint32_t m_nTxPktCount
 
uint32_t m_nInjectPktCount
 
std::chrono::time_point< std::chrono::steady_clock > m_time1stRxPkt
 
std::chrono::time_point< std::chrono::steady_clock > m_time1stTxPkt
 
std::chrono::time_point< std::chrono::steady_clock > m_time1stInjectPkt
 
std::map< pge_network::MsgApp::TMsgId, uint32_t > m_nRxMsgCount
 
std::map< pge_network::MsgApp::TMsgId, uint32_t > m_nTxMsgCount
 
std::map< pge_network::MsgApp::TMsgId, uint32_t > m_nInjectMsgCount
 
std::map< pge_network::MsgApp::TMsgId, std::string > m_mapMsgAppId2String
 
uint32_t m_nRxByteCount
 
uint32_t m_nTxByteCount
 
uint32_t m_nInjectByteCount
 
std::string m_sAppVersion
 Expected client app version in case of server instance, or simply client app version in case of client instance.
 
- Static Protected Attributes inherited from PgeGnsWrapper
static PgeGnsWrappers_pCallbackInstance = nullptr
 

Constructor & Destructor Documentation

◆ ~PgeGnsClient()

PgeGnsClient::~PgeGnsClient ( )
virtual

Definition at line 38 of file PgeGnsClient.cpp.

◆ PgeGnsClient() [1/2]

PgeGnsClient::PgeGnsClient ( PGEcfgProfiles & cfgProfiles)
explicitprivate

Definition at line 273 of file PgeGnsClient.cpp.

◆ PgeGnsClient() [2/2]

PgeGnsClient::PgeGnsClient ( const PgeGnsClient & other)
private

Definition at line 282 of file PgeGnsClient.cpp.

Member Function Documentation

◆ connectToServer()

bool PgeGnsClient::connectToServer ( const std::string & sServerAddress,
const std::string & sAppVersion = "" )

Sets up GameNetworkingSockets client connection to a GameNetworkingSockets server instance.

First you need to initialize GameNetworkingSockets subsystem by calling PgeGnsWrapper::init(), and only after that you can try establishing connection to a server instance. After a successful call, isConnected() is expected to return true.

Parameters
sServerAddressIPv4 or IPv6 address of GameNetworkingSockets server we want to connect to.
sAppVersionClient application version. If server expects a specific client version, we should fill it here.
Returns
True on success, false on failure.

Definition at line 58 of file PgeGnsClient.cpp.

◆ createAndGet()

PgeGnsClient & PgeGnsClient::createAndGet ( PGEcfgProfiles & cfgProfiles)
static

Creates and gets the singleton implementation instance.

Creates and gets the singleton instance.

Definition at line 32 of file PgeGnsClient.cpp.

◆ destroy()

bool PgeGnsClient::destroy ( )
overridevirtual

Calls disconnectClient() and PgeGnsWrapper::destroy().

Normally this should be called only once: exiting the application. You don't need to call this just for disconnecting the client, for that use disconnectClient().

After a call to destroy(), and before you can connect to a server again, you need to reinitialize the GameNetworkingSockets subsystem by calling PgeGnsWrapper::init().

Returns
True if uninitialization is successful or not initialized, false otherwise.

Reimplemented from PgeGnsWrapper.

Definition at line 43 of file PgeGnsClient.cpp.

◆ disconnectClient()

bool PgeGnsClient::disconnectClient ( const std::string & sExtraDebugText = "")

Disconnects the client from the server.

If client was connected at time of calling this function, a MsgUserDisconnectedFromServer will be injected into the message queue with the server's connection handle, so at application level the handleUserDisconnected() is expected to be invoked with connHandleServerSide = pge_network::ServerConnHandle, for which the client is expected to remove all other players as well since they are/were also connecting to the same server.

After a successful call, isConnected() is expected to return false, but PgeGnsWrapper::isInitialized() state stays unchanged, so connectToServer() can be invoked again.

Parameters
sExtraDebugTextAn optional text that will be sent to the other side and will be logged to help debugging.
Returns
Always true, even if client was not connected before calling this function.

Definition at line 125 of file PgeGnsClient.cpp.

◆ getConnectionHandle()

const HSteamNetConnection & PgeGnsClient::getConnectionHandle ( ) const

Definition at line 169 of file PgeGnsClient.cpp.

◆ getConnectionHandleServerSide()

const HSteamNetConnection & PgeGnsClient::getConnectionHandleServerSide ( ) const

Definition at line 174 of file PgeGnsClient.cpp.

◆ getDetailedConnectionStatus()

std::string PgeGnsClient::getDetailedConnectionStatus ( ) const

Definition at line 255 of file PgeGnsClient.cpp.

◆ getRealTimeStatus()

const SteamNetConnectionRealTimeStatus_t & PgeGnsClient::getRealTimeStatus ( bool bForceUpdate)

Definition at line 238 of file PgeGnsClient.cpp.

◆ getServerAddress()

const char * PgeGnsClient::getServerAddress ( ) const

Definition at line 179 of file PgeGnsClient.cpp.

◆ isConnected()

bool PgeGnsClient::isConnected ( ) const

Gets if we are logically connected to a server.

Basically it always returns true after a successful call to connectToServer(), and returns false after a call to disconnectClient().

Returns
True if connected, false otherwise.

Definition at line 164 of file PgeGnsClient.cpp.

◆ onSteamNetConnectionStatusChanged()

void PgeGnsClient::onSteamNetConnectionStatusChanged ( SteamNetConnectionStatusChangedCallback_t * pInfo)
overrideprotectedvirtual

Implements PgeGnsWrapper.

Definition at line 316 of file PgeGnsClient.cpp.

◆ operator=()

PgeGnsClient & PgeGnsClient::operator= ( const PgeGnsClient & )
private

Definition at line 288 of file PgeGnsClient.cpp.

◆ pgeMessageIsHandledAtGnsLevel()

bool PgeGnsClient::pgeMessageIsHandledAtGnsLevel ( const pge_network::PgePacket & pktReceivedFromServer)
protectedvirtual

Implements PgeGnsWrapper.

Definition at line 293 of file PgeGnsClient.cpp.

◆ receiveMessages()

int PgeGnsClient::receiveMessages ( ISteamNetworkingMessage ** pIncomingMsg,
int nIncomingMsgArraySize ) const
overrideprotectedvirtual

Implements PgeGnsWrapper.

Definition at line 299 of file PgeGnsClient.cpp.

◆ sendToServer()

void PgeGnsClient::sendToServer ( const pge_network::PgePacket & pkt)

Definition at line 184 of file PgeGnsClient.cpp.

◆ updateIncomingPgePacket()

void PgeGnsClient::updateIncomingPgePacket ( pge_network::PgePacket & pkt,
const HSteamNetConnection & connHandle ) const
overrideprotectedvirtual

Implements PgeGnsWrapper.

Definition at line 311 of file PgeGnsClient.cpp.

◆ validateSteamNetworkingMessage()

bool PgeGnsClient::validateSteamNetworkingMessage ( const HSteamNetConnection & connHandle) const
overrideprotectedvirtual

Implements PgeGnsWrapper.

Definition at line 306 of file PgeGnsClient.cpp.

Member Data Documentation

◆ m_addrServer

SteamNetworkingIPAddr PgeGnsClient::m_addrServer
private

Definition at line 118 of file PgeGnsClient.h.

◆ m_connRtStatus

SteamNetConnectionRealTimeStatus_t PgeGnsClient::m_connRtStatus
private

Definition at line 131 of file PgeGnsClient.h.

◆ m_hConnection

HSteamNetConnection PgeGnsClient::m_hConnection
private

Definition at line 120 of file PgeGnsClient.h.

◆ m_hConnectionServerSide

HSteamNetConnection PgeGnsClient::m_hConnectionServerSide
private

Definition at line 129 of file PgeGnsClient.h.

◆ m_szAddr

char PgeGnsClient::m_szAddr[SteamNetworkingIPAddr::k_cchMaxString]
private

Definition at line 119 of file PgeGnsClient.h.


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