Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

RakPeer Class Reference

The lowest communication end point in RakNet. More...

#include <RakPeer.h>

Inheritance diagram for RakPeer:

RakPeerInterface RakClient RakServer List of all members.

Public Member Functions

 RakPeer ()
virtual ~RakPeer ()
bool Initialize (unsigned short MaximumNumberOfPeers, unsigned short localPort, int _threadSleepTimer)
void InitializeSecurity (char *pubKeyP, char *pubKeyQ, char *privKeyE, char *privKeyN)
virtual void DisableSecurity (void)
void SetMaximumIncomingConnections (unsigned short numberAllowed)
unsigned short GetMaximumIncomingConnections (void) const
void SetIncomingPassword (char *passwordData, int passwordDataLength)
RakNet::BitStreamGetIncomingPassword (void)
bool Connect (char *host, unsigned short remotePort, char *passwordData, int passwordDataLength)
virtual void Disconnect (unsigned long blockDuration)
bool IsActive (void) const
bool GetConnectionList (PlayerID *remoteSystems, unsigned short *numberOfSystems) const
bool Send (char *data, const long length, PacketPriority priority, PacketReliability reliability, char orderingChannel, PlayerID playerId, bool broadcast)
bool Send (RakNet::BitStream *bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, PlayerID playerId, bool broadcast)
PacketReceive (void)
void DeallocatePacket (Packet *packet)
unsigned short GetMaximumNumberOfPeers (void) const
void RegisterAsRemoteProcedureCall (char *uniqueID, void(*functionName)(char *input, int numberOfBitsOfData, PlayerID sender))
void UnregisterAsRemoteProcedureCall (char *uniqueID)
bool RPC (char *uniqueID, char *data, unsigned long bitLength, PacketPriority priority, PacketReliability reliability, char orderingChannel, PlayerID playerId, bool broadcast, bool shiftTimestamp)
bool RPC (char *uniqueID, RakNet::BitStream *bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, PlayerID playerId, bool broadcast, bool shiftTimestamp)
void CloseConnection (PlayerID target, bool sendDisconnectionNotification, unsigned long blockDuration)
int GetIndexFromPlayerID (PlayerID playerId)
PlayerID GetPlayerIDFromIndex (int index)
void AddToBanList (const char *IP)
void RemoveFromBanList (const char *IP)
void ClearBanList (void)
bool IsBanned (const char *IP)
void Ping (PlayerID target)
void Ping (char *host, unsigned short remotePort, bool onlyReplyOnAcceptingConnections)
int GetAveragePing (PlayerID target)
int GetLastPing (PlayerID target) const
int GetLowestPing (PlayerID target) const
void SetOccasionalPing (bool doPing)
RakNet::BitStreamGetRemoteStaticData (PlayerID playerId)
void SetRemoteStaticData (PlayerID playerId, char *data, const long length)
void SendStaticData (PlayerID target)
void SetOfflinePingResponse (char *data, const unsigned long length)
PlayerID GetInternalID (void) const
PlayerID GetExternalID (PlayerID target) const
bool SetMTUSize (int size)
int GetMTUSize (void) const
unsigned GetNumberOfAddresses (void)
const char * PlayerIDToDottedIP (PlayerID playerId) const
void IPToPlayerID (const char *host, unsigned short remotePort, PlayerID *playerId)
const char * GetLocalIP (unsigned int index)
void AllowConnectionResponseIPMigration (bool allow)
void AdvertiseSystem (char *host, unsigned short remotePort)
void SetCompileFrequencyTable (bool doCompile)
bool GetOutgoingFrequencyTable (unsigned long outputFrequencyTable[256])
bool GenerateCompressionLayer (unsigned long inputFrequencyTable[256], bool inputLayer)
bool DeleteCompressionLayer (bool inputLayer)
float GetCompressionRatio (void) const
float GetDecompressionRatio (void) const
void GetPasswordData (char *passwordData, int *passwordDataLength)
void PushBackPacket (Packet *packet)
RakNetStatisticsStruct *const GetStatistics (PlayerID playerId)

Protected Types

enum  {
  requestedConnections_MUTEX, incomingPasswordBitStream_Mutex, outgoingPasswordBitStream_Mutex, remoteSystemList_Mutex,
  offlinePingResponse_Mutex, NUMBER_OF_RAKPEER_MUTEXES
}

Protected Member Functions

void RecordConnectionAttempt (const char *host, unsigned short remotePort)
void RemoveFromRequestedConnectionsList (PlayerID playerId)
bool SendConnectionRequest (const char *host, unsigned short remotePort)
RemoteSystemStructGetRemoteSystemFromPlayerID (PlayerID playerID) const
void HandleConnectionRequest (PlayerID playerId, unsigned char *AESKey, bool setAESKey)
unsigned GetNumberOfIncomingConnections (void) const
RemoteSystemStructAssignPlayerIDToRemoteSystemList (PlayerID playerId, unsigned char *AESKey, bool setAESKey)
void ResetRemoteSystemData (RemoteSystemStruct *remoteSystem, bool weInitiatedTheConnection)
void ShiftIncomingTimestamp (char *data, PlayerID playerId) const
unsigned long GetBestClockDifferential (PlayerID playerId) const
void PushPortRefused (PlayerID target)
bool HandleRPCPacket (char *data, int length, PlayerID playerId)
void GenerateSYNCookieRandomNumber (void)
void SecuredConnectionResponse (PlayerID playerId)
void SecuredConnectionConfirmation (PlayerID playerId, char *data)
bool RunUpdateCycle (void)

Protected Attributes

bool endThreads
bool isMainLoopThreadActive
bool occasionalPing
unsigned short maximumNumberOfPeers
unsigned short maximumIncomingConnections
RakNet::BitStream incomingPasswordBitStream
RakNet::BitStream outgoingPasswordBitStream
RakNet::BitStream localStaticData
RakNet::BitStream offlinePingResponse
PlayerID myPlayerId
RemoteSystemStructremoteSystemList
SimpleMutex rakPeerMutexes [NUMBER_OF_RAKPEER_MUTEXES]
bool updateCycleIsRunning
BasicDataStructures::Queue<
RequestedConnectionStruct * > 
requestedConnectionsList
unsigned long bytesSentPerSecond
unsigned long bytesReceivedPerSecond
unsigned long validationInteger
pthread_t processPacketsThreadHandle
pthread_t recvfromThreadHandle
SimpleMutex incomingQueueMutex
SimpleMutex banListMutex
BasicDataStructures::Queue<
Packet * > 
incomingPacketQueue
BasicDataStructures::List<
char * > 
banList
unsigned long frequencyTable [256]
HuffmanEncodingTreeinputTree
HuffmanEncodingTreeoutputTree
unsigned long rawBytesSent
unsigned long rawBytesReceived
unsigned long compressedBytesSent
unsigned long compressedBytesReceived
BasicDataStructures::AVLBalancedBinarySearchTree<
RPCNode
rpcTree
int MTUSize
bool trackFrequencyTable
int threadSleepTimer
SOCKET connectionSocket
big::RSACrypt< RSA_BIT_SIZE > rsacrypt
big::u32 publicKeyP
RSA_BIT_SIZE publicKeyQ
bool keysLocallyGenerated
bool usingSecurity
unsigned long randomNumberExpirationTime
unsigned char newRandomNumber [20]
unsigned char oldRandomNumber [20]
unsigned long lastUserUpdateCycle
bool allowConnectionResponseIPMigration

Friends

void ProcessNetworkPacket (unsigned long binaryAddress, unsigned short port, char *data, int length, RakPeer *rakPeer)
void * UpdateNetworkLoop (void *arguments)

Classes

struct  MemoryBlock
 Automatic Variable Synchronization Mechanism. More...
struct  PingAndClockDifferential
 Used to unify time. More...
struct  RemoteSystemStruct
 Store Remote System Description. More...

Detailed Description

The lowest communication end point in RakNet.

This class provide the lowest communication end point in RakNet. It is recommended that you use it if you are going to be at the same time client and server.


Member Enumeration Documentation

anonymous enum [protected]
 

Enumeration values:
requestedConnections_MUTEX 
incomingPasswordBitStream_Mutex 
outgoingPasswordBitStream_Mutex 
remoteSystemList_Mutex  This mutex is a writer lock for reserving player IDs only
offlinePingResponse_Mutex 
NUMBER_OF_RAKPEER_MUTEXES 


Constructor & Destructor Documentation

RakPeer::RakPeer  ) 
 

Constructor

RakPeer::~RakPeer  )  [virtual]
 

Destructor


Member Function Documentation

void RakPeer::AddToBanList const char *  IP  )  [virtual]
 

Bans an IP from connecting. Banned IPs persist between connections.

Parameters:
IP Dotted IP address. Can use * as a wildcard, such as 128.0.0.* will ban All IP addresses starting with 128.0.0

Implements RakPeerInterface.

Reimplemented in RakServer.

void RakPeer::AdvertiseSystem char *  host,
unsigned short  remotePort
[virtual]
 

Sends a one byte message ID_ADVERTISE_SYSTEM to the remote unconnected system. This will tell the remote system our external IP outside the LAN, and can be used for NAT punch through

Requires: The sender and recipient must already be started via a successful call to Initialize

Parameters:
host Either a dotted IP address or a domain name
remotePort Which port to connect to on the remote machine.

Implements RakPeerInterface.

Reimplemented in RakClient, and RakServer.

void RakPeer::AllowConnectionResponseIPMigration bool  allow  ) 
 

Allow or disallow connection responses from any IP. Normally this should be false, but may be necessary when connection to servers with multiple IP addresses.

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

Reimplemented from RakPeerInterface.

Reimplemented in RakClient.

RakPeer::RemoteSystemStruct * RakPeer::AssignPlayerIDToRemoteSystemList PlayerID  playerId,
unsigned char *  AESKey,
bool  setAESKey
[protected]
 

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

void RakPeer::ClearBanList void   )  [virtual]
 

Allows all previously banned IPs to connect.

Implements RakPeerInterface.

Reimplemented in RakServer.

void RakPeer::CloseConnection PlayerID  target,
bool  sendDisconnectionNotification,
unsigned long  blockDuration
[virtual]
 

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

Parameters:
target Which connection to close
sendDisconnectionNotification True to send ID_DISCONNECTION_NOTIFICATION to the recipient. False to close it silently.
blockDuration How long you should wait for all remaining packets to go out, per connected system If you set it to 0 then the disconnection notification probably won't arrive

Implements RakPeerInterface.

bool RakPeer::Connect char *  host,
unsigned short  remotePort,
char *  passwordData,
int  passwordDataLength
[virtual]
 

Call this to 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. You know the connection is successful when IsConnected() returns true or receive gets a packet with the type identifier ID_CONNECTION_ACCEPTED. If the connection is not successful, such as rejected connection or no response then neither of these things will happen. Requires that you first call Initialize

Parameters:
host Either a dotted IP address or a domain name
remotePort Which port to connect to on the remote machine.
passwordData A data block that must match the data block on the server. This can be just a password, or can be a stream of data
passwordDataLength The length in bytes of passwordData
Returns:
True on successful initiation. False on incorrect parameters, internal error, or too many existing peers

Implements RakPeerInterface.

void RakPeer::DeallocatePacket Packet packet  )  [virtual]
 

Call this to deallocate a packet returned by Receive when you are done handling it.

Parameters:
packet A packet to free

Implements RakPeerInterface.

Reimplemented in RakClient, and RakServer.

bool RakPeer::DeleteCompressionLayer bool  inputLayer  )  [virtual]
 

Deletes the output or input layer as specified. This is not necessary to call and is only valuable for freeing memory You should only call this when disconnected

Parameters:
inputLayer Specifies the corresponding compression layer generated by GenerateCompressionLayer.
Returns:
False on failure (we are connected). True otherwise

Implements RakPeerInterface.

Reimplemented in RakClient, and RakServer.

void RakPeer::DisableSecurity void   )  [virtual]
 

Disables all security.

Note:
Must be called while offline

Implements RakPeerInterface.

Reimplemented in RakServer.

void RakPeer::Disconnect unsigned long  blockDuration  )  [virtual]
 

Stops the network threads and close all connections. Multiple calls are ok.

Parameters:
blockDuration How long you should wait for all remaining packets to go out, per connected system If you set it to 0 then the disconnection notification probably won't arrive

Implements RakPeerInterface.

Reimplemented in RakClient, and RakServer.

bool RakPeer::GenerateCompressionLayer unsigned long  inputFrequencyTable[256],
bool  inputLayer
[virtual]
 

Generates the compression layer from the input frequency table. You should call this twice - once with inputLayer as true and once as false. The frequency table passed here with inputLayer=true should match the frequency table on the recipient with inputLayer=false. Likewise, the frequency table passed here with inputLayer=false should match the frequency table on the recipient with inputLayer=true Calling this function when there is an existing layer will overwrite the old layer You should only call this when disconnected

Parameters:
inputFrequencyTable The frequency table returned from GetSendFrequencyTable(...);
inputLayer Whether inputFrequencyTable represents incoming data from other systems (true) or outgoing data from this system (false)
Returns:
False on failure (we are connected). True otherwise

Implements RakPeerInterface.

Reimplemented in RakClient, and RakServer.

void RakPeer::GenerateSYNCookieRandomNumber void   )  [protected]
 

int RakPeer::GetAveragePing PlayerID  target  )  [virtual]
 

Gets the average of all ping times read for a specified target

Parameters:
target whose time to read
Returns:
The average of all ping times read for a specified target.

Implements RakPeerInterface.

Reimplemented in RakServer.

unsigned long RakPeer::GetBestClockDifferential PlayerID  playerId  )  const [protected]
 

Get the most probably accurate clock differential for a certain player

float RakPeer::GetCompressionRatio void   )  const [virtual]
 

Get the compression ratio. A low compression ratio is good. Compression is for outgoing data

Returns:
The compression ratio.

Implements RakPeerInterface.

Reimplemented in RakClient, and RakServer.

bool RakPeer::GetConnectionList PlayerID remoteSystems,
unsigned short *  numberOfSystems
const [virtual]
 

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

Parameters:
[out] remoteSystems An array of PlayerID structures to be filled with the PlayerIDs of the systems we are connected to
  • pass 0 to remoteSystems to only get the number of systems we are connected to
numberOfSystems As input, the size of remoteSystems array. As output, the number of elements put into the array

Implements RakPeerInterface.

float RakPeer::GetDecompressionRatio void   )  const [virtual]
 

Get the decompression ratio. A high decompression ratio is good. Decompression is for incoming data

Returns:
The decompression ratio.

Implements RakPeerInterface.

Reimplemented in RakClient, and RakServer.

PlayerID RakPeer::GetExternalID PlayerID  target  )  const [virtual]
 

Return the unique address identifier that represents you on the the network and is based on your external IP / port (the IP / port the specified player uses to communicate with you)

Note:
that unlike in previous versions, this is a struct and is not sequential
Parameters:
target Which remote system you are referring to for your external ID

Implements RakPeerInterface.

RakNet::BitStream * RakPeer::GetIncomingPassword void   ) 
 

Get the password set by SetIncomingPassword in a BitStream

Returns:
The password in a BitStream.

Reimplemented from RakPeerInterface.

int RakPeer::GetIndexFromPlayerID PlayerID  playerId  )  [virtual]
 

Given a playerID, returns an index from 0 to the maximum number of players allowed - 1.

Parameters:
playerId The playerID to search for
Returns:
An integer from 0 to the maximum number of peers -1, or -1 if that player is not found

Implements RakPeerInterface.

Reimplemented in RakServer.

PlayerID RakPeer::GetInternalID void   )  const [virtual]
 

Return the unique address identifier that represents you on the the network and is based on your local IP / port Note that unlike in previous versions, this is a struct and is not sequential

Implements RakPeerInterface.

int RakPeer::GetLastPing PlayerID  target  )  const [virtual]
 

Gets the last ping time read for the specific player or -1 if none read yet

Parameters:
target whose time to read
Returns:
Just the last ping

Implements RakPeerInterface.

const char * RakPeer::GetLocalIP unsigned int  index  )  [virtual]
 

Returns an IP address at index 0 to GetNumberOfAddresses-1

Implements RakPeerInterface.

Reimplemented in RakServer.

int RakPeer::GetLowestPing PlayerID  target  )  const [virtual]
 

Gets the lowest ping time read or -1 if none read yet

Parameters:
target whose time to read
Returns:
the lowest ping time

Implements RakPeerInterface.

unsigned short RakPeer::GetMaximumIncomingConnections void   )  const [virtual]
 

Get the number of maximum incomming connection.

Returns:
the maximum number of incoming connections, which is always <= MaximumNumberOfPeers

Implements RakPeerInterface.

unsigned short RakPeer::GetMaximumNumberOfPeers void   )  const [virtual]
 

Return the total number of connections we are allowed

Implements RakPeerInterface.

int RakPeer::GetMTUSize void   )  const [virtual]
 

Returns the current MTU size

Returns:
The MTU sized specified in SetMTUSize

Implements RakPeerInterface.

Reimplemented in RakClient, and RakServer.

unsigned int RakPeer::GetNumberOfAddresses void   )  [virtual]
 

Returns the number of IP addresses we have

Implements RakPeerInterface.

Reimplemented in RakServer.

unsigned RakPeer::GetNumberOfIncomingConnections void   )  const [protected]
 

Returns how many remote systems initiated a connection to us

bool RakPeer::GetOutgoingFrequencyTable unsigned long  outputFrequencyTable[256]  )  [virtual]
 

Returns the frequency of outgoing bytes into outputFrequencyTable The purpose is to save to file as either a master frequency table from a sample game session for passing to GenerateCompressionLayer(false); You should only call this when disconnected. Requires that you first enable data frequency tracking by calling SetCompileFrequencyTable(true)

Parameters:
[out] outputFrequencyTable The frequency of each corresponding byte
Returns:
False (failure) if connected or if frequency table tracking is not enabled. Otherwise true (success)

Implements RakPeerInterface.

void RakPeer::GetPasswordData char *  passwordData,
int *  passwordDataLength
[virtual]
 

Retrieves the data you passed to the passwordData parameter in Connect

Parameters:
[out] passwordData Should point to a block large enough to hold the password data you passed to Connect
passwordDataLength Maximum size of the array passwordData. Modified to hold the number of bytes actually written

Implements RakPeerInterface.

PlayerID RakPeer::GetPlayerIDFromIndex int  index  )  [virtual]
 

This function is only useful for looping through all players.

Parameters:
index an integer between 0 and the maximum number of players allowed - 1.
Returns:
A valid playerID or UNASSIGNED_PLAYER_ID if no such player at that index

Implements RakPeerInterface.

Reimplemented in RakServer.

RakNet::BitStream * RakPeer::GetRemoteStaticData PlayerID  playerId  )  [virtual]
 

All systems have a block of data associated with them, for user use. This block of data can be used to easily specify typical system data that you want to know on connection, such as the player's name.

Parameters:
playerId Which system you are referring to. Pass the value returned by GetInternalID to refer to yourself
Returns:
The data passed to SetRemoteStaticData stored as a bitstream

Implements RakPeerInterface.

RakPeer::RemoteSystemStruct * RakPeer::GetRemoteSystemFromPlayerID PlayerID  playerID  )  const [protected]
 

Get the reliability layer associated with a playerID.

Parameters:
playerID The player identifier
Returns:
0 if none

RakNetStatisticsStruct *const RakPeer::GetStatistics PlayerID  playerId  )  [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:
playerId Which connected system to get statistics for
Returns:
0 on can't find the specified system. A pointer to a set of data otherwise.

Implements RakPeerInterface.

Reimplemented in RakServer.

void RakPeer::HandleConnectionRequest PlayerID  playerId,
unsigned char *  AESKey,
bool  setAESKey
[protected]
 

When we get a connection request from an ip / port, either accept or reject it

bool RakPeer::HandleRPCPacket char *  data,
int  length,
PlayerID  playerId
[protected]
 

Handles an RPC packet. If you get a packet with the ID ID_RPC you should pass it to this function This is already done in Multiplayer.cpp, so if you use the Multiplayer class it is handled for you.

Parameters:
data A packet returned from Receive with the ID ID_RPC
length The size of the packet data
playerId The sender of the packet
Returns:
true on success, false on a bad packet or an unregistered function

bool RakPeer::Initialize unsigned short  MaximumNumberOfPeers,
unsigned short  localPort,
int  _threadSleepTimer
[virtual]
 

Starts the network threads, opens the listen port You must call this before calling SetMaximumIncomingConnections or Connect Multiple calls while already active are ignored. To call this function again with different settings, you must first call Disconnect() To accept incoming connections, use SetMaximumIncomingConnections

Parameters:

Parameters:
MaximumNumberOfPeers Required so 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
localPort The port to listen for connections on.
_threadSleepTimer >=0 for how many ms to Sleep each internal update cycle (recommended 30 for low performance, 0 for regular)
Returns:
False on failure (can't create socket or thread), true on success.

Implements RakPeerInterface.

void RakPeer::InitializeSecurity char *  pubKeyP,
char *  pubKeyQ,
char *  privKeyE,
char *  privKeyN
[virtual]
 

Must be called while offline Secures connections though a combination of SHA1, AES128, SYN Cookies, and RSA to prevent connection spoofing, replay attacks, data eavesdropping, packet tampering, and MitM attacks. There is a significant amount of processing and a slight amount of bandwidth overhead for this feature.

If you accept connections, you must call this or else secure connections will not be enabled for incoming connections. If you are connecting to another system, you can call this with values for the (e and p,q) public keys before connecting to prevent MitM

Parameters:
pubKeyP Public key generated from the RSACrypt class.
pubKeyQ Public key generated from the RSACrypt class.
privKeyE A pointer to the private keys from the RSACrypt class.
privKeyN A pointer to the private keys from the RSACrypt class. If the private keys are 0, then a new key will be generated when this function is called
See also:
the Encryption sample

Implements RakPeerInterface.

void RakPeer::IPToPlayerID const char *  host,
unsigned short  remotePort,
PlayerID playerId
[virtual]
 

Converts a dotted IP to a playerId

Parameters:
[in] host Either a dotted IP address or a domain name
[in] remotePort Which port to connect to on the remote machine.
[out] playerId The result of this operation

Implements RakPeerInterface.

bool RakPeer::IsActive void   )  const [virtual]
 

Returns true if the network threads are running

Implements RakPeerInterface.

Reimplemented in RakServer.

bool RakPeer::IsBanned const char *  IP  )  [virtual]
 

Determines if a particular IP is banned.

Parameters:
IP Complete dotted IP address
Returns:
  • True if IP matches any IPs in the ban list, accounting for any wildcards.
  • False otherwise.

Implements RakPeerInterface.

Reimplemented in RakServer.

void RakPeer::Ping char *  host,
unsigned short  remotePort,
bool  onlyReplyOnAcceptingConnections
[virtual]
 

Send a ping to the specified unconnected system. The remote system, if it is Initialized, will respond with ID_PONG. The final ping time will be encoded in the following 4 bytes (2-5) as an unsigned long

Requires: The sender and recipient must already be started via a successful call to Initialize

Parameters:
host Either a dotted IP address or a domain name. Can be 255.255.255.255 for LAN broadcast.
remotePort Which port to connect to on the remote machine.
onlyReplyOnAcceptingConnections Only request a reply if the remote system is accepting connections

Implements RakPeerInterface.

void RakPeer::Ping PlayerID  target  )  [virtual]
 

Send a ping to the specified connected system.

Parameters:
target who to ping

Implements RakPeerInterface.

const char * RakPeer::PlayerIDToDottedIP PlayerID  playerId  )  const [virtual]
 

Returns the dotted IP address for the specified playerId

Parameters:
playerId Any player ID other than UNASSIGNED_PLAYER_ID, even if that player is not currently connected

Implements RakPeerInterface.

Reimplemented in RakClient.

void RakPeer::PushBackPacket Packet packet  )  [virtual]
 

Put a packet back at the end of the receive queue in case you don't want to deal with it immediately

Parameters:
packet The packet you want to push back.

Implements RakPeerInterface.

Reimplemented in RakClient, and RakServer.

void RakPeer::PushPortRefused PlayerID  target  )  [protected]
 

Todo:
Document this

Packet * RakPeer::Receive void   )  [virtual]
 

Gets a packet from the incoming packet queue. Use DeallocatePacket to deallocate the packet after you are done with it. Check the Packet struct at the top of CoreNetworkStructures.h for the format of the struct

Returns:
0 if no packets are waiting to be handled, otherwise an allocated packet If the client is not active this will also return 0, as all waiting packets are flushed when the client is Disconnected This also updates all memory blocks associated with synchronized memory and distributed objects

Implements RakPeerInterface.

Reimplemented in RakClient, and RakServer.

void RakPeer::RecordConnectionAttempt const char *  host,
unsigned short  remotePort
[protected]
 

void RakPeer::RemoveFromBanList const char *  IP  )  [virtual]
 

Allows a previously banned IP to connect.

Parameters:
IP Dotted IP address. Can use * as a wildcard, such as 128.0.0.* will unban All IP addresses starting with 128.0.0

Implements RakPeerInterface.

Reimplemented in RakServer.

void RakPeer::RemoveFromRequestedConnectionsList PlayerID  playerId  )  [protected]
 

void RakPeer::ResetRemoteSystemData RemoteSystemStruct remoteSystem,
bool  weInitiatedTheConnection
[protected]
 

Reset the variables for a remote system

bool RakPeer::RunUpdateCycle void   )  [protected]
 

void RakPeer::SecuredConnectionConfirmation PlayerID  playerId,
char *  data
[protected]
 

void RakPeer::SecuredConnectionResponse PlayerID  playerId  )  [protected]
 

bool RakPeer::Send RakNet::BitStream bitStream,
PacketPriority  priority,
PacketReliability  reliability,
char  orderingChannel,
PlayerID  playerId,
bool  broadcast
[virtual]
 

Sends a block of data to the specified system that you are connected to. This function only works while the client is connected (Use the Connect function).

Parameters:
bitStream The bitstream to send
priority What priority level to send on.
reliability How reliability to send this data
orderingChannel When using ordered or sequenced packets, what channel to order these on.
  • Packets are only ordered relative to other packets on the same stream
playerId Who to send this packet to, or in the case of broadcasting who not to send it to. Use UNASSIGNED_PLAYER_ID to specify none
broadcast True to send this packet to all connected systems. If true, then playerId specifies who not to send the packet to.
Returns:
False if we are not connected to the specified recipient. True otherwise

Implements RakPeerInterface.

Reimplemented in RakServer.

bool RakPeer::Send char *  data,
const long  length,
PacketPriority  priority,
PacketReliability  reliability,
char  orderingChannel,
PlayerID  playerId,
bool  broadcast
[virtual]
 

Sends a block of data to the specified system that you are connected to. This function only works while the client is connected (Use the Connect function).

Parameters:
data The block of data to send
length The size in bytes of the data to send
priority What priority level to send on.
reliability How reliability to send this data
orderingChannel When using ordered or sequenced packets, what channel to order these on.
  • Packets are only ordered relative to other packets on the same stream
playerId Who to send this packet to, or in the case of broadcasting who not to send it to. Use UNASSIGNED_PLAYER_ID to specify none
broadcast True to send this packet to all connected systems. If true, then playerId specifies who not to send the packet to.
Returns:
False if we are not connected to the specified recipient. True otherwise

Implements RakPeerInterface.

Reimplemented in RakServer.

bool RakPeer::SendConnectionRequest const char *  host,
unsigned short  remotePort
[protected]
 

void RakPeer::SendStaticData PlayerID  target  )  [virtual]
 

Sends your static data to the specified system. This is automatically done on connection. You should call this when you change your static data. To send the static data of another system (such as relaying their data) you should do this normally with Send

Parameters:
target Who to send your static data to. Specify UNASSIGNED_PLAYER_ID to broadcast to all

Implements RakPeerInterface.

void RakPeer::SetCompileFrequencyTable bool  doCompile  )  [virtual]
 

Enables or disables our tracking of bytes input to and output from the network. This is required to get a frequency table, which is used to generate a new compression layer. You can call this at any time - however you SHOULD only call it when disconnected. Otherwise you will only track part of the values sent over the network. This value persists between connect calls and defaults to false (no frequency tracking)

Parameters:
doCompile - true to track bytes. Defaults to false

Implements RakPeerInterface.

void RakPeer::SetIncomingPassword char *  passwordData,
int  passwordDataLength
[virtual]
 

Sets the password incoming connections must match in the call to Connect (defaults to none) Pass 0 to passwordData to specify no password

Parameters:
passwordData A 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
passwordDataLength The length in bytes of passwordData

Implements RakPeerInterface.

void RakPeer::SetMaximumIncomingConnections unsigned short  numberAllowed  )  [virtual]
 

Sets how many incoming connections are allowed. If this 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.

Parameters:
numberAllowed Maximum number of incoming connections allowed.

Implements RakPeerInterface.

bool RakPeer::SetMTUSize int  size  )  [virtual]
 

Change the MTU size in order to improve performance when sending large packets This can only be called when not connected. A too high of value will cause packets not to arrive at worst and be fragmented at best. A too low of value will split packets unnecessarily.

Parameters:

Parameters:
size,: Set according to the following table:
  • 1500. The largest Ethernet packet size; it is also the default value. This is the typical setting for non-PPPoE, non-VPN connections. The default value for NETGEAR routers, adapters and switches.
  • 1492. The size PPPoE prefers.
  • 1472. Maximum size to use for pinging. (Bigger packets are fragmented.)
  • 1468. The size DHCP prefers.
  • 1460. Usable by AOL if you don't have large email attachments, etc.
  • 1430. The size VPN and PPTP prefer.
  • 1400. Maximum size for AOL DSL.
  • 576. Typical value to connect to dial-up ISPs. (Default)
Returns:
False on failure (we are connected). True on success. Maximum allowed size is MAXIMUM_MTU_SIZE

Implements RakPeerInterface.

Reimplemented in RakClient, and RakServer.

void RakPeer::SetOccasionalPing bool  doPing  )  [virtual]
 

Ping the remote systems every so often. This is off by default This will work anytime

Parameters:
doPing True to start occasional pings. False to stop them.

Implements RakPeerInterface.

void RakPeer::SetOfflinePingResponse char *  data,
const unsigned long  length
[virtual]
 

Sets the data to send with an (LAN server discovery) /(offline ping) response See the Ping sample project for how this is used.

Parameters:
data a block of data to store, or 0 for none
length The length of data in bytes, or 0 for none

Implements RakPeerInterface.

Reimplemented in RakServer.

void RakPeer::SetRemoteStaticData PlayerID  playerId,
char *  data,
const long  length
[virtual]
 

All systems have a block of data associated with them, for user use. This block of data can be used to easily specify typical system data that you want to know on connection, such as the player's name.

Parameters:
playerId Whose static data to change. Use your own playerId to change your own static data
data a block of data to store
length The length of data in bytes

Implements RakPeerInterface.

void RakPeer::ShiftIncomingTimestamp char *  data,
PlayerID  playerId
const [protected]
 

An incoming packet has a timestamp, so adjust it to be relative to this system


Friends And Related Function Documentation

void ProcessNetworkPacket unsigned long  binaryAddress,
unsigned short  port,
char *  data,
int  length,
RakPeer rakPeer
[friend]
 

void* UpdateNetworkLoop void *  arguments  )  [friend]
 


Member Data Documentation

bool RakPeer::allowConnectionResponseIPMigration [protected]
 

BasicDataStructures::List<char*> RakPeer::banList [protected]
 

SimpleMutex RakPeer::banListMutex [protected]
 

unsigned long RakPeer::bytesReceivedPerSecond [protected]
 

Data that both the client and the server needs

unsigned long RakPeer::bytesSentPerSecond [protected]
 

Data that both the client and the server needs

unsigned long RakPeer::compressedBytesReceived [protected]
 

unsigned long RakPeer::compressedBytesSent [protected]
 

SOCKET RakPeer::connectionSocket [protected]
 

bool RakPeer::endThreads [protected]
 

Set this to true to terminate the Peer thread execution

unsigned long RakPeer::frequencyTable[256] [protected]
 

BasicDataStructures::Queue<Packet *> RakPeer::incomingPacketQueue [protected]
 

RakNet::BitStream RakPeer::incomingPasswordBitStream [protected]
 

localStaticData necessary because we may not have a RemoteSystemStruct representing ourselves in the list

SimpleMutex RakPeer::incomingQueueMutex [protected]
 

HuffmanEncodingTree* RakPeer::inputTree [protected]
 

bool RakPeer::isMainLoopThreadActive [protected]
 

true if the peer thread is active.

bool RakPeer::keysLocallyGenerated [protected]
 

unsigned long RakPeer::lastUserUpdateCycle [protected]
 

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

RakNet::BitStream RakPeer::localStaticData [protected]
 

localStaticData necessary because we may not have a RemoteSystemStruct representing ourselves in the list

unsigned short RakPeer::maximumIncomingConnections [protected]
 

Store the maximum incoming connection allowed

unsigned short RakPeer::maximumNumberOfPeers [protected]
 

Store the maximal number of peer

int RakPeer::MTUSize [protected]
 

PlayerID RakPeer::myPlayerId [protected]
 

Local Player ID

unsigned char RakPeer::newRandomNumber[20] [protected]
 

bool RakPeer::occasionalPing [protected]
 

Do we occasionally ping the other systems?

RakNet::BitStream RakPeer::offlinePingResponse [protected]
 

localStaticData necessary because we may not have a RemoteSystemStruct representing ourselves in the list

unsigned char RakPeer::oldRandomNumber[20] [protected]
 

RakNet::BitStream RakPeer::outgoingPasswordBitStream [protected]
 

localStaticData necessary because we may not have a RemoteSystemStruct representing ourselves in the list

HuffmanEncodingTree * RakPeer::outputTree [protected]
 

pthread_t RakPeer::processPacketsThreadHandle [protected]
 

big::u32 RakPeer::publicKeyP [protected]
 

RSA_BIT_SIZE RakPeer::publicKeyQ [protected]
 

SimpleMutex RakPeer::rakPeerMutexes[NUMBER_OF_RAKPEER_MUTEXES] [protected]
 

unsigned long RakPeer::randomNumberExpirationTime [protected]
 

unsigned long RakPeer::rawBytesReceived [protected]
 

unsigned long RakPeer::rawBytesSent [protected]
 

pthread_t RakPeer::recvfromThreadHandle [protected]
 

RemoteSystemStruct* 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 playerId and moving elements in the list by copying pointers variables without affecting running threads, even if they are in the reliability layer

BasicDataStructures::Queue<RequestedConnectionStruct*> RakPeer::requestedConnectionsList [protected]
 

The list of people we have tried to connect to recently

BasicDataStructures::AVLBalancedBinarySearchTree<RPCNode> RakPeer::rpcTree [protected]
 

big::RSACrypt<RSA_BIT_SIZE> RakPeer::rsacrypt [protected]
 

int RakPeer::threadSleepTimer [protected]
 

bool RakPeer::trackFrequencyTable [protected]
 

bool RakPeer::updateCycleIsRunning [protected]
 

RunUpdateCycle is not thread safe but we don't need to mutex calls. Just skip calls if it is running already

bool RakPeer::usingSecurity [protected]
 

unsigned long RakPeer::validationInteger [protected]
 


The documentation for this class was generated from the following files:
Generated on Mon May 30 17:45:42 2005 for raknet by  doxygen 1.4.2