# FCMHost Class Reference
[FullyConnectedMeshHost]

In a fully connected mesh of peers, allows all peers to agree that another peer is hot. More...

`#include <FCMHost.h>`

Inheritance diagram for FCMHost:

List of all members.

## Public Member Functions
| FCMHost ()
| Constructor.
virtual | ~FCMHost ()
| Destructor.
void | AddParticipant (RakNetGUID guid, FCMHostGroupID groupId=0)
void | RemoveParticipantFromAllGroups (RakNetGUID guid)
void | RemoveParticipant (RakNetGUID guid, FCMHostGroupID groupId=0)
void | SetAutoAddNewConnections (bool autoAdd, FCMHostGroupID groupId=0)
RakNetGUID | GetHost (FCMHostGroupID groupId=0) const
bool | AmIHost (FCMHostGroupID groupId=0) const
bool | HasConnectedHost (FCMHostGroupID groupId=0) const
bool | AmIConnectedHost (FCMHostGroupID groupId=0) const
virtual void | OnAttach (RakPeerInterface *peer)
virtual PluginReceiveResult | OnReceive (RakPeerInterface *peer, Packet *packet)
virtual void | OnShutdown (RakPeerInterface *peer)
virtual void | OnCloseConnection (RakPeerInterface *peer, SystemAddress systemAddress)
## Protected Attributes
DataStructures::Map < FCMHostGroupID, DataStructures::List < RakNetGUID > * > | hostListsGroup
| List of hosts, in a map of groupIDs.

## Detailed Description

In a fully connected mesh of peers, allows all peers to agree that another peer is hot.

In peer to peer games it is often still useful to have one system act as a host / server For example, if the game has AI, only the host / server should control the AI This plugin automatically determines the host, changing the host as the prior host disconnects, and allowing all peers to agree on who is the host

Algorithm: 1. Every system has a synchronized list of RakNetGuid, representing remote systems in the mesh 2. The system at the head of the list is the host. 3. New systems to join the mesh are added to the end of the list. 4. To avoid contention, only the current host modifies or broadcasts the list. Modifications are broadcast to other systems. 5. If the connection to the host is lost, the next connected system in the list becomes the host. 6. If two meshes join each other, the host with the lower RakNetGuid takes precedence, and the lower priority mesh is appended.

Precondition:
  A fully connected mesh is required among the participants - e.g. all participants must eventually connect to all other participants. Otherwise the algorithm will not return the same host among all systems.

Note:
  ID_FCM_HOST_CHANGED is returned to RakPeerInterface::Receive() every time the host changes.

## Member Function Documentation

void FCMHost::AddParticipant | ( | RakNetGUID | guid,
|  | FCMHostGroupID | groupId = `0` |
| ) |  |  |

Add a connected system to the list of systems to manage host tracking

Parameters:

  `[in]` | guid | The system to add
  `[in]` | groupId | Which group to assign this system to. Groups are used if you want to manage more than one list at a time. Use 0 if you don't care.

bool FCMHost::AmIConnectedHost | ( | FCMHostGroupID | groupId = `0` | ) | const

Convenience function to return if the attached instance of RakPeerInterface is the host Differs from AmIHost in that if this system is the only system in the mesh, returns false

Parameters:

  `[in]` | groupId | Which group we are referring to.

Returns:
  true if this system is the host, false otherwise.

bool FCMHost::AmIHost | ( | FCMHostGroupID | groupId = `0` | ) | const

Convenience function to return if the attached instance of RakPeerInterface is the host

Parameters:

  `[in]` | groupId | Which group we are referring to.

Returns:
  true if this system is the host, false otherwise.

RakNetGUID FCMHost::GetHost | ( | FCMHostGroupID | groupId = `0` | ) | const

Get the current host. This will usually be the oldest system added with AddParticipant() or automatically added with SetAutoAddNewConnections()

Parameters:

  `[in]` | groupId | Which group we are referring to.

Returns:
  A RakNetGuid representing which system should be the host. We are NOT necessarily connected to this system, if the mesh is not fully connected (yet?)

bool FCMHost::HasConnectedHost | ( | FCMHostGroupID | groupId = `0` | ) | const

Returns if we are connected to other systems, and one of those systems (possibly ourselves) is a host If we are not connected to other systems, then our own system is always the host, and in a sense the host is undetermined This function could also be named HasValidHost, or IsHostDetermined

Parameters:

  `[in]` | groupId | Which group we are referring to.

Returns:
  true If there is a networked host

void FCMHost::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 FCMHost::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.

PluginReceiveResult FCMHost::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 FCMHost::OnShutdown | ( | RakPeerInterface * | peer | ) | `[virtual]`

Called when RakPeer is shutdown

Parameters:

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

Reimplemented from PluginInterface.

void FCMHost::RemoveParticipant | ( | RakNetGUID | guid,
|  | FCMHostGroupID | groupId = `0` |
| ) |  |  |

Remove a participant added with AddParticipant(), or automatically added with SetAutoAddNewConnections()

Parameters:

  `[in]` | guid | The system to remove
  `[in]` | groupId | Which group to remove this system from. Groups are used if you want to manage more than one list at a time. Use 0 if you don't care.

void FCMHost::RemoveParticipantFromAllGroups | ( | RakNetGUID | guid | ) |

Remove a participant added with AddParticipant(), or automatically added with SetAutoAddNewConnections(), from all groups

Parameters:

  `[in]` | guid | The system to remove

void FCMHost::SetAutoAddNewConnections | ( | bool | autoAdd,
|  | FCMHostGroupID | groupId = `0` |
| ) |  |  |

If set to true, all subsequent new connections will be added to groupId.

Parameters:

  `[in]` | autoAdd | If true, removes the need to call AddParticipant() on ID_NEW_INCOMING_CONNECTION or ID_CONNECTION_REQUEST_ACCEPTED Which group to automatically add systems to. Unused parameter if autoAdd is false

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

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