# 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 (void)
virtual void | OnDetach (void)
virtual PluginReceiveResult | OnReceive (Packet *packet)

## 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 | ( | void |  | ) | `[virtual]`

Called when the interface is attached

Parameters:

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

Reimplemented from PluginInterface2.

void Router::OnDetach | ( | void |  | ) | `[virtual]`

Called when the interface is detached

Parameters:

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

Reimplemented from PluginInterface2.

PluginReceiveResult Router::OnReceive | ( | Packet * | packet | ) | `[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.

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).

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

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