#include <RakPeer.h>
Inheritance diagram for RakPeer:
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::BitStream * | GetIncomingPassword (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) |
Packet * | Receive (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::BitStream * | GetRemoteStaticData (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) |
RemoteSystemStruct * | GetRemoteSystemFromPlayerID (PlayerID playerID) const |
void | HandleConnectionRequest (PlayerID playerId, unsigned char *AESKey, bool setAESKey) |
unsigned | GetNumberOfIncomingConnections (void) const |
RemoteSystemStruct * | AssignPlayerIDToRemoteSystemList (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 |
RemoteSystemStruct * | remoteSystemList |
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] |
HuffmanEncodingTree * | inputTree |
HuffmanEncodingTree * | outputTree |
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... |
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.
|
|
|
Constructor |
|
Destructor |
|
Bans an IP from connecting. Banned IPs persist between connections.
Implements RakPeerInterface. Reimplemented in RakServer. |
|
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
Implements RakPeerInterface. |
|
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.
Reimplemented from RakPeerInterface. Reimplemented in RakClient. |
|
Get a free remote system from the list and assign our playerID to it |
|
Allows all previously banned IPs to connect. Implements RakPeerInterface. Reimplemented in RakServer. |
|
Close the connection to another host (if we initiated the connection it will disconnect, if they did it will kick them out).
Implements RakPeerInterface. |
|
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
Implements RakPeerInterface. |
|
Call this to deallocate a packet returned by Receive when you are done handling it.
Implements RakPeerInterface. |
|
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
Implements RakPeerInterface. |
|
Disables all security.
Implements RakPeerInterface. Reimplemented in RakServer. |
|
Stops the network threads and close all connections. Multiple calls are ok.
Implements RakPeerInterface. |
|
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
Implements RakPeerInterface. |
|
|
|
Gets the average of all ping times read for a specified target
Implements RakPeerInterface. Reimplemented in RakServer. |
|
Get the most probably accurate clock differential for a certain player |
|
Get the compression ratio. A low compression ratio is good. Compression is for outgoing data
Implements RakPeerInterface. |
|
Fills the array remoteSystems with the playerID of all the systems we are connected to
Implements RakPeerInterface. |
|
Get the decompression ratio. A high decompression ratio is good. Decompression is for incoming data
Implements RakPeerInterface. |
|
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)
Implements RakPeerInterface. |
|
Get the password set by SetIncomingPassword in a BitStream
Reimplemented from RakPeerInterface. |
|
Given a playerID, returns an index from 0 to the maximum number of players allowed - 1.
Implements RakPeerInterface. Reimplemented in RakServer. |
|
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. |
|
Gets the last ping time read for the specific player or -1 if none read yet
Implements RakPeerInterface. |
|
Returns an IP address at index 0 to GetNumberOfAddresses-1 Implements RakPeerInterface. Reimplemented in RakServer. |
|
Gets the lowest ping time read or -1 if none read yet
Implements RakPeerInterface. |
|
Get the number of maximum incomming connection.
Implements RakPeerInterface. |
|
Return the total number of connections we are allowed Implements RakPeerInterface. |
|
Returns the current MTU size
Implements RakPeerInterface. |
|
Returns the number of IP addresses we have Implements RakPeerInterface. Reimplemented in RakServer. |
|
Returns how many remote systems initiated a connection to us |
|
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)
Implements RakPeerInterface. |
|
Retrieves the data you passed to the passwordData parameter in Connect
Implements RakPeerInterface. |
|
This function is only useful for looping through all players.
Implements RakPeerInterface. Reimplemented in RakServer. |
|
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.
Implements RakPeerInterface. |
|
Get the reliability layer associated with a playerID.
|
|
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
Implements RakPeerInterface. Reimplemented in RakServer. |
|
When we get a connection request from an ip / port, either accept or reject it |
|
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.
|
|
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:
Implements RakPeerInterface. |
|
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
Implements RakPeerInterface. |
|
Converts a dotted IP to a playerId
Implements RakPeerInterface. |
|
Returns true if the network threads are running Implements RakPeerInterface. Reimplemented in RakServer. |
|
Determines if a particular IP is banned.
Implements RakPeerInterface. Reimplemented in RakServer. |
|
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
Implements RakPeerInterface. |
|
Send a ping to the specified connected system.
Implements RakPeerInterface. |
|
Returns the dotted IP address for the specified playerId
Implements RakPeerInterface. Reimplemented in RakClient. |
|
Put a packet back at the end of the receive queue in case you don't want to deal with it immediately
Implements RakPeerInterface. |
|
|
|
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
Implements RakPeerInterface. |
|
|
|
Allows a previously banned IP to connect.
Implements RakPeerInterface. Reimplemented in RakServer. |
|
|
|
Reset the variables for a remote system |
|
|
|
|
|
|
|
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).
Implements RakPeerInterface. Reimplemented in RakServer. |
|
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).
Implements RakPeerInterface. Reimplemented in RakServer. |
|
|
|
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
Implements RakPeerInterface. |
|
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)
Implements RakPeerInterface. |
|
Sets the password incoming connections must match in the call to Connect (defaults to none) Pass 0 to passwordData to specify no password
Implements RakPeerInterface. |
|
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.
Implements RakPeerInterface. |
|
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:
Implements RakPeerInterface. |
|
Ping the remote systems every so often. This is off by default This will work anytime
Implements RakPeerInterface. |
|
Sets the data to send with an (LAN server discovery) /(offline ping) response See the Ping sample project for how this is used.
Implements RakPeerInterface. Reimplemented in RakServer. |
|
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.
Implements RakPeerInterface. |
|
An incoming packet has a timestamp, so adjust it to be relative to this system |
|
|
|
|
|
|
|
|
|
|
|
Data that both the client and the server needs |
|
Data that both the client and the server needs |
|
|
|
|
|
|
|
Set this to true to terminate the Peer thread execution |
|
|
|
|
|
localStaticData necessary because we may not have a RemoteSystemStruct representing ourselves in the list |
|
|
|
|
|
true if the peer thread is active. |
|
|
|
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 |
|
localStaticData necessary because we may not have a RemoteSystemStruct representing ourselves in the list |
|
Store the maximum incoming connection allowed |
|
Store the maximal number of peer |
|
|
|
Local Player ID |
|
|
|
Do we occasionally ping the other systems? |
|
localStaticData necessary because we may not have a RemoteSystemStruct representing ourselves in the list |
|
|
|
localStaticData necessary because we may not have a RemoteSystemStruct representing ourselves in the list |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
The list of people we have tried to connect to recently |
|
|
|
|
|
|
|
|
|
RunUpdateCycle is not thread safe but we don't need to mutex calls. Just skip calls if it is running already |
|
|
|
|