Class SFSEvent


  • public class SFSEvent
    extends BaseEvent
    SFSEvent is the class representing most of the events dispatched by the SmartFoxServer 2X Java client API.

    The SFSEvent parent class provides a public property called arguments which contains specific parameters depending on the event type.

    Example
    The following example shows a generic usage of a SFSEvent; please refer to the specific event types for the params object content:
     package sfsTest;
     
     import com.smartfoxserver.v2.exceptions.SFSException;
     import sfs2x.client.SmartFox;
     import sfs2x.client.core.BaseEvent;
     import sfs2x.client.core.IEventListener;
     import sfs2x.client.core.SFSEvent;
     
     import java.util.Map;
     
     public class MyTest 
     {
         private SmartFox sfs;
         
         public MyTest() 
         {
                   // Create a SmartFox instance
                   sfs = new SmartFox();
             
             // Add event handler for connection
             sfs.addEventListener(SFSEvent.CONNECTION, new IEventListener() 
             {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     
                     // Retrieve event parameters
                     Map params = evt.getArguments();
                     
                     if ((Boolean)params.get("success"))
                         System.out.println("Connection established");
                     else
                         System.out.println("Connection failed");
                 }
             });
             
             // Connect to server
             sfs.connect("127.0.0.1", 9933);
         }
     }
     
    See Also:
    SFSBuddyEvent
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ADMIN_MESSAGE
      The SFSEvent.ADMIN_MESSAGE constant defines the value of the type property of the event object for a adminMessage event.
      static java.lang.String CONFIG_LOAD_FAILURE
      The SFSEvent.CONFIG_LOAD_FAILURE constant defines the value of the type property of the event object for a configLoadFailure event.
      static java.lang.String CONFIG_LOAD_SUCCESS
      The SFSEvent.CONFIG_LOAD_SUCCESS constant defines the value of the type property of the event object for a configLoadSuccess event.
      static java.lang.String CONNECTION
      The SFSEvent.CONNECTION constant defines the value of the type property of the event object for a connection event.
      static java.lang.String CONNECTION_ATTEMPT_HTTP
      The SFSEvent.CONNECTION_ATTEMPT_HTTP constant defines the value of the type property of the event object for a connectionAttemptHttp event.
      static java.lang.String CONNECTION_LOST
      The SFSEvent.CONNECTION_LOST constant defines the value of the type property of the event object for a connectionLost event.
      static java.lang.String CONNECTION_RESUME
      The SFSEvent.CONNECTION_RESUME constant defines the value of the type property of the event object for a connectionResume event.
      static java.lang.String CONNECTION_RETRY
      The SFSEvent.CONNECTION_RETRY constant defines the value of the type property of the event object for a connectionRetry event.
      static java.lang.String CRYPTO_INIT
      The SFSEvent.CRYPTO_INIT constant defines the value of the type property of the event object for a cryptoInit call.
      static java.lang.String EXTENSION_RESPONSE
      The SFSEvent.EXTENSION_RESPONSE constant defines the value of the type property of the event object for a extensionResponse event.
      static java.lang.String HANDSHAKE
      * API internal usage only *
      static java.lang.String INVITATION
      The SFSEvent.INVITATION constant defines the value of the type property of the event object for a invitation event.
      static java.lang.String INVITATION_REPLY
      The SFSEvent.INVITATION_REPLY constant defines the value of the type property of the event object for a invitationReply event.
      static java.lang.String INVITATION_REPLY_ERROR
      The SFSEvent.INVITATION_REPLY_ERROR constant defines the value of the type property of the event object for a invitationReplyError event.
      static java.lang.String LOGIN
      The SFSEvent.LOGIN constant defines the value of the type property of the event object for a login event.
      static java.lang.String LOGIN_ERROR
      The SFSEvent.LOGIN_ERROR constant defines the value of the type property of the event object for a loginError event.
      static java.lang.String LOGOUT
      The SFSEvent.LOGOUT constant defines the value of the type property of the event object for a logout event.
      static java.lang.String MMOITEM_VARIABLES_UPDATE
      The SFSEvent.MMOITEM_VARIABLES_UPDATE constant defines the value of the type property of the event object for a mmoItemVariablesUpdate event.
      static java.lang.String MODERATOR_MESSAGE
      The SFSEvent.MODERATOR_MESSAGE constant defines the value of the type property of the event object for a moderatorMessage event.
      static java.lang.String OBJECT_MESSAGE
      The SFSEvent.OBJECT_MESSAGE constant defines the value of the type property of the event object for a objectMessage event.
      static java.lang.String PING_PONG
      The SFSEvent.PING_PONG constant defines the value of the type property of the event object for a pingPong event.
      static java.lang.String PLAYER_TO_SPECTATOR
      The SFSEvent.PLAYER_TO_SPECTATOR constant defines the value of the type property of the event object for a playerToSpectator event.
      static java.lang.String PLAYER_TO_SPECTATOR_ERROR
      The SFSEvent.PLAYER_TO_SPECTATOR_ERROR constant defines the value of the type property of the event object for a playerToSpectatorError event.
      static java.lang.String PRIVATE_MESSAGE
      The SFSEvent.PRIVATE_MESSAGE constant defines the value of the type property of the event object for a privateMessage event.
      static java.lang.String PROXIMITY_LIST_UPDATE
      The SFSEvent.PROXIMITY_LIST_UPDATE constant defines the value of the type property of the event object for a proximityListUpdate event.
      static java.lang.String PUBLIC_MESSAGE
      The SFSEvent.PUBLIC_MESSAGE constant defines the value of the type property of the event object for a publicMessage event.
      static java.lang.String ROOM_ADD
      The SFSEvent.ROOM_ADD constant defines the value of the type property of the event object for a roomAdd event.
      static java.lang.String ROOM_CAPACITY_CHANGE
      The SFSEvent.ROOM_CAPACITY_CHANGE constant defines the value of the type property of the event object for a roomCapacityChange event.
      static java.lang.String ROOM_CAPACITY_CHANGE_ERROR
      The SFSEvent.ROOM_CAPACITY_CHANGE_ERROR constant defines the value of the type property of the event object for a roomCapacityChangeError event.
      static java.lang.String ROOM_CREATION_ERROR
      The SFSEvent.ROOM_CREATION_ERROR constant defines the value of the type property of the event object for a roomCreationError event.
      static java.lang.String ROOM_FIND_RESULT
      The SFSEvent.ROOM_FIND_RESULT constant defines the value of the type property of the event object for a roomFindResult event.
      static java.lang.String ROOM_GROUP_SUBSCRIBE
      The SFSEvent.ROOM_GROUP_SUBSCRIBE constant defines the value of the type property of the event object for a roomGroupSubscribe event.
      static java.lang.String ROOM_GROUP_SUBSCRIBE_ERROR
      The SFSEvent.ROOM_GROUP_SUBSCRIBE_ERROR constant defines the value of the type property of the event object for a roomGroupSubscribeError event.
      static java.lang.String ROOM_GROUP_UNSUBSCRIBE
      The SFSEvent.ROOM_GROUP_UNSUBSCRIBE constant defines the value of the type property of the event object for a roomGroupUnsubscribe event.
      static java.lang.String ROOM_GROUP_UNSUBSCRIBE_ERROR
      The SFSEvent.ROOM_GROUP_UNSUBSCRIBE_ERROR constant defines the value of the type property of the event object for a roomGroupUnsubscribeError event.
      static java.lang.String ROOM_JOIN
      The SFSEvent.ROOM_JOIN constant defines the value of the type property of the event object for a roomJoin event.
      static java.lang.String ROOM_JOIN_ERROR
      The SFSEvent.ROOM_JOIN_ERROR constant defines the value of the type property of the event object for a roomJoinError event.
      static java.lang.String ROOM_NAME_CHANGE
      The SFSEvent.ROOM_NAME_CHANGE constant defines the value of the type property of the event object for a roomNameChange event.
      static java.lang.String ROOM_NAME_CHANGE_ERROR
      The SFSEvent.ROOM_NAME_CHANGE_ERROR constant defines the value of the type property of the event object for a roomNameChangeError event.
      static java.lang.String ROOM_PASSWORD_STATE_CHANGE
      The SFSEvent.ROOM_PASSWORD_STATE_CHANGE constant defines the value of the type property of the event object for a roomPasswordStateChange event.
      static java.lang.String ROOM_PASSWORD_STATE_CHANGE_ERROR
      The SFSEvent.ROOM_PASSWORD_STATE_CHANGE_ERROR constant defines the value of the type property of the event object for a roomPasswordStateChangeError event.
      static java.lang.String ROOM_REMOVE
      The SFSEvent.ROOM_REMOVE constant defines the value of the type property of the event object for a roomRemove event.
      static java.lang.String ROOM_VARIABLES_UPDATE
      The SFSEvent.ROOM_VARIABLES_UPDATE constant defines the value of the type property of the event object for a roomVariablesUpdate event.
      static java.lang.String SOCKET_ERROR
      The SFSEvent.SOCKET_ERROR constant defines the value of the type property of the event object for a socketError event.
      static java.lang.String SPECTATOR_TO_PLAYER
      The SFSEvent.SPECTATOR_TO_PLAYER constant defines the value of the type property of the event object for a spectatorToPlayer event.
      static java.lang.String SPECTATOR_TO_PLAYER_ERROR
      The SFSEvent.SPECTATOR_TO_PLAYER_ERROR constant defines the value of the type property of the event object for a spectatorToPlayerError event.
      static java.lang.String UDP_INIT
      The SFSEvent.UDP_INIT constant defines the value of the type property of the event object for a udpInit event.
      static java.lang.String USER_COUNT_CHANGE
      The SFSEvent.USER_COUNT_CHANGE constant defines the value of the type property of the event object for a userCountChange event.
      static java.lang.String USER_ENTER_ROOM
      The SFSEvent.USER_ENTER_ROOM constant defines the value of the type property of the event object for a userEnterRoom event.
      static java.lang.String USER_EXIT_ROOM
      The SFSEvent.USER_EXIT_ROOM constant defines the value of the type property of the event object for a userExitRoom event.
      static java.lang.String USER_FIND_RESULT
      The SFSEvent.USER_FIND_RESULT constant defines the value of the type property of the event object for a userFindResult event.
      static java.lang.String USER_VARIABLES_UPDATE
      The SFSEvent.USER_VARIABLES_UPDATE constant defines the value of the type property of the event object for a userVariablesUpdate event.
    • Constructor Summary

      Constructors 
      Constructor Description
      SFSEvent​(java.lang.String type)  
      SFSEvent​(java.lang.String type, java.util.Map<java.lang.String,​java.lang.Object> args)
      Creates a new SFSEvent instance.
    • Field Detail

      • HANDSHAKE

        public static final java.lang.String HANDSHAKE
        * API internal usage only *
        See Also:
        Constant Field Values
      • UDP_INIT

        public static final java.lang.String UDP_INIT
        The SFSEvent.UDP_INIT constant defines the value of the type property of the event object for a udpInit event.

        Dispatched when the result of the UDP handshake is notified. This event is fired in response to a call to the initUDP() method.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        successBooleanThe connection result: true if a connection was established, false otherwise.
        Example
        The following example initializes the UDP communication and sends a custom UDP request to an Extension:
         private void someMethod() 
         {
             sfs.addEventListener(SFSEvent.UDP_INIT, new IEventListener() 
             {
                 public void dispatch(BaseEvent evt) throws SFSException 
                 {
                     if ((Boolean)evt.getArguments().get("success")) 
                     {
                         // Connection successful: execute an Extension call via UDP
                         sfs.send( new ExtensionRequest("udpTest", new SFSObject(), null, true) );
                     } else {
                         System.out.println("UDP initialization failed!");
                     }
                 }
             });
             
             sfs.initUdp();
         }
         
        See Also:
        SmartFox.initUdp(), ExtensionRequest, Constant Field Values
      • CONNECTION

        public static final java.lang.String CONNECTION
        The SFSEvent.CONNECTION constant defines the value of the type property of the event object for a connection event.

        Dispatched when a connection between the client and a SmartFoxServer 2X instance is attempted. This event is fired in response to a call to the connect() method.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        successBooleanThe connection result: true if a connection was established, false otherwise.
        Example
        The following example starts a connection:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.CONNECTION, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     if ((Boolean)evt.getArguments().get("success")) {
                         System.out.println("Connection established");
                     } else {
                         System.out.println("Connection failed");
                     }
                 }
             });
             
             sfs.connect();
         }
         
        See Also:
        SmartFox.connect(), CONNECTION_RETRY, CONNECTION_RESUME, CONNECTION_LOST, Constant Field Values
      • PING_PONG

        public static final java.lang.String PING_PONG
        The SFSEvent.PING_PONG constant defines the value of the type property of the event object for a pingPong event.

        Dispatched when a new lag value measurement is available. This event is fired when the automatic lag monitoring is turned on by passing true to the enableLagMonitor() method.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        lagValueintThe average of the last ten measured lag values, expressed in milliseconds.
        See Also:
        SmartFox.enableLagMonitor(boolean), Constant Field Values
      • SOCKET_ERROR

        public static final java.lang.String SOCKET_ERROR
        The SFSEvent.SOCKET_ERROR constant defines the value of the type property of the event object for a socketError event.

        Dispatched when a low level socket error is detected, for example bad/inconsistent data.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        errorMessageStringThe description of the error.
        See Also:
        Constant Field Values
      • CONNECTION_LOST

        public static final java.lang.String CONNECTION_LOST
        The SFSEvent.CONNECTION_LOST constant defines the value of the type property of the event object for a connectionLost event.

        Dispatched when the connection between the client and the SmartFoxServer 2X instance is interrupted. This event is fired in response to a call to the disconnect() method.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        reasonStringThe reason of the disconnection, among those available in the ClientDisconnectionReason class.
        Example
        The following example handles a disconnection event:
         private void someMethod() 
         {
             sfs.addEventListener(SFSEvent.CONNECTION_LOST, new IEventListener() 
             {
                 public void dispatch(BaseEvent evt) throws SFSException 
                 {
                     String reason = (String)evt.getArguments().get("reason");
                     
                     if (!reason.equals(ClientDisconnectionReason.MANUAL))
                     {
                         if (reason.equals(ClientDisconnectionReason.IDLE))
                             System.out.println("A disconnection occurred due to inactivity");
                         else if (reason.equals(ClientDisconnectionReason.KICK))
                             System.out.println("You have been kicked by the moderator");
                         else if (reason.equals(ClientDisconnectionReason.BAN))
                             System.out.println("You have been banned by the moderator");
                         else
                             System.out.println("A disconnection occurred due to unknown reason; please check the server log");
                     }
                     else
                     {
                         // Manual disconnection is usually ignored
                     }
                 }
             });
         }
         
        See Also:
        SmartFox.disconnect(), ClientDisconnectionReason, CONNECTION, CONNECTION_RETRY, Constant Field Values
      • CONNECTION_RETRY

        public static final java.lang.String CONNECTION_RETRY
        The SFSEvent.CONNECTION_RETRY constant defines the value of the type property of the event object for a connectionRetry event.

        Dispatched when the connection between the client and the SmartFoxServer 2X instance is interrupted abruptly while the SmartFoxServer 2X HRC system is available in the Zone.

        The HRC system allows a broken connection to be re-established transparently within a certain amount of time, without loosing any of the current application state. For example this allows any player to get back to a game without loosing the match because of a sloppy internet connection.

        When this event is dispatched the API enters a "freeze" mode where no new requests can be sent until the reconnection is successfully performed. It is highly recommended to handle this event and freeze the application interface accordingly until the connectionResume event is fired, or the reconnection fails and the user is definitely disconnected and the connectionLost event is fired.

        No parameters are available for this event object.

        Example
        The following example handles a temporary disconnection event and the following connection resume:
         private void someMethod() 
         {
             sfs.addEventListener(SFSEvent.CONNECTION_RETRY, new IEventListener() 
             {
                 public void dispatch(BaseEvent evt) throws SFSException 
                 {
                     // Freeze the GUI and provide some feedback to the player
                     ...
                 }
             });
             
             sfs.addEventListener(SFSEvent.CONNECTION_RESUME, new IEventListener() 
             {
                 public void dispatch(BaseEvent evt) throws SFSException 
                 {
                     // Unfreeze the GUI and let the player continue with the game
                     ...
                 }
             });
             
             sfs.addEventListener(SFSEvent.CONNECTION_LOST, new IEventListener() 
             {
                 public void dispatch(BaseEvent evt) throws SFSException 
                 {
                     System.out.println("Ouch, connection was lost. Reason: " + (String)evt.getArguments().get("reason"));
                 }
             });
         }
         
        See Also:
        CONNECTION_RESUME, CONNECTION_LOST, Constant Field Values
      • CONNECTION_RESUME

        public static final java.lang.String CONNECTION_RESUME
        The SFSEvent.CONNECTION_RESUME constant defines the value of the type property of the event object for a connectionResume event.

        Dispatched when the connection between the client and the SmartFoxServer 2X instance is re-established after a temporary disconnection, while the SmartFoxServer 2X HRC system is available in the Zone.

        The HRC system allows a broken connection to be re-established transparently within a certain amount of time, without loosing any of the current application state. For example this allows any player to get back to a game without loosing the match because of a sloppy internet connection.

        When this event is dispatched the application interface should be reverted to the state it had before the diconnection. In case the reconnection attempt fails, the connectionLost event is fired.

        No parameters are available for this event object.

        Example
        See the example provided in the CONNECTION_RETRY constant description.
        See Also:
        CONNECTION_RETRY, CONNECTION_LOST, Constant Field Values
      • CONNECTION_ATTEMPT_HTTP

        public static final java.lang.String CONNECTION_ATTEMPT_HTTP
        The SFSEvent.CONNECTION_ATTEMPT_HTTP constant defines the value of the type property of the event object for a connectionAttemptHttp event.

        Dispatched when the client cannot establish a socket connection to the server and the useBlueBox parameter is active in the configuration.

        The event can be used to notify the user that a second connection attempt is running, using the BlueBox (HTTP tunnelling).

        No parameters are available for this event object.

        See Also:
        CONNECTION, CONNECTION_LOST, Constant Field Values
      • CONFIG_LOAD_SUCCESS

        public static final java.lang.String CONFIG_LOAD_SUCCESS
        The SFSEvent.CONFIG_LOAD_SUCCESS constant defines the value of the type property of the event object for a configLoadSuccess event.

        Dispatched when the external client configuration file is loaded successfully. This event is fired in response to a call to the loadConfig() method, but only if the connectOnSuccess argument of the loadConfig() method is set to false; otherwise the connection is attempted and the related SFSEvent.CONNECTION event type is fired.

        No parameters are available for this event object.

        Example
        The following example loads an external configuration file:
         private void someMethod() 
         {
             sfs.addEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, new IEventListener() 
             {
                 public void dispatch(BaseEvent evt) throws SFSException 
                 {
                     // Configuration loaded successfully, now connect
                     sfs.connect();
                 }
             });
             
             sfs.addEventListener(SFSEvent.CONFIG_LOAD_FAILURE, new IEventListener() 
             {
                 public void dispatch(BaseEvent evt) throws SFSException 
                 {
                     System.out.println("Failed loading configuration file");
                 }
             });
             
             sfs.loadConfig("testConfig.xml", false);
         }
         
        See Also:
        SmartFox.loadConfig(), CONFIG_LOAD_FAILURE, Constant Field Values
      • CONFIG_LOAD_FAILURE

        public static final java.lang.String CONFIG_LOAD_FAILURE
        The SFSEvent.CONFIG_LOAD_FAILURE constant defines the value of the type property of the event object for a configLoadFailure event.

        Dispatched if an error occurs while loading the external client configuration file. This event is fired in response to a call to the loadConfig() method, typically when the configuration file is not found or it isn't accessible (no read permissions).

        No parameters are available for this event object.

        Example
        See the example provided in the CONFIG_LOAD_SUCCESS constant description.
        See Also:
        SmartFox.loadConfig(), CONFIG_LOAD_SUCCESS, Constant Field Values
      • LOGIN

        public static final java.lang.String LOGIN
        The SFSEvent.LOGIN constant defines the value of the type property of the event object for a login event.

        Dispatched when the current user performs a successful login in a server Zone. This event is fired in response to the LoginRequest request.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        userUserAn object representing the user who performed the login.
        dataISFSObjectAn object containing custom parameters returned by a custom login system, if any.
        Example
        The following example performs a login in the "SimpleChat" Zone:
         private void someMethod() 
         {
             sfs.addEventListener(SFSEvent.LOGIN, new IEventListener() 
             {
                 public void dispatch(BaseEvent evt) throws SFSException 
                 {
                     System.out.println("Login successful!");
                 }
             });
             
             sfs.addEventListener(SFSEvent.LOGIN_ERROR, new IEventListener() 
             {
                 public void dispatch(BaseEvent evt) throws SFSException 
                 {
                     System.out.println("Login failure: " + evt.getArguments().get("errorMessage"));
                 }
             });
             
             // Login
             sfs.send(new LoginRequest("FozzieTheBear", "", "SimpleChat"));
         }
         
        See Also:
        LoginRequest, User, LOGIN_ERROR, LOGOUT, Constant Field Values
      • LOGIN_ERROR

        public static final java.lang.String LOGIN_ERROR
        The SFSEvent.LOGIN_ERROR constant defines the value of the type property of the event object for a loginError event.

        Dispatched if an error occurs while the user login is being performed. This event is fired in response to the LoginRequest request in case the operation failed.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        errorMessageStringA message containing the description of the error.
        errorCodeshortThe error code.
        Example
        See the example provided in the LOGIN constant description.
        See Also:
        LoginRequest, LOGIN, Constant Field Values
      • LOGOUT

        public static final java.lang.String LOGOUT
        The SFSEvent.LOGOUT constant defines the value of the type property of the event object for a logout event.

        Dispatched when the current user performs logs out of the server Zone. This event is fired in response to the LogoutRequest request.

        No parameters are available for this event object.

        Example
        The following example performs a logout from the current Zone:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.LOGOUT, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Logout executed!");
                 }
             });
             
             // Logout
             sfs.send(new LogoutRequest());
         }
         
        See Also:
        LogoutRequest, LOGIN, Constant Field Values
      • ROOM_ADD

        public static final java.lang.String ROOM_ADD
        The SFSEvent.ROOM_ADD constant defines the value of the type property of the event object for a roomAdd event.

        Dispatched when a new Room is created inside the Zone under any of the Room Groups that the client subscribed. This event is fired in response to the CreateRoomRequest and CreateSFSGameRequest requests in case the operation is executed successfully.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        roomRoomAn object representing the Room that was created.
        Example
        The following example creates a new chat Room:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.ROOM_ADD, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Room created: " + (Room)evt.getArguments().get("room"));
                 }
             });
             sfs.addEventListener(SFSEvent.ROOM_CREATION_ERROR, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Room creation failure: " + evt.getArguments().get("errorMessage"));
                 }
             });
             
             // Define the settings of a new chat Room
             RoomSettings settings = new RoomSettings("My Chat Room");
             settings.setMaxUsers(40);
             settings.setGroupId("chats");
             
             // Create the Room
             sfs.send(new CreateRoomRequest(settings));
         }
         
        See Also:
        CreateRoomRequest, CreateSFSGameRequest, Room, ROOM_REMOVE, ROOM_CREATION_ERROR, Constant Field Values
      • ROOM_REMOVE

        public static final java.lang.String ROOM_REMOVE
        The SFSEvent.ROOM_REMOVE constant defines the value of the type property of the event object for a roomRemove event.

        Dispatched when a Room belonging to one of the Groups subscribed by the client is removed from the Zone.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        roomRoomAn object representing the Room that was removed.
        Example
        The following example shows how to handle this event type:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.ROOM_REMOVE, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("The following Room was removed: " + (Room)evt.getArguments().get("room"));
                 }
             });
         }
         
        See Also:
        Room, ROOM_ADD, Constant Field Values
      • ROOM_CREATION_ERROR

        public static final java.lang.String ROOM_CREATION_ERROR
        The SFSEvent.ROOM_CREATION_ERROR constant defines the value of the type property of the event object for a roomCreationError event.

        Dispatched if an error occurs while creating a new Room. This event is fired in response to the CreateRoomRequest and CreateSFSGameRequest requests in case the operation failed.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        errorMessageStringA message containing the description of the error.
        errorCodeshortThe error code.
        Example
        See the example provided in the ROOM_ADD constant description.
        See Also:
        CreateRoomRequest, CreateSFSGameRequest, ROOM_ADD, Constant Field Values
      • ROOM_JOIN

        public static final java.lang.String ROOM_JOIN
        The SFSEvent.ROOM_JOIN constant defines the value of the type property of the event object for a roomJoin event.

        Dispatched when a Room is joined by the current user. This event is fired in response to the JoinRoomRequest and QuickJoinGameRequest requests in case the operation is executed successfully.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        roomRoomAn object representing the Room that was joined.
        Example
        The following example makes the user join an existing Room:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.ROOM_JOIN, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Room joined successfully: " + (Room)evt.getArguments().get("room"));
                 }
             });
             sfs.addEventListener(SFSEvent.ROOM_JOIN, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Room joining failed: " + evt.getArguments().get("errorMessage"));
                 }
             });
             
             // Join a Room called "Lobby"
             sfs.send(new JoinRoomRequest("Lobby"));
         }
         
        See Also:
        JoinRoomRequest, QuickGameJoinRequest, Room, ROOM_JOIN_ERROR, Constant Field Values
      • ROOM_JOIN_ERROR

        public static final java.lang.String ROOM_JOIN_ERROR
        The SFSEvent.ROOM_JOIN_ERROR constant defines the value of the type property of the event object for a roomJoinError event.

        Dispatched when an error occurs while the current user is trying to join a Room. This event is fired in response to the JoinRoomRequest and QuickJoinGameRequest requests in case the operation failed.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        errorMessageStringA message containing the description of the error.
        errorCodeshortThe error code.
        Example
        See the example provided in the ROOM_JOIN constant description.
        See Also:
        JoinRoomRequest, QuickGameJoinRequest, ROOM_JOIN, Constant Field Values
      • USER_ENTER_ROOM

        public static final java.lang.String USER_ENTER_ROOM
        The SFSEvent.USER_ENTER_ROOM constant defines the value of the type property of the event object for a userEnterRoom event.

        Dispatched when one of the Rooms joined by the current user is entered by another user. This event is caused by a JoinRoomRequest and QuickJoinGameRequest requests; it might be fired or not depending on the Room configuration defined upon its creation (see the RoomSettings.events setting).

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        userUserAn object representing the user who joined the Room.
        roomRoomAn object representing the Room that was joined by a user.
        Example
        The following example shows how to handle this event type:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.USER_ENTER_ROOM, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     Room room = (Room) evt.getArguments().get("room");
                     User user = (User) evt.getArguments().get("user");
                     
                     System.out.println("User " + user.getName() + " just joined Room " + room.getName());
                 }
             });
         }
         
        See Also:
        JoinRoomRequest, QuickGameJoinRequest, RoomSettings.setEvents(sfs2x.client.requests.RoomEvents), User, Room, USER_EXIT_ROOM, USER_COUNT_CHANGE, Constant Field Values
      • USER_EXIT_ROOM

        public static final java.lang.String USER_EXIT_ROOM
        The SFSEvent.USER_EXIT_ROOM constant defines the value of the type property of the event object for a userExitRoom event.

        Dispatched when one of the Rooms joined by the current user is left by another user, or by the current user himself. This event is caused by a LeaveRoomRequest request; it might be fired or not depending on the Room configuration defined upon its creation (see the RoomSettings.events setting).

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        userUserAn object representing the user who left the Room.
        roomRoomAn object representing the Room that was left by a user.
        Example
        The following example shows how to handle this event type:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.USER_EXIT_ROOM, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     Room room = (Room) evt.getArguments().get("room");
                     User user = (User) evt.getArguments().get("user");
                     
                     System.out.println("User " + user.getName() + " just left Room " + room.getName());
                 }
             });
         }
         
        See Also:
        LeaveRoomRequest, RoomSettings.setEvents(sfs2x.client.requests.RoomEvents), User, Room, USER_ENTER_ROOM, USER_COUNT_CHANGE, Constant Field Values
      • USER_COUNT_CHANGE

        public static final java.lang.String USER_COUNT_CHANGE
        The SFSEvent.USER_COUNT_CHANGE constant defines the value of the type property of the event object for a userCountChange event.

        Dispatched when the number of users/players or spectators inside a Room changes. This event can be caused by either a JoinRoomRequest, QuickJoinGameRequest or a LeaveRoomRequest requests. The Room must belong to one of the Groups subscribed by the current client; also this event might be fired or not depending on the Room configuration defined upon its creation (see the RoomSettings.events setting).

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        roomRoomAn object representing the Room in which the users count changed.
        uCountintThe new users count (players in case of Game Room).
        sCountintThe new spectators count (Game Room only).
        Example
        The following example shows how to handle this event type:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.USER_COUNT_CHANGE, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     Room room = (Room) evt.getArguments().get("room");
                     int uCount = (Integer)evt.getArguments().get("uCount");
                     int sCount = (Integer)evt.getArguments().get("sCount");
                     
                     System.out.println("Room: " + room.getName() + " now contains " + uCount + " users and " + sCount + " spectators");
                 }
             });
         }
         
        See Also:
        JoinRoomRequest, QuickGameJoinRequest, LeaveRoomRequest, RoomSettings.setEvents(sfs2x.client.requests.RoomEvents), Room, USER_ENTER_ROOM, USER_EXIT_ROOM, Constant Field Values
      • PUBLIC_MESSAGE

        public static final java.lang.String PUBLIC_MESSAGE
        The SFSEvent.PUBLIC_MESSAGE constant defines the value of the type property of the event object for a publicMessage event.

        Dispatched when a public message is received by the current user. This event is caused by a PublicMessageRequest request sent by any user in the target Room, including the current user himself.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        roomRoomAn object representing the Room at which the message is targeted.
        senderUserAn object representing the user who sent the message.
        messageStringThe message sent by the user.
        dataISFSObjectAn object containing custom parameters which might accompany the message.
        Example
        The following example sends a public message and handles the respective event:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.PUBLIC_MESSAGE, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     // As messages are forwarded to the sender too,
                     // I have to check if I am the sender
                     
                     User sender = (User)evt.getArguments().get("sender");
                     if (sender.isItMe() == true)
                         System.out.println("I said:" + evt.getArguments().get("message"));
                     else
                         System.out.println("User " + sender.getName() + " said: " + evt.getArguments().get("message"));
                 }
             });
             
             // Send a public message
             sfs.send(new PublicMessageRequest("Hello everyone!"));
         }
         
        See Also:
        PublicMessageRequest, User, Room, PRIVATE_MESSAGE, Constant Field Values
      • PRIVATE_MESSAGE

        public static final java.lang.String PRIVATE_MESSAGE
        The SFSEvent.PRIVATE_MESSAGE constant defines the value of the type property of the event object for a privateMessage event.

        Dispatched when a private message is received by the current user. This event is caused by a PrivateMessageRequest request sent by any user in the Zone.

        NOTE: the same event is fired by the sender's client too, so that the user is aware that the message was delivered successfully to the recipient, and it can be displayed in the private chat area keeping the correct message ordering. In this case there is no default way to know who the message was originally sent to. As this information can be useful in scenarios where the sender is chatting privately with more than one user at the same time in separate windows or tabs (and we need to write his own message in the proper one), the data parameter can be used to store, for example, the id of the recipient user.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        senderUserAn object representing the user who sent the message.
        messageStringThe message sent by the user.
        dataISFSObjectAn object containing custom parameters which might accompany the message.
        Example
        The following example sends a private message and handles the respective event:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.PRIVATE_MESSAGE, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     // As messages are forwarded to the sender too,
                     // I have to check if I am the sender
                     
                     User sender = (User)evt.getArguments().get("sender");
                     if (sender.isItMe() == false)
                         System.out.println("User " + sender.getName() + " sent me this PM: " + evt.getArguments().get("message"));
                 }
             });
             
             // Send a private message to Jack
             User user = sfs.getUserManager().getUserByName("Jack");
             sfs.send(new PrivateMessageRequest("Hello everyone!", user.getId()));
         }
         
        See Also:
        PrivateMessageRequest, User, PUBLIC_MESSAGE, Constant Field Values
      • OBJECT_MESSAGE

        public static final java.lang.String OBJECT_MESSAGE
        The SFSEvent.OBJECT_MESSAGE constant defines the value of the type property of the event object for a objectMessage event.

        Dispatched when an object containing custom data is received by the current user. This event is caused by an ObjectMessageRequest request sent by any user in the target Room.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        senderUserAn object representing the user who sent the message.
        messageSFSObjectThe content of the message: an object containing the custom parameters sent by the sender.
        Example
        The following example sends the player's character movement coordinates and handles the respective event (note: the myCharacter instance is supposed to be the user sprite on the stage, while the getUserCharacter method retrieves the sprite of other users' characters):
         private void someMethod() {
             sfs.addEventListener(SFSEvent.OBJECT_MESSAGE, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     ISFSObject dataObj = (SFSObject)evt.getArguments().get("message");
                     
                     User sender = evt.getArguments().get("sender");
                     UserCharacter character = getUserCharacter(sender.getId());
                     
                     character.x = dataObj.getInt("x");
                     character.y = dataObj.getInt("y");
                     
                 }
             });
             
             // Send my movement to all players
             ISFSObject dataObj = new SFSObject();
             dataObj.putInt("x", myCharacter.x);
             dataObj.putInt("y", myCharacter.y);
             
             sfs.send(new ObjectMessageRequest(dataObj));
         }
         
        See Also:
        ObjectMessageRequest, User, Constant Field Values
      • MODERATOR_MESSAGE

        public static final java.lang.String MODERATOR_MESSAGE
        The SFSEvent.MODERATOR_MESSAGE constant defines the value of the type property of the event object for a moderatorMessage event.

        Dispatched when the current user receives a message from a moderator user. This event can be caused by either a ModeratorMessageRequest, KickUserRequest or a BanUserRequest requests sent by a user with at least moderation privileges. Also, this event can be caused by a kick/ban action performed through the SmartFoxServer 2X Administration Tool.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        senderUserAn object representing the moderator user who sent the message.
        messageStringThe message sent by the moderator.
        dataISFSObjectAn object containing custom parameters which might accompany the message.
        Example
        The following example sends a moderator message to all the users in the last joned Room; it also shows how to handle the related event:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.MODERATOR_MESSAGE, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("The moderator sent the following message: " + evt.getArguments().get("message"));
                 }
             });
             // Set the message recipients: all users in the current Room
             MessageRecipientMode recipMode = new MessageRecipientMode(MessageRecipientMode.TO_ROOM, sfs.getLastJoinedRoom());
             
             // Send the moderator message
             sfs.send(new ModeratorMessageRequest("Hello everybody, I'm the Moderator!", recipMode));
         }
         
        See Also:
        ModeratorMessageRequest, KickUserRequest, BanUserRequest, User, ADMIN_MESSAGE, Constant Field Values
      • ADMIN_MESSAGE

        public static final java.lang.String ADMIN_MESSAGE
        The SFSEvent.ADMIN_MESSAGE constant defines the value of the type property of the event object for a adminMessage event.

        Dispatched when the current user receives a message from an administrator user. This event is caused by the AdminMessageRequest request sent by a user with administration privileges.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        senderUserAn object representing the administrator user who sent the message.
        messageStringThe message sent by the administrator.
        dataISFSObjectAn object containing custom parameters which might accompany the message.
        Example
        The following example sends an administration message to all the users in the Zone; it also shows how to handle the related event:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.ADMIN_MESSAGE, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("The administrator sent the following message: " + evt.getArguments().get("message"));
                 }
             });
             
             // Set the message recipients: all users in the Zone
             MessageRecipientMode recipMode = new MessageRecipientMode(MessageRecipientMode.TO_ZONE, null);
             
             // Send the administrator message
             sfs.send(new AdminMessageRequest("Hello to everybody from the Administrator!", recipMode));
         }
         
        See Also:
        AdminMessageRequest, User, MODERATOR_MESSAGE, Constant Field Values
      • EXTENSION_RESPONSE

        public static final java.lang.String EXTENSION_RESPONSE
        The SFSEvent.EXTENSION_RESPONSE constant defines the value of the type property of the event object for a extensionResponse event.

        Dispatched when data coming from a server-side Extension is received by the current user. Data is usually sent by the server to one or more clients in response to an ExtensionRequest request, but not necessarily.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        cmdStringThe name of the command which identifies an action that should be executed by the client. If this event is fired in response to a request sent by the client, it is a common practice to use the same command name passed to the request also in the response.
        paramsISFSObjectAn object containing custom data sent by the Extension.
        sourceRoomNumber[DEPRECATED - Use room property] The id of the room which the Extension is attached to (for Room Extensions only).
        roomRoomAn object representing the Room which the Extension is attached to (for Room Extensions only, since 1.7.0).
        packetIdNumberThe id of the packet when the UDP protocol is used. As this is an auto-increment value generated by the server, it can be useful to detect UDP packets received in the wrong order.
        Example
        The following example sends a command to the Zone Extension; it also handles responses coming from the Extension by implementing the extensionResponse listener (the same command name is used in both the request and the response):
         private void someMethod() {
             sfs.addEventListener(SFSEvent.EXTENSION_RESPONSE, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     if (evt.getArguments().get("cmd").equals("add")) {
                         ISFSObject responseParams = (SFSObject)evt.getArguments().get("params");
                         
                         // We expect an int parameter called "sum"
                         System.out.println("The sum is: " + responseParams.getInt("sum"));
                     }
                 }
             });
             
             // Send two integers to the Zone extension and get their sum in return
             ISFSObject params = new SFSObject();
             params.putInt("n1", 26);
             params.putInt("n2", 16);
             
             sfs.send(new ExtensionRequest("add", params));
         }
         
        See Also:
        ExtensionRequest, Constant Field Values
      • ROOM_VARIABLES_UPDATE

        public static final java.lang.String ROOM_VARIABLES_UPDATE
        The SFSEvent.ROOM_VARIABLES_UPDATE constant defines the value of the type property of the event object for a roomVariablesUpdate event.

        Dispatched when a Room Variable is updated. This event is caused by the SetRoomVariablesRequest request. The request could have been sent by an user in the same Room of the current user or, in case of a global Room Variable, by a user in a Room belonging to one of the Groups subscribed by the current client.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        roomRoomAn object representing the Room where the Room Variable update occurred.
        changedVarsArrayThe list of names of the Room Variables that were updated (or created for the first time).
        Example
        The following example sets a number of Room Variables and handles the respective update event:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     List changedVars = (List)evt.getArguments().get("changedVars");
                     Room room = (Room)evt.getArguments().get("room");
                     
                     // Check if the "gameStarted" variable was changed
                     if (changedVars.indexOf("gameStarted") != -1)
                     {
                         if (room.getVariable("gameStarted").getBoolValue() == true)
                             System.out.println("Game started");
                         else
                             System.out.println("Game stopped");
                     }
                     
                 }
             });
             
             // Create some Room Variables
             List roomVars = new ArrayList();
             roomVars.add(new SFSRoomVariable("gameStarted", false));
             roomVars.add(new SFSRoomVariable("gameType", "Snooker"));
             roomVars.add(new SFSRoomVariable("minRank", 10));
             
             sfs.send(new SetRoomVariablesRequest(roomVars));
         }
         
        See Also:
        SetRoomVariablesRequest, Room, Constant Field Values
      • USER_VARIABLES_UPDATE

        public static final java.lang.String USER_VARIABLES_UPDATE
        The SFSEvent.USER_VARIABLES_UPDATE constant defines the value of the type property of the event object for a userVariablesUpdate event.

        Dispatched when a User Variable is updated. This event is caused by the SetUserVariablesRequest request sent by an user in one of the Rooms joined by the current user.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        userUserAn object representing the User who updated his own User Variables.
        changedVarsArrayThe list of names of the User Variables that were updated (or created for the first time).
        Example
        The following example sets a number of User Variables and handles the respective update event:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.USER_VARIABLES_UPDATE, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     List changedVars = (List)evt.getArguments().get("changedVars");
                     User user = (User)evt.getArguments().get("user");
                     
                     // Check if the user changed his x and/or y user variables
                     if (changedVars.indexOf("x") != -1 || changedVars.indexOf("y") != -1)
                     {
                         // Move the user avatar to a new position
                         ...
                     }
                 }
             });
             
             // Create some User Variables
             List userVars = new ArrayList();
             userVars.add(new SFSUserVariable("avatarType", "SwedishCook"));
             userVars.add(new SFSUserVariable("country", "Sweden"));
             userVars.add(new SFSUserVariable("x", 10));
             userVars.add(new SFSUserVariable("y", 5));
             
             sfs.send(new SetUserVariablesRequest(userVars));
         }
         
        See Also:
        SetUserVariablesRequest, User, Constant Field Values
      • ROOM_GROUP_SUBSCRIBE

        public static final java.lang.String ROOM_GROUP_SUBSCRIBE
        The SFSEvent.ROOM_GROUP_SUBSCRIBE constant defines the value of the type property of the event object for a roomGroupSubscribe event.

        Dispatched when a Group is subscribed by the current user. This event is fired in response to the SubscribeRoomGroupRequest request if the operation is executed successfully.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        groupIdStringThe name of the Group that was subscribed.
        newRoomsArrayA list of Room objects representing the Rooms belonging to the subscribed Group.
        Example
        The following example makes the current user subscribe a Group:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.ROOM_GROUP_SUBSCRIBE, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Group subscribed. The following rooms are now accessible: " + evt.getArguments().get("newRooms"));
                 }
             });
             sfs.addEventListener(SFSEvent.ROOM_GROUP_SUBSCRIBE_ERROR, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Group subscription failed: " + evt.getArguments().get("errorMessage"));
                 }
             });
             
             // Subscribe the "cardGames" group
             sfs.send(new SubscribeRoomGroupRequest("cardGames"));
             }
         
        See Also:
        SubscribeRoomGroupRequest, Room, ROOM_GROUP_SUBSCRIBE_ERROR, ROOM_GROUP_UNSUBSCRIBE, Constant Field Values
      • ROOM_GROUP_UNSUBSCRIBE

        public static final java.lang.String ROOM_GROUP_UNSUBSCRIBE
        The SFSEvent.ROOM_GROUP_UNSUBSCRIBE constant defines the value of the type property of the event object for a roomGroupUnsubscribe event.

        Dispatched when a Group is unsubscribed by the current user. This event is fired in response to the UnsubscribeRoomGroupRequest request if the operation is executed successfully.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        groupIdStringThe name of the Group that was unsubscribed.
        Example
        The following example makes the current user unsubscribe a Group:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.ROOM_GROUP_UNSUBSCRIBE, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Group unsubscribed: " + evt.getArguments().get("groupId"));
                 }
             });
             sfs.addEventListener(SFSEvent.ROOM_GROUP_UNSUBSCRIBE_ERROR, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Group unsubscribing failed: " + evt.getArguments().get("errorMessage"));
                 }
             });
             
             // Unsubscribe the "cardGames" group
             sfs.send(new UnsubscribeRoomGroupRequest("cardGames"));
         }
         
        See Also:
        UnsubscribeRoomGroupRequest, ROOM_GROUP_UNSUBSCRIBE_ERROR, ROOM_GROUP_SUBSCRIBE, Constant Field Values
      • ROOM_GROUP_SUBSCRIBE_ERROR

        public static final java.lang.String ROOM_GROUP_SUBSCRIBE_ERROR
        The SFSEvent.ROOM_GROUP_SUBSCRIBE_ERROR constant defines the value of the type property of the event object for a roomGroupSubscribeError event.

        Dispatched when an error occurs while a Room Group is being subscribed. This event is fired in response to the SubscribeRoomGroupRequest request in case the operation failed.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        errorMessageStringA message containing the description of the error.
        errorCodeshortThe error code.
        Example
        See the example provided in the ROOM_GROUP_SUBSCRIBE constant description.
        See Also:
        SubscribeRoomGroupRequest, ROOM_GROUP_SUBSCRIBE, Constant Field Values
      • ROOM_GROUP_UNSUBSCRIBE_ERROR

        public static final java.lang.String ROOM_GROUP_UNSUBSCRIBE_ERROR
        The SFSEvent.ROOM_GROUP_UNSUBSCRIBE_ERROR constant defines the value of the type property of the event object for a roomGroupUnsubscribeError event.

        Dispatched when an error occurs while a Room Group is being unsubscribed. This event is fired in response to the UnsubscribeRoomGroupRequest request in case the operation failed.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        errorMessageStringA message containing the description of the error.
        errorCodeshortThe error code.
        Example
        See the example provided in the ROOM_GROUP_UNSUBSCRIBE constant description.
        See Also:
        UnsubscribeRoomGroupRequest, ROOM_GROUP_UNSUBSCRIBE, Constant Field Values
      • SPECTATOR_TO_PLAYER

        public static final java.lang.String SPECTATOR_TO_PLAYER
        The SFSEvent.SPECTATOR_TO_PLAYER constant defines the value of the type property of the event object for a spectatorToPlayer event.

        Dispatched when a spectator is turned to a player inside a Game Room. This event is fired in response to the SpectatorToPlayerRequest request if the operation is executed successfully.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        roomRoomAn object representing the Room in which the spectator is turned to player.
        userUserAn object representing the spectator who was turned to player.
        playerIdintThe player id of the user.
        Example
        The following example turns the current user from spectator to player in the last joined Game Room:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.SPECTATOR_TO_PLAYER, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Spectator " + (User)evt.getArguments().get("user") + " is now a player");
                 }
             });
             sfs.addEventListener(SFSEvent.SPECTATOR_TO_PLAYER_ERROR, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Unable to become a player due to the following error: " + evt.getArguments().get("errorMessage"));
                 }
             });
             
             // Switch spectator to player
             sfs.send(new SpectatorToPlayerRequest());
         }
         
        See Also:
        SpectatorToPlayerRequest, User, Room, SPECTATOR_TO_PLAYER_ERROR, PLAYER_TO_SPECTATOR, Constant Field Values
      • PLAYER_TO_SPECTATOR

        public static final java.lang.String PLAYER_TO_SPECTATOR
        The SFSEvent.PLAYER_TO_SPECTATOR constant defines the value of the type property of the event object for a playerToSpectator event.

        Dispatched when a player is turned to a spectator inside a Game Room. This event is fired in response to the PlayerToSpectatorRequest request if the operation is executed successfully.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        roomRoomAn object representing the Room in which the player is turned to spectator.
        userUserAn object representing the player who was turned to spectator.
        Example
        The following example turns the current user from player to spectator in the last joined Game Room:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.PLAYER_TO_SPECTATOR, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Player " + (User)evt.getArguments().get("user") + " is now a spectator");
                 }
             });
             sfs.addEventListener(SFSEvent.PLAYER_TO_SPECTATOR_ERROR, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Unable to become a spectator due to the following error: " + evt.getArguments().get("errorMessage"));
                 }
             });
             
             // Switch player to spectator
             sfs.send(new PlayerToSpectatorRequest());
         }
         
        See Also:
        PlayerToSpectatorRequest, User, Room, PLAYER_TO_SPECTATOR_ERROR, SPECTATOR_TO_PLAYER, Constant Field Values
      • SPECTATOR_TO_PLAYER_ERROR

        public static final java.lang.String SPECTATOR_TO_PLAYER_ERROR
        The SFSEvent.SPECTATOR_TO_PLAYER_ERROR constant defines the value of the type property of the event object for a spectatorToPlayerError event.

        Dispatched when an error occurs while the current user is being turned from spectator to player in a Game Room. This event is fired in response to the SpectatorToPlayerRequest request in case the operation failed.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        errorMessageStringA message containing the description of the error.
        errorCodeshortThe error code.
        Example
        See the example provided in the SPECTATOR_TO_PLAYER constant description.
        See Also:
        SpectatorToPlayerRequest, SPECTATOR_TO_PLAYER, Constant Field Values
      • PLAYER_TO_SPECTATOR_ERROR

        public static final java.lang.String PLAYER_TO_SPECTATOR_ERROR
        The SFSEvent.PLAYER_TO_SPECTATOR_ERROR constant defines the value of the type property of the event object for a playerToSpectatorError event.

        Dispatched when an error occurs while the current user is being turned from player to spectator in a Game Room. This event is fired in response to the PlayerToSpectatorRequest request in case the operation failed.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        errorMessageStringA message containing the description of the error.
        errorCodeshortThe error code.
        Example
        See the example provided in the PLAYER_TO_SPECTATOR constant description.
        See Also:
        PlayerToSpectatorRequest, PLAYER_TO_SPECTATOR, Constant Field Values
      • ROOM_NAME_CHANGE

        public static final java.lang.String ROOM_NAME_CHANGE
        The SFSEvent.ROOM_NAME_CHANGE constant defines the value of the type property of the event object for a roomNameChange event.

        Dispatched when the name of a Room is changed. This event is fired in response to the ChangeRoomNameRequest request if the operation is executed successfully.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        roomRoomAn object representing the Room which was renamed.
        oldNameStringThe previous name of the Room.
        Example
        The following example makes renames an existing Room:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.ROOM_NAME_CHANGE, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Room " + evt.getArguments().get("oldName") + " was successfully renamed to " + ((Room)evt.getArguments().get("room")).getName());
                 }
             });
             sfs.addEventListener(SFSEvent.ROOM_NAME_CHANGE_ERROR, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Room name change failed: " + evt.getArguments().get("errorMessage"));
                 }
             });
             
             //Rename a Room called "Gonzo's Room" to "Gonzo The Great's Room"
             Room theRoom = sfs.getRoomByName("Gonzo's Room");
             sfs.send(new ChangeRoomNameRequest(theRoom, "Gonzo The Great's Room"));
         }
         
        See Also:
        ChangeRoomNameRequest, Room, ROOM_NAME_CHANGE_ERROR, Constant Field Values
      • ROOM_NAME_CHANGE_ERROR

        public static final java.lang.String ROOM_NAME_CHANGE_ERROR
        The SFSEvent.ROOM_NAME_CHANGE_ERROR constant defines the value of the type property of the event object for a roomNameChangeError event.

        Dispatched when an error occurs while attempting to change the name of a Room. This event is fired in response to the ChangeRoomNameRequest request in case the operation failed.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        errorMessageStringA message containing the description of the error.
        errorCodeshortThe error code.
        Example
        See the example provided in the ROOM_NAME_CHANGE constant description.
        See Also:
        ChangeRoomNameRequest, ROOM_NAME_CHANGE, Constant Field Values
      • ROOM_PASSWORD_STATE_CHANGE

        public static final java.lang.String ROOM_PASSWORD_STATE_CHANGE
        The SFSEvent.ROOM_PASSWORD_STATE_CHANGE constant defines the value of the type property of the event object for a roomPasswordStateChange event.

        Dispatched when the password of a Room is set, changed or removed. This event is fired in response to the ChangeRoomPasswordStateRequest request if the operation is executed successfully.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        roomRoomAn object representing the Room whose password was changed.
        Example
        The following example changes the password of an existing Room:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.ROOM_PASSWORD_STATE_CHANGE, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("The password of Room " + ((Room)evt.getArguments().get("room")).getName() + " was changed successfully");
                 }
             });
             sfs.addEventListener(SFSEvent.ROOM_PASSWORD_STATE_CHANGE_ERROR, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Room password change failed: " + evt.getArguments().get("errorMessage"));
                 }
             });
             
             //Change "Gonzo's Room" Room's password
             Room theRoom = sfs.getRoomByName("Gonzo's Room");
             sfs.send(new ChangeRoomPasswordStateRequest(theRoom, "mammamia"));
         }
         
        See Also:
        ChangeRoomPasswordStateRequest, Room, ROOM_PASSWORD_STATE_CHANGE_ERROR, Constant Field Values
      • ROOM_PASSWORD_STATE_CHANGE_ERROR

        public static final java.lang.String ROOM_PASSWORD_STATE_CHANGE_ERROR
        The SFSEvent.ROOM_PASSWORD_STATE_CHANGE_ERROR constant defines the value of the type property of the event object for a roomPasswordStateChangeError event.

        Dispatched when an error occurs while attempting to set, change or remove the password of a Room. This event is fired in response to the ChangeRoomPasswordStateRequest request in case the operation failed.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        errorMessageStringA message containing the description of the error.
        errorCodeshortThe error code.
        Example
        See the example provided in the ROOM_PASSWORD_STATE_CHANGE constant description.
        See Also:
        ChangeRoomPasswordStateRequest, ROOM_PASSWORD_STATE_CHANGE, Constant Field Values
      • ROOM_CAPACITY_CHANGE

        public static final java.lang.String ROOM_CAPACITY_CHANGE
        The SFSEvent.ROOM_CAPACITY_CHANGE constant defines the value of the type property of the event object for a roomCapacityChange event.

        Dispatched when the capacity of a Room is changed. This event is fired in response to the ChangeRoomCapacityRequest request if the operation is executed successfully.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        roomRoomAn object representing the Room whose capacity was changed.
        Example
        The following example changes the capacity of an existing Room:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.ROOM_CAPACITY_CHANGE, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("The capacity of Room " + ((Room)evt.getArguments().get("room")).getName() + " was changed successfully");
                 }
             });
             sfs.addEventListener(SFSEvent.ROOM_CAPACITY_CHANGE_ERROR, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Room capacity change failed: " + evt.getArguments().get("errorMessage"));
                 }
             });
             
             // Resize the Room so that it allows a maximum of 100 users and zero spectators
             Room theRoom = sfs.getRoomByName("Gonzo's Room");
             sfs.send(new ChangeRoomCapacityRequest(theRoom, 100, 0));
         }
         
        See Also:
        ChangeRoomCapacityRequest, Room, ROOM_CAPACITY_CHANGE_ERROR, Constant Field Values
      • ROOM_CAPACITY_CHANGE_ERROR

        public static final java.lang.String ROOM_CAPACITY_CHANGE_ERROR
        The SFSEvent.ROOM_CAPACITY_CHANGE_ERROR constant defines the value of the type property of the event object for a roomCapacityChangeError event.

        Dispatched when an error occurs while attempting to change the capacity of a Room. This event is fired in response to the ChangeRoomCapacityRequest request in case the operation failed.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        errorMessageStringA message containing the description of the error.
        errorCodeshortThe error code.
        Example
        See the example provided in the ROOM_CAPACITY_CHANGE constant description.
        See Also:
        ChangeRoomCapacityRequest, ROOM_CAPACITY_CHANGE, Constant Field Values
      • ROOM_FIND_RESULT

        public static final java.lang.String ROOM_FIND_RESULT
        The SFSEvent.ROOM_FIND_RESULT constant defines the value of the type property of the event object for a roomFindResult event.

        Dispatched when a Rooms search is completed. This event is fired in response to the FindRoomsRequest request to return the search result.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        roomsArrayA list of Room objects representing the Rooms matching the search criteria. If no Room is found, the list is empty
        Example
        The following example looks for all the server Rooms whose "country" Room Variable is set to "Sweden":
         private void someMethod() {
             sfs.addEventListener(SFSEvent.ROOM_FIND_RESULT, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Rooms found: " + evt.getArguments().get("rooms"));
                 }
             });
             
             // Create a matching expression to find Rooms with a "country" variable equal to "Sweden"
             MatchExpression exp = new MatchExpression("country", StringMatch.EQUALS, "Sweden");
             
             // Find the Rooms
             sfs.send(new FindRoomsRequest(exp));
         }
         
        See Also:
        FindRoomsRequest, Constant Field Values
      • USER_FIND_RESULT

        public static final java.lang.String USER_FIND_RESULT
        The SFSEvent.USER_FIND_RESULT constant defines the value of the type property of the event object for a userFindResult event.

        Dispatched when a Users search is completed. This event is fired in response to the FindUsersRequest request to return the search result.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        usersArrayA list of User objects representing the Users matching the search criteria. If no User is found, the list is empty
        Example
        The following example looks for all the Users whose "age" User Variable is greater than 29:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.USER_FIND_RESULT, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Users found: " + evt.getArguments().get("users"));
                 }
             });
             
             // Create a matching expression to find Users with an "age" variable greater than 29:
             MatchExpression exp = new MatchExpression("age", NumberMatch.GREATER_THAN, 29);
             
             // Find the Users
             sfs.send(new FindUsersRequest(exp));
         }
         
        See Also:
        FindUsersRequest, Constant Field Values
      • INVITATION

        public static final java.lang.String INVITATION
        The SFSEvent.INVITATION constant defines the value of the type property of the event object for a invitation event.

        Dispatched when the current user receives an invitation from another user. This event is caused by the InviteUsersRequest request; the user is supposed to reply using the InvitationReplyRequest request.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        invitationInvitationAn object representing the invitation received by the current user.
        Example
        The following example receives an invitation and accepts it automatically; in a real case scenario, the application interface usually allows the user choosing to accept or refuse the invitation, or even ignore it:
         private void someMethod() {
             sfs.addEventListener(SFSEvent.INVITATION, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     // Let's accept this invitation
                     sfs.send(new InvitationReplyRequest((Invitation) evt.getArguments().get("invitation"), InvitationReply.ACCEPT));
                 }
             });
             sfs.addEventListener(SFSEvent.INVITATION_REPLY_ERROR, new IEventListener() {
                 public void dispatch(BaseEvent evt) throws SFSException {
                     System.out.println("Failed to reply to invitation due to the following problem: " + evt.getArguments().get("errorMessage"));
                 }
             });
         }
         
        See Also:
        InviteUsersRequest, InvitationReplyRequest, Invitation, INVITATION_REPLY, Constant Field Values
      • INVITATION_REPLY

        public static final java.lang.String INVITATION_REPLY
        The SFSEvent.INVITATION_REPLY constant defines the value of the type property of the event object for a invitationReply event.

        Dispatched when the current user receives a reply to an invitation he sent previously. This event is caused by the InvitationReplyRequest request sent by the invitee.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        inviteeUserAn object representing the user who replied to the invitation.
        replyintThe answer to the invitation among those available as constants in the InvitationReply class.
        dataISFSObjectAn object containing custom parameters, for example a message describing the reason of refusal.
        Example
        See the example provided in the INVITATION constant description.
        See Also:
        InvitationReplyRequest, InvitationReply, INVITATION, INVITATION_REPLY_ERROR, Constant Field Values
      • INVITATION_REPLY_ERROR

        public static final java.lang.String INVITATION_REPLY_ERROR
        The SFSEvent.INVITATION_REPLY_ERROR constant defines the value of the type property of the event object for a invitationReplyError event.

        Dispatched when an error occurs while the current user is sending a reply to an invitation he received. This event is fired in response to the InvitationReplyRequest request in case the operation failed.

        The properties of the arguments object contained in the event object have the following values:

        PropertyTypeDescription
        errorMessageStringA message containing the description of the error.
        errorCodeshortThe error code.
        Example
        See the example provided in the INVITATION constant description.
        See Also:
        InvitationReplyRequest, INVITATION_REPLY, INVITATION, Constant Field Values
      • PROXIMITY_LIST_UPDATE

        public static final java.lang.String PROXIMITY_LIST_UPDATE
        The SFSEvent.PROXIMITY_LIST_UPDATE constant defines the value of the type property of the event object for a proximityListUpdate event.

        The properties of the params object contained in the event object have the following values:

        PropertyTypeDescription
        roomRoomThe Room where the event occurred.
        addedUsersList<Users>A list of User objects representing the users who entered the current user's Area of Interest.
        removedUsersList<Users>A list of User objects representing the users who left the current user's Area of Interest.
        addedItemsList<IMMOItem>A list of MMOItem objects which entered the current user's Area of Interest.
        removedItemsList<IMMOItem>A list of MMOItem objects which left the current user's Area of Interest.

        Example:The following example shows how to handle the proximity user list provided by the event in order to add new avatars on the stage and remove those who left the current user's proximity range:

         private void someMethod()
         {
                sfs.addEventListener(SFSEvent.PROXIMITY_LIST_UPDATE, new IEventListener() 
                {
                        public void dispatch(BaseEvent evt) throws SFSException 
                        {
                                List<Users> added = (List<Users>) getArguments().get("addedUsers");
                                List<Users> removed = (List<Users>) getArguments().get("removedUsers");
         
                                // Add users that entered the proximity list
                                for (User user : added)
                                {
                                        // Obtain the coordinates at which the user "appeared" in our range
                                        Vec3D entryPoint = user.getAOIEntryPoint();
         
                                        // Add new avatar on screen
                                        AvatarSprite avatarSprite = new AvatarSprite();
                                        avatarSprite.x = entryPoint.intX();
                                        avatarSprite.y = entryPoint.intY();
                                        ...
                                }
         
                                // Remove users that left the proximity list
                                for (User user : removed)
                                {
                                        // Remove the avatar from stage
                                        ...
                                }
                 }
                });
         }  
         
        See Also:
        SetUserPositionRequest, MMORoom, Constant Field Values
      • MMOITEM_VARIABLES_UPDATE

        public static final java.lang.String MMOITEM_VARIABLES_UPDATE
        The SFSEvent.MMOITEM_VARIABLES_UPDATE constant defines the value of the type property of the event object for a mmoItemVariablesUpdate event.

        The properties of the params object contained in the event have the following values:

        PropertyTypeDescription
        roomMMORoomThe MMORoom where the MMOItem whose Variables have been updated is located.
        mmoItemMMOItemThe MMOItem whose variables have been updated.
        changedVarsList<String>The list of names of the MMOItem Variables that were changed (or created for the first time).

        Example:

        The following example shows how to handle the MMOItem Variable update. Always makes sure to initialize cryptography right after having connected.

         private void someMethod()
         {
                sfs.addEventListener(MMOITEM_VARIABLES_UPDATE, new IEventListener() 
                {
                        public void dispatch(BaseEvent evt) throws SFSException 
                        {
                                List<String> changedVars = (List<String>) getArguments().get("changedVars");
                                IMMOItem mmoItem = (IMMOItem) getArguments().get("mmoItem");    
                                
                                // Check if the MMOItem was moved 
                                if (changedVars.contains("x") || changedVars.contains("y"))
                                {
                                        // Move the sprite representing the MMOItem
                                        ...
                                }  
                 }
                });
         }     
         
        See Also:
        MMORoom, MMOItem, MMOItemVariable, Constant Field Values
      • CRYPTO_INIT

        public static final java.lang.String CRYPTO_INIT
        The SFSEvent.CRYPTO_INIT constant defines the value of the type property of the event object for a cryptoInit call.

        The properties of the params object contained in the event object have the following values:

        PropertyTypeDescription
        successBooleantrue if a unique encryption key was successfully retrieved via HTTPS, false if the transaction failed.
        errorMsgBooleanMay contain further details if an error occurred (success==false)

        Example:

        The following example initializes the socket cryptography:

         SmartFox sfs = new SmartFox();
         SFSListener listener = new SFSListener();
         
         sfs.addEventListener(SFSEvent.CONNECTION, listener);
         sfs.addEventListener(SFSEvent.CRYPTO_INIT, listener);
         
         sfs.connect();
         
         class SFSListener implements IEventListener
         {
                public void dispatch(BaseEvent evt) throws SFSException 
                {
                        // Handle Connection event
                        if (event.getType().equals(SFSEvent.CONNECTION))
                        {
                                boolean success = (Boolean) event.getArguments().get("success");
                                
                                if (success)
                                        sfs.cryptoInit();
                                else
                                        System.out.println("Connection failed!");
                        }
                        
                        // Handle CryptoInit event
                        else if (event.getType().equals(SFSEvent.CRYPTO_INIT))
                        {
                                boolean success = (Boolean) event.getArguments().get("success");
         
                        if (success)
                        {
                                System.out.println("CRYPTO INIT SUCCESS!");
                
                                        // Proceed with login
                                sfs.send(new LoginRequest("UserName"));
                        }
                
                        else
                                {
                                System.out.println("CRYPTO INIT FAIL: " + event.getArguments().get("errorMsg"));
                                }
                        }       
            }
         }
         
        See Also:
        SmartFox.initCrypto(), Constant Field Values
    • Constructor Detail

      • SFSEvent

        public SFSEvent​(java.lang.String type,
                        java.util.Map<java.lang.String,​java.lang.Object> args)
        Creates a new SFSEvent instance.
        Parameters:
        type - The type of event.
        args - An object containing the parameters of the event.
      • SFSEvent

        public SFSEvent​(java.lang.String type)