Fully Connected 2 Mesh Plugin

Automatically generate a fully connected mesh, while automatically choosing a host based on the longest running system.

FullyConnectedMesh2 has two operations:

1. When the message ID_REMOTE_NEW_INCOMING_CONNECTION arrives, connect to that system.
2. Among all systems we are connected to, determine which system has been running the longest, and elect that system as the host.If uncertain, a system is chosen at random among systems that have been running a similar amount of time.

The first operation can be enabled or disabled through FullyConnectedMesh2::SetConnectOnNewRemoteConnection(). Note that ID_REMOTE_NEW_INCOMING_CONNECTION is generated by the ConnectionGraph2 plugin, so you must also use the ConnectionGraph2 plugin for this operation to work. If this is disabled, you can connect manually through RakPeer::Connect().

The second operation chooses a host among all 'participants.' Generally, the participants are all systems you are connected to, but this does not have to be the case. You can automatically set connections to be participants with FullyConnectedMesh2::SetAutoparticipateConnections(), which is true by default. You can manually add participants with FullyConnectedMesh2::AddParticipant().

The host is defined as the peer that has generally been running the longest, among all participants that it is connected to. Host determination takes about as long as it takes to do a ping, so is therefore nearly immediate. All peers agree on the same host. And when the current host disconnects, a new host is automatically and immediatelywith no network communiation needed.

To get the current host, call FullyConnectedMesh2::GetConnectedHost(), FullyConnectedMesh2::GetConnectedHostAddr, or FullyConnectedMesh2::GetHostSystem(). The difference between a connected host and not is that if you are not connected to any participants, you are the host in the unconnected version. Otherwise, UNASSIGNED_RAKNET_GUID is returned.

What is the use of knowing the host?

In a peer to peer game, some events or data cannot be resolved locally because two peers may disagree. For example:

1. Which objects exist in the level
2. AI decisions
3. Time level in the level
4. Resolution when data between two hosts conflicts

In that case it's useful to have one peer (the host) resolve or control this and send the outcome to all the other peers. While it's easy to do with a server, it's more difficult than it first looks to elect a common host that all peers agree on.

How do I know when the host changes?

You can poll for the current host with GetConnectedHost(). Or you can check for a network message which is locally generated and returned, ID_FCM2_NEW_HOST. The systemAddress parameter in the Packet structure will contain the address of the host. The guid parameter in the Packet structure will similarly contain the RakNetGUID of the host.

See Samples/FCMHost for a demonstration of this plugin

See Also

Index PluginInterface NAT-Punchthrough Ready Event