Searching for Rooms¶
Generally, games with matchmaking functionality provide their players with the ability to search for specific matches to join. In Strix, this is provided through several search methods.
Search Methods¶
The most fundamental SearchRoom
method is the one taking seven arguments.
void SearchRoom(ICondition condition, Order order, int limit, int offset, RoomSearchEventHandler handler, FailureEventHandler failureHandler, RequestConfig config = null)
There are two overloads of the SearchRoom
method
that omit the condition and the order of the results.
They are added for convenience.
void SearchRoom(int limit, int offset, RoomSearchEventHandler handler, FailureEventHandler failureHandler, RequestConfig config = null)
void SearchRoom(ICondition condition, int limit, int offset, RoomSearchEventHandler handler, FailureEventHandler failureHandler, RequestConfig config = null)
Also, there are two specialized methods (with a different name) that search only for rooms that more members can join in.
void SearchJoinableRoom(int limit, int offset, RoomSearchEventHandler handler, FailureEventHandler failureHandler, RequestConfig config = null)
void SearchJoinableRoom(ICondition condition, Order order, int limit, int offset, RoomSearchEventHandler handler, FailureEventHandler failureHandler, RequestConfig config = null)
Note
If there is no room at all, search methods complete successfully and invoke a success handler, passing an empty collection as found rooms.
The same is true for a case that a search condition is specified and no room matched the condition.
Search Conditions¶
To narrow search results, Strix provides an argument called condition
to some of the search functions.
This lets you build complex search queries using a specialized API.
The ConditionBuilder
class provides a simple interface for building queries.
First, you call ConditionBuilder.Builder()
.
Every condition starts with a field,
so you can call the Field method on the builder and specify the field’s name.
ConditionBuilder.Builder()
.Field("capacity")
Then, you have to add any of the following condition clauses. Most of these accept either some terminal value or another field.
For example, you can check if the capacity equals 4 in the following way:
ConditionBuilder.Builder()
.Field("capacity")
.EqualTo(4)
Or check if the capacity equals the member count:
ConditionBuilder.Builder()
.Field("capacity")
.EqualTo(new Field("memberCount"))
After that,
you can either add additional clauses using the And()
and Or()
methods,
or just finish the condition using the Build()
method.
Note
All the clauses that operate on strings are case-sensitive.
Search Order¶
Strix provides an order
argument to some search functions.
This describes how to order the list of search results.
Order order = new Order("MyField", OrderType.Ascending);
// Or Descending
order.SetOrderType(OrderType.Descending);
The fieldName
is a field name to order on,
and the orderType
is the direction to order the list by.
Code Example¶
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;
// This is a placeholder value. Change this to your application ID
// It can be found on the Strix Cloud application information tab: https://www.strixcloud.net/app/applist
strixNetwork.applicationId = "00000000-0000-0000-0000-000000000000";
// First we connect to the master server
strixNetwork.ConnectMasterServer(
// This is a placeholder value. Change this to your master hostname
// It can be found on the Strix Cloud application information tab: https://www.strixcloud.net/app/applist
host: "000000000000000000000000.game.strixcloud.net",
connectEventHandler: _ => {
Debug.Log("Connection established.");
// After we've connected to the master server we can create a room
strixNetwork.CreateRoom(
new RoomProperties { name = "My Game Room" },
new RoomMemberProperties { name = "My Player Name" },
handler: __ => {
Debug.Log("Room 1 created.");
// Now that the room is created let's see if we can find it by its name
strixNetwork.SearchRoom(
condition: ConditionBuilder.Builder().Field("name").EqualTo("My Game Room").Build(), // Search for all rooms named "My Game Room"
limit: 10, // Only get 10 results
offset: 0, // Starting from the very first one
handler: searchResults => {
Debug.Log(searchResults.roomInfoCollection.Count + " rooms found.");
// After the search is finished we print the information about all the found rooms
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)
);
}
}
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.