Photon Unity Networking 2: LoadBalancingPeer Class Reference

Photon Unity Networking 2

A LoadbalancingPeer provides the operations and enum definitions needed to use the loadbalancing server application which is also used in Photon Cloud. More...

Inherits PhotonPeer.

Public Member Functions

 LoadBalancingPeer (ConnectionProtocol protocolType)
 Creates a Peer with specified connection protocol. You need to set the Listener before using the peer. More...
 
 LoadBalancingPeer (IPhotonPeerListener listener, ConnectionProtocol protocolType)
 Creates a Peer with specified connection protocol and a Listener for callbacks. More...
 
virtual bool OpGetRegions (string appId)
 
virtual bool OpJoinLobby (TypedLobby lobby=null)
 Joins the lobby on the Master Server, where you get a list of RoomInfos of currently open rooms. This is an async request which triggers a OnOperationResponse() call. More...
 
virtual bool OpLeaveLobby ()
 Leaves the lobby on the Master Server. This is an async request which triggers a OnOperationResponse() call. More...
 
virtual bool OpCreateRoom (EnterRoomParams opParams)
 Creates a room (on either Master or Game Server). The OperationResponse depends on the server the peer is connected to: Master will return a Game Server to connect to. Game Server will return the joined Room's data. This is an async request which triggers a OnOperationResponse() call. More...
 
virtual bool OpJoinRoom (EnterRoomParams opParams)
 Joins a room by name or creates new room if room with given name not exists. The OperationResponse depends on the server the peer is connected to: Master will return a Game Server to connect to. Game Server will return the joined Room's data. This is an async request which triggers a OnOperationResponse() call. More...
 
virtual bool OpJoinRandomRoom (OpJoinRandomRoomParams opJoinRandomRoomParams)
 Operation to join a random, available room. Overloads take additional player properties. This is an async request which triggers a OnOperationResponse() call. If all rooms are closed or full, the OperationResponse will have a returnCode of ErrorCode.NoRandomMatchFound. If successful, the OperationResponse contains a gameserver address and the name of some room. More...
 
virtual bool OpLeaveRoom (bool becomeInactive, bool sendAuthCookie=false)
 Leaves a room with option to come back later or "for good". More...
 
virtual bool OpGetGameList (TypedLobby lobby, string queryData)
 Gets a list of games matching a SQL-like where clause. More...
 
virtual bool OpFindFriends (string[] friendsToFind)
 Request the rooms and online status for a list of friends (each client must set a unique username via OpAuthenticate). More...
 
bool OpSetCustomPropertiesOfActor (int actorNr, Hashtable actorProperties)
 
bool OpSetCustomPropertiesOfRoom (Hashtable gameProperties)
 
virtual bool OpAuthenticate (string appId, string appVersion, AuthenticationValues authValues, string regionCode, bool getLobbyStatistics)
 Sends this app's appId and appVersion to identify this application server side. This is an async request which triggers a OnOperationResponse() call. More...
 
virtual bool OpAuthenticateOnce (string appId, string appVersion, AuthenticationValues authValues, string regionCode, EncryptionMode encryptionMode, ConnectionProtocol expectedProtocol)
 Sends this app's appId and appVersion to identify this application server side. This is an async request which triggers a OnOperationResponse() call. More...
 
virtual bool OpChangeGroups (byte[] groupsToRemove, byte[] groupsToAdd)
 Operation to handle this client's interest groups (for events in room). More...
 
virtual bool OpRaiseEvent (byte eventCode, object customEventContent, RaiseEventOptions raiseEventOptions, SendOptions sendOptions)
 Send an event with custom code/type and any content to the other players in the same room. More...
 
virtual bool OpSettings (bool receiveLobbyStats)
 Internally used operation to set some "per server" settings. This is for the Master Server. More...
 

Protected Member Functions

void OpSetPropertyOfRoom (byte propCode, object value)
 

Detailed Description

A LoadbalancingPeer provides the operations and enum definitions needed to use the loadbalancing server application which is also used in Photon Cloud.

Internally used by PUN. The LoadBalancingPeer does not keep a state, instead this is done by a LoadBalancingClient.

Constructor & Destructor Documentation

LoadBalancingPeer ( ConnectionProtocol  protocolType)

Creates a Peer with specified connection protocol. You need to set the Listener before using the peer.

Each connection protocol has it's own default networking ports for Photon.

Parameters
protocolTypeThe preferred option is UDP.
LoadBalancingPeer ( IPhotonPeerListener  listener,
ConnectionProtocol  protocolType 
)

Creates a Peer with specified connection protocol and a Listener for callbacks.

Member Function Documentation

virtual bool OpAuthenticate ( string  appId,
string  appVersion,
AuthenticationValues  authValues,
string  regionCode,
bool  getLobbyStatistics 
)
virtual

Sends this app's appId and appVersion to identify this application server side. This is an async request which triggers a OnOperationResponse() call.

This operation makes use of encryption, if that is established before. See: EstablishEncryption(). Check encryption with IsEncryptionAvailable. This operation is allowed only once per connection (multiple calls will have ErrorCode != Ok).

Parameters
appIdYour application's name or ID to authenticate. This is assigned by Photon Cloud (webpage).
appVersionThe client's version (clients with differing client appVersions are separated and players don't meet).
authValuesContains all values relevant for authentication. Even without account system (external Custom Auth), the clients are allowed to identify themselves.
regionCodeOptional region code, if the client should connect to a specific Photon Cloud Region.
getLobbyStatisticsSet to true on Master Server to receive "Lobby Statistics" events.
Returns
If the operation could be sent (has to be connected).
virtual bool OpAuthenticateOnce ( string  appId,
string  appVersion,
AuthenticationValues  authValues,
string  regionCode,
EncryptionMode  encryptionMode,
ConnectionProtocol  expectedProtocol 
)
virtual

Sends this app's appId and appVersion to identify this application server side. This is an async request which triggers a OnOperationResponse() call.

This operation makes use of encryption, if that is established before. See: EstablishEncryption(). Check encryption with IsEncryptionAvailable. This operation is allowed only once per connection (multiple calls will have ErrorCode != Ok).

Parameters
appIdYour application's name or ID to authenticate. This is assigned by Photon Cloud (webpage).
appVersionThe client's version (clients with differing client appVersions are separated and players don't meet).
authValuesOptional authentication values. The client can set no values or a UserId or some parameters for Custom Authentication by a server.
regionCodeOptional region code, if the client should connect to a specific Photon Cloud Region.
encryptionMode
expectedProtocol
Returns
If the operation could be sent (has to be connected).
virtual bool OpChangeGroups ( byte[]  groupsToRemove,
byte[]  groupsToAdd 
)
virtual

Operation to handle this client's interest groups (for events in room).

Note the difference between passing null and byte[0]: null won't add/remove any groups. byte[0] will add/remove all (existing) groups. First, removing groups is executed. This way, you could leave all groups and join only the ones provided.

Changes become active not immediately but when the server executes this operation (approximately RTT/2).

Parameters
groupsToRemoveGroups to remove from interest. Null will not remove any. A byte[0] will remove all.
groupsToAddGroups to add to interest. Null will not add any. A byte[0] will add all current.
Returns
If operation could be enqueued for sending. Sent when calling: Service or SendOutgoingCommands.
virtual bool OpCreateRoom ( EnterRoomParams  opParams)
virtual

Creates a room (on either Master or Game Server). The OperationResponse depends on the server the peer is connected to: Master will return a Game Server to connect to. Game Server will return the joined Room's data. This is an async request which triggers a OnOperationResponse() call.

If the room is already existing, the OperationResponse will have a returnCode of ErrorCode.GameAlreadyExists.

virtual bool OpFindFriends ( string[]  friendsToFind)
virtual

Request the rooms and online status for a list of friends (each client must set a unique username via OpAuthenticate).

Used on Master Server to find the rooms played by a selected list of users. Users identify themselves by using OpAuthenticate with a unique username. The list of usernames must be fetched from some other source (not provided by Photon).

The server response includes 2 arrays of info (each index matching a friend from the request): ParameterCode.FindFriendsResponseOnlineList = bool[] of online states ParameterCode.FindFriendsResponseRoomIdList = string[] of room names (empty string if not in a room)

Parameters
friendsToFindArray of friend's names (make sure they are unique).
Returns
If the operation could be sent (requires connection).
virtual bool OpGetGameList ( TypedLobby  lobby,
string  queryData 
)
virtual

Gets a list of games matching a SQL-like where clause.

Operation is only available in lobbies of type SqlLobby. This is an async request which triggers a OnOperationResponse() call. Returned game list is stored in RoomInfoList.

https://doc.photonengine.com/en-us/realtime/current/reference/matchmaking-and-lobby::sql_lobby_type

Parameters
lobbyThe lobby to query. Has to be of type SqlLobby.
queryDataThe sql query statement.
Returns
If the operation could be sent (has to be connected).
virtual bool OpJoinLobby ( TypedLobby  lobby = null)
virtual

Joins the lobby on the Master Server, where you get a list of RoomInfos of currently open rooms. This is an async request which triggers a OnOperationResponse() call.

Parameters
lobbyThe lobby join to.
Returns
If the operation could be sent (has to be connected).
virtual bool OpJoinRandomRoom ( OpJoinRandomRoomParams  opJoinRandomRoomParams)
virtual

Operation to join a random, available room. Overloads take additional player properties. This is an async request which triggers a OnOperationResponse() call. If all rooms are closed or full, the OperationResponse will have a returnCode of ErrorCode.NoRandomMatchFound. If successful, the OperationResponse contains a gameserver address and the name of some room.

Returns
If the operation could be sent currently (requires connection).
virtual bool OpJoinRoom ( EnterRoomParams  opParams)
virtual

Joins a room by name or creates new room if room with given name not exists. The OperationResponse depends on the server the peer is connected to: Master will return a Game Server to connect to. Game Server will return the joined Room's data. This is an async request which triggers a OnOperationResponse() call.

If the room is not existing (anymore), the OperationResponse will have a returnCode of ErrorCode.GameDoesNotExist. Other possible ErrorCodes are: GameClosed, GameFull.

Returns
If the operation could be sent (requires connection).
virtual bool OpLeaveLobby ( )
virtual

Leaves the lobby on the Master Server. This is an async request which triggers a OnOperationResponse() call.

Returns
If the operation could be sent (requires connection).
virtual bool OpLeaveRoom ( bool  becomeInactive,
bool  sendAuthCookie = false 
)
virtual

Leaves a room with option to come back later or "for good".

Parameters
becomeInactiveAsync games can be re-joined (loaded) later on. Set to false, if you want to abandon a game entirely.
sendAuthCookieWebFlag: Securely transmit the encrypted object AuthCookie to the web service in PathLeave webhook when available
Returns
If the opteration can be send currently.
virtual bool OpRaiseEvent ( byte  eventCode,
object  customEventContent,
RaiseEventOptions  raiseEventOptions,
SendOptions  sendOptions 
)
virtual

Send an event with custom code/type and any content to the other players in the same room.

This override explicitly uses another parameter order to not mix it up with the implementation for Hashtable only.

Parameters
eventCodeIdentifies this type of event (and the content). Your game's event codes can start with 0.
customEventContentAny serializable datatype (including Hashtable like the other OpRaiseEvent overloads).
raiseEventOptionsContains (slightly) less often used options. If you pass null, the default options will be used.
sendOptionsSend options for reliable, encryption etc
Returns
If operation could be enqueued for sending. Sent when calling: Service or SendOutgoingCommands.
virtual bool OpSettings ( bool  receiveLobbyStats)
virtual

Internally used operation to set some "per server" settings. This is for the Master Server.

Parameters
receiveLobbyStatsSet to true, to get Lobby Statistics (lists of existing lobbies).
Returns
False if the operation could not be sent.
Online Documentation  -  Dashboard  -  Support Forum Exit Games GmbH