SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Typedefs
TeamBalancer
Plugins

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

## Classes

class | SLNet::TeamBalancer
| Set and network team selection (supports peer to peer or client/server) More...
struct | SLNet::TeamBalancer::MyTeamMembers
struct | SLNet::TeamBalancer::TeamMember

## Typedefs

typedef unsigned char | SLNet::TeamId

## 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

Deprecated:
  Use TeamManager intead

## Class Documentation

class SLNet::TeamBalancer

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

Deprecated:
  Use TeamManager intead

Definition at line 58 of file TeamBalancer.h.

Inheritance diagram for SLNet::TeamBalancer:

### Public Types

enum | DefaultAssigmentAlgorithm { SMALLEST_TEAM, FILL_IN_ORDER }

### Public Member Functions

| TeamBalancer ()
virtual | ~TeamBalancer ()
void | SetTeamSizeLimit (TeamId team, unsigned short limit)
| Set the limit to the number of players on the specified 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.
void | RequestSpecificTeam (NetworkID memberId, TeamId desiredTeam)
void | CancelRequestSpecificTeam (NetworkID memberId)
void | RequestAnyTeam (NetworkID memberId)
TeamId | GetMyTeam (NetworkID memberId) const
void | DeleteMember (NetworkID memberId)
Public Member Functions inherited from SLNet::PluginInterface2
| PluginInterface2 ()
virtual | ~PluginInterface2 ()
virtual void | OnDetach (void)
| Called when the interface is detached.
virtual void | Update (void)
| Update is called every time a packet is checked for .
virtual void | OnRakPeerStartup (void)
| Called when RakPeer is initialized.
virtual void | OnRakPeerShutdown (void)
| Called when RakPeer is shutdown.
virtual void | OnNewConnection (const SystemAddress &systemAddress, RakNetGUID rakNetGUID, bool isIncoming)
virtual void | OnFailedConnectionAttempt (Packet *packet, PI2_FailedConnectionAttemptReason failedConnectionAttemptReason)
virtual bool | UsesReliabilityLayer (void) const
virtual void | OnDirectSocketSend (const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
virtual void | OnDirectSocketReceive (const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
virtual void | OnReliabilityLayerNotification (const char *errorMessage, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress, bool isError)
virtual void | OnInternalPacket (InternalPacket *internalPacket, unsigned frameNumber, SystemAddress remoteSystemAddress, SLNet::TimeMS time, int isSend)
virtual void | OnAck (unsigned int messageNumber, SystemAddress remoteSystemAddress, SLNet::TimeMS time)
virtual void | OnPushBackPacket (const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
RakPeerInterface * | GetRakPeerInterface (void) const
RakNetGUID | GetMyGUIDUnified (void) const
void | SetRakPeerInterface (RakPeerInterface *ptr)
void | SetTCPInterface (TCPInterface *ptr)

### Protected Member Functions

virtual PluginReceiveResult | OnReceive (Packet *packet)
virtual void | OnClosedConnection (const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason)
void | OnAttach (void)
| Called when the interface is attached.
void | OnStatusUpdateToNewHost (Packet *packet)
void | OnCancelTeamRequest (Packet *packet)
void | OnRequestAnyTeam (Packet *packet)
void | OnRequestSpecificTeam (Packet *packet)
unsigned int | GetMemberIndex (NetworkID memberId, RakNetGUID guid) const
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, NetworkID memberId)
void | NotifyNoTeam (NetworkID memberId, RakNetGUID target)
void | SwapTeamMembersByRequest (unsigned int memberIndex1, unsigned int memberIndex2)
void | RemoveByGuid (RakNetGUID rakNetGUID)
bool | TeamsWouldBeEvenOnSwitch (TeamId t1, TeamId t2)
Protected Member Functions inherited from SLNet::PluginInterface2
void | SendUnified (const SLNet::BitStream *bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast)
void | SendUnified (const char *data, const int length, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast)
bool | SendListUnified (const char **data, const int *lengths, const int numParameters, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, bool broadcast)
Packet * | AllocatePacketUnified (unsigned dataSize)
void | PushBackPacketUnified (Packet *packet, bool pushAtHead)
void | DeallocPacketUnified (Packet *packet)

### Protected Attributes

RakNetGUID | hostGuid
DefaultAssigmentAlgorithm | defaultAssigmentAlgorithm
bool | forceTeamsToBeEven
bool | lockTeams
DataStructures::List < MyTeamMembers > | myTeamMembers
DataStructures::List< unsigned short > | teamLimits
DataStructures::List< unsigned short > | teamMemberCounts
DataStructures::List< TeamMember > | teamMembers
Protected Attributes inherited from SLNet::PluginInterface2
RakPeerInterface * | rakPeerInterface
TCPInterface * | tcpInterface

#### Member Enumeration Documentation

enum SLNet::TeamBalancer::DefaultAssigmentAlgorithm

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 74 of file TeamBalancer.h.

#### Constructor & Destructor Documentation

SLNet::TeamBalancer::TeamBalancer | ( |  | ) |

virtual SLNet::TeamBalancer::~TeamBalancer | ( |  | ) |

virtual

#### Member Function Documentation

unsigned int SLNet::TeamBalancer::AddTeamMember | ( | const TeamMember & | tm | ) |

protected

void SLNet::TeamBalancer::CancelRequestSpecificTeam | ( | NetworkID | memberId | ) |

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.

Parameters

  [in] | memberId | If there is more than one player per computer, this number identifies that player. Use any consistent value, such as UNASSIGNED_NETWORK_ID if there is only one player.

void SLNet::TeamBalancer::DeleteMember | ( | NetworkID | memberId | ) |

If you called RequestSpecificTeam() or RequestAnyTeam() with a value for memberId that Has since been deleted, call DeleteMember(). to notify this plugin of that event. Not necessary with only one team member per system

Parameters

  [in] | memberId | If there is more than one player per computer, this number identifies that player. Use any consistent value, such as UNASSIGNED_NETWORK_ID if there is only one player.

void SLNet::TeamBalancer::EvenTeams | ( | void |  | ) |

protected

TeamId SLNet::TeamBalancer::GetFirstNonFullTeam | ( | void |  | ) | const

protected

unsigned int SLNet::TeamBalancer::GetMemberIndex | ( | NetworkID | memberId,
|  | RakNetGUID | guid
| ) |  | const

protected

unsigned int SLNet::TeamBalancer::GetMemberIndexToSwitchTeams | ( | const DataStructures::List< TeamId > & | sourceTeamNumbers,
|  | TeamId | targetTeamNumber
| ) |  |

protected

void SLNet::TeamBalancer::GetMinMaxTeamMembers | ( | int & | minMembersOnASingleTeam,
|  | int & | maxMembersOnASingleTeam
| ) |  |

protected

TeamId SLNet::TeamBalancer::GetMyTeam | ( | NetworkID | memberId | ) | 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

Parameters

  [in] | memberId | If there is more than one player per computer, this number identifies that player. Use any consistent value, such as UNASSIGNED_NETWORK_ID if there is only one player.

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

TeamId SLNet::TeamBalancer::GetNextDefaultTeam | ( | void |  | ) |

protected

void SLNet::TeamBalancer::GetOverpopulatedTeams | ( | DataStructures::List< TeamId > & | overpopulatedTeams,
|  | int | maxTeamSize
| ) |  |

protected

TeamId SLNet::TeamBalancer::GetSmallestNonFullTeam | ( | void |  | ) | const

protected

void SLNet::TeamBalancer::MoveMemberThatWantsToJoinTeam | ( | TeamId | teamId | ) |

protected

TeamId SLNet::TeamBalancer::MoveMemberThatWantsToJoinTeamInternal | ( | TeamId | teamId | ) |

protected

void SLNet::TeamBalancer::NotifyNoTeam | ( | NetworkID | memberId,
|  | RakNetGUID | target
| ) |  |

protected

void SLNet::TeamBalancer::NotifyTeamAssigment | ( | unsigned int | teamMemberIndex | ) |

protected

void SLNet::TeamBalancer::NotifyTeamsLocked | ( | RakNetGUID | target,
|  | TeamId | requestedTeam
| ) |  |

protected

void SLNet::TeamBalancer::NotifyTeamSwitchPending | ( | RakNetGUID | target,
|  | TeamId | requestedTeam,
|  | NetworkID | memberId
| ) |  |

protected

void SLNet::TeamBalancer::OnAttach | ( | void |  | ) |

protectedvirtual

Called when the interface is attached.

Reimplemented from SLNet::PluginInterface2.

void SLNet::TeamBalancer::OnCancelTeamRequest | ( | Packet * | packet | ) |

protected

virtual void SLNet::TeamBalancer::OnClosedConnection | ( | const SystemAddress & | systemAddress,
|  | RakNetGUID | rakNetGUID,
|  | PI2_LostConnectionReason | lostConnectionReason
| ) |  |

protectedvirtual

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 SLNet::PluginInterface2.

virtual PluginReceiveResult SLNet::TeamBalancer::OnReceive | ( | Packet * | packet | ) |

protectedvirtual

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 SLNet::PluginInterface2.

void SLNet::TeamBalancer::OnRequestAnyTeam | ( | Packet * | packet | ) |

protected

PluginReceiveResult SLNet::TeamBalancer::OnRequestedTeamChangePending | ( | Packet * | packet | ) |

protected

void SLNet::TeamBalancer::OnRequestSpecificTeam | ( | Packet * | packet | ) |

protected

void SLNet::TeamBalancer::OnStatusUpdateToNewHost | ( | Packet * | packet | ) |

protected

PluginReceiveResult SLNet::TeamBalancer::OnTeamAssigned | ( | Packet * | packet | ) |

protected

PluginReceiveResult SLNet::TeamBalancer::OnTeamsLocked | ( | Packet * | packet | ) |

protected

void SLNet::TeamBalancer::RemoveByGuid | ( | RakNetGUID | rakNetGUID | ) |

protected

void SLNet::TeamBalancer::RemoveTeamMember | ( | unsigned int | index | ) |

protected

void SLNet::TeamBalancer::RequestAnyTeam | ( | NetworkID | memberId | ) |

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

Parameters

  [in] | memberId | If there is more than one player per computer, this number identifies that player. Use any consistent value, such as UNASSIGNED_NETWORK_ID if there is only one player.

void SLNet::TeamBalancer::RequestSpecificTeam | ( | NetworkID | memberId,
|  | 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] | memberId | If there is more than one player per computer, this number identifies that player. Use any consistent value, such as UNASSIGNED_NETWORK_ID if there is only one player.
  [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)

void SLNet::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

void SLNet::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

void SLNet::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

void SLNet::TeamBalancer::SetTeamSizeLimit | ( | TeamId | team,
|  | unsigned short | limit
| ) |  |

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

SetTeamSizeLimit() must be called on the host, so the host can enforce the maximum number of players on each team. SetTeamSizeLimit() 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.

Parameters

  [in] | team | Which team to set the limit for
  [in] | limit | The maximum number of people on this team

void SLNet::TeamBalancer::SwapTeamMembersByRequest | ( | unsigned int | memberIndex1,
|  | unsigned int | memberIndex2
| ) |  |

protected

void SLNet::TeamBalancer::SwitchMemberTeam | ( | unsigned int | teamMemberIndex,
|  | TeamId | destinationTeam
| ) |  |

protected

bool SLNet::TeamBalancer::TeamsWouldBeEvenOnSwitch | ( | TeamId | t1,
|  | TeamId | t2
| ) |  |

protected

bool SLNet::TeamBalancer::TeamWouldBeOverpopulatedOnAddition | ( | TeamId | teamId,
|  | unsigned int | teamMemberSize
| ) |  |

protected

bool SLNet::TeamBalancer::TeamWouldBeUnderpopulatedOnLeave | ( | TeamId | teamId,
|  | unsigned int | teamMemberSize
| ) |  |

protected

bool SLNet::TeamBalancer::WeAreHost | ( | void |  | ) | const

protected

#### Member Data Documentation

DefaultAssigmentAlgorithm SLNet::TeamBalancer::defaultAssigmentAlgorithm

protected

Definition at line 169 of file TeamBalancer.h.

bool SLNet::TeamBalancer::forceTeamsToBeEven

protected

Definition at line 170 of file TeamBalancer.h.

RakNetGUID SLNet::TeamBalancer::hostGuid

protected

Definition at line 168 of file TeamBalancer.h.

bool SLNet::TeamBalancer::lockTeams

protected

Definition at line 171 of file TeamBalancer.h.

DataStructures::List<MyTeamMembers> SLNet::TeamBalancer::myTeamMembers

protected

Definition at line 173 of file TeamBalancer.h.

DataStructures::List<unsigned short> SLNet::TeamBalancer::teamLimits

protected

Definition at line 175 of file TeamBalancer.h.

DataStructures::List<unsigned short> SLNet::TeamBalancer::teamMemberCounts

protected

Definition at line 176 of file TeamBalancer.h.

DataStructures::List<TeamMember> SLNet::TeamBalancer::teamMembers

protected

Definition at line 177 of file TeamBalancer.h.

struct SLNet::TeamBalancer::MyTeamMembers

Definition at line 147 of file TeamBalancer.h.

Class Members
TeamId | currentTeam |
NetworkID | memberId |
TeamId | requestedTeam |

struct SLNet::TeamBalancer::TeamMember

Definition at line 140 of file TeamBalancer.h.

Class Members
TeamId | currentTeam |
RakNetGUID | memberGuid |
NetworkID | memberId |
TeamId | requestedTeam |

## Typedef Documentation

typedef unsigned char SLNet::TeamId

0...254 for your team number identifiers. 255 is reserved as undefined.

Deprecated:
  Use TeamManager intead

Definition at line 49 of file TeamBalancer.h.