Click or drag to resize

StrixNetworkCreateRoom Method (IDictionaryString, Object, String, RoomCreateEventHandler, FailureEventHandler, RequestConfig)

Creates a new room with the given properties and immediately joins the room as the owner with the given player name.

Namespace:  SoftGear.Strix.Unity.Runtime
Assembly:  StrixUnityRuntime (in StrixUnityRuntime.dll) Version: 1.5.0
public void CreateRoom(
	IDictionary<string, Object> roomProperties,
	string playerName,
	RoomCreateEventHandler handler,
	FailureEventHandler failureHandler,
	RequestConfig config = null


Type: System.Collections.GenericIDictionaryString, Object
Use this to set room name, member capacity, password, etc.
Type: SystemString
Name of the room's owner
Type: SoftGear.Strix.Unity.Runtime.EventRoomCreateEventHandler
This callback is invoked when the room creation is finished.
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.
NullReferenceExceptionThrown if called before connecting to the master server.
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.
RoomNotFoundCould not leave the current room before creating a new one. Either the room does not exist or you're not a member of this room.
InvalidCredentialsType Credentials type does not match the server authentication configuration. This can happen if, for example, the server is configured to authenticate by password instead of application ID. On Strix Cloud this error should never occur since currently it always uses application ID authentication.
InternalError Internal server error. This can be caused by a bug or some other problem on the server and should be reported to the developers.
UnsupportedLibraryVersion Current client library is not supported by the server. This can happen if the client version is too old. To fix this error, update the Strix SDK to the latest version.
InvalidApplicationIdToken Application ID token provided via applicationId does not match the one on the server. Check if the application ID is the same as the one listed on Information tab of the Dashboard on the Strix Cloud web page.
SocketExceptionAn error occurred when attempting to access the socket.
WebException There has been an error when connecting to the authentication server.
It's either an HTTP error such as 404/Not Found, or a network error like failure to resolve a DNS entry, a socket error, etc.
ArgumentException When using an authentication server this error can happen if the server returns an invalid authorization token.
It could be an invalid UTF-8 string or an invalid JSON.
Exception This can happen if the address for the given host couldn't be resolved when establishing socket connection.
In this example we first connect to a master server to be able to create a new room. Then we create a match room for up to 20 members, give it a name, set a password, and a description. Strix match rooms have 1 string property (stringKey) and 8 double properties (key1, ..., key8)) that can be set to any value and later be used in a search criteria. In the current example we use key1 to signify the difficulty of the game match and set it to 4.0. Since we define description as a custom property, we cannot use it in a search condition, but we can still read its value in the search results. After creating the room we perform a search for all rooms that have difficulty set to 2.0 or greater to check if the room was created correctly. Then we output the information about the found room to see if the properties we have set are readable.
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.
When using this overload, properties are set by means of a dictionary, so you have to be careful to provide the values of the correct type. In this example if we used 4 or 4.0f instead of 4.0 the request would fail since key1's type is double. To find out the expected types, please refer to the RoomProperties class.
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;

        strixNetwork.applicationId = "00000000-0000-0000-0000-000000000000";
            host: "",
            connectEventHandler: _ => {
                Debug.Log("Connection established.");

                    new Dictionary<string, object> {
                        { "name", "Fire Tournament" },
                        { "password", "66e3f2nk" },
                        { "capacity", 20 },
                        { "key1", 4.0 },
                        { "properties", new Dictionary<string, object> {
                            { "description", "The first major tournament of the new season." }
                        } }
                    playerName: "Braille",
                    handler: __ => {
                        Debug.Log("Room created.");

                            condition: ConditionBuilder.Builder().Field("key1").GreaterThan(2.0).Build(),
                            order: new Order("memberCount", OrderType.Ascending),
                            limit: 10,
                            offset: 0,
                            handler: searchResults => {
                                var foundRooms = searchResults.roomInfoCollection;
                                Debug.Log(foundRooms.Count + " rooms found.");

                                foreach (var roomInfo in foundRooms)
                                    Debug.Log("Room ID: " +
                                        + "\nHost: " +
                                        + "\nMember count: " + roomInfo.memberCount
                                        + "\nCapacity: " + roomInfo.capacity
                                        + "\nDifficulty: " + roomInfo.key1
                                        + "\nDescription: " + ( != null &&"description") ?["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)
See Also