Click or drag to resize

QuickJoinOrCreateRoomRequest Class

Quickly joins the current user in a public Room, or creates a new Room if none is found.
Inheritance Hierarchy
SystemObject
  BaseRequest
    Sfs2X.RequestsQuickJoinOrCreateRoomRequest

Namespace:  Sfs2X.Requests
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.8.0.0 (1.8.0)
Syntax
C#
public class QuickJoinOrCreateRoomRequest : BaseRequest
Constructors
Remarks
SmartFoxServer searches for a public Room that meets the criteria expressed by the passed matching expression in the passed Room Groups. If no suitable Room can be found, a new Room is created, based on the passed settings.

If a Room is created, the ROOM_ADD event is dispatched to all the users who subscribed the Group to which the Room is associated, including the Room creator. In any case, if a Room to join could be found or was created, the ROOM_JOIN event is then dispatched.

Error conditions (Room creation error, Room join error) should always be checked adding the appropriate listeners.

Examples
The following example makes the user quickly join a Room:
void SomeMethod() {
    sfs.AddEventListener(SFSEvent.ROOM_ADD, OnRoomAdd);
    sfs.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin);

       // Create a matching expression to find a Darts game with a "maxBet" variable less than 100
    MatchExpression exp = new MatchExpression("type", StringMatch.EQUALS, "Darts").And("maxBet", NumberMatch.LESS_THAN, 100);

       // Set the Room settings to create a new Room if a matching one is not found
       RoomSettings settings = new RoomSettings("NewRoom__" + new System.Random().Next());
       settings.GroupId = "games";
       settings.IsPublic = true;
       settings.IsGame = true;
       settings.MaxUsers = 10;
       settings.MinPlayersToStartGame = 2;

       // Set requirements to allow users find the Room (see match expression above) in Room Variables
       List<RoomVariable> roomVars = new List<RoomVariable>();
       roomVars.Add(new SFSRoomVariable("type", "Darts"));
       roomVars.Add(new SFSRoomVariable("maxBet", 50));
       settings.Variables = roomVars;

       // Search (or create) and join a public Room within the "games" Group
       sfs.Send(new QuickJoinOrCreateRoomRequest(exp, new List<string>(){"games"}, settings));
}

void OnRoomAdd(BaseEvent evt) {    
    Console.WriteLine("Room created: " + (Room)evt.Params["room"]);                         // .Net / Unity
    System.Diagnostics.Debug.WriteLine("Room created: " + (Room)evt.Params["room"]);        // UWP
}

void OnRoomJoin(BaseEvent evt) {    
    Console.WriteLine("Successfully joined Room: " + (Room)evt.Params["room"]);                         // .Net / Unity
    System.Diagnostics.Debug.WriteLine("Successfully joined Room: " + (Room)evt.Params["room"]);        // UWP
}
See Also