GOG GALAXY SDK Documentation
INetworking Class Referenceabstract

The interface for communicating with other Galaxy Peers. More...

#include <INetworking.h>

Public Member Functions

virtual bool SendP2PPacket (GalaxyID galaxyID, const void *data, uint32_t dataSize, P2PSendType sendType, uint8_t channel=0)=0
 Sends a P2P packet to a specified user. More...
 
virtual bool PeekP2PPacket (void *dest, uint32_t destSize, uint32_t *outMsgSize, GalaxyID &outGalaxyID, uint8_t channel=0)=0
 Reads an incoming packet that was sent from another Galaxy Peer by calling SendP2PPacket() with the same channel number. More...
 
virtual bool IsP2PPacketAvailable (uint32_t *outMsgSize, uint8_t channel=0)=0
 Checks for any incoming packets on a specified channel. More...
 
virtual bool ReadP2PPacket (void *dest, uint32_t destSize, uint32_t *outMsgSize, GalaxyID &outGalaxyID, uint8_t channel=0)=0
 Reads an incoming packet that was sent from another Galaxy Peer by calling SendP2PPacket() with the same channel number. More...
 
virtual void PopP2PPacket (uint8_t channel=0)=0
 Removes the first packet from the packet queue. More...
 
virtual int GetPingWith (GalaxyID galaxyID)=0
 Retrieves current ping value in milliseconds with a specified entity, i.e. More...
 
virtual void RequestNatTypeDetection ()=0
 Initiates a NAT type detection process. More...
 
virtual NatType GetNatType ()=0
 Retrieves determined NAT type. More...
 
virtual ConnectionType GetConnectionType (GalaxyID userID)=0
 Retrieves connection type of the specified user. More...
 

Detailed Description

The interface for communicating with other Galaxy Peers.

Member Function Documentation

◆ GetConnectionType()

virtual ConnectionType GetConnectionType ( GalaxyID  userID)
pure virtual

Retrieves connection type of the specified user.

Remarks
CONNECTION_TYPE_DIRECT is returned for the current user ID.
Parameters
[in]userIDID of the specified user to check connection type.
Returns
The connection type of the specified user.

◆ GetNatType()

virtual NatType GetNatType ( )
pure virtual

Retrieves determined NAT type.

Precondition
Initial value of NAT type is NAT_TYPE_UNKNOWN.
NAT type detection is performed automatically when creating or joining a lobby for the first time.
NAT type can be detected by calling RequestNatTypeDetection() without creating or joining a lobby.
Returns
The determined NAT type.

◆ GetPingWith()

virtual int GetPingWith ( GalaxyID  galaxyID)
pure virtual

Retrieves current ping value in milliseconds with a specified entity, i.e.

another member of the same lobby that the current user is in, or the lobby itself, in which case the returned value is the ping with the lobby owner. For lobbies that the current user is not in, an approximate ping is returned.

Precondition
To get an approximate ping, the lobby has to be first retrieved with either IMatchmaking::RequestLobbyList() or IMatchmaking::RequestLobbyData().
Parameters
[in]galaxyIDID of the specified user or lobby to check ping with.
Returns
Ping with the target entity or -1 if the target entity is not connected or the ping has not been determined yet.

◆ IsP2PPacketAvailable()

virtual bool IsP2PPacketAvailable ( uint32_t *  outMsgSize,
uint8_t  channel = 0 
)
pure virtual

Checks for any incoming packets on a specified channel.

Remarks
Do not call this method if employing INetworkingListener. Instead, during the notification about an incoming packet read packets by calling PeekP2PPacket().
Parameters
[in,out]outMsgSizeThe size of the first incoming message if there is any.
[in]channelThe number of the channel to use.
Returns
true if there are any awaiting incoming packets, false otherwise.

◆ PeekP2PPacket()

virtual bool PeekP2PPacket ( void *  dest,
uint32_t  destSize,
uint32_t *  outMsgSize,
GalaxyID outGalaxyID,
uint8_t  channel = 0 
)
pure virtual

Reads an incoming packet that was sent from another Galaxy Peer by calling SendP2PPacket() with the same channel number.

The packet that was read this way is left in the packet queue.

If the buffer that is supposed to take the data is too small, the message will be truncated to its size. The size of the packet is provided in the notification about an incoming packet in INetworkingListener during which this call is intended to be performed.

This call is non-blocking and operates on the awaiting packets that have already come to the Galaxy Peer, thus instantly finishes, claiming a failure if there are no packets on the specified channel yet.

Remarks
This call works similarly to ReadP2PPacket(), yet does not remove the packet from the packet queue.
Parameters
[in,out]destThe buffer to pass the data to.
[in]destSizeThe size of the buffer.
[in,out]outMsgSizeThe size of the message.
[out]outGalaxyIDThe ID of the user who sent the packet.
[in]channelThe number of the channel to use.
Returns
true if succeeded, false when there are no packets.

◆ PopP2PPacket()

virtual void PopP2PPacket ( uint8_t  channel = 0)
pure virtual

Removes the first packet from the packet queue.

Remarks
Do not call this method if employing INetworkingListener, since the packet that the notification is related to is automatically removed from the packet queue right after all the related notifications are finished.
Parameters
[in]channelThe number of the channel to use.

◆ ReadP2PPacket()

virtual bool ReadP2PPacket ( void *  dest,
uint32_t  destSize,
uint32_t *  outMsgSize,
GalaxyID outGalaxyID,
uint8_t  channel = 0 
)
pure virtual

Reads an incoming packet that was sent from another Galaxy Peer by calling SendP2PPacket() with the same channel number.

The packet that was read this way is removed from the packet queue.

This call is non-blocking and operates on the awaiting packets that have already come to the Galaxy Peer, thus instantly finishes, claiming a failure if there are no packets on the specified channel yet.

Remarks
This call is equivalent to calling PeekP2PPacket(), and then calling PopP2PPacket().
Do not call this method if employing INetworkingListener since the packet that the notification is related to is automatically removed from the packet queue right after all the related notifications are finished. Instead, read the incoming packet by calling PeekP2PPacket() during the notification.
Precondition
If the buffer that is supposed to take the data is too small, the message will be truncated to its size. For that reason prior to reading a packet it is recommended to check for it by calling IsP2PPacketAvailable(), which also returns the packet size.
Parameters
[in,out]destThe buffer to pass the data to.
[in]destSizeThe size of the buffer.
[in,out]outMsgSizeThe size of the message.
[out]outGalaxyIDThe ID of the user who sent the packet.
[in]channelThe number of the channel to use.
Returns
true if succeeded, false when there are no packets.

◆ RequestNatTypeDetection()

virtual void RequestNatTypeDetection ( )
pure virtual

Initiates a NAT type detection process.

This call is asynchronous. Responses come to the INatTypeDetectionListener.

Remarks
NAT type detection is performed automatically when creating or joining a lobby for the first time.

◆ SendP2PPacket()

virtual bool SendP2PPacket ( GalaxyID  galaxyID,
const void *  data,
uint32_t  dataSize,
P2PSendType  sendType,
uint8_t  channel = 0 
)
pure virtual

Sends a P2P packet to a specified user.

It is possible to communicate only with the users within the same lobby. It is recommended to send 1200 bytes at most in a single packet.

The channel is a routing number that allows to implement separate layers of communication while using the same existing connection in order to save some network resources. Since there is only a single connection between each two Galaxy Peers, the Galaxy Peer that is supposed to receive the packet needs to know which channel number to use when checking for incoming packets.

In order to receive the packet on the other Galaxy Peer, call there ReadP2PPacket() with the same channel number.

Packets addressed to a user (by providing a user ID as the GalaxyID) need to be received with the networking interface. Packets addressed to a lobby (by providing a lobby ID as the GalaxyID) come to the lobby owner that also acts as the game server.

Parameters
[in]galaxyIDID of the specified user to whom the packet is to be sent.
[in]dataThe data to send.
[in]dataSizeThe size of the data.
[in]sendTypeThe level of reliability of the operation.
[in]channelThe number of the channel to use.
Returns
true if the packet was scheduled for sending, false otherwise.