sfs2x.client.requests.game
Class CreateSFSGameRequest

java.lang.Object
  extended by sfs2x.client.requests.BaseRequest
      extended by sfs2x.client.requests.game.CreateSFSGameRequest
All Implemented Interfaces:
sfs2x.client.requests.IRequest

public class CreateSFSGameRequest
extends BaseRequest

Creates a new public or private game, including player matching criteria, invitations settings and more.

A game is created through the instantiation 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 roomAdd event is dispatched to all the users who subscribed the Group to which the Room is associated, including the game creator. Otherwise, a roomCreationError 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.

Example
The following example creates a new game:

 private void someMethod() {
     sfs.addEventListener(SFSEvent.ROOM_ADD, new IEventListener() {
         public void dispatch(BaseEvent evt) throws SFSException {
             System.out.println("Room created: " + evt.getArguments().get("room"));
         }
     });
     sfs.addEventListener(SFSEvent.ROOM_CREATION_ERROR, new IEventListener() {
         public void dispatch(BaseEvent evt) throws SFSException {
             System.out.println("Room creation failed: " + evt.getArguments().get("errorMessage"));
         }
     });
     
     // Prepare the settings for a public game
     SFSGameSettings settings = new SFSGameSettings("DartsGame");
     settings.setMaxUsers(2);
     settings.setMaxSpectators(8);
     settings.setPublic(true);
     settings.setMinPlayersToStartGame(2);
     settings.setNotifyGameStarted(true);
     
     // Set the matching expression for filtering users joining the Room
     settings.setPlayerMatchExpression(new MatchExpression("bestScore", NumberMatch.GREATER_THAN, 100));
     
     // Set a Room Variable containing the description of the game
     List roomVariables = new ArrayList();
     roomVariables.add(new SFSRoomVariable("desc", "Darts game, public, bestScore > 100"));
     settings.setVariables(roomVariables);
     
     // Create the game
     sfs.send(new CreateSFSGameRequest(settings));
 }
 

See Also:
SFSGameSettings, SFSEvent.ROOM_ADD, SFSEvent.ROOM_CREATION_ERROR, SFSEvent.INVITATION

Field Summary
static java.lang.String KEY_INVITATION_EXPIRY
          * API internal usage only *
static java.lang.String KEY_INVITATION_PARAMS
          * API internal usage only *
static java.lang.String KEY_INVITED_PLAYERS
          * API internal usage only *
static java.lang.String KEY_IS_PUBLIC
          * API internal usage only *
static java.lang.String KEY_LEAVE_ROOM
          * API internal usage only *
static java.lang.String KEY_MIN_PLAYERS
          * API internal usage only *
static java.lang.String KEY_NOTIFY_GAME_STARTED
          * API internal usage only *
static java.lang.String KEY_PLAYER_MATCH_EXP
          * API internal usage only *
static java.lang.String KEY_SEARCHABLE_ROOMS
          * API internal usage only *
static java.lang.String KEY_SPECTATOR_MATCH_EXP
          * API internal usage only *
 
Fields inherited from class sfs2x.client.requests.BaseRequest
AddBuddy, AdminMessage, AutoJoin, BanUser, BlockBuddy, CallExtension, ChangeRoomCapacity, ChangeRoomName, ChangeRoomPassword, CreateRoom, CreateSFSGame, FindRooms, FindUsers, GenericMessage, GetRoomList, GoOnline, Handshake, InitBuddyList, InvitationReply, InviteUser, JoinRoom, JoinRoomInvite, KEY_ERROR_CODE, KEY_ERROR_PARAMS, KickUser, LeaveRoom, Login, Logout, ManualDisconnection, ModeratorMessage, ObjectMessage, PingPong, PlayerToSpectator, PrivateMessage, PublicMessage, QuickJoinGame, RemoveBuddy, SetBuddyVariables, SetRoomVariables, SetUserPosition, SetUserVariables, SpectatorToPlayer, SubscribeRoomGroup, UnsubscribeRoomGroup
 
Constructor Summary
CreateSFSGameRequest(SFSGameSettings settings)
          Creates a new CreateSFSGameRequest instance.
 
Method Summary
 void execute(ISmartFox sfs)
          * API internal usage only *
 void validate(ISmartFox sfs)
          * API internal usage only *
 
Methods inherited from class sfs2x.client.requests.BaseRequest
getId, getMessage, getTargetController, isEncrypted, setEncrypted, setId, setTargetController
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_IS_PUBLIC

public static final java.lang.String KEY_IS_PUBLIC
* API internal usage only *

See Also:
Constant Field Values

KEY_MIN_PLAYERS

public static final java.lang.String KEY_MIN_PLAYERS
* API internal usage only *

See Also:
Constant Field Values

KEY_INVITED_PLAYERS

public static final java.lang.String KEY_INVITED_PLAYERS
* API internal usage only *

See Also:
Constant Field Values

KEY_SEARCHABLE_ROOMS

public static final java.lang.String KEY_SEARCHABLE_ROOMS
* API internal usage only *

See Also:
Constant Field Values

KEY_PLAYER_MATCH_EXP

public static final java.lang.String KEY_PLAYER_MATCH_EXP
* API internal usage only *

See Also:
Constant Field Values

KEY_SPECTATOR_MATCH_EXP

public static final java.lang.String KEY_SPECTATOR_MATCH_EXP
* API internal usage only *

See Also:
Constant Field Values

KEY_INVITATION_EXPIRY

public static final java.lang.String KEY_INVITATION_EXPIRY
* API internal usage only *

See Also:
Constant Field Values

KEY_LEAVE_ROOM

public static final java.lang.String KEY_LEAVE_ROOM
* API internal usage only *

See Also:
Constant Field Values

KEY_NOTIFY_GAME_STARTED

public static final java.lang.String KEY_NOTIFY_GAME_STARTED
* API internal usage only *

See Also:
Constant Field Values

KEY_INVITATION_PARAMS

public static final java.lang.String KEY_INVITATION_PARAMS
* API internal usage only *

See Also:
Constant Field Values
Constructor Detail

CreateSFSGameRequest

public CreateSFSGameRequest(SFSGameSettings settings)
Creates a new CreateSFSGameRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.

Parameters:
settings - An object containing the SFSGame configuration settings.
See Also:
SmartFox.send(sfs2x.client.requests.IRequest), SFSGameSettings
Method Detail

validate

public void validate(ISmartFox sfs)
              throws sfs2x.client.exceptions.SFSValidationException
* API internal usage only *

Throws:
sfs2x.client.exceptions.SFSValidationException

execute

public void execute(ISmartFox sfs)
* API internal usage only *