Creating a New Room

The easiest way to create a new room is to call one of the CreateRoom methods on the StrixNetwork singleton.

void CreateRoom(RoomProperties roomProperties, RoomMemberProperties memberProperties, RoomCreateEventHandler handler, FailureEventHandler failureHandler, RequestConfig config = null)
void CreateRoom(IDictionary<string, object> roomProperties, string playerName, RoomCreateEventHandler handler, FailureEventHandler failureHandler, RequestConfig config = null)
void CreateRoom(IDictionary<string, object> roomProperties, IDictionary<string, object> memberProperties, RoomCreateEventHandler handler, FailureEventHandler failureHandler, RequestConfig config = null)

Note

Although CreateRoom method doesn’t have any argument to identify which room server the room will be created on, you don’t need to connect by yourself to a room server beforehand. An appropriate room server is selected by Strix if you have multiple room servers.

Property Requirements

These functions require both room properties and member properties.

The room properties are the initial properties of the room. Here you can specify custom values to define your room within the context of the game. Member properties are necessary as creation of a room will always connect the current player automatically.

Required Member Properties:

Name

Type

Description

name

String

The name of the room member

Required Room Properties:

Name

Type

Description

capacity

int

The number of players allowed in the room

name

String

The name of the room

Note

Even if you omitted any or all of these required properties, the room creation will success using their default values. However, the default values may not suit your game, and the resulting room may not work as intended. Please always specify all of the above properties.

Note

Pay attention to the names of the dictionary string keys. They should match the names of the properties as listed in the tables on the Getting Room and Room Member Information page. Case is significant in property names.

Note

Since Strix Unity SDK currently does not support joining multiple rooms simultaneously, creating a new one while being joined to another will make you leave the room you were in. This may in turn lead to the room being destroyed if you were the last member.

Code Example

using SoftGear.Strix.Client.Core.Model.Manager.Filter;
using SoftGear.Strix.Client.Core.Model.Manager.Filter.Builder;
using SoftGear.Strix.Unity.Runtime;
using System.Collections.Generic;
using UnityEngine;

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

        // This is a placeholder value. Change it 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 it 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 = "Fire Tournament",
                        password = "66e3f2nk",                                              // This room will be password-protected so clients without the password won't be able to join it
                        capacity = 20,                                                      // The maximum number of clients the room will hold
                        key1 = 4.0,                                                         // We will use key1 to define the difficulty level of the NPCs used in this match
                        properties = new Dictionary<string, object> { {                     // We use custom properties to give a description to our room
                            "description", "The first major tournament of the new season."  // This description can be displayed later when searching for rooms
                        } }
                    },
                    new RoomMemberProperties {
                        name = "Braille"                                                           // This will be the name of our player
                    },
                    handler: __ => {
                        Debug.Log("Room created.");

                        // Now that the room is created let's see if we can find it using the SearchRoom method
                        strixNetwork.SearchRoom(
                            condition: ConditionBuilder.Builder().Field("key1").GreaterThan(2.0).Build(),  // Search for rooms whose difficulty level is greater than 2
                            order: new Order("memberCount", OrderType.Ascending),                          // Order them in such a way that the first room will be the least crowded
                            limit: 10,                                                                     // Only get 10 results
                            offset: 0,                                                                     // Starting from the very first one
                            handler: searchResults => {
                                var foundRooms = searchResults.roomInfoCollection;
                                Debug.Log(foundRooms.Count + " rooms found.");

                                // After the search is finished we print the information about all the found rooms
                                foreach (var roomInfo in foundRooms)
                                    Debug.Log("Room ID: " + roomInfo.id
                                        + "\nHost: " + roomInfo.host
                                        + "\nMember count: " + roomInfo.memberCount
                                        + "\nCapacity: " + roomInfo.capacity
                                        + "\nDifficulty: " + roomInfo.key1
                                        + "\nDescription: " + (roomInfo.properties != null && roomInfo.properties.ContainsKey("description") ? roomInfo.properties["description"] : "None")
                                    );
                            },
                            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.