Click or drag to resize

StrixNetworkSearchRoom Method (ICondition, Int32, Int32, RoomSearchEventHandler, FailureEventHandler, RequestConfig)

Starts an asynchronous search for match rooms that meet the given criteria. After search is complete handler callback is invoked with a list of found rooms.

Namespace:  SoftGear.Strix.Unity.Runtime
Assembly:  StrixUnityRuntime (in StrixUnityRuntime.dll) Version: 1.5.0
Syntax
C#
public void SearchRoom(
	ICondition condition,
	int limit,
	int offset,
	RoomSearchEventHandler handler,
	FailureEventHandler failureHandler,
	RequestConfig config = null
)

Parameters

condition
Type: SoftGear.Strix.Client.Core.Model.Manager.FilterICondition
Search request criteria. See ICondition.
limit
Type: SystemInt32
Limits the number of search results. This value must be greater than 0.
offset
Type: SystemInt32
The starting offset in the search results, e.g. if limit is set to 10, and offset is set to 15, the search will result in rooms 15 to 25.
handler
Type: SoftGear.Strix.Unity.Runtime.EventRoomSearchEventHandler
This callback is invoked when the room search completes.
failureHandler
Type: SoftGear.Strix.Unity.Runtime.EventFailureEventHandler
This callback is invoked in case of a failure.
config (Optional)
Type: SoftGear.Strix.Client.Core.RequestRequestConfig
If not null, used to configure the request timeout. Default timeout is 30 seconds. See RequestConfig for more details.
Exceptions
ExceptionCondition
NullReferenceExceptionThrown if called before connecting to the master server.
Remarks
To use this method you have to connect to the master server at least once. If disconnected, calling this method will reconnect to the master server with the last used host and port parameters.

Possible exception types in FailureEventArgs's cause:
ErrorCodeException Strix error which can be further separated by an error code:
ConnectionErrorFailed to send the request because of a connection error.
RequestTimeoutServer did not respond within the specified timeout interval.
Examples
Note: Make sure to change the placeholder values of applicationId and host to the real ones that can be found on the Strix Cloud application information tab.
using SoftGear.Strix.Client.Core.Model.Manager.Filter.Builder;
using SoftGear.Strix.Unity.Runtime;
using UnityEngine;

public class StrixSearchRoomExample : MonoBehaviour
{
    void Start()
    {
        var strixNetwork = StrixNetwork.instance;

        strixNetwork.applicationId = "00000000-0000-0000-0000-000000000000";
        strixNetwork.ConnectMasterServer(
            host: "0123456789abcdef01234567.game.strixcloud.net",
            connectEventHandler: _ => {
                Debug.Log("Connection established.");

                strixNetwork.CreateRoom(
                    new RoomProperties { name = "My Game Room" },
                    new RoomMemberProperties { name = "My Player Name" },
                    handler: __ => {
                        Debug.Log("Room 1 created.");

                        strixNetwork.SearchRoom(
                            condition: ConditionBuilder.Builder().Field("name").EqualTo("My Game Room").Build(),
                            limit: 10,
                            offset: 0,
                            handler: searchResults => {
                                Debug.Log(searchResults.roomInfoCollection.Count + " rooms found.");

                                foreach (var roomInfo in searchResults.roomInfoCollection)
                                    Debug.Log("Room ID: " + roomInfo.id
                                        + "\nHost: " + roomInfo.host
                                        + "\nMember count: " + roomInfo.memberCount
                                        + "\nCapacity: " + roomInfo.capacity
                                    );
                            },
                            failureHandler: searchError => Debug.LogError("Search failed. Reason: " + searchError.cause));
                    },
                    failureHandler: createRoomError => Debug.LogError("Could not create room. Reason: " + createRoomError.cause)
                );
            },
            errorEventHandler: connectError => Debug.LogError("Connection failed. Reason: " + connectError.cause)
        );
    }
}
See Also