How to Find Rooms for Specific Rules or Specific Maps

Each room may have various parameters like current game map, mode, stage, etc. Using the SearchJoinableRoom() function and the ICondition object it is possible to find a collection of rooms which meet the search conditions.

Let’s say there are the following game modes and maps.

public enum GameRule {
    TeamDeathMatch = 0,
    DeathMatch,
    GroundBattle
}

public enum GameMap {
    Island = 0,
    Sea,
    River
}

They are properties specific to a particular game title, so we use custom properties to represent them. That is, use key1 to store a GameRule and key2 to store a GameMap.

The script to create a room (in a DeathMatch rule on Island map) will look like:

StrixNetwork.instance.CreateRoom(
    new RoomProperties {
        name = "New Room",
        capacity = 4,
        key1 = (double)GameRule.DeathMatch,
        key2 = (double)GameMap.Island
    },
    new RoomMemberProperties {
        name = "Player name"
    },
    args => {
        Debug.Log("CreateRoom succeeded");
    },
    args => {
        Debug.Log("CreateRoom failed. error = " + args.cause);
    }
);

One can search for rooms by conditions by creating an ICondition object. It is necessary to pass the property’s name (called field in the search API) and its expected value in a condition object to perform a search.

StrixNetwork.instance.SearchJoinableRoom(
    new Equals(new Field("key1"), new Value((double)GameRule.DeathMatch)),
    null, 10, 0,
    args => {
        foreach (var roomInfo in args.roomInfoCollection) {
            Debug.Log("roomId " + roomInfo.roomId + " name " + roomInfo.name);
        }
    },
    args => {
        Debug.Log("SearchJoinableRoom failed. error = " + args.cause);
    }
);

Alternatively, you can use ConditionBuilder to create an ICondition object provides a more convenient and readable expression.

StrixNetwork.instance.SearchJoinableRoom(
    ConditionBuilder.Builder().Field("key1").EqualTo((double)GameRule.DeathMatch).Build(),
    null, 10, 0,
    args => {
        foreach (var roomInfo in args.roomInfoCollection) {
            logger.Info("roomId " + roomInfo.roomId + " name " + roomInfo.name);
        }
    },
    args => {
        logger.Info("SearchJoinableRoom failed. error = " + args.cause);
    }
);

Using an And object it is possible to search for rooms using several conditions.

StrixNetwork.instance.SearchJoinableRoom(
    new And(
        new List<ICondition> {
            new Equals(new Field("key1"), new Value((double)GameRule.DeathMatch)),
            new Equals(new Field("key2"), new Value((double)GameMap.Island))
        }
    ), null, 10, 0,
    args => {
        foreach (var roomInfo in args.roomInfoCollection) {
            logger.Info("roomId " + roomInfo.roomId + " name " + roomInfo.name);
        }
    },
    args => {
        logger.Info("SearchJoinableRoom failed. error = " + args.cause);
    }
);

Or, the same search below using ConditionBuilder.

StrixNetwork.instance.SearchJoinableRoom(
    ConditionBuilder.Builder()
        .Field("key1").EqualTo((double)GameRule.DeathMatch)
        .And()
        .Field("key2").EqualTo((double)GameMap.Island)
        .Build(),
    null, 10, 0,
    args => {
        foreach (var roomInfo in args.roomInfoCollection) {
            logger.Info("roomId " + roomInfo.roomId + " name " + roomInfo.name);
        }
    },
    args => {
        logger.Info("SearchJoinableRoom failed. error = " + args.cause);
    }
);

Strix provides the following condition constructs.

Condition type

Builder method

Data Type

Description

Equals

EqualTo

any

key == value

NotEquals

NotEqualTo

any

key != value

GreaterThan

GreaterThan

number

key > value

GreaterThanEquals

GreaterThanEquals

number

key >= value

LessThan

LessThan

number

key < value

LessThanEquals

LessThanEquals

number

key <= value

IsNull

IsNull

string

key is null

IsNotNull

IsNotNull

string

key is not null

Like

Like

string

key is like value (pattern)

NotLike

(unavailable)

string

key is not like value (pattern)

And

And

condition

Both condition A and Condition B

Or

Or

condition

Condition A, Condition B, or both

  • In this table, any means bool, int, long, double, or string, and number means either int, long, or double.

Note

Strix supports more condition constructs. See the API Reference for the full list.

The following property (field) names can be used in search conditions.

Field name

Type

roomId

long

capacity

int

memberCount

int

primaryKey

long

isPasswordProtected

bool

isJoinable

bool

state

int

name

string

key1

double

key2

double

key3

double

key4

double

key5

double

key6

double

key7

double

key8

double

stringKey

string

Note

You can search a room using standard properties (such as capacity or memberCount) as well as standard custom properties (such as state or key1), but you can’t using full-custom properties (those stored in properties).

Note

Type of these properties are significant when performing a search. No automatic type conversion takes place. If the name of a room property and the specified type don’t match, no errors are detected, but the search returns unusable results.

For example, if you want to find a room whose capacity is not two, you can pass the following condition to a search method:

new Equals(new Field("capacity"), new Value(2))

However, if you would make a mistake to write it as follows, for whatever reason, it doesn’t work.

new  Equals(new Field("capacity"), new Value(2.0))

The search with the latter condition will return list of rooms including those with the capacity equals to 2. Strix condition system distinguishes an int value 2 and a double value 2.0, and the type of “capacity” property is int, so the search returns the room whose capacity is not “a double value 2.0”.

In the example presented on this page, GameRule and GameMap are enums, while key1 and key2 custom properties are of type double. That’s why these enum values are always casted to double in the above example codes.

You need a special attention when passing one of the enum values to a Value constructor or a comparison method like EqualTo (in condition builder), because they have overloads taking int and double (among other types) for different properties. If you pass an enum value to them without a cast, C# grammar implicitly casts them to int to invoke an int version, which creates an unusable ICondition object.