Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes

RakNet::TeamBalancer Class Reference
[TeamBalancer]

Set and network team selection (supports peer to peer or client/server). More...

#include <TeamBalancer.h>

Inherits PluginInterface2.

Collaboration diagram for RakNet::TeamBalancer:
Collaboration graph
[legend]

List of all members.

Classes

struct  TeamMember

Public Types

enum  DefaultAssigmentAlgorithm { SMALLEST_TEAM, FILL_IN_ORDER }

Public Member Functions

 TeamBalancer ()
virtual ~TeamBalancer ()
void SetHostGuid (RakNetGUID _hostGuid)
 Define which system processes team communication and maintains the list of teams.
void SetTeamSizeLimits (const DataStructures::List< unsigned short > &_teamLimits)
 Set the limit to the number of players on each team.
void SetTeamSizeLimits (unsigned short *values, int valuesLength)
 Set the limit to the number of players on each team.
void SetDefaultAssignmentAlgorithm (DefaultAssigmentAlgorithm daa)
 Determine how players' teams will be set when they call RequestAnyTeam().
void SetForceEvenTeams (bool force)
 By default, teams can be unbalanced up to the team size limit defined by SetTeamSizeLimits().
void SetLockTeams (bool lock)
 If set, calls to RequestSpecificTeam() and RequestAnyTeam() will return the team you are currently on.
bool RequestSpecificTeam (TeamId desiredTeam)
void CancelRequestSpecificTeam (void)
void RequestAnyTeam (void)
TeamId GetMyTeam (void) const
void SetAllowHostMigration (bool allow)

Protected Member Functions

virtual PluginReceiveResult OnReceive (Packet *packet)
virtual void OnClosedConnection (SystemAddress systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason)
void OnStatusUpdateToNewHost (Packet *packet)
void OnCancelTeamRequest (Packet *packet)
void OnRequestAnyTeam (Packet *packet)
void OnRequestSpecificTeam (Packet *packet)
unsigned int GetMemberIndex (RakNetGUID guid)
unsigned int AddTeamMember (const TeamMember &tm)
void RemoveTeamMember (unsigned int index)
void EvenTeams (void)
unsigned int GetMemberIndexToSwitchTeams (const DataStructures::List< TeamId > &sourceTeamNumbers, TeamId targetTeamNumber)
void GetOverpopulatedTeams (DataStructures::List< TeamId > &overpopulatedTeams, int maxTeamSize)
void SwitchMemberTeam (unsigned int teamMemberIndex, TeamId destinationTeam)
void NotifyTeamAssigment (unsigned int teamMemberIndex)
bool WeAreHost (void) const
PluginReceiveResult OnTeamAssigned (Packet *packet)
PluginReceiveResult OnRequestedTeamChangePending (Packet *packet)
PluginReceiveResult OnTeamsLocked (Packet *packet)
void GetMinMaxTeamMembers (int &minMembersOnASingleTeam, int &maxMembersOnASingleTeam)
TeamId GetNextDefaultTeam (void)
bool TeamWouldBeOverpopulatedOnAddition (TeamId teamId, unsigned int teamMemberSize)
bool TeamWouldBeUnderpopulatedOnLeave (TeamId teamId, unsigned int teamMemberSize)
TeamId GetSmallestNonFullTeam (void) const
TeamId GetFirstNonFullTeam (void) const
void MoveMemberThatWantsToJoinTeam (TeamId teamId)
TeamId MoveMemberThatWantsToJoinTeamInternal (TeamId teamId)
void NotifyTeamsLocked (RakNetGUID target, TeamId requestedTeam)
void NotifyTeamSwitchPending (RakNetGUID target, TeamId requestedTeam)
void NotifyNoTeam (RakNetGUID target)
void SwapTeamMembersByRequest (unsigned int memberIndex1, unsigned int memberIndex2)
void RemoveByGuid (RakNetGUID rakNetGUID)
bool TeamsWouldBeEvenOnSwitch (TeamId t1, TeamId t2)

Protected Attributes

RakNetGUID hostGuid
TeamId currentTeam
TeamId requestedTeam
DefaultAssigmentAlgorithm defaultAssigmentAlgorithm
bool forceTeamsToBeEven
bool lockTeams
bool expectingToReceiveTeamNumber
bool allowHostMigration
DataStructures::List< unsigned
short > 
teamLimits
DataStructures::List< unsigned
short > 
teamMemberCounts
DataStructures::List< TeamMemberteamMembers

Detailed Description

Set and network team selection (supports peer to peer or client/server).

Automatically handles transmission and resolution of team selection, including team switching and balancing.
Usage: TODO

Definition at line 40 of file TeamBalancer.h.


Member Enumeration Documentation

Enumerator:
SMALLEST_TEAM 

Among all the teams, join the team with the smallest number of players.

FILL_IN_ORDER 

Join the team with the lowest index that has open slots.

Definition at line 69 of file TeamBalancer.h.


Constructor & Destructor Documentation

TeamBalancer::TeamBalancer (  ) 

Definition at line 20 of file TeamBalancer.cpp.

TeamBalancer::~TeamBalancer (  )  [virtual]

Definition at line 31 of file TeamBalancer.cpp.


Member Function Documentation

unsigned int TeamBalancer::AddTeamMember ( const TeamMember tm  )  [protected]

Definition at line 467 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamBalancer::CancelRequestSpecificTeam ( void   ) 

If ID_TEAM_BALANCER_REQUESTED_TEAM_CHANGE_PENDING is returned after a call to RequestSpecificTeam(), the request will stay in memory on the host and execute when available, or until the teams become locked. You can cancel the request by calling CancelRequestSpecificTeam(), in which case you will stay on your existing team.

Note:
Due to latency, even after calling CancelRequestSpecificTeam() you may still get ID_TEAM_BALANCER_SET_TEAM if the packet was already in transmission.

Definition at line 159 of file TeamBalancer.cpp.

Here is the call graph for this function:

void TeamBalancer::EvenTeams ( void   )  [protected]

Definition at line 497 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

TeamId TeamBalancer::GetFirstNonFullTeam ( void   )  const [protected]

Definition at line 683 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int TeamBalancer::GetMemberIndex ( RakNetGUID  guid  )  [protected]

Definition at line 458 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int TeamBalancer::GetMemberIndexToSwitchTeams ( const DataStructures::List< TeamId > &  sourceTeamNumbers,
TeamId  targetTeamNumber 
) [protected]

Definition at line 523 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamBalancer::GetMinMaxTeamMembers ( int &  minMembersOnASingleTeam,
int &  maxMembersOnASingleTeam 
) [protected]

Definition at line 489 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

TeamId TeamBalancer::GetMyTeam ( void   )  const

Returns your team. As your team changes, you are notified through the ID_TEAM_BALANCER_TEAM_ASSIGNED packet in byte 1. Returns UNASSIGNED_TEAM_ID initially

Precondition:
For this to return anything other than UNASSIGNED_TEAM_ID, connect to a properly initialized host and RequestSpecificTeam() or RequestAnyTeam() first
Returns:
UNASSIGNED_TEAM_ID for no team. Otherwise, the index should range from 0 to one less than the size of the list passed to SetTeamSizeLimits() on the host

Definition at line 186 of file TeamBalancer.cpp.

Here is the caller graph for this function:

TeamId TeamBalancer::GetNextDefaultTeam ( void   )  [protected]

Definition at line 621 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamBalancer::GetOverpopulatedTeams ( DataStructures::List< TeamId > &  overpopulatedTeams,
int  maxTeamSize 
) [protected]

Definition at line 564 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

TeamId TeamBalancer::GetSmallestNonFullTeam ( void   )  const [protected]

Definition at line 668 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamBalancer::MoveMemberThatWantsToJoinTeam ( TeamId  teamId  )  [protected]

Definition at line 695 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

TeamId TeamBalancer::MoveMemberThatWantsToJoinTeamInternal ( TeamId  teamId  )  [protected]

Definition at line 704 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamBalancer::NotifyNoTeam ( RakNetGUID  target  )  [protected]

Definition at line 746 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamBalancer::NotifyTeamAssigment ( unsigned int  teamMemberIndex  )  [protected]

Definition at line 573 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamBalancer::NotifyTeamsLocked ( RakNetGUID  target,
TeamId  requestedTeam 
) [protected]

Definition at line 724 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamBalancer::NotifyTeamSwitchPending ( RakNetGUID  target,
TeamId  requestedTeam 
) [protected]

Definition at line 731 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamBalancer::OnCancelTeamRequest ( Packet packet  )  [protected]

Definition at line 349 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamBalancer::OnClosedConnection ( SystemAddress  systemAddress,
RakNetGUID  rakNetGUID,
PI2_LostConnectionReason  lostConnectionReason 
) [protected, virtual]

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

Parameters:
[in] systemAddress The system whose connection was closed
[in] rakNetGuid The guid of the specified system
[in] lostConnectionReason How the connection was closed: manually, connection lost, or notification of disconnection

Reimplemented from PluginInterface2.

Definition at line 249 of file TeamBalancer.cpp.

Here is the call graph for this function:

PluginReceiveResult TeamBalancer::OnReceive ( Packet packet  )  [protected, 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.

Definition at line 192 of file TeamBalancer.cpp.

Here is the call graph for this function:

void TeamBalancer::OnRequestAnyTeam ( Packet packet  )  [protected]

Definition at line 358 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

PluginReceiveResult TeamBalancer::OnRequestedTeamChangePending ( Packet packet  )  [protected]

Definition at line 603 of file TeamBalancer.cpp.

Here is the caller graph for this function:

void TeamBalancer::OnRequestSpecificTeam ( Packet packet  )  [protected]

Definition at line 378 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamBalancer::OnStatusUpdateToNewHost ( Packet packet  )  [protected]

Definition at line 285 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

PluginReceiveResult TeamBalancer::OnTeamAssigned ( Packet packet  )  [protected]

Definition at line 588 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

PluginReceiveResult TeamBalancer::OnTeamsLocked ( Packet packet  )  [protected]

Definition at line 612 of file TeamBalancer.cpp.

Here is the caller graph for this function:

void TeamBalancer::RemoveByGuid ( RakNetGUID  rakNetGUID  )  [protected]

Definition at line 256 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamBalancer::RemoveTeamMember ( unsigned int  index  )  [protected]

Definition at line 484 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void TeamBalancer::RequestAnyTeam ( void   ) 

Allow host to pick your team, based on whatever algorithm it uses for default team assignments. This only has an effect if you are not currently on a team (GetMyTeam() returns UNASSIGNED_TEAM_ID)

Precondition:
Call SetTeamSizeLimits() on the host and call SetHostGuid() on this system

Definition at line 172 of file TeamBalancer.cpp.

Here is the call graph for this function:

bool TeamBalancer::RequestSpecificTeam ( TeamId  desiredTeam  ) 

Set your requested team. UNASSIGNED_TEAM_ID means no team. After enough time for network communication, ID_TEAM_BALANCER_SET_TEAM will be returned with your current team, or If team switch is not possible, ID_TEAM_BALANCER_REQUESTED_TEAM_CHANGE_PENDING or ID_TEAM_BALANCER_TEAMS_LOCKED will be returned. In the case of ID_TEAM_BALANCER_REQUESTED_TEAM_CHANGE_PENDING the request will stay in memory. ID_TEAM_BALANCER_SET_TEAM will be returned when someone on the desired team leaves or wants to switch to your team. If SetLockTeams(true) is called while you have a request pending, you will get ID_TEAM_BALANCER_TEAMS_LOCKED

Precondition:
Call SetTeamSizeLimits() on the host and call SetHostGuid() on this system. If the host is not running the TeamBalancer plugin or did not have SetTeamSizeLimits() called, then you will not get any response.
Parameters:
[in] desiredTeam An index representing your team number. The index should range from 0 to one less than the size of the list passed to SetTeamSizeLimits() on the host. You can also pass UNASSIGNED_TEAM_ID to not be on any team (such as if spectating)
Returns:
True on request sent, false on SetHostGuid() was not called.

Definition at line 144 of file TeamBalancer.cpp.

Here is the call graph for this function:

void TeamBalancer::SetAllowHostMigration ( bool  allow  ) 

Allow systems to change the host If true, this is a security hole, but needed for peer to peer For client server, set to false Defaults to true param[in] allow True to allow host migration, false to not allow

Definition at line 759 of file TeamBalancer.cpp.

void TeamBalancer::SetDefaultAssignmentAlgorithm ( DefaultAssigmentAlgorithm  daa  ) 

Determine how players' teams will be set when they call RequestAnyTeam().

Based on the specified enumeration, a player will join a team automatically Defaults to SMALLEST_TEAM This function is only used by the host

Parameters:
[in] daa Enumeration describing the algorithm to use

Definition at line 71 of file TeamBalancer.cpp.

void TeamBalancer::SetForceEvenTeams ( bool  force  ) 

By default, teams can be unbalanced up to the team size limit defined by SetTeamSizeLimits().

If SetForceEvenTeams(true) is called on the host, then teams cannot be unbalanced by more than 1 player If teams are uneven at the time that SetForceEvenTeams(true) is called, players at randomly will be switched, and will be notified of ID_TEAM_BALANCER_TEAM_ASSIGNED If players disconnect from the host such that teams would not be even, and teams are not locked, then a player from the largest team is randomly moved to even the teams. Defaults to false

Note:
SetLockTeams(true) takes priority over SetForceEvenTeams(), so if teams are currently locked, this function will have no effect until teams become unlocked.
Parameters:
[in] force True to force even teams. False to allow teams to not be evenly matched

Definition at line 76 of file TeamBalancer.cpp.

Here is the call graph for this function:

void TeamBalancer::SetHostGuid ( RakNetGUID  _hostGuid  ) 

Define which system processes team communication and maintains the list of teams.

One system is responsible for maintaining the team list and determining which system is on which team. For a client/server system, this would be the server. For a peer to peer system, this would be one of the peers. If using FullyConnectedMesh2, this would be called with the value returned by FullyConnectedMesh2::GetHostSystem(). Update when you get ID_FCM2_INFORM_FCMGUID

See also:
SetAllowHostMigration()
Parameters:
[in] _hostGuid One system we are connected to that will resolve team assignments.

Definition at line 35 of file TeamBalancer.cpp.

Here is the call graph for this function:

void TeamBalancer::SetLockTeams ( bool  lock  ) 

If set, calls to RequestSpecificTeam() and RequestAnyTeam() will return the team you are currently on.

However, if those functions are called and you do not have a team, then you will be assigned to a default team according to SetDefaultAssignmentAlgorithm() and possibly SetForceEvenTeams(true) If lock is false, and SetForceEvenTeams() was called with force as true, and teams are currently uneven, they will be made even, and those players randomly moved will get ID_TEAM_BALANCER_TEAM_ASSIGNED Defaults to false

Parameters:
[in] lock True to lock teams, false to unlock

Definition at line 91 of file TeamBalancer.cpp.

Here is the call graph for this function:

void TeamBalancer::SetTeamSizeLimits ( const DataStructures::List< unsigned short > &  _teamLimits  ) 

Set the limit to the number of players on each team.

SetTeamSizeLimits() must be called on the host, so the host can enforce the maximum number of players on each team. SetTeamSizeLimits() can be called on all systems if desired - for example, in a P2P environment you may wish to call it on all systems in advanced in case you become host. Calling this function when teams have already been created does not affect existing teams.

Parameters:
[in] teamLimits The maximum number of people per team, by index. For example, a list of size 3 with values 1,2,3 would allow 1 person on team 0, 2 people on team 1, adn 3 people on team 2.

Definition at line 55 of file TeamBalancer.cpp.

Here is the call graph for this function:

void TeamBalancer::SetTeamSizeLimits ( unsigned short *  values,
int  valuesLength 
)

Set the limit to the number of players on each team.

SetTeamSizeLimits() must be called on the host, so the host can enforce the maximum number of players on each team. SetTeamSizeLimits() can be called on all systems if desired - for example, in a P2P environment you may wish to call it on all systems in advanced in case you become host. Calling this function when teams have already been created does not affect existing teams.

Parameters:
[in] values The maximum number of people per team, by index. For example, a list of size 3 with values 1,2,3 would allow 1 person on team 0, 2 people on team 1, adn 3 people on team 2.
[in] valuesLength Length of the values array

Definition at line 64 of file TeamBalancer.cpp.

Here is the call graph for this function:

void TeamBalancer::SwapTeamMembersByRequest ( unsigned int  memberIndex1,
unsigned int  memberIndex2 
) [protected]

Definition at line 738 of file TeamBalancer.cpp.

Here is the caller graph for this function:

void TeamBalancer::SwitchMemberTeam ( unsigned int  teamMemberIndex,
TeamId  destinationTeam 
) [protected]

Definition at line 556 of file TeamBalancer.cpp.

Here is the caller graph for this function:

bool TeamBalancer::TeamsWouldBeEvenOnSwitch ( TeamId  t1,
TeamId  t2 
) [protected]

Definition at line 753 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool TeamBalancer::TeamWouldBeOverpopulatedOnAddition ( TeamId  teamId,
unsigned int  teamMemberSize 
) [protected]

Definition at line 643 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool TeamBalancer::TeamWouldBeUnderpopulatedOnLeave ( TeamId  teamId,
unsigned int  teamMemberSize 
) [protected]

Definition at line 659 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool TeamBalancer::WeAreHost ( void   )  const [protected]

Definition at line 584 of file TeamBalancer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 159 of file TeamBalancer.h.

Definition at line 153 of file TeamBalancer.h.

Definition at line 155 of file TeamBalancer.h.

Definition at line 158 of file TeamBalancer.h.

Definition at line 156 of file TeamBalancer.h.

Definition at line 152 of file TeamBalancer.h.

Definition at line 157 of file TeamBalancer.h.

Definition at line 154 of file TeamBalancer.h.

Definition at line 161 of file TeamBalancer.h.

Definition at line 162 of file TeamBalancer.h.

Definition at line 163 of file TeamBalancer.h.


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