#include <FCMHost.h>
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. |
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.
void FCMHost::AddParticipant | ( | RakNetGUID | guid, | |
FCMHostGroupID | groupId = 0 | |||
) |
Add a connected system to the list of systems to manage host tracking
[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
[in] | groupId | Which group we are referring to. |
bool FCMHost::AmIHost | ( | FCMHostGroupID | groupId = 0 |
) | const |
Convenience function to return if the attached instance of RakPeerInterface is the host
[in] | groupId | Which group we are referring to. |
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()
[in] | groupId | Which group we are referring to. |
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
[in] | groupId | Which group we are referring to. |
void FCMHost::OnAttach | ( | RakPeerInterface * | peer | ) | [virtual] |
Called when the interface is attached
[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
[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.
[in] | peer | the instance of RakPeer that is calling Receive |
[in] | packet | the packet that is being returned to the user |
Reimplemented from PluginInterface.
void FCMHost::OnShutdown | ( | RakPeerInterface * | peer | ) | [virtual] |
Called when RakPeer is shutdown
[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()
[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
[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.
[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 |