|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectit.gotoandplay.smartfoxclient.SFSEvent
public class SFSEvent
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.
| 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 |
|---|
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.
String): the Administrator's message.
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"));
}
}
onModeratorMessage,
Constant Field Valuespublic static final java.lang.String onBuddyList
The params object contains the following parameters.
List<Buddy>): the buddy list.
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();
onBuddyListError,
onBuddyListUpdate,
onBuddyRoom,
SmartFoxClient.buddyList,
SmartFoxClient.loadBuddyList(),
SmartFoxClient.addBuddy(java.lang.String),
SmartFoxClient.removeBuddy(java.lang.String),
Constant Field Valuespublic static final java.lang.String onBuddyListError
The params object contains the following parameters.
String): the error message.
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();
onBuddyList,
Constant Field Valuespublic static final java.lang.String onBuddyListUpdate
The params object contains the following parameters.
Buddy): the buddy whose status or Buddy Variables have changed.
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);
}
});
onBuddyList,
SmartFoxClient.buddyList,
SmartFoxClient.setBuddyBlockStatus(java.lang.String, boolean),
SmartFoxClient.setBuddyVariables(java.util.Map) ,
Constant Field Valuespublic static final java.lang.String onBuddyPermissionRequest
The params object contains the following parameters.
String): the name of the user requesting to add the current user to his/her buddy list.
String): a message accompaining the permission request.
This message can't be sent from the client-side, but it's part of the
advanced server-side buddy list features.
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"));
}
});
SmartFoxClient.addBuddy(java.lang.String),
Constant Field Valuespublic static final java.lang.String onBuddyRoom
SmartFoxClient.getBuddyRoom(it.gotoandplay.smartfoxclient.data.Buddy) request.
The params object contains the following parameters.
int[]): the list of id of the rooms in which the buddy is currently logged;
if users can't be present in more than one room at the same time,
the list will contain one room id only, at 0 index.
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);
SmartFoxClient.getBuddyRoom(it.gotoandplay.smartfoxclient.data.Buddy),
Constant Field Valuespublic static final java.lang.String onConfigLoadFailure
The params object contains the following parameters.
String): the error message.
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");
onConfigLoadSuccess,
SmartFoxClient.loadConfig(java.lang.String),
Constant Field Valuespublic static final java.lang.String onConfigLoadSuccess
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);
onConfigLoadFailure,
SmartFoxClient.loadConfig(java.lang.String),
Constant Field Valuespublic static final java.lang.String onConnection
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.
Boolean): the connection result: true if the connection succeeded,
false if the connection failed.
String): the error message in case of connection failure.
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);
SmartFoxClient.connect(java.lang.String),
Constant Field Valuespublic static final java.lang.String onConnectionLost
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!");
}
});
SmartFoxClient.disconnect(),
Constant Field Valuespublic static final java.lang.String onCreateRoomError
The params object contains the following parameters.
String): the error message.
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);
SmartFoxClient.createRoom(java.lang.String, int, java.util.Map) ,
Constant Field Valuespublic static final java.lang.String onDebugMessage
In order to receive this event you have to enable debug messages.
The params object contains the following parameters.
String): the debug message.
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);
SmartFoxClient.setDebug(boolean),
Constant Field Valuespublic static final java.lang.String onExtensionResponse
The params object contains the following parameters.
SFSObject for XML protocol,
JSONObject for JSON protocol and String[] for String protocol.
By convention, a String property called _cmd should always be present,
to distinguish between different responses coming from the same extension
(in case of String protocol the element at zero index of the array).
String): one of the following response protocol types:
SmartFoxClient.XTMSG_TYPE_XML,
SmartFoxClient.XTMSG_TYPE_STR,
SmartFoxClient.XTMSG_TYPE_JSON.
By default SmartFoxClient.XTMSG_TYPE_XML is used.
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
}
}
});
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 Valuespublic static final java.lang.String onJoinRoom
The params object contains the following parameters.
Room): the Room object representing the joined room.
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");
onJoinRoomError,
Room,
SmartFoxClient.joinRoom(int),
Constant Field Valuespublic static final java.lang.String onJoinRoomError
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.
String): the error message.
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");
onJoinRoom,
SmartFoxClient.joinRoom(int),
Constant Field Valuespublic static final java.lang.String onLogin
The params object contains the following parameters.
Boolean): the login result: true if the login to the provided zone succeeded;
false if login failed.
String): the user's actual username.
String): the error message in case of login failure.
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", "");
onLogout,
SmartFoxClient.login(java.lang.String, java.lang.String, java.lang.String),
Constant Field Valuespublic static final java.lang.String onLogout
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();
onLogin,
SmartFoxClient.logout(),
Constant Field Valuespublic static final java.lang.String onModeratorMessage
The params object contains the following parameters.
String): the Moderator's message.
User): the User object representing
the Moderator.
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);
}
});
onAdminMessage,
User,
SmartFoxClient.sendModeratorMessage(java.lang.String, java.lang.String, int),
Constant Field Valuespublic static final java.lang.String onObjectReceived
The params object contains the following parameters.
SFSObject): the object received.
User): object representing the user that sent the object.
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);
}
});
User,
SmartFoxClient.sendObject(it.gotoandplay.smartfoxclient.data.SFSObject),
SmartFoxClient.sendObjectToGroup(it.gotoandplay.smartfoxclient.data.SFSObject, int[]),
Constant Field Valuespublic static final java.lang.String onPrivateMessage
The params object contains the following parameters.
String): the private message received.
User): the User object representing
the user that sent the message;
this property is null if the sender isn't in the same room of
the recipient.
Integer): the id of the room where the sender is.
Integer): the user id of the sender (useful in case of private messages across
different rooms, when the sender object is not available).
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);
onPublicMessage,
User,
SmartFoxClient.sendPrivateMessage(java.lang.String, int),
Constant Field Valuespublic static final java.lang.String onPublicMessage
The params object contains the following parameters.
String): the public message received.
User): the User object representing the
user that sent the message.
Integer): the id of the room where the sender is.
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!");
onPrivateMessage,
User,
SmartFoxClient.sendPublicMessage(java.lang.String),
Constant Field Valuespublic static final java.lang.String onRandomKey
SmartFoxClient.getRandomKey() request.
The params object contains the following parameters.
String): a unique random key generated by the server.
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();
SmartFoxClient.getRandomKey(),
Constant Field Valuespublic static final java.lang.String onRoomAdded
The params object contains the following parameters.
Room): the Room object representing the room that was created.
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
}
});
onRoomDeleted,
Room,
SmartFoxClient.createRoom(java.lang.String, int, java.util.Map) ,
Constant Field Valuespublic static final java.lang.String onRoomDeleted
The params object contains the following parameters.
Room): the Room object representing the room that was removed.
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
}
});
onRoomAdded,
Room,
Constant Field Valuespublic static final java.lang.String onRoomLeft
SmartFoxClient.leaveRoom(int) request.
The params object contains the following parameters.
Integer): the id of the room that was left.
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);
}
});
SmartFoxClient.leaveRoom(int),
Constant Field Valuespublic static final java.lang.String onRoomListUpdate
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.
Map<Integer, Room>): a Map with room id as key and
Room objects as key.
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");
Room,
SmartFoxClient.getRoomList(),
Constant Field Valuespublic static final java.lang.String onRoomVariablesUpdate
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.
Room): the Room object representing the room where the update took place.
Set<String>): Set with the names of the changed variables.
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());
}
}
});
Room,
SmartFoxClient.setRoomVariables(java.util.Map) ,
Constant Field Valuespublic static final java.lang.String onRoundTripResponse
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.
Long): the roundtrip time.
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();
SmartFoxClient.roundTripBench(),
Constant Field Valuespublic static final java.lang.String onSpectatorSwitched
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.
Boolean): the switch result: true if the spectator was turned into a player,
otherwise false.
Integer): the player id assigned by the server to the user.
Room): the Room object representing the room where the switch occurred.
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();
User.getPlayerId(),
Room,
SmartFoxClient.switchSpectator(),
Constant Field Valuespublic static final java.lang.String onPlayerSwitched
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.
Boolean): the switch result: true if the player was turned into a spectator,
otherwise false.
Integer): the player id assigned by the server to the user.
If the switch is successful it's -1.
Room): the Room object representing the room where the switch occurred.
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();
User.getPlayerId(),
Room,
SmartFoxClient.switchPlayer(),
Constant Field Valuespublic static final java.lang.String onUserCountChange
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.
Room): the Room object representing the room where the change occurred.
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();
onUserEnterRoom,
onUserLeaveRoom,
Room,
SmartFoxClient.createRoom(java.lang.String, int, java.util.Map) ,
Constant Field Valuespublic static final java.lang.String onUserEnterRoom
The params object contains the following parameters.
Integer): the id of the room joined by a user
(useful in case multi-room presence is allowed).
User): the User object representing the user
that joined the room.
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");
}
});
onUserLeaveRoom,
onUserCountChange,
User,
Constant Field Valuespublic static final java.lang.String onUserLeaveRoom
This event is also dispatched when a user gets disconnected from the server.
The params object contains the following parameters.
Integer): the id of the room left by a user
(useful in case multi-room presence is allowed).
Integer): the id of the user that left the room (or got disconnected).
String): the name of the user.
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");
}
});
onUserEnterRoom,
onUserCountChange,
Constant Field Valuespublic static final java.lang.String onUserVariablesUpdate
The params object contains the following parameters.
User): the User object representing the user who
updated his/her variables.
Set<String>): Set with the names of the changed variables.
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"));
}
}
});
User,
SmartFoxClient.setUserVariables(java.util.Map) ,
Constant Field Values| Constructor Detail |
|---|
public SFSEvent(java.lang.String name,
SFSObject params)
| Method Detail |
|---|
public java.lang.String getName()
public SFSObject getParams()
public java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||