/// <summary>Operation to join a random room if available. You can use room properties to filter accepted rooms.</summary> /// <remarks> /// You can use expectedCustomRoomProperties and expectedMaxPlayers as filters for accepting rooms. /// If you set expectedCustomRoomProperties, a room must have the exact same key values set at Custom Properties. /// You need to define which Custom Room Properties will be available for matchmaking when you create a room. /// See: OpCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby) /// /// This operation fails if no rooms are fitting or available (all full, closed or not visible). /// Override this class and implement OnOperationResponse(OperationResponse operationResponse). /// /// OpJoinRandomRoom can only be called while the client is connected to a Master Server. /// You should check LoadBalancingClient.Server and LoadBalancingClient.IsConnectedAndReady before calling this method. /// Alternatively, check the returned bool value. /// /// While the server is looking for a game, the State will be Joining. /// It's set immediately when this method sent the Operation. /// /// If successful, the LoadBalancingClient will get a Game Server Address and use it automatically /// to switch servers and join the room. When you're in the room, this client's State will become /// ClientState.Joined (both, for joining or creating it). /// Set a OnStateChangeAction method to check for states. /// /// When joining a room, this client's Player Custom Properties will be sent to the room. /// Use LocalPlayer.SetCustomProperties to set them, even while not yet in the room. /// Note that the player properties will be cached locally and sent to any next room you would join, too. /// /// The parameter lobby can be null (using the defaul lobby) or a typed lobby you make up. /// Lobbies are created on the fly, as required by the clients. If you organize matchmaking with lobbies, /// keep in mind that they also fragment your matchmaking. Using more lobbies will put less rooms in each. /// /// The parameter sqlLobbyFilter can only be combined with the LobbyType.SqlLobby. In that case, it's used /// to define a sql-like "WHERE" clause for filtering rooms. This is useful for skill-based matchmaking e.g.. /// /// More about matchmaking: /// http://doc.photonengine.com/en/realtime/current/reference/matchmaking-and-lobby /// </remarks> /// <param name="expectedCustomRoomProperties">Optional. A room will only be joined, if it matches these custom properties (with string keys).</param> /// <param name="expectedMaxPlayers">Filters for a particular maxplayer setting. Use 0 to accept any maxPlayer value.</param> /// <param name="matchmakingMode">Selects one of the available matchmaking algorithms. See MatchmakingMode enum for options.</param> /// <param name="lobby">The lobby in which to find a room. Use null for default lobby.</param> /// <param name="sqlLobbyFilter">Can be used with LobbyType.SqlLobby only. This is a "where" clause of a sql statement. Use null for random game.</param> /// <returns>If the operation could be sent currently (requires connection to Master Server).</returns> public bool OpJoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, MatchmakingMode matchmakingMode, TypedLobby lobby, string sqlLobbyFilter) { if (lobby == null) { lobby = TypedLobby.Default; } this.State = ClientState.Joining; this.lastJoinType = JoinType.JoinRandomRoom; this.CurrentLobby = lobby; this.enterRoomParamsCache = new LoadBalancingPeer.EnterRoomParams(); this.enterRoomParamsCache.Lobby = lobby; LoadBalancingPeer.OpJoinRandomRoomParams opParams = new LoadBalancingPeer.OpJoinRandomRoomParams(); opParams.ExpectedCustomRoomProperties = expectedCustomRoomProperties; opParams.ExpectedMaxPlayers = expectedMaxPlayers; opParams.MatchingType = matchmakingMode; opParams.TypedLobby = lobby; opParams.SqlLobbyFilter = sqlLobbyFilter; return this.loadBalancingPeer.OpJoinRandomRoom(opParams); //return this.loadBalancingPeer.OpJoinRandomRoom(expectedCustomRoomProperties, expectedMaxPlayers, playerPropsToSend, matchmakingMode, lobby, sqlLobbyFilter); }
/// <summary> /// Joins a room by roomName. If this client returns to the room, set the previously used Player.ID as actorNumber. /// </summary> /// <remarks> /// This method is useful when you are using a lobby to list rooms and know their names. /// A room's name has to be unique (per region and game version), so it does not matter which lobby it's in. /// /// If this client returns to the room, set the previously used Player.ID as actorNumber. /// When you are using Custom Authentication with unique user IDs, the server will use the userID /// to find the previously assigned actorNumber in the room. /// /// For turnbased games, this is especially useful as rooms can be continued after hours or days. /// To return to a room, set the actorNumber to anything but 0. It's best practice to use -1 with /// Custom Authentication and unique user accounts. /// /// If the room is full, closed or not existing, this will fail. Override this class and implement /// OnOperationResponse(OperationResponse operationResponse) to get the errors. /// /// OpJoinRoom can only be called while the client is connected to a Master Server. /// You should check LoadBalancingClient.Server and LoadBalancingClient.IsConnectedAndReady before calling this method. /// Alternatively, check the returned bool value. /// /// While the server is joining the game, the State will be ClientState.Joining. /// It's set immediately when this method sends the Operation. /// /// If successful, the LoadBalancingClient will get a Game Server Address and use it automatically /// to switch servers and join the room. When you're in the room, this client's State will become /// ClientState.Joined (both, for joining or creating it). /// Set a OnStateChangeAction method to check for states. /// /// When joining a room, this client's Player Custom Properties will be sent to the room. /// Use LocalPlayer.SetCustomProperties to set them, even while not yet in the room. /// Note that the player properties will be cached locally and sent to any next room you would join, too. /// /// It's usually better to use OpJoinOrCreateRoom for invitations. /// Then it does not matter if the room is already setup. /// </remarks> /// <param name="roomName">The name of the room to join. Must be existing already, open and non-full or can't be joined.</param> /// <param name="actorNumber">When returning to a room, use a non-0 value. For Turnbased games, set the previously assigned Player.ID or -1 when using Custom Authentication.</param> /// <returns>If the operation could be sent currently (requires connection to Master Server).</returns> public bool OpJoinRoom(string roomName, int actorNumber) { this.State = ClientState.Joining; this.lastJoinType = JoinType.JoinRoom; bool onGameServer = this.Server == ServerConnection.GameServer; LoadBalancingPeer.EnterRoomParams opParams = new LoadBalancingPeer.EnterRoomParams(); this.enterRoomParamsCache = opParams; opParams.RoomName = roomName; opParams.ActorNumber = actorNumber; opParams.OnGameServer = onGameServer; return this.loadBalancingPeer.OpJoinRoom(opParams); }
/// <summary> /// Joins a specific room by name. If the room does not exist (yet), it will be created implicitly. /// </summary> /// <remarks> /// Unlike OpJoinRoom, this operation does not fail if the room does not exist. /// This can be useful when you send invitations to a room before actually creating it: /// Any invited player (whoever is first) can call this and on demand, the room gets created implicitly. /// /// If you set room properties in RoomOptions, they get ignored when the room is existing already. /// This avoids changing the room properties by late joining players. Only when the room gets created, /// the RoomOptions are set in this case. /// /// If this client returns to the room, set the previously used Player.ID as actorNumber. /// When you are using Custom Authentication with unique user IDs, the server will use the userID /// to find the previously assigned actorNumber in the room. /// /// For turnbased games, this is especially useful as rooms can be continued after hours or days. /// To return to a room, set the actorNumber to anything but 0. It's best practice to use -1 with /// Custom Authentication and unique user accounts. /// /// If the room is full or closed, this will fail. Override this class and implement /// OnOperationResponse(OperationResponse operationResponse) to get the errors. /// /// This method can only be called while the client is connected to a Master Server. /// You should check LoadBalancingClient.Server and LoadBalancingClient.IsConnectedAndReady before calling this method. /// Alternatively, check the returned bool value. /// /// While the server is joining the game, the State will be ClientState.Joining. /// It's set immediately when this method sends the Operation. /// /// If successful, the LoadBalancingClient will get a Game Server Address and use it automatically /// to switch servers and join the room. When you're in the room, this client's State will become /// ClientState.Joined (both, for joining or creating it). /// Set a OnStateChangeAction method to check for states. /// /// When entering the room, this client's Player Custom Properties will be sent to the room. /// Use LocalPlayer.SetCustomProperties to set them, even while not yet in the room. /// Note that the player properties will be cached locally and sent to any next room you would join, too. /// </remarks> /// <param name="roomName">The name of the room to join (might be created implicitly).</param> /// <param name="actorNumber">When returning to a room, use a non-0 value. For Turnbased games, set the previously assigned Player.ID or -1 when using Custom Authentication.</param> /// <param name="roomOptions">Contains the parameters and properties of the new room. See RoomOptions class for a description of each.</param> /// <param name="lobby">Typed lobby to be used if the roomname is not in use (and room gets created). If != null, it will also set CurrentLobby.</param> /// <returns>If the operation could be sent currently (requires connection to Master Server).</returns> public bool OpJoinOrCreateRoom(string roomName, int actorNumber, RoomOptions roomOptions, TypedLobby lobby) { this.State = ClientState.Joining; this.lastJoinType = JoinType.JoinOrCreateRoom; this.CurrentLobby = lobby; bool onGameServer = this.Server == ServerConnection.GameServer; LoadBalancingPeer.EnterRoomParams opParams = new LoadBalancingPeer.EnterRoomParams(); this.enterRoomParamsCache = opParams; opParams.RoomName = roomName; opParams.ActorNumber = actorNumber; opParams.RoomOptions = roomOptions; opParams.Lobby = lobby; opParams.CreateIfNotExists = true; opParams.OnGameServer = onGameServer; return this.loadBalancingPeer.OpJoinRoom(opParams); //return this.loadBalancingPeer.OpJoinRoom(roomName, playerPropsToSend, actorNumber, roomOptions, lobby, true, onGameServer); }