// --------------------------------------------------------------------------------------------Major Low Level Functions - Functions needed by most users--------------------------------------------------------------------------------------------
/// \brief Starts the network threads, opens the listen port.
/// You must call this before calling Connect().
/// Multiple calls while already active are ignored. To call this function again with different settings, you must first call Disconnect().
/// \note Call SetMaximumIncomingConnections if you want to accept incoming connections
/// \param[in] maxConnections The maximum number of connections between this instance of RakPeer and another instance of RakPeer. 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
/// \param[in] localPort The port to listen for connections on.
/// \param[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))
/// \param[in] forceHostAddress Can force RakNet to use a particular IP to host on. Pass 0 to automatically pick an IP
/// \return False on failure (can't create socket or thread), true on success.
/// 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
/// \pre Must be called before Initialize
/// \param[in] pubKeyE A pointer to the public keys from the RSACrypt class.
/// \param[in] pubKeyN A pointer to the public keys from the RSACrypt class.
/// \param[in] privKeyP Public key generated from the RSACrypt class.
/// \param[in] privKeyQ Public key generated from the RSACrypt class. If the private keys are 0, then a new key will be generated when this function is called@see the Encryption sample
/// Sets the password incoming connections 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
/// \param[in] 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
/// \param[in] passwordDataLength The length in bytes of passwordData
/// 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 message with the type identifier ID_CONNECTION_ACCEPTED.
/// If the connection is not successful, such as a rejected connection or no response then neither of these things will happen.
/// \pre Requires that you first call Initialize
/// \param[in] host Either a dotted IP address or a domain name
/// \param[in] remotePort Which port to connect to on the remote machine.
/// \param[in] passwordData A 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.
/// \param[in] passwordDataLength The length in bytes of passwordData
/// \return True on successful initiation. False on incorrect parameters, internal error, or too many existing peers. Returning true does not mean you connected!
/// \brief Stops the network threads and closes all connections.
/// \param[in] blockDuration How long you should wait for all remaining messages to go out, including ID_DISCONNECTION_NOTIFICATION. If 0, it doesn't wait at all.
/// \param[in] orderingChannel If blockDuration > 0, ID_DISCONNECTION_NOTIFICATION will be sent on this channel
/// If you set it to 0 then the disconnection notification won't be sent
/// Fills the array remoteSystems with the SystemID of all the systems we are connected to
/// \param[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
/// \param[in, out] numberOfSystems As input, the size of remoteSystems array. As output, the number of elements put into the array
/// Sends a block of data to the specified system that you are connected to.
/// This function only works while the connected
/// \param[in] data The block of data to send
/// \param[in] length The size in bytes of the data to send
/// \param[in] priority What priority level to send on. See PacketPriority.h
/// \param[in] reliability How reliability to send this data. See PacketPriority.h
/// \param[in] orderingChannel When using ordered or sequenced messages, what channel to order these on. Messages are only ordered relative to other messages on the same stream
/// \param[in] 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
/// \param[in] broadcast True to send this packet to all connected systems. If true, then playerId specifies who not to send the packet to.
/// \return False if we are not connected to the specified recipient. True otherwise
/// 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.
/// \param[in] bitStream The bitstream to send
/// \param[in] priority What priority level to send on. See PacketPriority.h
/// \param[in] reliability How reliability to send this data. See PacketPriority.h
/// \param[in] orderingChannel When using ordered or sequenced messages, what channel to order these on. Messages are only ordered relative to other messages on the same stream
/// \param[in] 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
/// \param[in] broadcast True to send this packet to all connected systems. If true, then playerId specifies who not to send the packet to.
/// \return False if we are not connected to the specified recipient. True otherwise
// --------------------------------------------------------------------------------------------Remote Procedure Call Functions - Functions to initialize and perform RPC--------------------------------------------------------------------------------------------
/// \ingroup RAKNET_RPC
/// Register a C or static member function as available for calling as a remote procedure call
/// \param[in] uniqueID A null-terminated unique string to identify this procedure. See RegisterClassMemberRPC() for class member functions.
/// \param[in] functionPointer(...) The name of the function to be used as a function pointer. This can be called whether active or not, and registered functions stay registered unless unregistered
/// Register a C++ member function as available for calling as a remote procedure call.
/// \param[in] uniqueID A null terminated string to identify this procedure. Recommended you use the macro REGISTER_CLASS_MEMBER_RPC to create the string. Use RegisterAsRemoteProcedureCall() for static functions.
/// \param[in] functionPointer The name of the function to be used as a function pointer. This can be called whether active or not, and registered functions stay registered unless unregistered with UnregisterAsRemoteProcedureCall
/// Unregisters a C function as available for calling as a remote procedure call that was formerly registered with RegisterAsRemoteProcedureCall. Only call offline.
/// \param[in] uniqueID A string of only letters to identify this procedure. Recommended you use the macro CLASS_MEMBER_ID for class member functions.
/// Calls a C function on the remote system that was already registered using RegisterAsRemoteProcedureCall().
/// \param[in] uniqueID A NULL terminated string identifying the function to call. Recommended you use the macro CLASS_MEMBER_ID for class member functions.
/// \param[in] data The data to send
/// \param[in] bitLength The number of bits of \a data
/// \param[in] priority What priority level to send on. See PacketPriority.h.
/// \param[in] reliability How reliability to send this data. See PacketPriority.h.
/// \param[in] orderingChannel When using ordered or sequenced message, what channel to order these on.
/// \param[in] playerId Who to send this message to, or in the case of broadcasting who not to send it to. Use UNASSIGNED_PLAYER_ID to specify none
/// \param[in] broadcast True to send this packet to all connected systems. If true, then playerId specifies who not to send the packet to.
/// \param[in] shiftTimestamp True to add a timestamp to your data, such that the first byte is ID_TIMESTAMP and the next sizeof(RakNetTime) is the timestamp.
/// \param[in] networkID For static functions, pass UNASSIGNED_NETWORK_ID. For member functions, you must derive from NetworkIDGenerator and pass the value returned by NetworkIDGenerator::GetNetworkID for that object.
/// \param[in] replyFromTarget If 0, this function is non-blocking. Otherwise it will block while waiting for a reply from the target procedure, which should be remotely written to RPCParameters::replyToSender and copied to replyFromTarget. The block will return early on disconnect or if the sent packet is unreliable and more than 3X the ping has elapsed.
/// \return True on a successful packet send (this does not indicate the recipient performed the call), false on failure
/// Calls a C function on the remote system that was already registered using RegisterAsRemoteProcedureCall.
/// If you want that function to return data you should call RPC from that system in the same wayReturns true on a successful packet
/// send (this does not indicate the recipient performed the call), false on failure
/// \param[in] uniqueID A NULL terminated string identifying the function to call. Recommended you use the macro CLASS_MEMBER_ID for class member functions.
/// \param[in] data The data to send
/// \param[in] bitLength The number of bits of \a data
/// \param[in] priority What priority level to send on. See PacketPriority.h.
/// \param[in] reliability How reliability to send this data. See PacketPriority.h.
/// \param[in] orderingChannel When using ordered or sequenced message, what channel to order these on.
/// \param[in] playerId Who to send this message to, or in the case of broadcasting who not to send it to. Use UNASSIGNED_PLAYER_ID to specify none
/// \param[in] broadcast True to send this packet to all connected systems. If true, then playerId specifies who not to send the packet to.
/// \param[in] shiftTimestamp True to add a timestamp to your data, such that the first byte is ID_TIMESTAMP and the next sizeof(RakNetTime) is the timestamp.
/// \param[in] networkID For static functions, pass UNASSIGNED_NETWORK_ID. For member functions, you must derive from NetworkIDGenerator and pass the value returned by NetworkIDGenerator::GetNetworkID for that object.
/// \param[in] replyFromTarget If 0, this function is non-blocking. Otherwise it will block while waiting for a reply from the target procedure, which should be remotely written to RPCParameters::replyToSender and copied to replyFromTarget. The block will return early on disconnect or if the sent packet is unreliable and more than 3X the ping has elapsed.
/// \return True on a successful packet send (this does not indicate the recipient performed the call), false on failure
/// param[in] Dotted IP address. Can use * as a wildcard, such as 128.0.0.* will banAll IP addresses starting with 128.0.0
voidRemoveFromBanList(constchar*IP);
/// Allows all previously banned IPs to connect.
voidClearBanList(void);
/// Returns true or false indicating if a particular IP is banned.
/// \param[in] IP - Dotted IP address.
/// \return true if IP matches any IPs in the ban list, accounting for any wildcards. False otherwise.
boolIsBanned(constchar*IP);
// --------------------------------------------------------------------------------------------Pinging Functions - Functions dealing with the automatic ping mechanism--------------------------------------------------------------------------------------------
/// Send a ping to the specified connected system.
/// \pre The sender and recipient must already be started via a successful call to Initialize()
/// \param[in] target Which system to ping
voidPing(constPlayerIDtarget);
/// 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 sizeof(RakNetTime) bytes. (Default is 4 bytes - See __GET_TIME_64BIT in NetworkTypes.h
/// \param[in] host Either a dotted IP address or a domain name. Can be 255.255.255.255 for LAN broadcast.
/// \param[in] remotePort Which port to connect to on the remote machine.
/// \param[in] onlyReplyOnAcceptingConnections Only request a reply if the remote system is accepting connections
/// Returns the average of all ping times read for the specific system or -1 if none read yet
/// \param[in] playerId Which system we are referring to
/// \return The ping time for this system, or -1
intGetAveragePing(constPlayerIDplayerId);
/// Returns the last ping time read for the specific system or -1 if none read yet
/// \param[in] playerId Which system we are referring to
/// \return The last ping time for this system, or -1
intGetLastPing(constPlayerIDplayerId)const;
/// Returns the lowest ping time read or -1 if none read yet
/// \param[in] playerId Which system we are referring to
/// \return The lowest ping time for this system, or -1
intGetLowestPing(constPlayerIDplayerId)const;
/// Ping the remote systems every so often, or not. This is off by default. Can be called anytime.
/// \param[in] doPing True to start occasional pings. False to stop them.
voidSetOccasionalPing(booldoPing);
// --------------------------------------------------------------------------------------------Static Data Functions - Functions dealing with API defined synchronized memory--------------------------------------------------------------------------------------------
/// 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.
/// \param[in] playerId Which system you are referring to. Pass the value returned by GetInternalID to refer to yourself
/// \return The data passed to SetRemoteStaticData stored as a bitstream
//--------------------------------------------------------------------------------------------Network Functions - Functions dealing with the network in general--------------------------------------------------------------------------------------------
/// Return the unique address identifier that represents you on the the network and is based on your local IP / port.
/// \return the identifier of your system internally, which may not be how other systems see if you if you are behind a NAT or proxy
/// Return the unique address identifier that represents you on the the network and is based on your externalIP / port
/// (the IP / port the specified player uses to communicate with you)
/// \param[in] target Which remote system you are referring to for your external ID. Usually the same for all systems, unless you have two or more network cards.
PlayerIDGetExternalID(constPlayerIDtarget)const;
/// 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.
/// 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.
/// Recommended size is 1500
/// sa MTUSize.h
/// \pre Can only be called when not connected.
/// \return false on failure (we are connected), else true
// --------------------------------------------------------------------------------------------Compression Functions - Functions related to the compression layer--------------------------------------------------------------------------------------------
/// 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)
/// \pre 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.
/// 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
/// \param[in] messageHandler Pointer to a plugin to attach
voidAttachPlugin(PluginInterface*plugin);
/// Detaches a Plugin interface to run code automatically on message receipt
/// \param[in] messageHandler Pointer to a plugin to detach
/// Put a message back at the end of the receive queue in case you don't want to deal with it immediately
/// \param[in] packet The packet you want to push back.
/// \param[in] pushAtHead 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)
voidPushBackPacket(Packet*packet,boolpushAtHead);
/// \Internal
// \param[in] routerInterface The router to use to route messages to systems not directly connected to this system.
/// 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
/// \param[in] maxSendBPS Maximum bits per second to send. Packetloss grows linearly. 0 to disable.
/// \param[in] minExtraPing The minimum time to delay sends.
/// \param[in] extraPingVariance The additional random time to delay sends.
/// Returns if you previously called ApplyNetworkSimulator
/// \return If you previously called ApplyNetworkSimulator
boolIsNetworkSimulatorActive(void);
// --------------------------------------------------------------------------------------------Statistical Functions - Functions dealing with API performance--------------------------------------------------------------------------------------------
/// 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
/// \param[in] playerId: Which connected system to get statistics for
/// \return 0 on can't find the specified system. A pointer to a set of data otherwise.
// --------------------------------------------------------------------------------------------EVERYTHING AFTER THIS COMMENT IS FOR INTERNAL USE ONLY--------------------------------------------------------------------------------------------
/// \internal
RPCMap*GetRPCMap(constPlayerIDplayerId);
/// \internal
/// \brief Holds the clock differences between systems, along with the ping
structPingAndClockDifferential
{
unsignedshortpingTime;
RakNetTimeclockDifferential;
};
/// \internal
/// \brief All the information representing a connected system system
structRemoteSystemStruct
{
boolisActive;// Is this structure in use?
PlayerIDplayerId;/// The remote system associated with this reliability layer
PlayerIDmyExternalPlayerId;/// Your own IP, as reported by the remote system
ReliabilityLayerreliabilityLayer;/// The reliability layer associated with this player
boolweInitiatedTheConnection;/// True if we started this connection via Connect. False if someone else connected to us.
PingAndClockDifferentialpingAndClockDifferential[PING_TIMES_ARRAY_SIZE];/// last x ping times and calculated clock differentials with it
intpingAndClockDifferentialWriteIndex;/// The index we are writing into the pingAndClockDifferential circular buffer
unsignedshortlowestPing;///The lowest ping value encountered
RakNetTimenextPingTime;/// When to next ping this player
RakNetTimelastReliableSend;/// When did the last reliable send occur. Reliable sends must occur at least once every timeoutTime/2 units to notice disconnects
RakNet::BitStreamstaticData;/// static data. This cannot be a pointer because it might be accessed in another thread.
RakNetTimeconnectionTime;/// connection time, if active.
unsignedcharAESKey[16];/// Security key.
boolsetAESKey;/// true if security is enabled.
RPCMaprpcMap;/// Mapping of RPC calls to single byte integers to save transmission bandwidth.
// Sends static data using immediate send mode or not (if called from user thread, put false for performImmediate. If called from update thread, put true).
// This is done for efficiency, so we don't buffer send calls that are from the network thread anyway
///How long it has been since things were updated by a call to receiveUpdate thread uses this to determine how long to sleep for
//unsigned int lastUserUpdateCycle;
/// True to allow connection accepted packets from anyone. False to only allow these packets from servers we requested a connection to.
boolallowConnectionResponseIPMigration;
intsplitMessageProgressInterval;
RakNetTimeunreliableTimeout;
// The packetSingleProducerConsumer transfers the packets from the network thread to the user thread. The pushedBackPacket holds packets that couldn't be processed