Quantum 3 3.1.0

Public Member Functions | Properties | List of all members
Photon.Realtime.Room Class Reference

This class represents a room a client joins/joined. More...

Inheritance diagram for Photon.Realtime.Room:
Photon.Realtime.RoomInfo

Public Member Functions

 Room (string roomName, RoomOptions options, bool isOffline=false)
 Creates a Room (representation) with given name and properties and the "listing options" as provided by parameters. More...
 
virtual bool AddPlayer (Player player)
 Checks if the player is in the room's list already and calls StorePlayer() if not. More...
 
bool ClearExpectedUsers ()
 Attempts to remove all current expected users from the server's Slot Reservation list. More...
 
virtual Player GetPlayer (int id, bool findMaster=false)
 Tries to find the player with given actorNumber (a.k.a. ID). Only useful when in a Room, as IDs are only valid per Room. More...
 
virtual bool SetCustomProperties (PhotonHashtable propertiesToSet, PhotonHashtable expectedValues=null)
 Updates and synchronizes this Room's Custom Properties. Optionally, expectedProperties can be provided as condition. More...
 
bool SetExpectedUsers (string[] newExpectedUsers)
 Attempts to update the expected users from the server's Slot Reservation list. More...
 
bool SetMasterClient (Player masterClientPlayer)
 Asks the server to assign another player as Master Client of your current room. More...
 
bool SetPropertiesListedInLobby (object[] lobbyProps)
 Enables you to define the properties available in the lobby if not all properties are needed to pick a room. More...
 
virtual Player StorePlayer (Player player)
 Updates a player reference in the Players dictionary (no matter if it existed before or not). More...
 
override string ToString ()
 Returns a summary of this Room instance as string. More...
 
new string ToStringFull ()
 Returns a summary of this Room instance as longer string, including Custom Properties. More...
 
- Public Member Functions inherited from Photon.Realtime.RoomInfo
override bool Equals (object other)
 Makes RoomInfo comparable (by name). More...
 
override int GetHashCode ()
 Accompanies Equals, using the name's HashCode as return. More...
 
override string ToString ()
 Returns most interesting room values as string. More...
 
string ToStringFull ()
 Returns most interesting room values as string, including custom properties. More...
 

Properties

bool AutoCleanUp [get]
 Gets if this room cleans up the event cache when a player (actor) leaves. More...
 
bool BroadcastPropertiesChangeToAll [get]
 Define if the client who calls SetProperties should receive the properties update event or not. More...
 
bool DeleteNullProperties [get]
 Define if actor or room properties with null values are removed on the server or kept. More...
 
int EmptyRoomTtl [get, set]
 Room Time To Live. How long a room stays available (and in server-memory), after the last player becomes inactive. After this time, the room gets persisted or destroyed. More...
 
string[] ExpectedUsers [get]
 List of users who are expected to join this room. In matchmaking, Photon blocks a slot for each of these UserIDs out of the MaxPlayers. More...
 
bool IsOffline [get]
 True if this is an offline room (special case for PUN). More...
 
new bool IsOpen [get, set]
 Defines if the room can be joined. More...
 
new bool IsVisible [get, set]
 Defines if the room is listed in its lobby. More...
 
TypedLobby Lobby [get]
 The room's lobby (derived/tracked by the parameters of join, join random and create room operations). More...
 
int MasterClientId [get]
 The ID (actorNumber, actorNumber) of the player who's the master of this Room. Note: This changes when the current master leaves the room. More...
 
new int? MaxPlayers [get, set]
 Sets a limit of players to this room. This property is synced and shown in lobby, too. If the room is full (players count == maxplayers), joining this room will fail. More...
 
new string Name [get]
 The name of a room. Unique identifier (per region and virtual appid) for a room/match. More...
 
new int PlayerCount [get]
 The count of players in this Room (using this.Players.Count). More...
 
Dictionary< int, Player > Players [get]
 While inside a Room, this is the list of players who are also in that room. More...
 
int PlayerTtl [get, set]
 Player Time To Live. How long any player can be inactive (due to disconnect or leave) before the user gets removed from the player list (freeing a slot). More...
 
object[] PropertiesListedInLobby [get]
 Gets a list of custom properties that are in the RoomInfo of the Lobby. This list is defined when creating the room and can't be changed afterwards. Compare: RealtimeClient.OpCreateRoom() More...
 
bool PublishUserId [get]
 Define if UserIds of the players are broadcast in the room. Useful for FindFriends and reserving slots for expected users. More...
 
RealtimeClient RealtimeClient [get, set]
 A reference to the RealtimeClient which is currently keeping the connection and state. More...
 
bool SuppressPlayerInfo [get]
 Extends SuppressRoomEvents: Define if Join and Leave events but also the actors' list and their respective properties should not be sent to clients. More...
 
bool SuppressRoomEvents [get]
 Define if Join and Leave events should not be sent to clients in the room. More...
 
- Properties inherited from Photon.Realtime.RoomInfo
PhotonHashtable CustomProperties [get]
 Read-only "cache" of custom properties of a room. Set via Room.SetCustomProperties (not available for RoomInfo class!). More...
 
bool IsOpen [get]
 Defines if the room can be joined. This does not affect listing in a lobby but joining the room will fail if not open. If not open, the room is excluded from random matchmaking. Due to racing conditions, found matches might become closed even while you join them. Simply re-connect to master and find another. Use property "IsVisible" to not list the room. More...
 
bool IsVisible [get]
 Defines if the room is listed in its lobby. Rooms can be created invisible, or changed to invisible. To change if a room can be joined, use property: open. More...
 
int MaxPlayers [get]
 The limit of players for this room. This property is shown in lobby, too. If the room is full (players count == maxplayers), joining this room will fail. More...
 
string Name [get]
 The name of a room. Unique identifier for a room/match (per AppId + game-Version). More...
 
int PlayerCount [get]
 Count of players currently in room. This property is overwritten by the Room class (used when you're in a Room). More...
 

Additional Inherited Members

- Public Attributes inherited from Photon.Realtime.RoomInfo
bool RemovedFromList
 Used in lobby, to mark rooms that are no longer listed (for being full, closed or hidden). More...
 
- Protected Attributes inherited from Photon.Realtime.RoomInfo
bool autoCleanUp = true
 Backing field for property. False unless the GameProperty is set to true (else it's not sent). More...
 
int emptyRoomTtl = 0
 Backing field for property. More...
 
string[] expectedUsers
 Backing field for property. More...
 
bool isOpen = true
 Backing field for property. More...
 
bool isVisible = true
 Backing field for property. More...
 
int masterClientId
 Backing field for master client id (actorNumber). defined by server in room props and ev leave. More...
 
int maxPlayers = 0
 Backing field for property. More...
 
string name
 Backing field for property. More...
 
int playerTtl = 0
 Backing field for property. More...
 
object[] propertiesListedInLobby
 Backing field for property. More...
 

Detailed Description

This class represents a room a client joins/joined.

Contains a list of current players, their properties and those of this room, too. A room instance has a number of "well known" properties like IsOpen, MaxPlayers which can be changed. Your own, custom properties can be set via SetCustomProperties() while being in the room.

Typically, this class should be extended by a game-specific implementation with logic and extra features.

Constructor & Destructor Documentation

◆ Room()

Photon.Realtime.Room.Room ( string  roomName,
RoomOptions  options,
bool  isOffline = false 
)
inline

Creates a Room (representation) with given name and properties and the "listing options" as provided by parameters.

Parameters
roomNameName of the room (can be null until it's actually created on server).
optionsRoom options.
isOfflineTrue when using the special case for offline rooms in PUN.

Member Function Documentation

◆ SetCustomProperties()

virtual bool Photon.Realtime.Room.SetCustomProperties ( PhotonHashtable  propertiesToSet,
PhotonHashtable  expectedValues = null 
)
inlinevirtual

Updates and synchronizes this Room's Custom Properties. Optionally, expectedProperties can be provided as condition.

Custom Properties are a set of string keys and arbitrary values which is synchronized for the players in a Room. They are available when the client enters the room, as they are in the response of OpJoin and OpCreate.

Custom Properties either relate to the (current) Room or a Player (in that Room).

Both classes locally cache the current key/values and make them available as property: CustomProperties. This is provided only to read them. You must use the method SetCustomProperties to set/modify them.

Any client can set any Custom Properties anytime (when in a room). It's up to the game logic to organize how they are best used.

You should call SetCustomProperties only with key/values that are new or changed. This reduces traffic and performance.

Unless you define some expectedProperties, setting key/values is always permitted. In this case, the property-setting client will not receive the new values from the server but instead update its local cache in SetCustomProperties.

If you define expectedProperties, the server will skip updates if the server property-cache does not contain all expectedProperties with the same values. In this case, the property-setting client will get an update from the server and update it's cached key/values at about the same time as everyone else.

The benefit of using expectedProperties can be only one client successfully sets a key from one known value to another. As example: Store who owns an item in a Custom Property "ownedBy". It's 0 initally. When multiple players reach the item, they all attempt to change "ownedBy" from 0 to their actorNumber. If you use expectedProperties {"ownedBy", 0} as condition, the first player to take the item will have it (and the others fail to set the ownership).

Properties get saved with the game state for Turnbased games (which use IsPersistent = true).

Parameters
propertiesToSetPhotonHashtable of Custom Properties that changes.
expectedValuesProvide some keys/values to use as condition for setting the new values. Client must be in room.
Returns
False if propertiesToSet is null or empty or have no keys (of allowed types). True in offline mode even if expectedProperties are used. Otherwise, returns if this operation could be sent to the server.

◆ SetPropertiesListedInLobby()

bool Photon.Realtime.Room.SetPropertiesListedInLobby ( object[]  lobbyProps)
inline

Enables you to define the properties available in the lobby if not all properties are needed to pick a room.

Limit the amount of properties sent to users in the lobby to improve speed and stability.

Parameters
lobbyPropsAn array of custom room property names to forward to the lobby.
Returns
If the operation could be sent to the server.

◆ SetMasterClient()

bool Photon.Realtime.Room.SetMasterClient ( Player  masterClientPlayer)
inline

Asks the server to assign another player as Master Client of your current room.

RaiseEvent has the option to send messages only to the Master Client of a room. SetMasterClient affects which client gets those messages.

This method calls an operation on the server to set a new Master Client, which takes a roundtrip. In case of success, this client and the others get the new Master Client from the server.

SetMasterClient tells the server which current Master Client should be replaced with the new one. It will fail, if anything switches the Master Client moments earlier. There is no callback for this error. All clients should get the new Master Client assigned by the server anyways.

See also: MasterClientId

Parameters
masterClientPlayerThe player to become the next Master Client.
Returns
False when this operation couldn't be done currently. Requires a v4 Photon Server.

◆ AddPlayer()

virtual bool Photon.Realtime.Room.AddPlayer ( Player  player)
inlinevirtual

Checks if the player is in the room's list already and calls StorePlayer() if not.

Parameters
playerThe new player - identified by ID.
Returns
False if the player could not be added (cause it was in the list already).

◆ StorePlayer()

virtual Player Photon.Realtime.Room.StorePlayer ( Player  player)
inlinevirtual

Updates a player reference in the Players dictionary (no matter if it existed before or not).

Parameters
playerThe Player instance to insert into the room.

◆ GetPlayer()

virtual Player Photon.Realtime.Room.GetPlayer ( int  id,
bool  findMaster = false 
)
inlinevirtual

Tries to find the player with given actorNumber (a.k.a. ID). Only useful when in a Room, as IDs are only valid per Room.

Parameters
idID to look for.
findMasterIf true, the Master Client is returned for ID == 0.
Returns
The player with the ID or null.

◆ ClearExpectedUsers()

bool Photon.Realtime.Room.ClearExpectedUsers ( )
inline

Attempts to remove all current expected users from the server's Slot Reservation list.

Note that this operation can conflict with new/other users joining. They might be adding users to the list of expected users before or after this client called ClearExpectedUsers.

This room's expectedUsers value will update, when the server sends a successful update.

Internals: This methods wraps up setting the ExpectedUsers property of a room.

Returns
If the operation could be sent to the server.

◆ SetExpectedUsers()

bool Photon.Realtime.Room.SetExpectedUsers ( string[]  newExpectedUsers)
inline

Attempts to update the expected users from the server's Slot Reservation list.

Note that this operation can conflict with new/other users joining. They might be adding users to the list of expected users before or after this client called SetExpectedUsers.

This room's expectedUsers value will update, when the server sends a successful update.

Internals: This methods wraps up setting the ExpectedUsers property of a room.

Parameters
newExpectedUsersThe new array of UserIDs to be reserved in the room.
Returns
If the operation could be sent to the server.

◆ ToString()

override string Photon.Realtime.Room.ToString ( )
inline

Returns a summary of this Room instance as string.

Returns
Summary of this Room instance.

◆ ToStringFull()

new string Photon.Realtime.Room.ToStringFull ( )
inline

Returns a summary of this Room instance as longer string, including Custom Properties.

Returns
Summary of this Room instance.

Property Documentation

◆ RealtimeClient

RealtimeClient Photon.Realtime.Room.RealtimeClient
getset

A reference to the RealtimeClient which is currently keeping the connection and state.

◆ Name

new string Photon.Realtime.Room.Name
get

The name of a room. Unique identifier (per region and virtual appid) for a room/match.

The name can't be changed once it's set by the server.

◆ IsOffline

bool Photon.Realtime.Room.IsOffline
get

True if this is an offline room (special case for PUN).

◆ IsOpen

new bool Photon.Realtime.Room.IsOpen
getset

Defines if the room can be joined.

This does not affect listing in a lobby but joining the room will fail if not open. If not open, the room is excluded from random matchmaking. Due to racing conditions, found matches might become closed while users are trying to join. Simply re-connect to master and find another. Use property "IsVisible" to not list the room.

As part of RoomInfo this can't be set. As part of a Room (which the player joined), the setter will update the server and all clients.

◆ IsVisible

new bool Photon.Realtime.Room.IsVisible
getset

Defines if the room is listed in its lobby.

Rooms can be created invisible, or changed to invisible. To change if a room can be joined, use property: open.

As part of RoomInfo this can't be set. As part of a Room (which the player joined), the setter will update the server and all clients.

◆ MaxPlayers

new int? Photon.Realtime.Room.MaxPlayers
getset

Sets a limit of players to this room. This property is synced and shown in lobby, too. If the room is full (players count == maxplayers), joining this room will fail.

As part of RoomInfo this can't be set. As part of a Room (which the player joined), the setter will update the server and all clients.

◆ PlayerCount

new int Photon.Realtime.Room.PlayerCount
get

The count of players in this Room (using this.Players.Count).

◆ Players

Dictionary<int, Player> Photon.Realtime.Room.Players
get

While inside a Room, this is the list of players who are also in that room.

◆ ExpectedUsers

string [] Photon.Realtime.Room.ExpectedUsers
get

List of users who are expected to join this room. In matchmaking, Photon blocks a slot for each of these UserIDs out of the MaxPlayers.

The corresponding feature in Photon is called "Slot Reservation" and can be found in the doc pages. Define expected players in the methods: RealtimeClient.OpCreateRoom, RealtimeClient.OpJoinRoom and RealtimeClient.OpJoinRandomRoom.

◆ PlayerTtl

int Photon.Realtime.Room.PlayerTtl
getset

Player Time To Live. How long any player can be inactive (due to disconnect or leave) before the user gets removed from the player list (freeing a slot).

///

If room.isOffline is true, no property will be set and there is no property-changed callback.

◆ EmptyRoomTtl

int Photon.Realtime.Room.EmptyRoomTtl
getset

Room Time To Live. How long a room stays available (and in server-memory), after the last player becomes inactive. After this time, the room gets persisted or destroyed.

If room.isOffline is true, no property will be set and there is no property-changed callback.

◆ MasterClientId

int Photon.Realtime.Room.MasterClientId
get

The ID (actorNumber, actorNumber) of the player who's the master of this Room. Note: This changes when the current master leaves the room.

◆ PropertiesListedInLobby

object [] Photon.Realtime.Room.PropertiesListedInLobby
get

Gets a list of custom properties that are in the RoomInfo of the Lobby. This list is defined when creating the room and can't be changed afterwards. Compare: RealtimeClient.OpCreateRoom()

You could name properties that are not set from the beginning. Those will be synced with the lobby when added later on.

◆ AutoCleanUp

bool Photon.Realtime.Room.AutoCleanUp
get

Gets if this room cleans up the event cache when a player (actor) leaves.

This affects which events joining players get.

Set in room creation via RoomOptions.CleanupCacheOnLeave.

Within PUN, auto cleanup of events means that cached RPCs and instantiated networked objects are deleted from the room.

◆ BroadcastPropertiesChangeToAll

bool Photon.Realtime.Room.BroadcastPropertiesChangeToAll
get

Define if the client who calls SetProperties should receive the properties update event or not.

◆ SuppressRoomEvents

bool Photon.Realtime.Room.SuppressRoomEvents
get

Define if Join and Leave events should not be sent to clients in the room.

◆ SuppressPlayerInfo

bool Photon.Realtime.Room.SuppressPlayerInfo
get

Extends SuppressRoomEvents: Define if Join and Leave events but also the actors' list and their respective properties should not be sent to clients.

◆ PublishUserId

bool Photon.Realtime.Room.PublishUserId
get

Define if UserIds of the players are broadcast in the room. Useful for FindFriends and reserving slots for expected users.

◆ DeleteNullProperties

bool Photon.Realtime.Room.DeleteNullProperties
get

Define if actor or room properties with null values are removed on the server or kept.

◆ Lobby

TypedLobby Photon.Realtime.Room.Lobby
get

The room's lobby (derived/tracked by the parameters of join, join random and create room operations).