RakClient Class Reference

Defines the functions used by a game client. More...

#include <RakClient.h>

Inheritance diagram for RakClient:

RakPeer RakClientInterface RakPeerInterface List of all members.

Public Member Functions

 RakClient ()
 Constructor.
virtual ~RakClient ()
 Destructor.
bool Connect (const char *host, unsigned short serverPort, unsigned short clientPort, unsigned int depreciated, int threadSleepTimer)
void Disconnect (unsigned int blockDuration, unsigned char orderingChannel=0)
void InitializeSecurity (const char *privKeyP, const char *privKeyQ)
void SetPassword (const char *_password)
bool HasPassword (void) const
bool Send (const char *data, const int length, PacketPriority priority, PacketReliability reliability, char orderingChannel)
bool Send (RakNet::BitStream *bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel)
PacketReceive (void)
void DeallocatePacket (Packet *packet)
void PingServer (void)
 Send a ping to the server.
void PingServer (const char *host, unsigned short serverPort, unsigned short clientPort, bool onlyReplyOnAcceptingConnections)
int GetAveragePing (void)
 Returns the average of all ping times read.
int GetLastPing (void) const
int GetLowestPing (void) const
int GetPlayerPing (const PlayerID playerId)
void StartOccasionalPing (void)
void StopOccasionalPing (void)
bool IsConnected (void) const
unsigned int GetSynchronizedRandomInteger (void) const
bool GenerateCompressionLayer (unsigned int inputFrequencyTable[256], bool inputLayer)
bool DeleteCompressionLayer (bool inputLayer)
void RegisterAsRemoteProcedureCall (char *uniqueID, void(*functionPointer)(RPCParameters *rpcParms))
void RegisterClassMemberRPC (char *uniqueID, void *functionPointer)
void UnregisterAsRemoteProcedureCall (char *uniqueID)
bool RPC (char *uniqueID, const char *data, unsigned int bitLength, PacketPriority priority, PacketReliability reliability, char orderingChannel, bool shiftTimestamp, NetworkID networkID, RakNet::BitStream *replyFromTarget)
bool RPC (char *uniqueID, RakNet::BitStream *bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, bool shiftTimestamp, NetworkID networkID, RakNet::BitStream *replyFromTarget)
void SetTrackFrequencyTable (bool b)
bool GetSendFrequencyTable (unsigned int outputFrequencyTable[256])
float GetCompressionRatio (void) const
float GetDecompressionRatio (void) const
void AttachPlugin (PluginInterface *messageHandler)
void DetachPlugin (PluginInterface *messageHandler)
RakNet::BitStreamGetStaticServerData (void)
void SetStaticServerData (const char *data, const int length)
RakNet::BitStreamGetStaticClientData (const PlayerID playerId)
void SetStaticClientData (const PlayerID playerId, const char *data, const int length)
void SendStaticClientDataToServer (void)
PlayerID GetServerID (void) const
PlayerID GetPlayerID (void) const
PlayerID GetInternalID (void) const
 Return the unique address identifier that represents you on the the network and is based on your local IP / portNote that unlike in previous versions, this is a struct and is not sequential.
const char * PlayerIDToDottedIP (const PlayerID playerId) const
void PushBackPacket (Packet *packet, bool pushAtHead)
void SetRouterInterface (RouterInterface *routerInterface)
 

For internal use only.


void RemoveRouterInterface (RouterInterface *routerInterface)
 

For internal use only.


void SetTimeoutTime (RakNetTime timeMS)
bool SetMTUSize (int size)
int GetMTUSize (void) const
void AllowConnectionResponseIPMigration (bool allow)
void AdvertiseSystem (const char *host, unsigned short remotePort, const char *data, int dataLength)
RakNetStatisticsStruct *const GetStatistics (void)
void ApplyNetworkSimulator (double maxSendBPS, unsigned short minExtraPing, unsigned short extraPingVariance)
bool IsNetworkSimulatorActive (void)
PlayerIndex GetPlayerIndex (void)

Private Member Functions

int GetOtherClientIndexByPlayerID (const PlayerID playerId)
int GetFreeOtherClientIndex (void)

Private Attributes

RakNet::BitStream password
RakClient::OtherClientsStruct otherClients [32]
unsigned int seed
unsigned int nextSeed
RakNetTime nextSeedUpdate
PlayerIndex localPlayerIndex
PlayerID externalPlayerID

Classes

struct  OtherClientsStruct

Detailed Description

Defines the functions used by a game client.

This is a user-interface class to act as a game client. All it does is implement some functionality on top of RakPeer. See the individual functions for what the class can do.


Member Function Documentation

void RakClient::AdvertiseSystem const char *  host,
unsigned short  remotePort,
const char *  data,
int  dataLength
[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 along with some user data.

Precondition:
The sender and recipient must already be started via a successful call to Initialize
Parameters:
[in] host Either a dotted IP address or a domain name
[in] remotePort Which port to connect to on the remote machine.
[in] data Optional data to append to the packet.
[in] dataLength length of data in bytes. Use 0 if no data.

Implements RakClientInterface.

void RakClient::AllowConnectionResponseIPMigration bool  allow  )  [virtual]
 

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:
[in] allow - True to allow this behavior, false to not allow. Defaults to false. Value persists between connections

Implements RakClientInterface.

void RakClient::ApplyNetworkSimulator double  maxSendBPS,
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 maxSendBPS value on each. You can exclude network simulator code with the _RELEASE define to decrease code size

Parameters:
[in] maxSendBPS The maximum window size for the windowing algorithm before 100% packetloss. The chance of each packet being lost is RakNetStatisticsStruct::windowSize / maxSendBPS . Recommended you set this between 100 and 1000 with lower numbers corresponding to greater packetloss. This approximates the real condition where the more data you send the more likely you are to lose data. Call with 0 to disable.
[in] minExtraPing The minimum time to delay sends.
[in] extraPingVariance The additional random time to delay sends.

Implements RakClientInterface.

void RakClient::AttachPlugin PluginInterface messageHandler  )  [virtual]
 

Attatches a Plugin interface to run code automatically on message receipt in the Receive call

Note:
If plugins have dependencies on each other then the order does matter - for example the router plugin should go first because it might route messages for other plugins
Parameters:
[in] messageHandler Pointer to a message handler to attach

Implements RakClientInterface.

bool RakClient::Connect const char *  host,
unsigned short  serverPort,
unsigned short  clientPort,
unsigned int  depreciated,
int  threadSleepTimer
[virtual]
 

Call this to connect the client to the specified host (ip or domain name) and server port. 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_REQUEST_ACCEPTED.

Parameters:
[in] host Dotted IP or a domain name
[in] serverPort The port on which to connect to host
[in] clientPort The port to use localy
[in] depreciated Ignore this
[in] threadSleepTimer How many ms to Sleep each internal update cycle (30 to give the game priority, 0 for regular (recommended), -1 to not Sleep() (may be slower))
Returns:
true on successful initiation, false otherwise

Implements RakClientInterface.

void RakClient::DeallocatePacket Packet packet  )  [virtual]
 

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

Parameters:
[in] packet The packet to deallocate.

Implements RakClientInterface.

bool RakClient::DeleteCompressionLayer bool  inputLayer  )  [virtual]
 

Delete the output or input layer as specified. This is not necessary to call and is only valuable for freeing memory.

Precondition:
You should only call this when disconnected
Parameters:
[in] inputLayer True to mean the inputLayer, false to mean the output layer
Returns:
false (failure) if connected. Otherwise true (success)

Implements RakClientInterface.

void RakClient::DetachPlugin PluginInterface messageHandler  )  [virtual]
 

Detaches a Plugin interface to run code automatically on message receipt

Parameters:
[in] messageHandler Pointer to a message handler to detach

Implements RakClientInterface.

void RakClient::Disconnect unsigned int  blockDuration,
unsigned char  orderingChannel = 0
[virtual]
 

Stops the client, stops synchronized data, and resets all internal data. Does nothing if the client is not connected to begin wit

Parameters:
[in] blockDuration how long you should wait for all remaining packets to go outIf you set it to 0 then the disconnection notification probably won't arrive
[in] orderingChannel If blockDuration > 0, the disconnect packet will be sent on this channel

Implements RakClientInterface.

bool RakClient::GenerateCompressionLayer unsigned int  inputFrequencyTable[256],
bool  inputLayer
[virtual]
 

This is an optional function to generate the compression layer based on the input frequency table. If you want to use it 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.

Precondition:
You should only call this when disconnected
Parameters:
[in] inputFrequencyTable A frequency table for your data
[in] inputLayer Is this the input layer?
Returns:
false (failure) if connected. Otherwise true (success)
See also:
Compression.cpp

Implements RakClientInterface.

float RakClient::GetCompressionRatio void   )  const [virtual]
 

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

Returns:
The compression ratio

Implements RakClientInterface.

float RakClient::GetDecompressionRatio void   )  const [virtual]
 

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

Returns:
The decompression ratio

Implements RakClientInterface.

int RakClient::GetLastPing void   )  const [virtual]
 

Returns the last ping time read

Returns:
last ping value

Implements RakClientInterface.

int RakClient::GetLowestPing void   )  const [virtual]
 

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

Returns:
lowest ping value

Implements RakClientInterface.

int RakClient::GetMTUSize void   )  const [virtual]
 

Returns the current MTU size

Returns:
The current MTU size

Implements RakClientInterface.

PlayerID RakClient::GetPlayerID void   )  const [virtual]
 

Return the player number the server has assigned to you.

Returns:
our player ID
Note:
that unlike in previous versions, this is a struct and is not sequential

Implements RakClientInterface.

int RakClient::GetPlayerPing const PlayerID  playerId  )  [virtual]
 

Returns the last ping for the specified player. This information is broadcast by the server automatically In order to save bandwidth this information is updated only infrequently and only for the first 32 players

Parameters:
[in] playerId The id of the player you want to have the ping (it might be your id)
Returns:
the last ping for this player
Note:
You can read your own ping with this method by passing your own playerId, however for more up-to-date readings you should use one of the three functions above

Implements RakClientInterface.

bool RakClient::GetSendFrequencyTable unsigned int  outputFrequencyTable[256]  )  [virtual]
 

Returns the frequency of outgoing bytes into outputFrequencyTable. This is required to get a frequency table, which is used in GenerateCompressionLayer() The purpose is to save to file as either a master frequency table from a sample game session.

Precondition:
You should only call this when disconnected

Requires that you first enable data frequency tracking by calling SetTrackFrequencyTable(true)

Parameters:
[out] outputFrequencyTable The Frequency Table used in the compression layer
Returns:
false (failure) if connected or if frequency table tracking is not enabled. Otherwise true (success)

Implements RakClientInterface.

PlayerID RakClient::GetServerID void   )  const [virtual]
 

Return the player number of the server.

Returns:
the server playerID

Implements RakClientInterface.

RakNet::BitStream * RakClient::GetStaticClientData const PlayerID  playerId  )  [virtual]
 

The client internally maintains a data struct that is automatically sent to the server on connection This is useful to contain data such as the player name. Access that struct with this function. Pass UNASSIGNED_PLAYER_ID for playerId to reference your internal data. A playerId value to access the data of another player. NOTE ** * If you change any data in the struct the server won't reflect this change unless you manually update it Do so by calling SendStaticClientDataToServer The data is entered as an array and stored and returned as a BitStream. Everytime you call GetStaticServerData it resets the read pointer to the start of the bitstream. To do multiple reads without reseting the pointer Maintain a pointer copy to the bitstream as in RakNet::BitStream *copy = ...->GetStaticServerData(...); To store a bitstream, use the GetData() and GetNumberOfBytesUsed() methods of the bitstream for the 2nd and 3rd parameters

Implements RakClientInterface.

RakNet::BitStream * RakClient::GetStaticServerData void   )  [virtual]
 

The server internally maintains a data struct that is automatically sent to clients when the connect. This is useful to contain data such as the server name or message of the day. Access that struct with this function. The data is entered as an array and stored and returned as a BitStream. Everytime you call GetStaticServerData it resets the read pointer to the start of the bitstream. To do multiple reads without reseting the pointer Maintain a pointer copy to the bitstream as in RakNet::BitStream *copy = ...->GetStaticServerData(...); To store a bitstream, use the GetData() and GetNumberOfBytesUsed() methods of the bitstream for the 2nd and 3rd parameters Note that the server may change at any time the data contents and/or its length!

Returns:
a bitstream containing static server data

Implements RakClientInterface.

RakNetStatisticsStruct *const RakClient::GetStatistics void   )  [virtual]
 

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

See also:
RakNetStatistics.h

Implements RakClientInterface.

unsigned int RakClient::GetSynchronizedRandomInteger void   )  const [virtual]
 

Returns a number automatically synchronized between the server and client which randomly changes every 9 seconds. The time it changes is accurate to within a few ms and is best used to seed random number generators that you want to usually return the same output on all systems. Keep in mind thisisn't perfectly accurate as there is always a very small chance the numbers will by out of synch. You should should confine its use to visual effects or functionality that has a backup method to maintain synchronization. If you don't need this functionality and want to save the bandwidth callStopSynchronizedRandomInteger after starting the server

Returns:
A number, which is probably synchronized among all clients and the server.

Implements RakClientInterface.

bool RakClient::HasPassword void   )  const [virtual]
 

Returns true if a password was set, false otherwise

Returns:
true if a password has previously been set using SetPassword

Implements RakClientInterface.

void RakClient::InitializeSecurity const char *  privKeyP,
const char *  privKeyQ
[virtual]
 

In order to prevent altered keys. Will return ID_RSA_PUBLIC_KEY_MISMATCH in a packet if a key has been altered.

Parameters:
[in] privKeyP Private keys generated from the RSACrypt class. Can be 0
[in] privKeyQ Private keys generated from the RSACrypt class. Can be 0
See also:
Encryption.cpp

Implements RakClientInterface.

bool RakClient::IsConnected void   )  const [virtual]
 

Returns true if the client is connected to a responsive server

Returns:
true if connected to a server

Implements RakClientInterface.

bool RakClient::IsNetworkSimulatorActive void   )  [virtual]
 

Returns if you previously called ApplyNetworkSimulator

Returns:
If you previously called ApplyNetworkSimulator

Implements RakClientInterface.

void RakClient::PingServer const char *  host,
unsigned short  serverPort,
unsigned short  clientPort,
bool  onlyReplyOnAcceptingConnections
[virtual]
 

Sends a ping request to a server we are not connected to. This will also initialize the networking system if it is not already initialized. You can stop the networking system by calling Disconnect() The final ping time will be encoded in the following sizeof(RakNetTime) bytes. (Default is 4 bytes - See __GET_TIME_64BIT in NetworkTypes.h You can specify if the server should only reply if it has an open connection or not This must be true for LAN broadcast server discovery on "255.255.255.255" or you will get replies from clients as well.

Parameters:
[in] host The host to contact
[in] ServerPort the port used by the server
[in] clientPort the port used to receive the answer
[in] onlyReplyOnAcceptingConnections if true the server must be ready to accept incomming connection.

Implements RakClientInterface.

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

Returns the dotted IP address for the specified playerId

Parameters:
[in] playerId Any player ID other than UNASSIGNED_PLAYER_ID, even if that player is not currently connected
Returns:
a dotted notation string representation of the address of playerId.

Implements RakClientInterface.

void RakClient::PushBackPacket Packet packet,
bool  pushAtHead
[virtual]
 

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

Parameters:
[in] packet the packet to delayed True to push the packet so that the next receive call returns it. False to push it at the end of the queue (obviously pushing it at the end makes the packets out of order)

Implements RakClientInterface.

Packet * RakClient::Receive void   )  [virtual]
 

Gets a packet from the incoming packet queue. Use DeallocatePacket() to deallocate the packet 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.

Implements RakClientInterface.

bool RakClient::Send RakNet::BitStream bitStream,
PacketPriority  priority,
PacketReliability  reliability,
char  orderingChannel
[virtual]
 

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

Parameters:
[in] bitStream The bitstream to send
[in] priority What priority level to send on.
[in] reliability How reliability to send this data
[in] 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
Returns:
False if we are not connected to the specified recipient. True otherwise

Implements RakClientInterface.

bool RakClient::Send const char *  data,
const int  length,
PacketPriority  priority,
PacketReliability  reliability,
char  orderingChannel
[virtual]
 

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

Parameters:
[in] data The block of data to send
[in] length The size in bytes of the data to send
[in] priority What priority level to send on.
[in] reliability How reliability to send this data
[in] 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
Returns:
False if we are not connected to the specified recipient. True otherwise

Implements RakClientInterface.

void RakClient::SendStaticClientDataToServer void   )  [virtual]
 

Send the static server data to the server The only time you need to call this function is to update clients that are already connected when you change the static server data by calling GetStaticServerData and directly modifying the object pointed to. Obviously if the connected clients don't need to know the new data you don't need to update them, so it's up to you The server must be active for this to have meaning

Implements RakClientInterface.

bool RakClient::SetMTUSize int  size  )  [virtual]
 

Set the MTU per datagram. It's important to set this correctly - otherwise packets will be needlessly split, decreasing performance and throughput. Maximum allowed size is MAXIMUM_MTU_SIZE. Too high of a value will cause packets not to arrive at worst and be fragmented at best. Too low of a value will split packets unnecessarily. sa MTUSize.h

Precondition:
Can only be called when not connected.
Returns:
false on failure (we are connected), else true

Implements RakClientInterface.

void RakClient::SetPassword const char *  _password  )  [virtual]
 

Set the password to use when connecting to a server. The password persists between connections.

Parameters:
[in] _password The password to use to connect to a server, or 0 for none.

Implements RakClientInterface.

void RakClient::SetStaticClientData const PlayerID  playerId,
const char *  data,
const int  length
[virtual]
 

Set Local statistical information for playId. Call this function when you receive statistical information from a client.

Parameters:
[in] playerId the player ID
[in] data the packet data
[in] length the size of the data

Implements RakClientInterface.

void RakClient::SetStaticServerData const char *  data,
const int  length
[virtual]
 

The server internally maintains a data struct that is automatically sent to clients when the connect. This is useful to contain data such as the server name or message of the day. Access that struct with this function. The data is entered as an array and stored and returned as a BitStream. Everytime you call GetStaticServerData it resets the read pointer to the start of the bitstream. To do multiple reads without reseting the pointer Maintain a pointer copy to the bitstream as in RakNet::BitStream *copy = ...->GetStaticServerData(...); To store a bitstream, use the GetData() and GetNumberOfBytesUsed() methods of the bitstream for the 2nd and 3rd parameters Note that the server may change at any time the data contents and/or its length!

Implements RakClientInterface.

void RakClient::SetTimeoutTime RakNetTime  timeMS  )  [virtual]
 

Set the time, in MS, to use before considering ourselves disconnected after not being able to deliver a reliable packet Default time is 10,000 or 10 seconds in release and 30,000 or 30 seconds in debug.

Parameters:
[in] timeMS Time, in MS

Implements RakClientInterface.

void RakClient::SetTrackFrequencyTable bool  b  )  [virtual]
 

Enables or disables frequency table tracking. This is required to get a frequency table, which is used in GenerateCompressionLayer() This value persists between connect calls and defaults to false (no frequency tracking)

Precondition:
You can call this at any time - however you SHOULD only call it when disconnected. Otherwise you will only trackpart of the values sent over the network.
Parameters:
[in] b True to enable tracking

Implements RakClientInterface.

void RakClient::StartOccasionalPing void   )  [virtual]
 

Ping the server every so often. This is on by default. In games where you don't care about ping you can callStopOccasionalPing to save the bandwidth. This can be called anytime.

Implements RakClientInterface.

void RakClient::StopOccasionalPing void   )  [virtual]
 

Stop pinging the server every so often. The server is pinged by default. In games where you don't care about ping you can call this to save the bandwidth This will work anytime

Implements RakClientInterface.


The documentation for this class was generated from the following files:
Generated on Sat Oct 14 08:37:38 2006 for RakNet by  doxygen 1.4.6-NO