Photon C++ Client API  5.0.7.3
Public Member Functions | List of all members
Player Class Reference
Inheritance diagram for Player:
Inheritance graph
[legend]
Collaboration diagram for Player:
Collaboration graph
[legend]

Public Member Functions

virtual ~Player (void)
 
 Player (const Player &toCopy)
 
virtual Playeroperator= (const Player &toCopy)
 
int getNumber (void) const
 
const Common::JStringgetName () const
 
const Common::JStringgetUserID () const
 
const Common::HashtablegetCustomProperties () const
 
bool getIsInactive (void) const
 
bool getIsMasterClient (void) const
 
bool operator== (const Player &player) const
 
virtual Common::JStringtoString (Common::JString &retStr, bool withTypes=false) const
 
virtual Common::JString toString (bool withTypes, bool withCustomProperties) const
 
virtual JStringtoString (JString &retStr, bool withTypes=false) const=0
 
JString toString (bool withTypes=false) const
 
- Public Member Functions inherited from ToString
virtual ~ToString (void)
 
virtual JString typeToString (void) const
 
JString toString (bool withTypes=false) const
 

Detailed Description

Each client inside a MutableRoom is represented by an instance of this class.

Player instances are only valid in the context of the MutableRoom() instance from which they have been retrieved.

See also
MutablePlayer, MutableRoom, MutableRoom::getPlayers(), MutableRoom::getPlayerForNumber()

Constructor & Destructor Documentation

◆ ~Player()

~Player ( void  )
virtual

Destructor.

◆ Player()

Player ( const Player toCopy)

Copy-Constructor: Creates a new instance that is a deep copy of the argument instance.

Parameters
toCopyThe instance to copy.

Member Function Documentation

◆ operator=()

Player & operator= ( const Player toCopy)
virtual

operator=.

Makes a deep copy of its right operand into its left operand.

This overwrites old data in the left operand.

Reimplemented in MutablePlayer.

◆ getNumber()

int getNumber ( void  ) const
Returns
the player number

The player number serves as a the unique identifier of a player inside the current room.

It is assigned per room and only valid in the context of that room. A player number is never re-used for another player inside the same room.

If a player leaves a room entirely (either explicitly through a call to Client::opLeaveRoom() without passing 'true' for parameter 'willComeBack' or implicitly because his playerTtl runs out (see RoomOptions::setPlayerTtl())) and joins it again afterwards, then he is treated as an entirely new player and gets assigned a new player number.

If a player becomes inactive (either explicitly through a call to Client::opLeaveRoom() with passing 'true' for parameter 'willComeBack' or implicitly by by getting disconnected) and then rejoins the same room before his playerTtl runs out, then he is treated as the same player an keeps his previously assigned player number.

◆ getName()

const JString & getName ( ) const
Returns
the non-unique nickname of this player

A player might change his own name.

Such a change is synced automatically with the server and other clients in the same room.

◆ getUserID()

const JString & getUserID ( ) const
Returns
the unique user ID of this player

This value is only available when the room got created with RoomOptions::setPublishUserID(true). Otherwise it will be an empty string.

Useful for Client::opFindFriends() and and for blocking slots in a room for expected users (see MutableRoom::getExpectedUsers()).

See also
AuthenticationValues

◆ getCustomProperties()

const Hashtable & getCustomProperties ( ) const
Returns
the custom properties of this player

Read-only cache for the custom properties of a player. A client can change the custom properties of his local player instance through class MutablePlayer. The Custom Properties of remote players are automatically updated when they change.

◆ getIsInactive()

bool getIsInactive ( void  ) const
Returns
'true' if a player is inactive, 'false' otherwise.

Inactive players keep their spot in a room but otherwise behave as if offline (no matter what their actual connection status is).

The room needs a PlayerTtl != 0 (see RoomOptions::setPlayerTtl()) for players to be able to become inactive. If a player is inactive for longer than the PlayerTtl, then the server will remove this player from the room.

◆ getIsMasterClient()

bool getIsMasterClient ( void  ) const
Returns
'true' if this player is the Master Client of the current room, 'false' otherwise.

There is always exactly one master client. The creator of a room gets assigned the role of master client on room creation.

When the current master client leaves the room or becomes inactive and there is at least one active player inside the room, then the role of master client gets reassigned by the server to an active client. As soon as one client becomes active again in a room with only inactive clients, the role of master client will be assigned to this active client.

Whenever the role of master client gets assigned to a different client, all active clients inside the same room get informed about it by a call to Listener::onMasterClientChanged().

You can use the master client when you want one client to be an authoritative instance.

See also
MutableRoom::getMasterClientID(), Listener::onMasterClientChanged(), DirectMode::MASTER_TO_ALL

◆ operator==()

bool operator== ( const Player player) const

operator==.

Returns
true, if both operands are equal, false otherwise.

Two Player instances are considered equal, if getNumber() returns equal values for both of them.

◆ toString() [1/4]

JString & toString ( Common::JString retStr,
bool  withTypes = false 
) const
virtual
Remarks
The cost of this function depends a lot on implementation details of the implementing subclasses, but for container classes this function can become quite expensive, if the instance contains huge amounts of data, as its cost for many container class implementations increases disproportionately high to the size of the payload.
Parameters
retStrreference to a string, to store the return-value in; the information, which is generated by this function, will be attached at the end of any eventually existing previous content of the string
withTypesset to true, to include type information in the generated string
Returns
a JString representation of the instance and its contents for debugging purposes.

Implements ToString.

◆ toString() [2/4]

JString toString ( bool  withTypes,
bool  withCustomProperties 
) const
virtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
withTypesset to true, to include type information in the generated string
withCustomPropertiesset to true, to include the custom properties in the generated string

◆ toString() [3/4]

toString
Remarks
The cost of this function depends a lot on implementation details of the implementing subclasses, but for container classes this function can become quite expensive, if the instance contains huge amounts of data, as its cost for many container class implementations increases disproportionately high to the size of the payload.
Parameters
retStrreference to a string, to store the return-value in; the information, which is generated by this function, will be attached at the end of any eventually existing previous content of the string
withTypesset to true, to include type information in the generated string
Returns
a JString representation of the instance and its contents for debugging purposes.

◆ toString() [4/4]

JString toString

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
withTypesset to true, to include type information in the generated string
Returns
a JString representation of the instance and its contents for debugging purposes.
See also
JString