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

Server Wrapper for GameNetworkingSockets library. More...

Detailed Description

Server Wrapper for GameNetworkingSockets library.

Definition at line 29 of file PgeGnsServer.h.

#include <PgeGnsServer.h>

+ Inheritance diagram for PgeGnsServer:

Classes

struct  TClient
 

Public Member Functions

virtual ~PgeGnsServer ()
 
virtual bool destroy () override
 Calls stopListening() and PgeGnsWrapper::destroy().
 
bool startListening (const std::string &sAppVersion="")
 Starts GameNetworkingSockets server listening to incoming GameNetworkingSockets client connections.
 
bool stopListening (const std::string &sExtraDebugText="")
 Destroys all connections to clients and stops listening.
 
bool isListening () const
 Gets if we are listening to incoming client connections.
 
void sendToClient (const HSteamNetConnection &conn, const pge_network::PgePacket &pkt)
 
void sendToAllClientsExcept (const pge_network::PgePacket &pkt, const HSteamNetConnection &except=k_HSteamNetConnection_Invalid)
 
void inject (const pge_network::PgePacket &pkt)
 
void WriteServerClientList ()
 
void setClientDebugName (HSteamNetConnection connHandle, const char *nick)
 
const SteamNetConnectionRealTimeStatus_t & getRealTimeStatus (const HSteamNetConnection &connHandle, bool bForceUpdate)
 
std::string getDetailedConnectionStatus (const HSteamNetConnection &connHandle) 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 PgeGnsServercreateAndGet (PGEcfgProfiles &cfgProfiles)
 Creates and gets the singleton implementation instance.
 

Protected Member Functions

virtual bool pgeMessageIsHandledAtGnsLevel (const pge_network::PgePacket &pktReceivedFromClient) override
 
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 Types

typedef std::map< HSteamNetConnection, TClientSteamNetConnHandle2TClientMap
 

Private Member Functions

 PgeGnsServer (PGEcfgProfiles &cfgProfiles)
 
 PgeGnsServer (const PgeGnsServer &)
 
PgeGnsServeroperator= (const PgeGnsServer &)
 
const TClientisClientConnectionHandleValid (const HSteamNetConnection &connHandle) const
 
TClientisClientConnectionHandleValid (const HSteamNetConnection &connHandle)
 

Private Attributes

uint16 m_nPort
 
HSteamListenSocket m_hListenSock
 
HSteamNetPollGroup m_hPollGroup
 
SteamNetConnHandle2TClientMap m_mapClients
 

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
 

Member Typedef Documentation

◆ SteamNetConnHandle2TClientMap

std::map< HSteamNetConnection, TClient > PgeGnsServer::SteamNetConnHandle2TClientMap
private

Definition at line 114 of file PgeGnsServer.h.

Constructor & Destructor Documentation

◆ ~PgeGnsServer()

PgeGnsServer::~PgeGnsServer ( )
virtual

Definition at line 38 of file PgeGnsServer.cpp.

◆ PgeGnsServer() [1/2]

PgeGnsServer::PgeGnsServer ( PGEcfgProfiles & cfgProfiles)
explicitprivate

Definition at line 600 of file PgeGnsServer.cpp.

◆ PgeGnsServer() [2/2]

PgeGnsServer::PgeGnsServer ( const PgeGnsServer & other)
private

Definition at line 608 of file PgeGnsServer.cpp.

Member Function Documentation

◆ createAndGet()

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

Creates and gets the singleton implementation instance.

Creates and gets the singleton instance.

Definition at line 32 of file PgeGnsServer.cpp.

◆ destroy()

bool PgeGnsServer::destroy ( )
overridevirtual

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

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

Reimplemented from PgeGnsWrapper.

Definition at line 43 of file PgeGnsServer.cpp.

◆ getDetailedConnectionStatus()

std::string PgeGnsServer::getDetailedConnectionStatus ( const HSteamNetConnection & connHandle) const

Definition at line 352 of file PgeGnsServer.cpp.

◆ getRealTimeStatus()

const SteamNetConnectionRealTimeStatus_t & PgeGnsServer::getRealTimeStatus ( const HSteamNetConnection & connHandle,
bool bForceUpdate )

Definition at line 334 of file PgeGnsServer.cpp.

◆ inject()

void PgeGnsServer::inject ( const pge_network::PgePacket & pkt)

Definition at line 278 of file PgeGnsServer.cpp.

◆ isClientConnectionHandleValid() [1/2]

PgeGnsServer::TClient * PgeGnsServer::isClientConnectionHandleValid ( const HSteamNetConnection & connHandle)
private

Definition at line 645 of file PgeGnsServer.cpp.

◆ isClientConnectionHandleValid() [2/2]

const PgeGnsServer::TClient * PgeGnsServer::isClientConnectionHandleValid ( const HSteamNetConnection & connHandle) const
private

Definition at line 619 of file PgeGnsServer.cpp.

◆ isListening()

bool PgeGnsServer::isListening ( ) const

Gets if we are listening to incoming client connections.

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

Returns
True if listening, false otherwise.

Definition at line 192 of file PgeGnsServer.cpp.

◆ onSteamNetConnectionStatusChanged()

void PgeGnsServer::onSteamNetConnectionStatusChanged ( SteamNetConnectionStatusChangedCallback_t * pInfo)
overrideprotectedvirtual

Implements PgeGnsWrapper.

Definition at line 446 of file PgeGnsServer.cpp.

◆ operator=()

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

Definition at line 614 of file PgeGnsServer.cpp.

◆ pgeMessageIsHandledAtGnsLevel()

bool PgeGnsServer::pgeMessageIsHandledAtGnsLevel ( const pge_network::PgePacket & pktReceivedFromClient)
overrideprotectedvirtual

Implements PgeGnsWrapper.

Definition at line 368 of file PgeGnsServer.cpp.

◆ receiveMessages()

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

Implements PgeGnsWrapper.

Definition at line 416 of file PgeGnsServer.cpp.

◆ sendToAllClientsExcept()

void PgeGnsServer::sendToAllClientsExcept ( const pge_network::PgePacket & pkt,
const HSteamNetConnection & except = k_HSteamNetConnection_Invalid )

Definition at line 257 of file PgeGnsServer.cpp.

◆ sendToClient()

void PgeGnsServer::sendToClient ( const HSteamNetConnection & conn,
const pge_network::PgePacket & pkt )

Definition at line 197 of file PgeGnsServer.cpp.

◆ setClientDebugName()

void PgeGnsServer::setClientDebugName ( HSteamNetConnection connHandle,
const char * nick )

Definition at line 319 of file PgeGnsServer.cpp.

◆ startListening()

bool PgeGnsServer::startListening ( const std::string & sAppVersion = "")

Starts GameNetworkingSockets server listening to incoming GameNetworkingSockets client connections.

First you need to initialize GameNetworkingSockets subsystem by calling PgeGnsWrapper::init(), and only after that you can try start listening. After a successful call, isListening() is expected to return true.

Parameters
sAppVersionServer application version. We should fill it in if we expect connecting clients to have this same application version.
Returns
True on success, false on failure.

Definition at line 54 of file PgeGnsServer.cpp.

◆ stopListening()

bool PgeGnsServer::stopListening ( const std::string & sExtraDebugText = "")

Destroys all connections to clients and stops listening.

On success, startListening() can be invoked again. After a successful call, isListening() is expected to return false, but PgeGnsWrapper::isInitialized() state stays unchanged.

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

Definition at line 124 of file PgeGnsServer.cpp.

◆ updateIncomingPgePacket()

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

Implements PgeGnsWrapper.

Definition at line 441 of file PgeGnsServer.cpp.

◆ validateSteamNetworkingMessage()

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

Implements PgeGnsWrapper.

Definition at line 423 of file PgeGnsServer.cpp.

◆ WriteServerClientList()

void PgeGnsServer::WriteServerClientList ( )

Definition at line 300 of file PgeGnsServer.cpp.

Member Data Documentation

◆ m_hListenSock

HSteamListenSocket PgeGnsServer::m_hListenSock
private

Definition at line 118 of file PgeGnsServer.h.

◆ m_hPollGroup

HSteamNetPollGroup PgeGnsServer::m_hPollGroup
private

Definition at line 119 of file PgeGnsServer.h.

◆ m_mapClients

SteamNetConnHandle2TClientMap PgeGnsServer::m_mapClients
private

Definition at line 121 of file PgeGnsServer.h.

◆ m_nPort

uint16 PgeGnsServer::m_nPort
private

Definition at line 116 of file PgeGnsServer.h.


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