RakNet  4.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
RakNet::RakPeer Class Reference

Main interface for network communications. More...

#include <RakPeer.h>

Inheritance diagram for RakNet::RakPeer:
RakNet::RakPeerInterface

Public Member Functions

 RakPeer ()
 Constructor.
 
virtual ~RakPeer ()
 Destructor.
 
StartupResult Startup (unsigned int maxConnections, SocketDescriptor *socketDescriptors, unsigned socketDescriptorCount, int threadPriority=-99999)
 Starts the network threads and opens the listen port.
 
bool InitializeSecurity (const char *publicKey, const char *privateKey, bool bRequireClientKey=false)
 
void DisableSecurity (void)
 
void AddToSecurityExceptionList (const char *ip)
 This is useful if you have a fixed-address internal server behind a LAN.
 
void RemoveFromSecurityExceptionList (const char *ip)
 Remove a specific connection previously added via AddToSecurityExceptionList.
 
bool IsInSecurityExceptionList (const char *ip)
 Checks to see if a given IP is in the security exception list.
 
void SetMaximumIncomingConnections (unsigned short numberAllowed)
 Sets the maximum number of incoming connections allowed.
 
unsigned int GetMaximumIncomingConnections (void) const
 Returns the value passed to SetMaximumIncomingConnections().
 
unsigned short NumberOfConnections (void) const
 Returns how many open connections exist at this time.
 
void SetIncomingPassword (const char *passwordData, int passwordDataLength)
 Sets the password for the incoming connections.
 
void GetIncomingPassword (char *passwordData, int *passwordDataLength)
 Gets the password passed to SetIncomingPassword.
 
ConnectionAttemptResult Connect (const char *host, unsigned short remotePort, const char *passwordData, int passwordDataLength, PublicKey *publicKey=0, unsigned connectionSocketIndex=0, unsigned sendConnectionAttemptCount=6, unsigned timeBetweenSendConnectionAttemptsMS=1000, RakNet::TimeMS timeoutTime=0)
 Connect to the specified host (ip or domain name) and server port.
 
virtual ConnectionAttemptResult ConnectWithSocket (const char *host, unsigned short remotePort, const char *passwordData, int passwordDataLength, RakNetSocket2 *socket, PublicKey *publicKey=0, unsigned sendConnectionAttemptCount=6, unsigned timeBetweenSendConnectionAttemptsMS=1000, RakNet::TimeMS timeoutTime=0)
 Connect to the specified host (ip or domain name) and server port.
 
void Shutdown (unsigned int blockDuration, unsigned char orderingChannel=0, PacketPriority disconnectionNotificationPriority=LOW_PRIORITY)
 Stops the network threads and closes all connections.
 
bool IsActive (void) const
 Returns true if the network thread is running.
 
bool GetConnectionList (SystemAddress *remoteSystems, unsigned short *numberOfSystems) const
 Fills the array remoteSystems with the SystemAddress of all the systems we are connected to.
 
virtual uint32_t GetNextSendReceipt (void)
 
virtual uint32_t IncrementNextSendReceipt (void)
 
uint32_t Send (const char *data, const int length, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast, uint32_t forceReceiptNumber=0)
 Sends a block of data to the specified system that you are connected to.
 
void SendLoopback (const char *data, const int length)
 "Send" to yourself rather than a remote system.
 
uint32_t Send (const RakNet::BitStream *bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast, uint32_t forceReceiptNumber=0)
 Sends a block of data to the specified system that you are connected to.
 
uint32_t SendList (const char **data, const int *lengths, const int numParameters, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast, uint32_t forceReceiptNumber=0)
 Sends multiple blocks of data, concatenating them automatically.
 
PacketReceive (void)
 Gets a message from the incoming message queue.
 
void DeallocatePacket (Packet *packet)
 Call this to deallocate a message returned by Receive() when you are done handling it.
 
unsigned int GetMaximumNumberOfPeers (void) const
 Return the total number of connections we are allowed.
 
void CloseConnection (const AddressOrGUID target, bool sendDisconnectionNotification, unsigned char orderingChannel=0, PacketPriority disconnectionNotificationPriority=LOW_PRIORITY)
 Close the connection to another host (if we initiated the connection it will disconnect, if they did it will kick them out).
 
void CancelConnectionAttempt (const SystemAddress target)
 Cancel a pending connection attempt.
 
ConnectionState GetConnectionState (const AddressOrGUID systemIdentifier)
 
int GetIndexFromSystemAddress (const SystemAddress systemAddress) const
 Given systemAddress, returns its index into remoteSystemList.
 
SystemAddress GetSystemAddressFromIndex (unsigned int index)
 Given index into remoteSystemList, will return a SystemAddress. This function is only useful for looping through all systems.
 
RakNetGUID GetGUIDFromIndex (unsigned int index)
 Same as GetSystemAddressFromIndex but returns RakNetGUID.
 
void GetSystemList (DataStructures::List< SystemAddress > &addresses, DataStructures::List< RakNetGUID > &guids) const
 Same as calling GetSystemAddressFromIndex and GetGUIDFromIndex for all systems, but more efficient Indices match each other, so addresses[0] and guids[0] refer to the same system.
 
void AddToBanList (const char *IP, RakNet::TimeMS milliseconds=0)
 Bans an IP from connecting.
 
void RemoveFromBanList (const char *IP)
 Allows a previously banned IP to connect. param[in] Dotted IP address. You can use * as a wildcard. An IP such as 128.0.0.* will ban all IP addresses starting with 128.0.0.
 
void ClearBanList (void)
 Allows all previously banned IPs to connect.
 
bool IsBanned (const char *IP)
 Returns true or false indicating if a particular IP is banned.
 
void SetLimitIPConnectionFrequency (bool b)
 Enable or disable allowing frequent connections from the same IP adderss.
 
void Ping (const SystemAddress target)
 
bool Ping (const char *host, unsigned short remotePort, bool onlyReplyOnAcceptingConnections, unsigned connectionSocketIndex=0)
 Send a ping to the specified unconnected system.
 
int GetAveragePing (const AddressOrGUID systemIdentifier)
 Returns the average of all ping times read for the specific system or -1 if none read yet.
 
int GetLastPing (const AddressOrGUID systemIdentifier) const
 Returns the last ping time read for the specific system or -1 if none read yet.
 
int GetLowestPing (const AddressOrGUID systemIdentifier) const
 Returns the lowest ping time read or -1 if none read yet.
 
void SetOccasionalPing (bool doPing)
 
void SetOfflinePingResponse (const char *data, const unsigned int length)
 Sets the data to send along with a LAN server discovery or offline ping reply.
 
void GetOfflinePingResponse (char **data, unsigned int *length)
 Returns pointers to a copy of the data passed to SetOfflinePingResponse.
 
SystemAddress GetInternalID (const SystemAddress systemAddress=UNASSIGNED_SYSTEM_ADDRESS, const int index=0) const
 Returns the unique address identifier that represents you or another system on the the network.
 
void SetInternalID (SystemAddress systemAddress, int index=0)
 Sets your internal IP address, for platforms that do not support reading it, or to override a value.
 
SystemAddress GetExternalID (const SystemAddress target) const
 Returns the unique address identifier that represents the target on the the network and is based on the target's external IP / port.
 
const RakNetGUID GetMyGUID (void) const
 Return my own GUID.
 
SystemAddress GetMyBoundAddress (const int socketIndex=0)
 Return the address bound to a socket at the specified index.
 
const RakNetGUIDGetGuidFromSystemAddress (const SystemAddress input) const
 Given a connected system address, this method gives the unique GUID representing that instance of RakPeer. This will be the same on all systems connected to that instance of RakPeer, even if the external system addresses are different. Complexity is O(log2(n)). If input is UNASSIGNED_SYSTEM_ADDRESS, will return your own GUID.
 
SystemAddress GetSystemAddressFromGuid (const RakNetGUID input) const
 Gives the system address of a connected system, given its GUID. The GUID will be the same on all systems connected to that instance of RakPeer, even if the external system addresses are different. Currently O(log(n)), but this may be improved in the future If input is UNASSIGNED_RAKNET_GUID, UNASSIGNED_SYSTEM_ADDRESS is returned.
 
bool GetClientPublicKeyFromSystemAddress (const SystemAddress input, char *client_public_key) const
 
void SetTimeoutTime (RakNet::TimeMS timeMS, const SystemAddress target)
 Set the time, in MS, to use before considering ourselves disconnected after not being able to deliver a reliable message.
 
RakNet::TimeMS GetTimeoutTime (const SystemAddress target)
 Returns the Timeout time for the given system.
 
int GetMTUSize (const SystemAddress target) const
 Returns the current MTU size.
 
unsigned GetNumberOfAddresses (void)
 Returns the number of IP addresses this system has internally.
 
const char * GetLocalIP (unsigned int index)
 
bool IsLocalIP (const char *ip)
 
void AllowConnectionResponseIPMigration (bool allow)
 Allow or disallow connection responses from any IP.
 
bool AdvertiseSystem (const char *host, unsigned short remotePort, const char *data, int dataLength, unsigned connectionSocketIndex=0)
 Sends a one byte message ID_ADVERTISE_SYSTEM to the remote unconnected system. This will send our external IP outside the LAN along with some user data to the remote system.
 
void SetSplitMessageProgressInterval (int interval)
 Controls how often to return ID_DOWNLOAD_PROGRESS for large message downloads.
 
int GetSplitMessageProgressInterval (void) const
 Returns what was passed to SetSplitMessageProgressInterval().
 
void SetUnreliableTimeout (RakNet::TimeMS timeoutMS)
 Set how long to wait before giving up on sending an unreliable message. Useful if the network is clogged up. Set to 0 or less to never timeout. Defaults to 0.
 
void SendTTL (const char *host, unsigned short remotePort, int ttl, unsigned connectionSocketIndex=0)
 Send a message to a host, with the IP socket option TTL set to 3.
 
void AttachPlugin (PluginInterface2 *plugin)
 Attaches a Plugin interface to an instance of the base class (RakPeer or PacketizedTCP) to run code automatically on message receipt in the Receive call. If the plugin returns false from PluginInterface::UsesReliabilityLayer(), which is the case for all plugins except PacketLogger, you can call AttachPlugin() and DetachPlugin() for this plugin while RakPeer is active.
 
void DetachPlugin (PluginInterface2 *messageHandler)
 Detaches a Plugin interface from the instance of the base class (RakPeer or PacketizedTCP) it is attached to.
 
void PushBackPacket (Packet *packet, bool pushAtHead)
 Puts a message back in the receive queue in case you don't want to deal with it immediately.
 
PacketAllocatePacket (unsigned dataSize)
 Returns a packet for you to write to if you want to create a Packet for some reason. You can add it to the receive buffer with PushBackPacket.
 
virtual RakNetSocket2 * GetSocket (const SystemAddress target)
 Get the socket used with a particular active connection. The smart pointer reference counts the RakNetSocket object, so the socket will remain active as long as the smart pointer does, even if RakNet were to shutdown or close the connection.
 
virtual void GetSockets (DataStructures::List< RakNetSocket2 * > &sockets)
 Gets all sockets in use.
 
virtual void SetUserUpdateThread (void(*_userUpdateThreadPtr)(RakPeerInterface *, void *), void *_userUpdateThreadData)
 
virtual void SetIncomingDatagramEventHandler (bool(*_incomingDatagramEventHandler)(RNS2RecvStruct *))
 
virtual void ApplyNetworkSimulator (float packetloss, unsigned short minExtraPing, unsigned short extraPingVariance)
 
virtual void SetPerConnectionOutgoingBandwidthLimit (unsigned maxBitsPerSecond)
 
virtual bool IsNetworkSimulatorActive (void)
 
RakNetStatisticsGetStatistics (const SystemAddress systemAddress, RakNetStatistics *rns=0)
 Returns a structure containing a large set of network statistics for the specified system. You can map this data to a string using the C style StatisticsToString() function.
 
bool GetStatistics (const unsigned int index, RakNetStatistics *rns)
 Returns the network statistics of the system at the given index in the remoteSystemList.
 
virtual void GetStatisticsList (DataStructures::List< SystemAddress > &addresses, DataStructures::List< RakNetGUID > &guids, DataStructures::List< RakNetStatistics > &statistics)
 Returns the list of systems, and statistics for each of those systems Each system has one entry in each of the lists, in the same order.
 
virtual unsigned int GetReceiveBufferSize (void)
 how many messages are waiting when you call Receive()
 
- Public Member Functions inherited from RakNet::RakPeerInterface
virtual ~RakPeerInterface ()
 Destructor.
 

Protected Member Functions

RemoteSystemStruct * GetRemoteSystemFromSystemAddress (const SystemAddress systemAddress, bool calledFromNetworkThread, bool onlyActive) const
 
void ParseConnectionRequestPacket (RakPeer::RemoteSystemStruct *remoteSystem, const SystemAddress &systemAddress, const char *data, int byteSize)
 Parse out a connection request packet.
 
void NotifyAndFlagForShutdown (const SystemAddress systemAddress, bool performImmediate, unsigned char orderingChannel, PacketPriority disconnectionNotificationPriority)
 Send a reliable disconnect packet to this player and disconnect them when it is delivered.
 
unsigned int GetNumberOfRemoteInitiatedConnections (void) const
 Returns how many remote systems initiated a connection to us.
 
RemoteSystemStruct * AssignSystemAddressToRemoteSystemList (const SystemAddress systemAddress, RemoteSystemStruct::ConnectMode connectionMode, RakNetSocket2 *incomingRakNetSocket, bool *thisIPConnectedRecently, SystemAddress bindingAddress, int incomingMTU, RakNetGUID guid, bool useSecurity)
 Get a free remote system from the list and assign our systemAddress to it.
 
void ShiftIncomingTimestamp (unsigned char *data, const SystemAddress &systemAddress) const
 Adjust the timestamp of the incoming packet to be relative to this system.
 
RakNet::Time GetBestClockDifferential (const SystemAddress systemAddress) const
 

Protected Attributes

volatile bool endThreads
 Set this to true to terminate the Peer thread execution.
 
volatile bool isMainLoopThreadActive
 true if the peer thread is active.
 
*unsigned int maximumNumberOfPeers
 Store the maximum number of peers allowed to connect.
 
unsigned int maximumIncomingConnections
 Store the maximum number of peers able to connect, including reserved connection slots for pings, etc.
 
char incomingPassword [256]
 Local Player ID.
 
RemoteSystemStruct * remoteSystemList
 
RemoteSystemStruct ** activeSystemList
 
bool updateCycleIsRunning
 RunUpdateCycle is not thread safe but we don't need to mutex calls. Just skip calls if it is running already.
 
unsigned int bytesSentPerSecond
 The list of people we have tried to connect to recently.
 
bool allowConnectionResponseIPMigration
 How long it has been since things were updated by a call to receiveUpdate thread uses this to determine how long to sleep for.
 
SimpleMutex sendReceiptSerialMutex
 

Additional Inherited Members

- Static Public Member Functions inherited from RakNet::RakPeerInterface
static uint64_t Get64BitUniqueRandomNumber (void)
 Get a random number (to generate a GUID)
 

Detailed Description

Main interface for network communications.

It implements most of RakNet's functionality and is the primary interface for RakNet.

Inherits RakPeerInterface.

See the individual functions for what the class can do.

Member Function Documentation

void RakNet::RakPeer::AddToBanList ( const char *  IP,
RakNet::TimeMS  milliseconds = 0 
)
virtual

Bans an IP from connecting.

Banned IPs persist between connections but are not saved on shutdown nor loaded on startup.

Parameters
[in]IPDotted IP address. You can use * for a wildcard address, such as 128.0.0. * will ban all IP addresses starting with 128.0.0.
[in]millisecondsGives time in milli seconds for a temporary ban of the IP address. Use 0 for a permanent ban.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::AddToSecurityExceptionList ( const char *  ip)
virtual

This is useful if you have a fixed-address internal server behind a LAN.

Secure connections are determined by the recipient of an incoming connection. This has no effect if called on the system attempting to connect.

Note
If secure connections are on, do not use secure connections for a specific IP address.
Parameters
[in]ipIP address to add. * wildcards are supported.

Implements RakNet::RakPeerInterface.

bool RakNet::RakPeer::AdvertiseSystem ( const char *  host,
unsigned short  remotePort,
const char *  data,
int  dataLength,
unsigned  connectionSocketIndex = 0 
)
virtual

Sends a one byte message ID_ADVERTISE_SYSTEM to the remote unconnected system. This will send our external IP outside the LAN along with some user data to the remote system.

Precondition
The sender and recipient must already be started via a successful call to Initialize
Parameters
[in]hostEither a dotted IP address or a domain name
[in]remotePortWhich port to connect to on the remote machine.
[in]dataOptional data to append to the packet.
[in]dataLengthLength of data in bytes. Use 0 if no data.
[in]connectionSocketIndexIndex into the array of socket descriptors passed to socketDescriptors in RakPeer::Startup() to send on.
Returns
False if IsActive()==false or the host is unresolvable. True otherwise.

Implements RakNet::RakPeerInterface.

Packet* RakNet::RakPeer::AllocatePacket ( unsigned  dataSize)
virtual

Returns a packet for you to write to if you want to create a Packet for some reason. You can add it to the receive buffer with PushBackPacket.

Parameters
[in]dataSizeHow many bytes to allocate for the buffer
Returns
A packet.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::AllowConnectionResponseIPMigration ( bool  allow)
virtual

Allow or disallow connection responses from any IP.

Normally this should be false, but may be necessary when connecting to servers with multiple IP addresses.

Parameters
[in]allow- True to allow this behavior, false to not allow. Defaults to false. Value persists between connections.

Implements RakNet::RakPeerInterface.

virtual void RakNet::RakPeer::ApplyNetworkSimulator ( float  packetloss,
unsigned short  minExtraPing,
unsigned short  extraPingVariance 
)
virtual

Adds simulated ping and packet loss to the outgoing data flow. To simulate bi-directional ping and packet loss, you should call this on both the sender and the recipient, with half the total ping and packetloss value on each. You can exclude network simulator code with the _RELEASE #define to decrease code size

Deprecated:
Use http://www.jenkinssoftware.com/forum/index.php?topic=1671.0 instead.
Note
Doesn't work past version 3.6201
Parameters
[in]packetlossChance to lose a packet. Ranges from 0 to 1.
[in]minExtraPingThe minimum time to delay sends.
[in]extraPingVarianceThe additional random time to delay sends.

Implements RakNet::RakPeerInterface.

RemoteSystemStruct* RakNet::RakPeer::AssignSystemAddressToRemoteSystemList ( const SystemAddress  systemAddress,
RemoteSystemStruct::ConnectMode  connectionMode,
RakNetSocket2 *  incomingRakNetSocket,
bool *  thisIPConnectedRecently,
SystemAddress  bindingAddress,
int  incomingMTU,
RakNetGUID  guid,
bool  useSecurity 
)
protected

Get a free remote system from the list and assign our systemAddress to it.

Note
Should only be called from the update thread - not the user thread.
Parameters
[in]systemAddresssystemAddress to be assigned
[in]connectionModeconnection mode of the RemoteSystem.
[in]rakNetSocket
[in]thisIPConnectedRecentlyIs this IP connected recently? set to False;
[in]bindingAddressAddress to be binded with the remote system
[in]incomingMTUMTU for the remote system
void RakNet::RakPeer::AttachPlugin ( PluginInterface2 plugin)
virtual

Attaches a Plugin interface to an instance of the base class (RakPeer or PacketizedTCP) to run code automatically on message receipt in the Receive call. If the plugin returns false from PluginInterface::UsesReliabilityLayer(), which is the case for all plugins except PacketLogger, you can call AttachPlugin() and DetachPlugin() for this plugin while RakPeer is active.

Parameters
[in]messageHandlerPointer to the plugin to attach.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::CancelConnectionAttempt ( const SystemAddress  target)
virtual

Cancel a pending connection attempt.

If we are already connected, the connection stays open

Parameters
[in]targetTarget system to cancel.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::CloseConnection ( const AddressOrGUID  target,
bool  sendDisconnectionNotification,
unsigned char  orderingChannel = 0,
PacketPriority  disconnectionNotificationPriority = LOW_PRIORITY 
)
virtual

Close the connection to another host (if we initiated the connection it will disconnect, if they did it will kick them out).

This method closes the connection irrespective of who initiated the connection.

Parameters
[in]targetWhich system to close the connection to.
[in]sendDisconnectionNotificationTrue to send ID_DISCONNECTION_NOTIFICATION to the recipient. False to close it silently.
[in]channelWhich ordering channel to send the disconnection notification on, if any
[in]disconnectionNotificationPriorityPriority to send ID_DISCONNECTION_NOTIFICATION on.

Implements RakNet::RakPeerInterface.

ConnectionAttemptResult RakNet::RakPeer::Connect ( const char *  host,
unsigned short  remotePort,
const char *  passwordData,
int  passwordDataLength,
PublicKey publicKey = 0,
unsigned  connectionSocketIndex = 0,
unsigned  sendConnectionAttemptCount = 6,
unsigned  timeBetweenSendConnectionAttemptsMS = 1000,
RakNet::TimeMS  timeoutTime = 0 
)
virtual

Connect to the specified host (ip or domain name) and server port.

Calling Connect and not calling SetMaximumIncomingConnections acts as a dedicated client. Calling both acts as a true peer.

This is a non-blocking connection.

The connection is successful when GetConnectionState() returns IS_CONNECTED or Receive() gets a message with the type identifier ID_CONNECTION_REQUEST_ACCEPTED. If the connection is not successful, such as a rejected connection or no response then neither of these things will happen.

Precondition
Requires that you first call Startup().
Parameters
[in]hostEither a dotted IP address or a domain name.
[in]remotePortPort to connect to on the remote machine.
[in]passwordDataA data block that must match the data block on the server passed to SetIncomingPassword(). This can be a string or can be a stream of data. Use 0 for no password.
[in]passwordDataLengthThe length in bytes of passwordData.
[in]publicKeyThe public key the server is using. If 0, the server is not using security. If non-zero, the publicKeyMode member determines how to connect
[in]connectionSocketIndexIndex into the array of socket descriptors passed to socketDescriptors in RakPeer::Startup() to determine the one to send on.
[in]sendConnectionAttemptCountNumber of datagrams to send to the other system to try to connect.
[in]timeBetweenSendConnectionAttemptsMSTime to elapse before a datagram is sent to the other system to try to connect. After sendConnectionAttemptCount number of attempts, ID_CONNECTION_ATTEMPT_FAILED is returned. Under low bandwidth conditions with multiple simultaneous outgoing connections, this value should be raised to 1000 or higher, or else the MTU detection can overrun the available bandwidth.
[in]timeoutTimeTime to elapse before dropping the connection if a reliable message could not be sent. 0 to use the default value from SetTimeoutTime(UNASSIGNED_SYSTEM_ADDRESS);
Returns
CONNECTION_ATTEMPT_STARTED on successful initiation. Otherwise, an appropriate enumeration indicating failure.
Note
CONNECTION_ATTEMPT_STARTED does not mean you are already connected!
It is possible to immediately get back ID_CONNECTION_ATTEMPT_FAILED if you exceed the maxConnections parameter passed to Startup(). This could happen if you call CloseConnection() with sendDisconnectionNotificaiton true, then immediately call Connect() before the connection has closed.

Implements RakNet::RakPeerInterface.

virtual ConnectionAttemptResult RakNet::RakPeer::ConnectWithSocket ( const char *  host,
unsigned short  remotePort,
const char *  passwordData,
int  passwordDataLength,
RakNetSocket2 *  socket,
PublicKey publicKey = 0,
unsigned  sendConnectionAttemptCount = 6,
unsigned  timeBetweenSendConnectionAttemptsMS = 1000,
RakNet::TimeMS  timeoutTime = 0 
)
virtual

Connect to the specified host (ip or domain name) and server port.

Parameters
[in]hostEither a dotted IP address or a domain name.
[in]remotePortWhich port to connect to on the remote machine.
[in]passwordDataA data block that must match the data block on the server passed to SetIncomingPassword(). This can be a string or can be a stream of data. Use 0 for no password.
[in]passwordDataLengthThe length in bytes of passwordData.
[in]socketA bound socket returned by another instance of RakPeerInterface.
[in]sendConnectionAttemptCountNumber of datagrams to send to the other system to try to connect.
[in]timeBetweenSendConnectionAttemptsMSTime to elapse before a datagram is sent to the other system to try to connect. After sendConnectionAttemptCount number of attempts, ID_CONNECTION_ATTEMPT_FAILED is returned.. Under low bandwidth conditions with multiple simultaneous outgoing connections, this value should be raised to 1000 or higher, or else the MTU detection can overrun the available bandwidth.
[in]timeoutTimeTime to elapse before dropping the connection if a reliable message could not be sent. 0 to use the default from SetTimeoutTime(UNASSIGNED_SYSTEM_ADDRESS);
Returns
CONNECTION_ATTEMPT_STARTED on successful initiation. Otherwise, an appropriate enumeration indicating failure.
Note
CONNECTION_ATTEMPT_STARTED does not mean you are already connected!

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::DeallocatePacket ( Packet packet)
virtual

Call this to deallocate a message returned by Receive() when you are done handling it.

Parameters
[in]packetMessage to deallocate.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::DetachPlugin ( PluginInterface2 messageHandler)
virtual

Detaches a Plugin interface from the instance of the base class (RakPeer or PacketizedTCP) it is attached to.

This method disables the plugin code from running automatically on base class's updates or message receipt. If the plugin returns false from PluginInterface::UsesReliabilityLayer(), which is the case for all plugins except PacketLogger, you can call AttachPlugin() and DetachPlugin() for this plugin while RakPeer is active.

Parameters
[in]messageHandlerPointer to a plugin to detach.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::DisableSecurity ( void  )
virtual

Disables security for incoming connections.

Note
Must be called while offline

Implements RakNet::RakPeerInterface.

int RakNet::RakPeer::GetAveragePing ( const AddressOrGUID  systemIdentifier)
virtual

Returns the average of all ping times read for the specific system or -1 if none read yet.

Parameters
[in]systemAddressWhich system we are referring to
Returns
The ping time for this system, or -1

Implements RakNet::RakPeerInterface.

RakNet::Time RakNet::RakPeer::GetBestClockDifferential ( const SystemAddress  systemAddress) const
protected

Get the most accurate clock differential for a certain player.

Parameters
[in]systemAddressThe player with whose clock the time difference is calculated.
Returns
The clock differential for a certain player.
bool RakNet::RakPeer::GetClientPublicKeyFromSystemAddress ( const SystemAddress  input,
char *  client_public_key 
) const
virtual

Given the SystemAddress of a connected system, get the public key they provided as an identity Returns false if system address was not found or client public key is not known

Parameters
[in]inputThe RakNetGUID of the system
[in]client_public_keyThe connected client's public key is copied to this address. Buffer must be cat::EasyHandshake::PUBLIC_KEY_BYTES bytes in length.

Implements RakNet::RakPeerInterface.

bool RakNet::RakPeer::GetConnectionList ( SystemAddress remoteSystems,
unsigned short *  numberOfSystems 
) const
virtual

Fills the array remoteSystems with the SystemAddress of all the systems we are connected to.

Parameters
[out]remoteSystemsAn array of SystemAddress structures, to be filled with the SystemAddresss of the systems we are connected to. Pass 0 to remoteSystems to get the number of systems we are connected to.
[in,out]numberOfSystemsAs input, the size of remoteSystems array. As output, the number of elements put into the array.

Implements RakNet::RakPeerInterface.

ConnectionState RakNet::RakPeer::GetConnectionState ( const AddressOrGUID  systemIdentifier)
virtual

Returns if a system is connected, disconnected, connecting in progress, or various other states

Parameters
[in]systemIdentifierThe system we are referring to
Note
This locks a mutex, do not call too frequently during connection attempts or the attempt will take longer and possibly even timeout
Returns
What state the remote system is in

Implements RakNet::RakPeerInterface.

SystemAddress RakNet::RakPeer::GetExternalID ( const SystemAddress  target) const
virtual

Returns the unique address identifier that represents the target on the the network and is based on the target's external IP / port.

Parameters
[in]targetThe SystemAddress of the remote system. Usually the same for all systems, unless you have two or more network cards.

Implements RakNet::RakPeerInterface.

RakNetGUID RakNet::RakPeer::GetGUIDFromIndex ( unsigned int  index)
virtual

Same as GetSystemAddressFromIndex but returns RakNetGUID.

Parameters
[in]indexIndex should range between 0 and the maximum number of players allowed - 1.
Returns
The RakNetGUID

Implements RakNet::RakPeerInterface.

const RakNetGUID& RakNet::RakPeer::GetGuidFromSystemAddress ( const SystemAddress  input) const
virtual

Given a connected system address, this method gives the unique GUID representing that instance of RakPeer. This will be the same on all systems connected to that instance of RakPeer, even if the external system addresses are different. Complexity is O(log2(n)). If input is UNASSIGNED_SYSTEM_ADDRESS, will return your own GUID.

Precondition
Call Startup() first, or the function will return UNASSIGNED_RAKNET_GUID
Parameters
[in]inputThe system address of the target system we are connected to.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::GetIncomingPassword ( char *  passwordData,
int *  passwordDataLength 
)
virtual

Gets the password passed to SetIncomingPassword.

Parameters
[out]passwordDataShould point to a block large enough to hold the password data you passed to SetIncomingPassword()
[in,out]passwordDataLengthMaximum size of the passwordData array. Modified to hold the number of bytes actually written.

Implements RakNet::RakPeerInterface.

int RakNet::RakPeer::GetIndexFromSystemAddress ( const SystemAddress  systemAddress) const
virtual

Given systemAddress, returns its index into remoteSystemList.

Values range from 0 to the maximum number of players allowed - 1. This includes systems which were formerly connected, but are now not connected.

Parameters
[in]systemAddressThe SystemAddress we are referring to
Returns
The index of this SystemAddress or -1 on system not found.

Implements RakNet::RakPeerInterface.

SystemAddress RakNet::RakPeer::GetInternalID ( const SystemAddress  systemAddress = UNASSIGNED_SYSTEM_ADDRESS,
const int  index = 0 
) const
virtual

Returns the unique address identifier that represents you or another system on the the network.

Note
Not supported by the XBOX
Parameters
[in]systemAddressUse UNASSIGNED_SYSTEM_ADDRESS to get your behind-LAN address. Use a connected system to get their behind-LAN address. This does not return the port.
[in]indexWhen you have multiple internal IDs, which index to return? Currently limited to MAXIMUM_NUMBER_OF_INTERNAL_IDS (so the maximum value of this variable is MAXIMUM_NUMBER_OF_INTERNAL_IDS-1)
Returns
Identifier of your system internally, which may not be how other systems see if you if you are behind a NAT or proxy.

Implements RakNet::RakPeerInterface.

int RakNet::RakPeer::GetLastPing ( const AddressOrGUID  systemIdentifier) const
virtual

Returns the last ping time read for the specific system or -1 if none read yet.

Parameters
[in]systemAddressWhich system we are referring to
Returns
The last ping time for this system, or -1.

Implements RakNet::RakPeerInterface.

const char* RakNet::RakPeer::GetLocalIP ( unsigned int  index)
virtual

Returns an IP address at index 0 to GetNumberOfAddresses-1 in ipList array.

Parameters
[in]indexindex into the list of IP addresses
Returns
The local IP address at this index

Implements RakNet::RakPeerInterface.

int RakNet::RakPeer::GetLowestPing ( const AddressOrGUID  systemIdentifier) const
virtual

Returns the lowest ping time read or -1 if none read yet.

Parameters
[in]systemAddressWhich system we are referring to
Returns
The lowest ping time for this system, or -1.

Implements RakNet::RakPeerInterface.

unsigned int RakNet::RakPeer::GetMaximumIncomingConnections ( void  ) const
virtual

Returns the value passed to SetMaximumIncomingConnections().

Returns
Maximum number of incoming connections, which is always <= maxConnections

Implements RakNet::RakPeerInterface.

unsigned int RakNet::RakPeer::GetMaximumNumberOfPeers ( void  ) const
virtual

Return the total number of connections we are allowed.

Returns
Total number of connections allowed.

Implements RakNet::RakPeerInterface.

int RakNet::RakPeer::GetMTUSize ( const SystemAddress  target) const
virtual

Returns the current MTU size.

Parameters
[in]targetWhich system to get MTU for. UNASSIGNED_SYSTEM_ADDRESS to get the default
Returns
The current MTU size of the target system.

Implements RakNet::RakPeerInterface.

virtual uint32_t RakNet::RakPeer::GetNextSendReceipt ( void  )
virtual

Returns the next uint32_t that Send() will return

Note
If using RakPeer from multiple threads, this may not be accurate for your thread. Use IncrementNextSendReceipt() in that case.
Returns
The next uint32_t that Send() or SendList will return

Implements RakNet::RakPeerInterface.

unsigned RakNet::RakPeer::GetNumberOfAddresses ( void  )
virtual

Returns the number of IP addresses this system has internally.

Get the actual addresses from GetLocalIP()

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::GetOfflinePingResponse ( char **  data,
unsigned int *  length 
)
virtual

Returns pointers to a copy of the data passed to SetOfflinePingResponse.

Parameters
[out]dataA pointer to a copy of the data passed to SetOfflinePingResponse()
[out]lengthA pointer filled in with the length parameter passed to SetOfflinePingResponse()
See Also
SetOfflinePingResponse

Implements RakNet::RakPeerInterface.

RemoteSystemStruct* RakNet::RakPeer::GetRemoteSystemFromSystemAddress ( const SystemAddress  systemAddress,
bool  calledFromNetworkThread,
bool  onlyActive 
) const
protected

Get the reliability layer associated with a systemAddress.

Parameters
[in]systemAddressThe player identifier
Returns
0 if none
virtual RakNetSocket2* RakNet::RakPeer::GetSocket ( const SystemAddress  target)
virtual

Get the socket used with a particular active connection. The smart pointer reference counts the RakNetSocket object, so the socket will remain active as long as the smart pointer does, even if RakNet were to shutdown or close the connection.

Note
This sends a query to the thread and blocks on the return value for up to one second. In practice it should only take a millisecond or so.
Parameters
[in]targetWhich system.
Returns
A smart pointer object containing the socket information about the target. Be sure to check IsNull() which is returned if the update thread is unresponsive, shutting down, or if this system is not connected.

Implements RakNet::RakPeerInterface.

virtual void RakNet::RakPeer::GetSockets ( DataStructures::List< RakNetSocket2 * > &  sockets)
virtual

Gets all sockets in use.

Note
This sends a query to the thread and blocks on the return value for up to one second. In practice it should only take a millisecond or so.
Parameters
[out]socketsList of RakNetSocket structures in use.

Implements RakNet::RakPeerInterface.

int RakNet::RakPeer::GetSplitMessageProgressInterval ( void  ) const
virtual

Returns what was passed to SetSplitMessageProgressInterval().

Returns
Number of messages to be recieved before a download progress notification is returned. Default to 0.

Implements RakNet::RakPeerInterface.

RakNetStatistics* RakNet::RakPeer::GetStatistics ( const SystemAddress  systemAddress,
RakNetStatistics rns = 0 
)
virtual

Returns a structure containing a large set of network statistics for the specified system. You can map this data to a string using the C style StatisticsToString() function.

Parameters
[in]systemAddressWhich connected system to get statistics for.
[in]rnsIf you supply this structure,the network statistics will be written to it. Otherwise the method uses a static struct to write the data, which is not threadsafe.
Returns
0 if the specified system can't be found. Otherwise a pointer to the struct containing the specified system's network statistics.
See Also
RakNetStatistics.h

Implements RakNet::RakPeerInterface.

bool RakNet::RakPeer::GetStatistics ( const unsigned int  index,
RakNetStatistics rns 
)
virtual

Returns the network statistics of the system at the given index in the remoteSystemList.

Returns
True if the index is less than the maximum number of peers allowed and the system is active. False otherwise.

Implements RakNet::RakPeerInterface.

virtual void RakNet::RakPeer::GetStatisticsList ( DataStructures::List< SystemAddress > &  addresses,
DataStructures::List< RakNetGUID > &  guids,
DataStructures::List< RakNetStatistics > &  statistics 
)
virtual

Returns the list of systems, and statistics for each of those systems Each system has one entry in each of the lists, in the same order.

Parameters
[out]addressesSystemAddress for each connected system
[out]guidsRakNetGUID for each connected system
[out]statisticsCalculated RakNetStatistics for each connected system

Implements RakNet::RakPeerInterface.

SystemAddress RakNet::RakPeer::GetSystemAddressFromGuid ( const RakNetGUID  input) const
virtual

Gives the system address of a connected system, given its GUID. The GUID will be the same on all systems connected to that instance of RakPeer, even if the external system addresses are different. Currently O(log(n)), but this may be improved in the future If input is UNASSIGNED_RAKNET_GUID, UNASSIGNED_SYSTEM_ADDRESS is returned.

Parameters
[in]inputThe RakNetGUID of the target system.

Implements RakNet::RakPeerInterface.

SystemAddress RakNet::RakPeer::GetSystemAddressFromIndex ( unsigned int  index)
virtual

Given index into remoteSystemList, will return a SystemAddress. This function is only useful for looping through all systems.

Parameters
[in]indexIndex should range between 0 and the maximum number of players allowed - 1.
Returns
The SystemAddress structure corresponding to index in remoteSystemList.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::GetSystemList ( DataStructures::List< SystemAddress > &  addresses,
DataStructures::List< RakNetGUID > &  guids 
) const
virtual

Same as calling GetSystemAddressFromIndex and GetGUIDFromIndex for all systems, but more efficient Indices match each other, so addresses[0] and guids[0] refer to the same system.

Parameters
[out]addressesAll system addresses. Size of the list is the number of connections. Size of the addresses list will match the size of the guids list.
[out]guidsAll guids. Size of the list is the number of connections. Size of the list will match the size of the addresses list.

Implements RakNet::RakPeerInterface.

RakNet::TimeMS RakNet::RakPeer::GetTimeoutTime ( const SystemAddress  target)
virtual

Returns the Timeout time for the given system.

Parameters
[in]targetTarget system to get the TimeoutTime for. Pass UNASSIGNED_SYSTEM_ADDRESS to get the default value.
Returns
Timeout time for a given system.

Implements RakNet::RakPeerInterface.

virtual uint32_t RakNet::RakPeer::IncrementNextSendReceipt ( void  )
virtual

Returns the next uint32_t that Send() will return, and increments the value by one

Note
If using RakPeer from multiple threads, pass this to forceReceipt in the send function
Returns
The next uint32_t that Send() or SendList will return

Implements RakNet::RakPeerInterface.

bool RakNet::RakPeer::InitializeSecurity ( const char *  publicKey,
const char *  privateKey,
bool  bRequireClientKey = false 
)
virtual

If you accept connections, you must call this or else security will not be enabled for incoming connections. This feature requires more round trips, bandwidth, and CPU time for the connection handshake x64 builds require under 25% of the CPU time of other builds See the Encryption sample for example usage

Precondition
Must be called while offline
LIBCAT_SECURITY must be defined to 1 in NativeFeatureIncludes.h for this function to have any effect
Parameters
[in]publicKeyA pointer to the public key for accepting new connections
[in]privateKeyA pointer to the private key for accepting new connections
[in]bRequireClientKey,:Should be set to false for most servers. Allows the server to accept a public key from connecting clients as a proof of identity but eats twice as much CPU time as a normal connection

Implements RakNet::RakPeerInterface.

bool RakNet::RakPeer::IsActive ( void  ) const
virtual

Returns true if the network thread is running.

Returns
True if the network thread is running, False otherwise

Implements RakNet::RakPeerInterface.

bool RakNet::RakPeer::IsBanned ( const char *  IP)
virtual

Returns true or false indicating if a particular IP is banned.

Parameters
[in]IPDotted IP address.
Returns
True if IP matches any IPs in the ban list, accounting for any wildcards. False otherwise.

Implements RakNet::RakPeerInterface.

bool RakNet::RakPeer::IsInSecurityExceptionList ( const char *  ip)
virtual

Checks to see if a given IP is in the security exception list.

Parameters
[in]IPaddress to check.
Returns
True if the IP address is found in security exception list, else returns false.

Implements RakNet::RakPeerInterface.

bool RakNet::RakPeer::IsLocalIP ( const char *  ip)
virtual

Is this a local IP? Checks if this ip is in the ipList array.

Parameters
[in]AnIP address to check, excluding the port.
Returns
True if this is one of the IP addresses returned by GetLocalIP

Implements RakNet::RakPeerInterface.

virtual bool RakNet::RakPeer::IsNetworkSimulatorActive ( void  )
virtual

Returns if you previously called ApplyNetworkSimulator

Returns
If you previously called ApplyNetworkSimulator

Implements RakNet::RakPeerInterface.

unsigned short RakNet::RakPeer::NumberOfConnections ( void  ) const
virtual

Returns how many open connections exist at this time.

Returns
Number of open connections.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::Ping ( const SystemAddress  target)
virtual

Send a ping to the specified connected system.

Precondition
The sender and recipient must already be started via a successful call to Startup()
Parameters
[in]targetWhich system to ping

Implements RakNet::RakPeerInterface.

bool RakNet::RakPeer::Ping ( const char *  host,
unsigned short  remotePort,
bool  onlyReplyOnAcceptingConnections,
unsigned  connectionSocketIndex = 0 
)
virtual

Send a ping to the specified unconnected system.

The remote system, if it is Initialized, will respond with ID_PONG followed by sizeof(RakNet::TimeMS) containing the system time the ping was sent. Default is 4 bytes - See __GET_TIME_64BIT in RakNetTypes.h System should reply with ID_PONG if it is active

Parameters
[in]hostEither a dotted IP address or a domain name. Can be 255.255.255.255 for LAN broadcast.
[in]remotePortWhich port to connect to on the remote machine.
[in]onlyReplyOnAcceptingConnectionsOnly request a reply if the remote system is accepting connections
[in]connectionSocketIndexIndex into the array of socket descriptors passed to socketDescriptors in RakPeer::Startup() to send on.
Returns
true on success, false on failure (unknown hostname)

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::PushBackPacket ( Packet packet,
bool  pushAtHead 
)
virtual

Puts a message back in the receive queue in case you don't want to deal with it immediately.

Parameters
[in]packetThe pointer to the packet you want to push back.
[in]pushAtHeadTrue to push the packet at the start of the queue so that the next receive call returns it. False to push it at the end of the queue.
Note
Setting pushAtHead to false end makes the packets out of order.

Implements RakNet::RakPeerInterface.

Packet* RakNet::RakPeer::Receive ( void  )
virtual

Gets a message from the incoming message queue.

Use DeallocatePacket() to deallocate the message after you are done with it. User-thread functions, such as RPC calls and the plugin function PluginInterface::Update occur here.

Returns
0 if no packets are waiting to be handled, otherwise a pointer to a packet.
Note
COMMON MISTAKE: Be sure to call this in a loop, once per game tick, until it returns 0. If you only process one packet per game tick they will buffer up.
See Also
RakNetTypes.h contains struct Packet.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::RemoveFromSecurityExceptionList ( const char *  ip)
virtual

Remove a specific connection previously added via AddToSecurityExceptionList.

Parameters
[in]ipIP address to remove. Pass 0 to remove all IP addresses. * wildcards are supported.

Implements RakNet::RakPeerInterface.

uint32_t RakNet::RakPeer::Send ( const char *  data,
const int  length,
PacketPriority  priority,
PacketReliability  reliability,
char  orderingChannel,
const AddressOrGUID  systemIdentifier,
bool  broadcast,
uint32_t  forceReceiptNumber = 0 
)
virtual

Sends a block of data to the specified system that you are connected to.

Note
This function only works while connected.
The first byte should be a message identifier starting at ID_USER_PACKET_ENUM.
Parameters
[in]dataBlock of data to send.
[in]lengthSize in bytes of the data to send.
[in]priorityPriority level to send on. See PacketPriority.h
[in]reliabilityHow reliably to send this data. See PacketPriority.h
[in]orderingChannelWhen using ordered or sequenced messages, the channel to order these on. Messages are only ordered relative to other messages on the same stream.
[in]systemIdentifierWho to send this packet to, or in the case of broadcasting who not to send it to. Pass either a SystemAddress structure or a RakNetGUID structure. Use UNASSIGNED_SYSTEM_ADDRESS or to specify none
[in]broadcastTrue to send this packet to all connected systems. If true, then systemAddress specifies who not to send the packet to.
[in]forceReceiptIf 0, will automatically determine the receipt number to return. If non-zero, will return what you give it.
Returns
0 on bad input. Otherwise a number that identifies this message. If reliability is a type that returns a receipt, on a later call to Receive() you will get ID_SND_RECEIPT_ACKED or ID_SND_RECEIPT_LOSS with bytes 1-4 inclusive containing this number

Implements RakNet::RakPeerInterface.

uint32_t RakNet::RakPeer::Send ( const RakNet::BitStream bitStream,
PacketPriority  priority,
PacketReliability  reliability,
char  orderingChannel,
const AddressOrGUID  systemIdentifier,
bool  broadcast,
uint32_t  forceReceiptNumber = 0 
)
virtual

Sends a block of data to the specified system that you are connected to.

Same as the above version, but takes a BitStream as input.

Parameters
[in]bitStreamBitstream to send
[in]priorityPriority level to send on. See PacketPriority.h
[in]reliabilityHow reliably to send this data. See PacketPriority.h
[in]orderingChannelChannel to order the messages on, when using ordered or sequenced messages. Messages are only ordered relative to other messages on the same stream.
[in]systemIdentifierSystem Address or RakNetGUID to send this packet to, or in the case of broadcasting, the address not to send it to. Use UNASSIGNED_SYSTEM_ADDRESS to specify none.
[in]broadcastTrue to send this packet to all connected systems. If true, then systemAddress specifies who not to send the packet to.
[in]forceReceiptIf 0, will automatically determine the receipt number to return. If non-zero, will return what you give it.
Returns
0 on bad input. Otherwise a number that identifies this message. If reliability is a type that returns a receipt, on a later call to Receive() you will get ID_SND_RECEIPT_ACKED or ID_SND_RECEIPT_LOSS with bytes 1-4 inclusive containing this number
Note
COMMON MISTAKE: When writing the first byte, bitStream->Write((unsigned char) ID_MY_TYPE) be sure it is casted to a byte, and you are not writing a 4 byte enumeration.

Implements RakNet::RakPeerInterface.

uint32_t RakNet::RakPeer::SendList ( const char **  data,
const int *  lengths,
const int  numParameters,
PacketPriority  priority,
PacketReliability  reliability,
char  orderingChannel,
const AddressOrGUID  systemIdentifier,
bool  broadcast,
uint32_t  forceReceiptNumber = 0 
)
virtual

Sends multiple blocks of data, concatenating them automatically.

This is equivalent to: RakNet::BitStream bs; bs.WriteAlignedBytes(block1, blockLength1); bs.WriteAlignedBytes(block2, blockLength2); bs.WriteAlignedBytes(block3, blockLength3); Send(&bs, ...)

This function only works when connected.

Parameters
[in]dataAn array of pointers to blocks of data
[in]lengthsAn array of integers indicating the length of each block of data
[in]numParametersLength of the arrays data and lengths
[in]priorityPriority level to send on. See PacketPriority.h
[in]reliabilityHow reliably to send this data. See PacketPriority.h
[in]orderingChannelChannel to order the messages on, when using ordered or sequenced messages. Messages are only ordered relative to other messages on the same stream.
[in]systemIdentifierSystem Address or RakNetGUID to send this packet to, or in the case of broadcasting, the address not to send it to. Use UNASSIGNED_SYSTEM_ADDRESS to specify none.
[in]broadcastTrue to send this packet to all connected systems. If true, then systemAddress specifies who not to send the packet to.
[in]forceReceiptIf 0, will automatically determine the receipt number to return. If non-zero, will return what you give it.
Returns
0 on bad input. Otherwise a number that identifies this message. If reliability is a type that returns a receipt, on a later call to Receive() you will get ID_SND_RECEIPT_ACKED or ID_SND_RECEIPT_LOSS with bytes 1-4 inclusive containing this number

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::SendLoopback ( const char *  data,
const int  length 
)
virtual

"Send" to yourself rather than a remote system.

The message will be processed through the plugins and returned to the game as usual. This function works anytime

Note
The first byte should be a message identifier starting at ID_USER_PACKET_ENUM
Parameters
[in]dataBlock of data to send.
[in]lengthSize in bytes of the data to send.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::SendTTL ( const char *  host,
unsigned short  remotePort,
int  ttl,
unsigned  connectionSocketIndex = 0 
)
virtual

Send a message to a host, with the IP socket option TTL set to 3.

This message will not reach the host, but will open the router.

Parameters
[in]hostThe address of the remote host in dotted notation.
[in]remotePortThe port number to send to.
[in]ttlMax hops of datagram, set to 3
[in]connectionSocketIndexuserConnectionSocketIndex.
Remarks
Used for NAT-Punchthrough

Implements RakNet::RakPeerInterface.

virtual void RakNet::RakPeer::SetIncomingDatagramEventHandler ( bool(*)(RNS2RecvStruct *)  _incomingDatagramEventHandler)
virtual

Set a C callback to be called whenever a datagram arrives Return true from the callback to have RakPeer handle the datagram. Return false and RakPeer will ignore the datagram. This can be used to filter incoming datagrams by system, or to share a recvfrom socket with RakPeer RNS2RecvStruct will only remain valid for the duration of the call

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::SetIncomingPassword ( const char *  passwordData,
int  passwordDataLength 
)
virtual

Sets the password for the incoming connections.

The password must match in the call to Connect (defaults to none). Pass 0 to passwordData to specify no password. This is a way to set a low level password for all incoming connections. To selectively reject connections, implement your own scheme using CloseConnection() to remove unwanted connections.

Parameters
[in]passwordDataA data block that incoming connections must match. This can be just a password, or can be a stream of data. Specify 0 for no password data
[in]passwordDataLengthThe length in bytes of passwordData

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::SetInternalID ( SystemAddress  systemAddress,
int  index = 0 
)
virtual

Sets your internal IP address, for platforms that do not support reading it, or to override a value.

Parameters
[in]systemAddress.The address to set. Use SystemAddress::FromString() if you want to use a dotted string
[in]indexWhen you have multiple internal IDs, which index to set?

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::SetLimitIPConnectionFrequency ( bool  b)
virtual

Enable or disable allowing frequent connections from the same IP adderss.

This is a security measure which is disabled by default, but can be set to true to prevent attackers from using up all connection slots.

Parameters
[in]bTrue to limit connections from the same ip to at most 1 per 100 milliseconds.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::SetMaximumIncomingConnections ( unsigned short  numberAllowed)
virtual

Sets the maximum number of incoming connections allowed.

If the number of incoming connections is less than the number of players currently connected, no more players will be allowed to connect. If this is greater than the maximum number of peers allowed, it will be reduced to the maximum number of peers allowed.

Defaults to 0, meaning by default, nobody can connect to you

Parameters
[in]numberAllowedMaximum number of incoming connections allowed.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::SetOccasionalPing ( bool  doPing)
virtual

Ping the remote systems every so often, or not. Can be called anytime. By default this is true. Recommended to leave on, because congestion control uses it to determine how often to resend lost packets. It would be true by default to prevent timestamp drift, since in the event of a clock spike, the timestamp deltas would no longer be accurate

Parameters
[in]doPingTrue to start occasional pings. False to stop them.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::SetOfflinePingResponse ( const char *  data,
const unsigned int  length 
)
virtual

Sets the data to send along with a LAN server discovery or offline ping reply.

Parameters
[in]dataBlock of data to send, or 0 for none
[in]lengthLength of the data in bytes, or 0 for none
Note
length should be under 400 bytes, as a security measure against flood attacks
See Also
Ping.cpp

Implements RakNet::RakPeerInterface.

virtual void RakNet::RakPeer::SetPerConnectionOutgoingBandwidthLimit ( unsigned  maxBitsPerSecond)
virtual

Limits how much outgoing bandwidth can be sent per-connection. This limit does not apply to the sum of all connections! Exceeding the limit queues up outgoing traffic

Parameters
[in]maxBitsPerSecondMaximum bits per second to send. Use 0 for unlimited (default). Once set, it takes effect immedately and persists until called again.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::SetSplitMessageProgressInterval ( int  interval)
virtual

Controls how often to return ID_DOWNLOAD_PROGRESS for large message downloads.

ID_DOWNLOAD_PROGRESS is returned to indicate a new partial message chunk, roughly the MTU size, has arrived. As it can be slow or cumbersome to get this notification for every chunk, you can set the interval at which it is returned. Defaults to 0 (never return this notification).

Parameters
[in]intervalHow many messages to use as an interval before a download progress notification is returned.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::SetTimeoutTime ( RakNet::TimeMS  timeMS,
const SystemAddress  target 
)
virtual

Set the time, in MS, to use before considering ourselves disconnected after not being able to deliver a reliable message.

Set the time, in MS, to use before considering ourselves disconnected after not being able to deliver a reliable message. Default time is 10,000 or 10 seconds in release and 30,000 or 30 seconds in debug. Do not set different values for different computers that are connected to each other, or you won't be able to reconnect after ID_CONNECTION_LOST

Parameters
[in]timeMSTime, in MS
[in]targetSystemAddress structure of the target system. Pass UNASSIGNED_SYSTEM_ADDRESS for all systems.

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::SetUnreliableTimeout ( RakNet::TimeMS  timeoutMS)
virtual

Set how long to wait before giving up on sending an unreliable message. Useful if the network is clogged up. Set to 0 or less to never timeout. Defaults to 0.

Parameters
[in]timeoutMSHow many ms to wait before simply not sending an unreliable message.

Implements RakNet::RakPeerInterface.

virtual void RakNet::RakPeer::SetUserUpdateThread ( void(*)(RakPeerInterface *, void *)  _userUpdateThreadPtr,
void *  _userUpdateThreadData 
)
virtual

If you need code to run in the same thread as RakNet's update thread, this function can be used for that

Parameters
[in]_userUpdateThreadPtrC callback function
[in]_userUpdateThreadDataPassed to C callback function

Implements RakNet::RakPeerInterface.

void RakNet::RakPeer::ShiftIncomingTimestamp ( unsigned char *  data,
const SystemAddress systemAddress 
) const
protected

Adjust the timestamp of the incoming packet to be relative to this system.

Parameters
[in]dataData in the incoming packet.
[in]systemAddressSender of the incoming packet.
void RakNet::RakPeer::Shutdown ( unsigned int  blockDuration,
unsigned char  orderingChannel = 0,
PacketPriority  disconnectionNotificationPriority = LOW_PRIORITY 
)
virtual

Stops the network threads and closes all connections.

Parameters
[in]blockDurationWait time(milli seconds) for all remaining messages to go out, including ID_DISCONNECTION_NOTIFICATION. If 0, it doesn't wait at all.
[in]orderingChannelChannel on which ID_DISCONNECTION_NOTIFICATION will be sent, if blockDuration > 0.
[in]disconnectionNotificationPriorityPriority of sending ID_DISCONNECTION_NOTIFICATION. If set to 0, the disconnection notification won't be sent.

Implements RakNet::RakPeerInterface.

StartupResult RakNet::RakPeer::Startup ( unsigned int  maxConnections,
SocketDescriptor socketDescriptors,
unsigned  socketDescriptorCount,
int  threadPriority = -99999 
)
virtual

Starts the network threads and opens the listen port.

You must call this before calling Connect().

Precondition
On the PS3, call Startup() after Client_Login()
Note
Multiple calls while already active are ignored. To call this function again with different settings, you must first call Shutdown().
Call SetMaximumIncomingConnections if you want to accept incoming connections.
Parameters
[in]maxConnectionsMaximum number of connections between this instance of RakPeer and another instance of RakPeer. Required so that the network can preallocate and for thread safety. A pure client would set this to 1. A pure server would set it to the number of allowed clients.A hybrid would set it to the sum of both types of connections.
[in]localPortThe port to listen for connections on. On linux the system may be set up so thast ports under 1024 are restricted for everything but the root user. Use a higher port for maximum compatibility.
[in]socketDescriptorsAn array of SocketDescriptor structures to force RakNet to listen on a particular IP address or port (or both). Each SocketDescriptor will represent one unique socket. Do not pass redundant structures. To listen on a specific port, you can pass SocketDescriptor(myPort,0); such as for a server. For a client, it is usually OK to just pass SocketDescriptor(); However, on the XBOX be sure to use IPPROTO_VDP
[in]socketDescriptorCountThe size of the socketDescriptors array. Pass 1 if you are not sure what to pass.
[in]threadPriorityPassed to the thread creation routine. Use THREAD_PRIORITY_NORMAL for Windows. For Linux based systems, you MUST pass something reasonable based on the thread priorities for your application.
Returns
RAKNET_STARTED on success, otherwise appropriate failure enumeration.

Implements RakNet::RakPeerInterface.

Member Data Documentation

RemoteSystemStruct** RakNet::RakPeer::activeSystemList
protected

activeSystemList holds a list of pointers and is preallocated to be the same size as remoteSystemList. It is updated only by the network thread, but read by both threads When the isActive member of RemoteSystemStruct is set to true or false, that system is added to this list of pointers Threadsafe because RemoteSystemStruct is preallocated, and the list is only added to, not removed from

bool RakNet::RakPeer::allowConnectionResponseIPMigration
protected

How long it has been since things were updated by a call to receiveUpdate thread uses this to determine how long to sleep for.

True to allow connection accepted packets from anyone. False to only allow these packets from servers we requested a connection to.

unsigned int RakNet::RakPeer::bytesSentPerSecond
protected

The list of people we have tried to connect to recently.

Data that both the client and the server needs

unsigned int RakNet::RakPeer::maximumIncomingConnections
protected

Store the maximum number of peers able to connect, including reserved connection slots for pings, etc.

Store the maximum incoming connection allowed

* unsigned int RakNet::RakPeer::maximumNumberOfPeers
protected

Store the maximum number of peers allowed to connect.

Do we occasionally ping the other systems?

RemoteSystemStruct* RakNet::RakPeer::remoteSystemList
protected

This is an array of pointers to RemoteSystemStruct This allows us to preallocate the list when starting, so we don't have to allocate or delete at runtime. Another benefit is that is lets us add and remove active players simply by setting systemAddress and moving elements in the list by copying pointers variables without affecting running threads, even if they are in the reliability layer

SimpleMutex RakNet::RakPeer::sendReceiptSerialMutex
protected

This is used to return a number to the user when they call Send identifying the message This number will be returned back with ID_SND_RECEIPT_ACKED or ID_SND_RECEIPT_LOSS and is only returned with the reliability types that contain RECEIPT in the name


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