# RakNet::RPC3 Class Reference
[RPC3]

`#include <RPC3.h>`

Inheritance diagram for RakNet::RPC3:

List of all members.

## Public Member Functions
| RPC3 ()
| Constructor.
virtual | ~RPC3 ()
| Destructor.
void | SetNetworkIDManager (NetworkIDManager *idMan)
template<typename Function >
bool | RegisterFunction (const char *uniqueIdentifier, Function functionPtr)
bool | UnregisterFunction (const char *uniqueIdentifier)
bool | IsFunctionRegistered (const char *uniqueIdentifier)
void | SetTimestamp (RakNetTime timeStamp)
void | SetSendParams (PacketPriority priority, PacketReliability reliability, char orderingChannel)
void | SetRecipientAddress (SystemAddress systemAddress, bool broadcast)
void | SetRecipientObject (NetworkID networkID)
RakNetTime | GetLastSenderTimestamp (void) const
SystemAddress | GetLastSenderAddress (void) const
RakPeerInterface * | GetRakPeer (void) const
| Returns the instance of RakPeer this plugin was attached to.
const char * | GetCurrentExecution (void) const
bool | Call (const char *uniqueIdentifier)
bool | CallExplicit (const char *uniqueIdentifier, const CallExplicitParameters *const callExplicitParameters)
## Protected Member Functions
void | OnAttach (void)
virtual PluginReceiveResult | OnReceive (Packet *packet)
virtual void | OnClosedConnection (SystemAddress systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason)
virtual void | OnShutdown (void)
| Called when RakPeer is shutdown.

## Detailed Description

The RPC3 plugin allows you to call remote functions as if they were local functions, using the standard function call syntax No serialization or deserialization is needed. Features: 1. Pointers to classes that derive from NetworkID are automatically looked up using NetworkIDManager 2. Types are written to BitStream, meaning built-in serialization operations are performed, including endian swapping 3. Types can customize autoserialization by providing an implementation of operator << and operator >> to and from BitStream

## Member Function Documentation

bool RakNet::RPC3::Call | ( | const char * | uniqueIdentifier | ) | `[inline]`

Calls a remote function, using as send parameters whatever was last passed to SetTimestamp(), SetSendParams(), SetRecipientAddress(), and SetRecipientObject() If you call a C++ class member function, don't forget to first call SetRecipientObject(). You can use CallExplicit() instead of Call() to force yourself not to forget.

Parameters passed to Call are processed as follows: 1. If the parameter is not a pointer 2. - And you overloaded RakNet::BitStream& operator<<(RakNet::BitStream& out, MyClass& in) then that will be used to do the serialization 3. - Otherwise, it will use bitStream.Write(myClass); BitStream already defines specializations for NetworkIDObject, SystemAddress, other BitStreams 4. If the parameter is a pointer 5. - And the pointer can be converted to NetworkIDObject, then it will write bitStream.Write(myClass->GetNetworkID()); To make it also dereference the pointer, use RakNet::_RPC3::Deref(myClass) 6. - And the pointer can not be converted to NetworkID, but it is a pointer to RakNet::RPC3, then it is skipped 7. Otherwise, the pointer is dereferenced and written as in step 2 and 3.

Note:
  If you need endian swapping (Mac talking to PC for example), you pretty much need to define operator << and operator >> for all classes you want to serialize. Otherwise the member variables will not be endian swapped.

  If the call fails on the remote system, you will get back ID_RPC_REMOTE_ERROR. packet->data[1] will contain one of the values of RPCErrorCodes. packet->data[2] and on will contain the name of the function.

Parameters:

  `[in]` | uniqueIdentifier | parameter of the same name passed to RegisterFunction() on the remote system

bool RakNet::RPC3::CallExplicit | ( | const char * | uniqueIdentifier,
|  | const CallExplicitParameters *const | callExplicitParameters |
| ) |  |  | `[inline]`

Calls a remote function, using whatever was last passed to SetTimestamp(), SetSendParams(), SetRecipientAddress(), and SetRecipientObject() Passed parameter(s), if any, are serialized using operator << with RakNet::BitStream. If you provide an overload it will be used, otherwise the seriailzation is equivalent to memcpy except for native RakNet types (NetworkIDObject, SystemAddress, etc.) If the type is a pointer to a type deriving from NetworkIDObject, then only the NetworkID is sent, and the object looked up on the remote system. Otherwise, the pointer is dereferenced and the contents serialized as usual.

Note:
  The this pointer, for this instance of RPC3, is pushed as the last parameter on the stack. See RPC3Sample.cpp for an example of this

  If the call fails on the remote system, you will get back ID_RPC_REMOTE_ERROR. packet->data[1] will contain one of the values of RPCErrorCodes. packet->data[2] and on will contain the name of the function.

Parameters:

  `[in]` | uniqueIdentifier | parameter of the same name passed to RegisterFunction() on the remote system
  `[in]` | timeStamp | See SetTimestamp()
  `[in]` | priority | See SetSendParams()
  `[in]` | reliability | See SetSendParams()
  `[in]` | orderingChannel | See SetSendParams()
  `[in]` | systemAddress | See SetRecipientAddress()
  `[in]` | broadcast | See SetRecipientAddress()
  `[in]` | networkID | See SetRecipientObject()

const char * RPC3::GetCurrentExecution | ( | void |  | ) | const

Returns the currently running RPC call identifier, set from RegisterFunction::uniqueIdentifier Returns an empty string "" if none

Returns:
  which RPC call is currently running

SystemAddress RPC3::GetLastSenderAddress | ( | void |  | ) | const

Returns the system address of the last system to send us a received function call Equivalent to the old system RPCParameters::sender

Returns:
  Last system to send an RPC call using this system

RakNetTime RPC3::GetLastSenderTimestamp | ( | void |  | ) | const

If the last received function call has a timestamp included, it is stored and can be retrieved with this function.

Returns:
  0 if the last call did not have a timestamp, else non-zero

bool RPC3::IsFunctionRegistered | ( | const char * | uniqueIdentifier | ) |

Returns if a function identifier was previously registered with RegisterFunction(), and not unregistered with UnregisterFunction()

Parameters:

  `[in]` | uniqueIdentifier | String identifying the function.

Returns:
  True if the function was registered, false otherwise

void RPC3::OnAttach | ( | void |  | ) | `[protected, virtual]`

Called when the interface is attached

Parameters:

  `[in]` | peer | the instance of RakPeer that is calling Receive

Reimplemented from PluginInterface2.

void RPC3::OnClosedConnection | ( | SystemAddress | systemAddress,
|  | RakNetGUID | rakNetGUID,
|  | PI2_LostConnectionReason | lostConnectionReason |
| ) |  |  | `[protected, virtual]`

Called when a connection is dropped because the user called RakPeer::CloseConnection() for a particular system

Parameters:

  `[in]` | systemAddress | The system whose connection was closed
  `[in]` | rakNetGuid | The guid of the specified system
  `[in]` | lostConnectionReason | How the connection was closed: manually, connection lost, or notification of disconnection

Reimplemented from PluginInterface2.

PluginReceiveResult RPC3::OnReceive | ( | Packet * | packet | ) | `[protected, virtual]`

OnReceive is called for every packet.

Parameters:

  `[in]` | packet | the packet that is being returned to the user

Returns:
  True to allow the game and other plugins to get this message, false to absorb it

Reimplemented from PluginInterface2.

template<typename Function >

bool RakNet::RPC3::RegisterFunction | ( | const char * | uniqueIdentifier,
|  | Function | functionPtr |
| ) |  |  | `[inline]`

Parameters:

  `[in]` | uniqueIdentifier | String identifying the function. Recommended that this is the name of the function
  `[in]` | functionPtr | Pointer to the function. For C, just pass the name of the function. For C++, use ARPC_REGISTER_CPP_FUNCTION

Returns:
  True on success, false on uniqueIdentifier already used

void RPC3::SetNetworkIDManager | ( | NetworkIDManager * | idMan | ) |

Sets the network ID manager to use for object lookup Required to call C++ object member functions via SetRecipientObject()

Parameters:

  `[in]` | idMan | Pointer to the network ID manager to use

void RPC3::SetRecipientAddress | ( | SystemAddress | systemAddress,
|  | bool | broadcast |
| ) |  |  |

Set system to send to for all following calls to Call() Defaults to UNASSIGNED_SYSTEM_ADDRESS, broadcast=true

Parameters:

  `[in]` | systemAddress | See RakPeer::Send()
  `[in]` | broadcast | See RakPeer::Send()

void RPC3::SetRecipientObject | ( | NetworkID | networkID | ) |

Set the NetworkID to pass for all following calls to Call() Defaults to UNASSIGNED_NETWORK_ID (none) If set, the remote function will be considered a C++ function, e.g. an object member function If set to UNASSIGNED_NETWORK_ID (none), the remote function will be considered a C function If this is set incorrectly, you will get back either RPC_ERROR_CALLING_C_AS_CPP or RPC_ERROR_CALLING_CPP_AS_C

See also:
  NetworkIDManager

Parameters:

  `[in]` | networkID | Returned from NetworkIDObject::GetNetworkID()

void RPC3::SetSendParams | ( | PacketPriority | priority,
|  | PacketReliability | reliability,
|  | char | orderingChannel |
| ) |  |  |

Set parameters to pass to RakPeer::Send() for all following calls to Call() Deafults to HIGH_PRIORITY, RELIABLE_ORDERED, ordering channel 0

Parameters:

  `[in]` | priority | See RakPeer::Send()
  `[in]` | reliability | See RakPeer::Send()
  `[in]` | orderingChannel | See RakPeer::Send()

void RPC3::SetTimestamp | ( | RakNetTime | timeStamp | ) |

Send or stop sending a timestamp with all following calls to Call() Use GetLastSenderTimestamp() to read the timestamp.

Parameters:

  `[in]` | timeStamp | Non-zero to pass this timestamp using the ID_TIMESTAMP system. 0 to clear passing a timestamp.

bool RPC3::UnregisterFunction | ( | const char * | uniqueIdentifier | ) |

Unregisters a function pointer to be callable given an identifier for the pointer

Parameters:

  `[in]` | uniqueIdentifier | String identifying the function.

Returns:
  True on success, false on function was not previously or is not currently registered.

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

- C:/RakNet/DependentExtensions/RPC3/RPC3.h
- C:/RakNet/DependentExtensions/RPC3/RPC3.cpp