it.gotoandplay.smartfoxclient
Class SFSEvent

java.lang.Object
  extended by it.gotoandplay.smartfoxclient.SFSEvent
Direct Known Subclasses:
HttpEvent

public class SFSEvent
extends java.lang.Object

SFSEvent is the class representing all events dispatched by the SmartFoxClient instance. The SFSEvent class provides a public method called getParams() that returns object of type SFSObject that can contain any number of parameters. In the rest of the documentation this object is refered as params object.

The following example show a generic usage of a SFSEvent. Please refer to the specific events for the params object content.

 package sfsTest;
 
 import it.gotoandplay.smartfoxclient.ISFSEventListener;
 import it.gotoandplay.smartfoxserver.SmartFoxClient;
 import it.gotoandplay.smartfoxserver.SFSEvent;
 
 public class MyTest implements ISFSEventListener
 {
     private SmartFoxClient smartFox;

     public MyTest()
     {
         // Create instance
         smartFox = new SmartFoxClient();

         // Add event handler for connection 
         smartFox.addEventListener(SFSEvent.onConnection, this);

         // Connect to server
         smartFox.connect("127.0.0.1", 9339);   
     }

     // Handle SFS events 
     public void handleEvent(SFSEvent event)
     {
         // Handle connection event
         if(event.getName().equals(SFSEvent.onConnection))
         {
             if(event.getParams().getBool("success"))
             {
                 System.out.println("Great, successfully connected!");
             }
             else
             {
                 System.out.println("Ouch, connection failed!");
             }
         }
     }
 }
 

NOTE: In the following examples, smartFox always indicates a SmartFoxClient instance.

Version:
1.1.0
Author:
The gotoAndPlay() Team
http://www.smartfoxserver.com
http://www.gotoandplay.it

Field Summary
static java.lang.String onAdminMessage
           Dispatched when a message from the Administrator is received.
static java.lang.String onBuddyList
          Dispatched when the buddy list for the current user is received or a buddy is added/removed.
static java.lang.String onBuddyListError
          Dispatched when an error occurs while loading the buddy list.
static java.lang.String onBuddyListUpdate
          Dispatched when the status or variables of a buddy in the buddy list change.
static java.lang.String onBuddyPermissionRequest
          Dispatched when the current user receives a request to be added to the buddy list of another user.
static java.lang.String onBuddyRoom
          Dispatched in response to a SmartFoxClient.getBuddyRoom(it.gotoandplay.smartfoxclient.data.Buddy) request.
static java.lang.String onConfigLoadFailure
          Dispatched when an error occurs while loading the external SmartFoxClient configuration file.
static java.lang.String onConfigLoadSuccess
          Dispatched when the external SmartFoxClient configuration file has been loaded successfully.
static java.lang.String onConnection
          Dispatched in response to the SmartFoxClient.connect(java.lang.String) request.
static java.lang.String onConnectionLost
          Dispatched when the connection with SmartFoxServer is closed (either from the client or from the server).
static java.lang.String onCreateRoomError
          Dispatched when an error occurs during the creation of a room.
static java.lang.String onDebugMessage
          Dispatched when a debug message is traced by the SmartFoxServer API.
static java.lang.String onExtensionResponse
          Dispatched when a command/response from a server-side extension is received.
static java.lang.String onJoinRoom
          Dispatched when a room is joined successfully.
static java.lang.String onJoinRoomError
          Dispatched when an error occurs while joining a room.
static java.lang.String onLogin
          Dispatched when the login to a SmartFoxServer zone has been attempted.
static java.lang.String onLogout
          Dispatched when the user logs out successfully.
static java.lang.String onModeratorMessage
          Dispatched when a message from a Moderator is received.
static java.lang.String onObjectReceived
          Dispatched when an object is received.
static java.lang.String onPlayerSwitched
          Dispatched in response to the SmartFoxClient.switchPlayer() request.
static java.lang.String onPrivateMessage
          Dispatched when a private chat message is received.
static java.lang.String onPublicMessage
          Dispatched when a public chat message is received.
static java.lang.String onRandomKey
          Dispatched in response to a SmartFoxClient.getRandomKey() request.
static java.lang.String onRoomAdded
          Dispatched when a new room is created in the zone where the user is currently logged in.
static java.lang.String onRoomDeleted
          Dispatched when a room is removed from the zone where the user is currently logged in.
static java.lang.String onRoomLeft
          Dispatched when a room is left in multi-room mode, in response of a SmartFoxClient.leaveRoom(int) request.
static java.lang.String onRoomListUpdate
          Dispatched when the list of rooms available in the current zone is received.
static java.lang.String onRoomVariablesUpdate
          Dispatched when Room Variables are updated.
static java.lang.String onRoundTripResponse
          Dispatched when a response to the SmartFoxClient.roundTripBench() request is received.
static java.lang.String onSpectatorSwitched
          Dispatched in response to the SmartFoxClient.switchSpectator() request.
static java.lang.String onUserCountChange
          Dispatched when the number of users and/or spectators changes in a room within the current zone.
static java.lang.String onUserEnterRoom
          Dispatched when another user joins the current room.
static java.lang.String onUserLeaveRoom
          Dispatched when a user leaves the current room.
static java.lang.String onUserVariablesUpdate
          Dispatched when a user in the current room updates his/her User Variables.
 
Constructor Summary
SFSEvent(java.lang.String name, SFSObject params)
           
 
Method Summary
 java.lang.String getName()
           
 SFSObject getParams()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

onAdminMessage

public static final java.lang.String onAdminMessage

Dispatched when a message from the Administrator is received.

Admin messages are special messages that can be sent by an Administrator to a user or group of users. All client applications should handle this event, or users won't be be able to receive important admin notifications!

The params object contains the following parameters.

The following example shows how to handle a message coming from the Administrator.

 smartFox.addEventListener(SFSEvent.onAdminMessage, this);
                        
 public void handleEvent(SFSEvent event)
 {
     if(event.getName().equals(SFSEvent.onAdminMessage))
     {
         System.out.println(getParams().getString("message"));
     }
 }
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
onModeratorMessage, Constant Field Values

onBuddyList

public static final java.lang.String onBuddyList
Dispatched when the buddy list for the current user is received or a buddy is added/removed.

The params object contains the following parameters.

The following example shows how to retrieve the properties of each buddy when the buddy list is received.

 smartFox.addEventListener(SFSEvent.onBuddyList, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           for(Buddy buddy : smartFox.buddyList)
           {
 
               // Trace buddy properties
               System.out.println("Buddy id: " + buddy.getId());
               System.out.println("Buddy name: " + buddy.getName());
               System.out.println("Is buddy online? " + (buddy.isOnline() ? "Yes" : "No"));
               System.out.println("Is buddy blocked? " + (buddy.isBlocked() ? "Yes" : "No"));
 
               // Trace all Buddy Variables
               for(String key : buddy.getVariables().keySet())
               {
                   System.out.println("\t" + key + " --> " + buddy.getVariables().get(key));
               }
           }
       }
   });
 smartFox.loadBuddyList();
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
onBuddyListError, onBuddyListUpdate, onBuddyRoom, SmartFoxClient.buddyList, SmartFoxClient.loadBuddyList(), SmartFoxClient.addBuddy(java.lang.String), SmartFoxClient.removeBuddy(java.lang.String), Constant Field Values

onBuddyListError

public static final java.lang.String onBuddyListError
Dispatched when an error occurs while loading the buddy list.

The params object contains the following parameters.

The following example shows how to handle a potential error in buddy list loading.

 smartFox.addEventListener(SFSEvent.onBuddyListError, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           System.out.println("An error occurred while loading the buddy list: " + evt.getParams().getString("error"));
       }
   });
 smartFox.loadBuddyList();
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
onBuddyList, Constant Field Values

onBuddyListUpdate

public static final java.lang.String onBuddyListUpdate
Dispatched when the status or variables of a buddy in the buddy list change.

The params object contains the following parameters.

The following example shows how to handle the online status change of a buddy.

 smartFox.addEventListener(SFSEvent.onBuddyListUpdate, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           Buddy buddy = (Buddy)evt.getParams().get("buddy");
           String name = buddy.getName();
           String status = (buddy.isOnline()) ? "online" : "offline";
                 System.out.println("Buddy " + name + " is currently " + status);
       }
   });
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
onBuddyList, SmartFoxClient.buddyList, SmartFoxClient.setBuddyBlockStatus(java.lang.String, boolean), SmartFoxClient.setBuddyVariables(java.util.Map), Constant Field Values

onBuddyPermissionRequest

public static final java.lang.String onBuddyPermissionRequest
Dispatched when the current user receives a request to be added to the buddy list of another user.

The params object contains the following parameters.

The following example shows how to handle the request to be added to a buddy list.

 smartFox.addEventListener(SFSEvent.onBuddyPermissionRequest, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           System.out.println(evt.getParams().getString("sender") + "wants to add you to his/her buddy list: " + evt.getParams().getString("message"));
       }
   });
 

Since:
SmartFoxServer Pro v1.6.0
See Also:
SmartFoxClient.addBuddy(java.lang.String), Constant Field Values

onBuddyRoom

public static final java.lang.String onBuddyRoom
Dispatched in response to a SmartFoxClient.getBuddyRoom(it.gotoandplay.smartfoxclient.data.Buddy) request.

The params object contains the following parameters.

The following example shows how to join the same room in which the buddy currently is.

 smartFox.addEventListener(SFSEvent.onBuddyRoom, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           int[]  = (int[])evt.getParams().get("idList");
           // Reach the buddy in his room
           smartFox.join(idList[0]);
       }
   });
 Buddy buddy = smartFox.getBuddyByName("jack");
 smartFox.getBuddyRoom(buddy);
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
SmartFoxClient.getBuddyRoom(it.gotoandplay.smartfoxclient.data.Buddy), Constant Field Values

onConfigLoadFailure

public static final java.lang.String onConfigLoadFailure
Dispatched when an error occurs while loading the external SmartFoxClient configuration file.

The params object contains the following parameters.

The following example shows how to handle a potential error in configuration loading.

 smartFox.addEventListener(SFSEvent.onConfigLoadFailure, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           System.out.println("Failed loading config file: " +
             evt.getParams().getString("message"));
       }
   });
 smartFox.loadConfig("testEnvironmentConfig.xml");
 

Since:
SmartFoxServer Pro v1.6.0
See Also:
onConfigLoadSuccess, SmartFoxClient.loadConfig(java.lang.String), Constant Field Values

onConfigLoadSuccess

public static final java.lang.String onConfigLoadSuccess
Dispatched when the external SmartFoxClient configuration file has been loaded successfully.

This event is dispatched only if the autoConnect parameter of the SmartFoxClient.loadConfig(java.lang.String) method is set to true; otherwise the connection is made and the onConnection event fired.

No parameters are provided.

The following example shows how to handle a successful configuration loading.

 smartFox.addEventListener(SFSEvent.onConfigLoadSuccess, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           System.out.println("Config file loaded, now connecting...");
           smartFox.connect(smartFox.ipAddress, smartFox.port);
       }
   });
 smartFox.loadConfig("testEnvironmentConfig.xml", false);
 

Since:
SmartFoxServer Pro v1.6.0
See Also:
onConfigLoadFailure, SmartFoxClient.loadConfig(java.lang.String), Constant Field Values

onConnection

public static final java.lang.String onConnection
Dispatched in response to the SmartFoxClient.connect(java.lang.String) request.

The connection to SmartFoxServer may have succeeded or failed: the success parameter must be checked.

The params object contains the following parameters.

The following example shows how to handle the connection result.

 smartFox.addEventListener(SFSEvent.onConnection, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           if(evt.getParams().getBool("success"))
           {
               System.out.println("Connection successful");
           }
           else
           {
               System.out.println("Connection failed");
           }
       }
   });
 smartFox.connect("127.0.0.1", 9339);
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
SmartFoxClient.connect(java.lang.String), Constant Field Values

onConnectionLost

public static final java.lang.String onConnectionLost
Dispatched when the connection with SmartFoxServer is closed (either from the client or from the server).

No parameters are provided.

The following example shows how to handle the connection result.

 smartFox.addEventListener(SFSEvent.onConnectionLost, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           System.out.println("Connection lost!");
       }
   });
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
SmartFoxClient.disconnect(), Constant Field Values

onCreateRoomError

public static final java.lang.String onCreateRoomError
Dispatched when an error occurs during the creation of a room. Usually this happens when a client tries to create a room but its name is already taken.

The params object contains the following parameters.

The following example shows how to handle a potential error in room creation.

 smartFox.addEventListener(SFSEvent.onCreateRoomError, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           System.out.println("Room creation error; the following error occurred: " + evt.getParams().getString("error"));
       }
   });
 
 Map<String, Object> roomProperties = new HashMap<String, Object>();
 roomProperties.put("isGame", true);
 Map<String, RoomVariableRequest> variables = new HashMap<String, RoomVariableRequest>();
 variables.put("ogres", new RoomVariableRequest("5", SFSVariable.TYPE_NUMBER, true));
 variables.put("skeletons", new RoomVariableRequest("4", SFSVariable.TYPE_NUMBER));
 roomProperties.put("vars", variables);
 smartFox.createRoom("The Cave", 15, roomProperties);
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
SmartFoxClient.createRoom(java.lang.String, int, java.util.Map), Constant Field Values

onDebugMessage

public static final java.lang.String onDebugMessage
Dispatched when a debug message is traced by the SmartFoxServer API.

In order to receive this event you have to enable debug messages.

The params object contains the following parameters.

The following example shows how to handle a potential error in room creation.

 smartFox.addEventListener(SFSEvent.onDebugMessage, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           System.out.println("[SFS DEBUG] : " + evt.getParams().getString("message"));
       }
   });
 
 Map<String, Object> roomProperties = new HashMap<String, Object>();
 roomProperties.put("isGame", true);
 Map<String, RoomVariableRequest> variables = new HashMap<String, RoomVariableRequest>();
 variables.put("ogres", new RoomVariableRequest("5", SFSVariable.TYPE_NUMBER, true));
 variables.put("skeletons", new RoomVariableRequest("4", SFSVariable.TYPE_NUMBER));
 roomProperties.put("vars", variables);
 smartFox.createRoom("The Cave", 15, roomProperties);
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
SmartFoxClient.setDebug(boolean), Constant Field Values

onExtensionResponse

public static final java.lang.String onExtensionResponse
Dispatched when a command/response from a server-side extension is received.

The params object contains the following parameters.

The following example shows how to handle an extension response.

 smartFox.addEventListener(SFSEvent.onExtensionResponse, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           String type = evt.getParams().getString("type");
           Object data = evt.getParams().get("dataObj");
 
           // Handle XML responses
           if(type.equals(SmartFoxClient.XTMSG_TYPE_XML))
           {
               // TODO: check command and perform required actions
           }
           // Handle RAW responses
           else if(type.equals(SmartFoxClient.XTMSG_TYPE_STR))
           {
               // TODO: check command and perform required actions
           }
           // Handle JSON responses
           else if(type.equals(SmartFoxClient.XTMSG_TYPE_JSON))
           {
               // TODO: check command and perform required actions
           }
       }
   });
 

Since:
SmartFoxServer Pro v1.x.x
See Also:
SmartFoxClient.XTMSG_TYPE_XML, SmartFoxClient.XTMSG_TYPE_STR, SmartFoxClient.XTMSG_TYPE_JSON, SmartFoxClient.sendXtMessage(java.lang.String, java.lang.String, it.gotoandplay.smartfoxclient.data.SFSObject), Constant Field Values

onJoinRoom

public static final java.lang.String onJoinRoom
Dispatched when a room is joined successfully.

The params object contains the following parameters.

The following example shows how to handle an successful room joining.

 smartFox.addEventListener(SFSEvent.onJoinRoom, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           Room joinedRoom = (Room)evt.getParams().get("room");
           System.out.println("Room " + joinedRoom.getName() + " joined successfully");
       }
   });
 smartFox.joinRoom("The Entrance");
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
onJoinRoomError, Room, SmartFoxClient.joinRoom(int), Constant Field Values

onJoinRoomError

public static final java.lang.String onJoinRoomError
Dispatched when an error occurs while joining a room.

This error could happen, for example, if the user is trying to join a room which is currently full.

The params object contains the following parameters.

The following example shows how to handle a potential error in room joining.

 smartFox.addEventListener(SFSEvent.onJoinRoomError, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           String error = evt.getParams().getString("error");
           System.out.println("Room join error; the following error occurred: " + error);
       }
   });
 smartFox.joinRoom("The Entrance");
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
onJoinRoom, SmartFoxClient.joinRoom(int), Constant Field Values

onLogin

public static final java.lang.String onLogin
Dispatched when the login to a SmartFoxServer zone has been attempted.

The params object contains the following parameters.

NOTE: the server sends the username back to the client because not all usernames are valid: for example, those containing bad words may have been filtered during the login process.

The following example shows how to handle the login result.

 smartFox.addEventListener(SFSEvent.onLogin, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           if(evt.getParams().getBool("success"))
           {
               System.out.println("Successfully logged in as " + evt.getParams().getString("name"));
           }
           else
           {
               System.out.println("Zone login error; the following error occurred: " + evt.getParams().getString("error"));
           }
       }
   });
 smartFox.login("simpleChat", "jack", "");
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
onLogout, SmartFoxClient.login(java.lang.String, java.lang.String, java.lang.String), Constant Field Values

onLogout

public static final java.lang.String onLogout
Dispatched when the user logs out successfully.

After a successful logout the user is still connected to the server, but he/she has to login again into a zone, in order to be able to interact with the server.

No parameters are provided.

The following example shows how to handle the "logout" event.

 smartFox.addEventListener(SFSEvent.onLogout, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           System.out.println("Logged out successfully");
       }
   });
 smartFox.logout();
 

Since:
SmartFoxServer Pro v1.5.5
See Also:
onLogin, SmartFoxClient.logout(), Constant Field Values

onModeratorMessage

public static final java.lang.String onModeratorMessage
Dispatched when a message from a Moderator is received.

The params object contains the following parameters.

The following example shows how to handle a message coming from a Moderator.

 smartFox.addEventListener(SFSEvent.onModeratorMessage, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           User sender = (User)evt.getParams().get("sender");
           String message = evt.getParams().getString("message");
           System.out.println("Moderator " + sender.getName() + " said: " + message);
       }
   });
 

Since:
SmartFoxServer Pro v1.4.5
See Also:
onAdminMessage, User, SmartFoxClient.sendModeratorMessage(java.lang.String, java.lang.String, int), Constant Field Values

onObjectReceived

public static final java.lang.String onObjectReceived
Dispatched when an object is received.

The params object contains the following parameters.

The following example shows how to handle an Actionscript object received from a user.

 smartFox.addEventListener(SFSEvent.onObjectReceived, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           // Assuming another client sent his X and Y positions in two properties called px, py
           User sender = (User)evt.getParams().get("sender");
           double px = evt.getParams().getNumber("px");
           double py = evt.getParams().getNumber("py");
           System.out.println("Data received from user:  " + sender.getName());
           System.out.println("X = " + px + ", Y = " + py);
       }
   });
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
User, SmartFoxClient.sendObject(it.gotoandplay.smartfoxclient.data.SFSObject), SmartFoxClient.sendObjectToGroup(it.gotoandplay.smartfoxclient.data.SFSObject, int[]), Constant Field Values

onPrivateMessage

public static final java.lang.String onPrivateMessage
Dispatched when a private chat message is received. Dispatched when an object is received.

The params object contains the following parameters.

The following example shows how to handle a private message.

 smartFox.addEventListener(SFSEvent.onPrivateMessage, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           System.out.println("User " +
             ((User)evt.getParams().getObj("sender")).getName() +
             " sent the following private message: " + evt.getParams().getString("message"));
       }
   });
 smartFox.sendPrivateMessage("Hallo Jack!", 22);
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
onPublicMessage, User, SmartFoxClient.sendPrivateMessage(java.lang.String, int), Constant Field Values

onPublicMessage

public static final java.lang.String onPublicMessage
Dispatched when a public chat message is received.

The params object contains the following parameters.

The following example shows how to handle a public message.

 smartFox.addEventListener(SFSEvent.onPublicMessage, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           System.out.println("User " +
             ((User)evt.getParams().getObj("sender")).getName() +
             " said: " + evt.getParams().getString("message"));
       }
   });
 smartFox.sendPublicMessage("Hello world!");
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
onPrivateMessage, User, SmartFoxClient.sendPublicMessage(java.lang.String), Constant Field Values

onRandomKey

public static final java.lang.String onRandomKey
Dispatched in response to a SmartFoxClient.getRandomKey() request.

The params object contains the following parameters.

The following example shows how to handle the request a random key to the server.

 smartFox.addEventListener(SFSEvent.onRandomKey, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           System.out.println("Random key received from server: " +
           evt.getParams().getString("key"));
       }
   });
 smartFox.getRandomKey();
 

Since:
SmartFoxServer Pro v1.x.x
See Also:
SmartFoxClient.getRandomKey(), Constant Field Values

onRoomAdded

public static final java.lang.String onRoomAdded
Dispatched when a new room is created in the zone where the user is currently logged in.

The params object contains the following parameters.

The following example shows how to handle a new room being created in the zone.

 smartFox.addEventListener(SFSEvent.onRoomAdded, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           Room room = (Room)evt.getParams().get("room");
           System.out.println("Room " + room.getName() + " was created");

           // TODO: update available rooms list in the application interface
       }
   });
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
onRoomDeleted, Room, SmartFoxClient.createRoom(java.lang.String, int, java.util.Map), Constant Field Values

onRoomDeleted

public static final java.lang.String onRoomDeleted
Dispatched when a room is removed from the zone where the user is currently logged in.

The params object contains the following parameters.

The following example shows how to handle a new room being removed in the zone.

 smartFox.addEventListener(SFSEvent.onRoomDeleted, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           Room room = (Room)evt.getParams().get("room");
           System.out.println("Room " + room.getName() + " was removed");

           // TODO: update available rooms list in the application interface
       }
   });
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
onRoomAdded, Room, Constant Field Values

onRoomLeft

public static final java.lang.String onRoomLeft
Dispatched when a room is left in multi-room mode, in response of a SmartFoxClient.leaveRoom(int) request.

The params object contains the following parameters.

The following example shows how to handle the "room left" event.

 smartFox.addEventListener(SFSEvent.onRoomLeft, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           int roomId = (Integer)evt.getParams().get("roomId");
           System.out.println("You left room " + roomId);
       }
   });
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
SmartFoxClient.leaveRoom(int), Constant Field Values

onRoomListUpdate

public static final java.lang.String onRoomListUpdate
Dispatched when the list of rooms available in the current zone is received.

If the default login mechanism provided by SmartFoxServer is used, then this event is dispatched right after a successful login. This is because the SmartFoxServer API, internally, call the SmartFoxClient.getRoomList() method after a successful login is performed. If a custom login handler is implemented, the room list must be manually requested to the server by calling the mentioned method.

The params object contains the following parameters.

The following example shows how to handle the list of rooms sent by SmartFoxServer.

 smartFox.addEventListener(SFSEvent.onRoomListUpdate, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           // Dump the names of the available rooms in the current zone
                for(Integer rId : evt.getParams().get("roomList").keySet())
                    System.out.println(evt.getParams().get("roomList").get(r).getName());
       }
   });
 smartFox.login("simpleChat", "jack");
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
Room, SmartFoxClient.getRoomList(), Constant Field Values

onRoomVariablesUpdate

public static final java.lang.String onRoomVariablesUpdate
Dispatched when Room Variables are updated.

A user receives this notification only from the room(s) where he/she is currently logged in. Also, only the variables that changed are transmitted.

The params object contains the following parameters.

The following example shows how to handle an update in Room Variables.

 smartFox.addEventListener(SFSEvent.onRoomVariablesUpdate, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           Set<String> changedVars = (Set<String>)evt.getParams().get("changedVars");
           Room room = (Room)evt.getParams().get("room");
           // Iterate on the 'changedVars' to check which variables were updated
           for(String v : changedVars)
           {
               System.out.println(v + " room variable was updated; new value is: " + room.getVariable(v).getValue());
           }
       }
   });
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
Room, SmartFoxClient.setRoomVariables(java.util.Map), Constant Field Values

onRoundTripResponse

public static final java.lang.String onRoundTripResponse
Dispatched when a response to the SmartFoxClient.roundTripBench() request is received.

The "roundtrip time" represents the number of milliseconds that it takes to a message to go from the client to the server and back to the client. A good way to measure the network lag is to send continuos requests (every 3 or 5 seconds) and then calculate the average roundtrip time on a fixed number of responses (i.e. the last 10 measurements).

The params object contains the following parameters.

The following example shows how to check the average network lag time.

 smartFox.addEventListener(SFSEvent.onRoundTripResponse, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           long lag = (Long)evt.getParams().get("elapsed");
           System.out.println("Lag: " + lag + "milliseconds.");
       }
   });
 smartFox.roundTripBench();
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
SmartFoxClient.roundTripBench(), Constant Field Values

onSpectatorSwitched

public static final java.lang.String onSpectatorSwitched
Dispatched in response to the SmartFoxClient.switchSpectator() request.

The request to turn a spectator into a player may fail if another user did the same before your request, and there was only one player slot available.

The params object contains the following parameters.

The following example shows how to handle the spectator switch.

 smartFox.addEventListener(SFSEvent.onSpectatorSwitched, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           if(evt.getParams().getBool("success"))
           {
               System.out.println("You have been turned into a player; your player id is " + evt.getParams().get("newId"));
           }
           else
           {
               System.out.println("The attempt to switch from spectator to player failed");
           }
       }
   });
 smartFox.switchSpectator();
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
User.getPlayerId(), Room, SmartFoxClient.switchSpectator(), Constant Field Values

onPlayerSwitched

public static final java.lang.String onPlayerSwitched
Dispatched in response to the SmartFoxClient.switchPlayer() request.

The request to turn a player into a spectator may fail if another user did the same before your request, and there was only one spectator slot available.

The params object contains the following parameters.

The following example shows how to handle the player switch.

 smartFox.addEventListener(SFSEvent.onPlayerSwitched, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           if(evt.getParams().getBool("success"))
           {
               System.out.println("You have been turned into a spectator; your id is " + evt.getParams().get("newId"));
           }
           else
           {
               System.out.println("The attempt to switch from player to spectator failed");
           }
       }
   });
 smartFox.switchPlayer();
 

Since:
SmartFoxServer Pro v1.6.6
See Also:
User.getPlayerId(), Room, SmartFoxClient.switchPlayer(), Constant Field Values

onUserCountChange

public static final java.lang.String onUserCountChange
Dispatched when the number of users and/or spectators changes in a room within the current zone.

This event allows to keep track in realtime of the status of all the zone rooms in terms of users and spectators. In case many rooms are used and the zone handles a medium to high traffic, this notification can be turned off to reduce bandwidth consumption, since a message is broadcasted to all users in the zone each time a user enters or exits a room.

The params object contains the following parameters.

The following example shows how to check the handle the user count cgange notification.

 smartFox.addEventListener(SFSEvent.onUserCountChange, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           // Assuming this is a game room
           Room room = (Room)evt.getParams().get("room");
           String roomName = room.getName();
           int playersNum = room.getUserCount();
           int spectatorsNum = room.getSpectatorCount();
           System.out.println("Room " + roomName + "has " + playersNum + " players and " + spectatorsNum + " spectators");
       }
   });
 smartFox.switchSpectator();
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
onUserEnterRoom, onUserLeaveRoom, Room, SmartFoxClient.createRoom(java.lang.String, int, java.util.Map), Constant Field Values

onUserEnterRoom

public static final java.lang.String onUserEnterRoom
Dispatched when another user joins the current room.

The params object contains the following parameters.

The following example shows how to check the handle the user entering room notification.

 smartFox.addEventListener(SFSEvent.onUserEnterRoom, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           User user = (User)evt.getParams().get("user");
           System.out.println("User " + user.getName() + " entered the room");
       }
   });
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
onUserLeaveRoom, onUserCountChange, User, Constant Field Values

onUserLeaveRoom

public static final java.lang.String onUserLeaveRoom
Dispatched when a user leaves the current room.

This event is also dispatched when a user gets disconnected from the server.

The params object contains the following parameters.

The following example shows how to check the handle the user leaving room notification.

 smartFox.addEventListener(SFSEvent.onUserLeaveRoom, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           System.out.println("User " + evt.getParams().getString("userName") + " left the room");
       }
   });
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
onUserEnterRoom, onUserCountChange, Constant Field Values

onUserVariablesUpdate

public static final java.lang.String onUserVariablesUpdate
Dispatched when a user in the current room updates his/her User Variables.

The params object contains the following parameters.

The following example shows how to handle an update in User Variables.

 smartFox.addEventListener(SFSEvent.onUserVariablesUpdate, new ISFSEventHandler()
   {
       public void handleEvent(SFSEvent evt)
       {
           // We assume that each user has px and py variables representing the users's avatar coordinates in a 2D environment
           Set<String> changedVars = (Set<String>)evt.getParams().get("changedVars");
           if(changedVars.contains("px") || changedVars.contains("py"))
           {
               User user = (user)evt.getParams().get("user");
               System.out.println("User " + user.getName() + " moved to new coordinates:");
               System.out.println("\t px: " + user.getVariable("px"));
               System.out.println("\t py: " + user.getVariable("py"));
           }
       }
   });
 

Since:
SmartFoxServer Basic / Pro v1.x.x
See Also:
User, SmartFoxClient.setUserVariables(java.util.Map), Constant Field Values
Constructor Detail

SFSEvent

public SFSEvent(java.lang.String name,
                SFSObject params)
Method Detail

getName

public java.lang.String getName()

getParams

public SFSObject getParams()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object