Click or drag to resize

CreateSFSGameRequest Class

Creates a new public or private game, including player matching criteria, invitations settings and more.
Inheritance Hierarchy
SystemObject
  BaseRequest
    Sfs2X.Requests.GameCreateSFSGameRequest

Namespace:  Sfs2X.Requests.Game
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.8.0.0 (1.8.0)
Syntax
C#
public class CreateSFSGameRequest : BaseRequest

The CreateSFSGameRequest type exposes the following members.

Constructors
  NameDescription
Public methodCreateSFSGameRequest
Creates a new CreateSFSGameRequest instance.
Top
Remarks
A game is created through the istantiation of a SFSGame on the server-side, a specialized Room type that provides advanced features during the creation phase of a game. Specific game-configuration settings are passed by means of the SFSGameSettings class.

If the creation is successful, a ROOM_ADD event is dispatched to all the users who subscribed the Group to which the Room is associated, including the game creator. Otherwise, a ROOM_CREATION_ERROR event is returned to the creator's client.

Also, if the settings passed in the SFSGameSettings object cause invitations to join the game to be sent, an invitation event is dispatched to all the recipient clients.

Check the SmartFoxServer 2X documentation for a more in-depth overview of the GAME API.

Examples
The following example creates a new game:
void SomeMethod() {
    sfs.AddEventListener(SFSEvent.ROOM_ADD, OnRoomCreated);
    sfs.AddEventListener(SFSEvent.ROOM_CREATION_ERROR, OnRoomError);

    // Prepare the settings for a public game
    SFSGameSettings settings = new SFSGameSettings("DartsGame");
    settings.MaxUsers = 2;
    settings.MaxSpectators = 8;
    settings.IsPublic = true;
    settings.MinPlayersToStartGame = 2;
    settings.NotifyGameStarted = true;

    // Set the matching expression to filter users joining the Room
    settings.PlayerMatchExpression = new MatchExpression("bestScore", NumberMatch.GREATER_THAN, 100);

    // Set a Room Variable containing the description of the game
    List<RoomVariable> roomVars = new List<RoomVariable>();
    roomVars.Add(new SFSRoomVariable("desc", "Darts game, public, bestScore > 100"));
    settings.variables = roomVars;

    // Create the game
    smartFox.Send( new CreateSFSGameRequest(settings) );
}

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

void OnRoomError(BaseEvent evt) {
    Console.WriteLine("Room creation failed: " + (string)evt.Params["errorMessage"]);                           // .Net / Unity
    System.Diagnostics.Debug.WriteLine("Room creation failed: " + (string)evt.Params["errorMessage"]);          // UWP
}
See Also