# Router Class Reference
[Router]

Used to route messages between peers. More...

`#include <Router.h>`

Inheritance diagram for Router:

List of all members.

## Public Member Functions
void | SetRestrictRoutingByType (bool restrict__)
void | AddAllowedType (unsigned char messageId)
void | RemoveAllowedType (unsigned char messageId)
void | SetConnectionGraph (DataStructures::WeightedGraph< ConnectionGraph::SystemAddressAndGroupId, unsigned short, false > *connectionGraph)
bool | Send (char *data, BitSize_t bitLength, PacketPriority priority, PacketReliability reliability, char orderingChannel, SystemAddressList *recipients)
virtual void | OnAttach (RakPeerInterface *peer)
virtual void | OnDetach (RakPeerInterface *peer)
virtual void | OnShutdown (RakPeerInterface *peer)
virtual void | Update (RakPeerInterface *peer)
virtual PluginReceiveResult | OnReceive (RakPeerInterface *peer, Packet *packet)
virtual void | OnCloseConnection (RakPeerInterface *peer, SystemAddress systemAddress)

## Detailed Description

Used to route messages between peers.

## Member Function Documentation

void Router::AddAllowedType | ( | unsigned char | messageId | ) |

If types are restricted, this adds an allowed message type to be routed

Parameters:

  `[in]` | messageId | The type to not allow routing of.

void Router::OnAttach | ( | RakPeerInterface * | peer | ) | `[virtual]`

Called when the interface is attached

Parameters:

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

Reimplemented from PluginInterface.

void Router::OnCloseConnection | ( | RakPeerInterface * | peer,
|  | SystemAddress | systemAddress |
| ) |  |  | `[virtual]`

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

Parameters:

  `[in]` | peer | the instance of RakPeer that is calling Receive
  `[in]` | systemAddress | The system whose connection was closed

Reimplemented from PluginInterface.

void Router::OnDetach | ( | RakPeerInterface * | peer | ) | `[virtual]`

Called when the interface is detached

Parameters:

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

Reimplemented from PluginInterface.

PluginReceiveResult Router::OnReceive | ( | RakPeerInterface * | peer,
|  | Packet * | packet |
| ) |  |  | `[virtual]`

OnReceive is called for every packet.

Parameters:

  `[in]` | peer | the instance of RakPeer that is calling Receive
  `[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 PluginInterface.

void Router::OnShutdown | ( | RakPeerInterface * | peer | ) | `[virtual]`

Called when RakPeer is shutdown

Parameters:

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

Reimplemented from PluginInterface.

void Router::RemoveAllowedType | ( | unsigned char | messageId | ) |

Removes a restricted type previously added with AddRestrictedType

Parameters:

  `[in]` | messageId | The type to no longer restrict routing of.

bool Router::Send | ( | char * | data,
|  | BitSize_t | bitLength,
|  | PacketPriority | priority,
|  | PacketReliability | reliability,
|  | char | orderingChannel,
|  | SystemAddressList * | recipients |
| ) |  |  |

Sends a bitstream to one or more systems. If multiple systems are specified, the message will be multicasted using a minimum spanning tree

Precondition:
  You just have called SetConnectionGraph with a valid graph representing the network topology

Note:
  Single target sends from RakPeer with this plugin installed will also be routed. Sends from other plugins will also be routed as long as this plugin is attached first.

Parameters:

  `[in]` | data | The data to send
  `[in]` | bitLength | How many bits long data is
  `[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
  `[in]` | recipients | A list of recipients to send to. To send to one recipient, just pass a SystemAddress

Returns:
  True on success, false mostly if the connection graph cannot find the destination.

void Router::SetConnectionGraph | ( | DataStructures::WeightedGraph< ConnectionGraph::SystemAddressAndGroupId, unsigned short, false > * | connectionGraph | ) |

Set the connection graph, which is a weighted graph of the topology of the network. You can easily get this from the ConnectionGraph plugin. See the 'router' sample for usage. This is necessary if you want to send (not necessary just to route).

Parameters:

  `[in]` | connectionGraph | A weighted graph representing the topology of the network.

void Router::SetRestrictRoutingByType | ( | bool | restrict__ | ) |

We can restrict what kind of messages are routed by this plugin. This is useful for security, since you usually want to restrict what kind of messages you have to worry about from (as an example) other clients in a client / server system

Parameters:

  `[in]` | restrict | True to restrict what messages will be routed. False to not do so (default).

void Router::Update | ( | RakPeerInterface * | peer | ) | `[virtual]`

Update is called every time a packet is checked for .

Parameters:

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

Reimplemented from PluginInterface.

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

- C:/RakNet/Source/Router.h
- C:/RakNet/Source/Router.cpp