|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectsfs2x.client.core.BaseEvent
sfs2x.client.core.SFSEvent
public class SFSEvent
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.
Examplepackage 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 Mapparams = 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); } }
SFSBuddyEvent
Field Summary | |
---|---|
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 | |
---|---|
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. |
Method Summary |
---|
Methods inherited from class sfs2x.client.core.BaseEvent |
---|
clone, getArguments, getTarget, getType, setArguments, setTarget, toString |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String HANDSHAKE
public static final java.lang.String UDP_INIT
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:
Property | Type | Description |
---|---|---|
success | Boolean | The connection result: true if a connection was established, false otherwise. |
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(); }
SmartFox.initUdp()
,
ExtensionRequest
,
Constant Field Valuespublic static final java.lang.String CONNECTION
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:
Property | Type | Description |
---|---|---|
success | Boolean | The connection result: true if a connection was established, false otherwise. |
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(); }
SmartFox.connect()
,
CONNECTION_RETRY
,
CONNECTION_RESUME
,
CONNECTION_LOST
,
Constant Field Valuespublic static final java.lang.String PING_PONG
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:
Property | Type | Description |
---|---|---|
lagValue | int | The average of the last ten measured lag values, expressed in milliseconds. |
SmartFox.enableLagMonitor(boolean)
,
Constant Field Valuespublic static final java.lang.String SOCKET_ERROR
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:
Property | Type | Description |
---|---|---|
errorMessage | String | The description of the error. |
public static final java.lang.String CONNECTION_LOST
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:
Property | Type | Description |
---|---|---|
reason | String | The reason of the disconnection, among those available in the ClientDisconnectionReason class. |
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 } } }); }
SmartFox.disconnect()
,
ClientDisconnectionReason
,
CONNECTION
,
CONNECTION_RETRY
,
Constant Field Valuespublic static final java.lang.String CONNECTION_RETRY
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.
Exampleprivate 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")); } }); }
CONNECTION_RESUME
,
CONNECTION_LOST
,
Constant Field Valuespublic static final java.lang.String CONNECTION_RESUME
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
CONNECTION_RETRY
,
CONNECTION_LOST
,
Constant Field Valuespublic static final java.lang.String CONNECTION_ATTEMPT_HTTP
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.
CONNECTION
,
CONNECTION_LOST
,
Constant Field Valuespublic static final java.lang.String CONFIG_LOAD_SUCCESS
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.
Exampleprivate 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); }
SmartFox.loadConfig()
,
CONFIG_LOAD_FAILURE
,
Constant Field Valuespublic static final java.lang.String CONFIG_LOAD_FAILURE
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
SmartFox.loadConfig()
,
CONFIG_LOAD_SUCCESS
,
Constant Field Valuespublic static final java.lang.String LOGIN
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:
Property | Type | Description |
---|---|---|
user | User | An object representing the user who performed the login. |
data | ISFSObject | An object containing custom parameters returned by a custom login system, if any. |
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")); }
LoginRequest
,
User
,
LOGIN_ERROR
,
LOGOUT
,
Constant Field Valuespublic static final java.lang.String LOGIN_ERROR
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | short | The error code. |
LoginRequest
,
LOGIN
,
Constant Field Valuespublic static final java.lang.String LOGOUT
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.
Exampleprivate 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()); }
LogoutRequest
,
LOGIN
,
Constant Field Valuespublic static final java.lang.String ROOM_ADD
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room that was created. |
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)); }
CreateRoomRequest
,
CreateSFSGameRequest
,
Room
,
ROOM_REMOVE
,
ROOM_CREATION_ERROR
,
Constant Field Valuespublic static final java.lang.String ROOM_REMOVE
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room that was removed. |
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")); } }); }
Room
,
ROOM_ADD
,
Constant Field Valuespublic static final java.lang.String ROOM_CREATION_ERROR
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | short | The error code. |
CreateRoomRequest
,
CreateSFSGameRequest
,
ROOM_ADD
,
Constant Field Valuespublic static final java.lang.String ROOM_JOIN
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room that was joined. |
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")); }
JoinRoomRequest
,
QuickGameJoinRequest
,
Room
,
ROOM_JOIN_ERROR
,
Constant Field Valuespublic static final java.lang.String ROOM_JOIN_ERROR
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | short | The error code. |
JoinRoomRequest
,
QuickGameJoinRequest
,
ROOM_JOIN
,
Constant Field Valuespublic static final java.lang.String USER_ENTER_ROOM
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:
Property | Type | Description |
---|---|---|
user | User | An object representing the user who joined the Room. |
room | Room | An object representing the Room that was joined by a user. |
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()); } }); }
JoinRoomRequest
,
QuickGameJoinRequest
,
RoomSettings.setEvents(sfs2x.client.requests.RoomEvents)
,
User
,
Room
,
USER_EXIT_ROOM
,
USER_COUNT_CHANGE
,
Constant Field Valuespublic static final java.lang.String USER_EXIT_ROOM
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:
Property | Type | Description |
---|---|---|
user | User | An object representing the user who left the Room. |
room | Room | An object representing the Room that was left by a user. |
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()); } }); }
LeaveRoomRequest
,
RoomSettings.setEvents(sfs2x.client.requests.RoomEvents)
,
User
,
Room
,
USER_ENTER_ROOM
,
USER_COUNT_CHANGE
,
Constant Field Valuespublic static final java.lang.String USER_COUNT_CHANGE
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room in which the users count changed. |
uCount | int | The new users count (players in case of Game Room). |
sCount | int | The new spectators count (Game Room only). |
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"); } }); }
JoinRoomRequest
,
QuickGameJoinRequest
,
LeaveRoomRequest
,
RoomSettings.setEvents(sfs2x.client.requests.RoomEvents)
,
Room
,
USER_ENTER_ROOM
,
USER_EXIT_ROOM
,
Constant Field Valuespublic static final java.lang.String PUBLIC_MESSAGE
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room at which the message is targeted. |
sender | User | An object representing the user who sent the message. |
message | String | The message sent by the user. |
data | ISFSObject | An object containing custom parameters which might accompany the message. |
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!")); }
PublicMessageRequest
,
User
,
Room
,
PRIVATE_MESSAGE
,
Constant Field Valuespublic static final java.lang.String PRIVATE_MESSAGE
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:
Property | Type | Description |
---|---|---|
sender | User | An object representing the user who sent the message. |
message | String | The message sent by the user. |
data | ISFSObject | An object containing custom parameters which might accompany the message. |
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())); }
PrivateMessageRequest
,
User
,
PUBLIC_MESSAGE
,
Constant Field Valuespublic static final java.lang.String OBJECT_MESSAGE
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:
Property | Type | Description |
---|---|---|
sender | User | An object representing the user who sent the message. |
message | SFSObject | The content of the message: an object containing the custom parameters sent by the sender. |
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)); }
ObjectMessageRequest
,
User
,
Constant Field Valuespublic static final java.lang.String MODERATOR_MESSAGE
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:
Property | Type | Description |
---|---|---|
sender | User | An object representing the moderator user who sent the message. |
message | String | The message sent by the moderator. |
data | ISFSObject | An object containing custom parameters which might accompany the message. |
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)); }
ModeratorMessageRequest
,
KickUserRequest
,
BanUserRequest
,
User
,
ADMIN_MESSAGE
,
Constant Field Valuespublic static final java.lang.String ADMIN_MESSAGE
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:
Property | Type | Description |
---|---|---|
sender | User | An object representing the administrator user who sent the message. |
message | String | The message sent by the administrator. |
data | ISFSObject | An object containing custom parameters which might accompany the message. |
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)); }
AdminMessageRequest
,
User
,
MODERATOR_MESSAGE
,
Constant Field Valuespublic static final java.lang.String EXTENSION_RESPONSE
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:
Property | Type | Description |
---|---|---|
cmd | String | The 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. |
params | ISFSObject | An object containing custom data sent by the Extension. |
sourceRoom | Number | [DEPRECATED - Use room property] The id of the room which the Extension is attached to (for Room Extensions only). |
room | Room | An object representing the Room which the Extension is attached to (for Room Extensions only, since 1.7.0). |
packetId | Number | The 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. |
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)); }
ExtensionRequest
,
Constant Field Valuespublic static final java.lang.String ROOM_VARIABLES_UPDATE
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room where the Room Variable update occurred. |
changedVars | Array | The list of names of the Room Variables that were updated (or created for the first time). |
private void someMethod() { sfs.addEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { ListchangedVars = (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)); }
SetRoomVariablesRequest
,
Room
,
Constant Field Valuespublic static final java.lang.String USER_VARIABLES_UPDATE
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:
Property | Type | Description |
---|---|---|
user | User | An object representing the User who updated his own User Variables. |
changedVars | Array | The list of names of the User Variables that were updated (or created for the first time). |
private void someMethod() { sfs.addEventListener(SFSEvent.USER_VARIABLES_UPDATE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { ListchangedVars = (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)); }
SetUserVariablesRequest
,
User
,
Constant Field Valuespublic static final java.lang.String ROOM_GROUP_SUBSCRIBE
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:
Property | Type | Description |
---|---|---|
groupId | String | The name of the Group that was subscribed. |
newRooms | Array | A list of Room objects representing the Rooms belonging to the subscribed 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")); }
SubscribeRoomGroupRequest
,
Room
,
ROOM_GROUP_SUBSCRIBE_ERROR
,
ROOM_GROUP_UNSUBSCRIBE
,
Constant Field Valuespublic static final java.lang.String ROOM_GROUP_UNSUBSCRIBE
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:
Property | Type | Description |
---|---|---|
groupId | String | The name of the Group that was unsubscribed. |
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")); }
UnsubscribeRoomGroupRequest
,
ROOM_GROUP_UNSUBSCRIBE_ERROR
,
ROOM_GROUP_SUBSCRIBE
,
Constant Field Valuespublic static final java.lang.String ROOM_GROUP_SUBSCRIBE_ERROR
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | short | The error code. |
SubscribeRoomGroupRequest
,
ROOM_GROUP_SUBSCRIBE
,
Constant Field Valuespublic static final java.lang.String ROOM_GROUP_UNSUBSCRIBE_ERROR
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | short | The error code. |
UnsubscribeRoomGroupRequest
,
ROOM_GROUP_UNSUBSCRIBE
,
Constant Field Valuespublic static final java.lang.String SPECTATOR_TO_PLAYER
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room in which the spectator is turned to player. |
user | User | An object representing the spectator who was turned to player. |
playerId | int | The player id of the user. |
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()); }
SpectatorToPlayerRequest
,
User
,
Room
,
SPECTATOR_TO_PLAYER_ERROR
,
PLAYER_TO_SPECTATOR
,
Constant Field Valuespublic static final java.lang.String PLAYER_TO_SPECTATOR
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room in which the player is turned to spectator. |
user | User | An object representing the player who was turned to spectator. |
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()); }
PlayerToSpectatorRequest
,
User
,
Room
,
PLAYER_TO_SPECTATOR_ERROR
,
SPECTATOR_TO_PLAYER
,
Constant Field Valuespublic static final java.lang.String SPECTATOR_TO_PLAYER_ERROR
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | short | The error code. |
SpectatorToPlayerRequest
,
SPECTATOR_TO_PLAYER
,
Constant Field Valuespublic static final java.lang.String PLAYER_TO_SPECTATOR_ERROR
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | short | The error code. |
PlayerToSpectatorRequest
,
PLAYER_TO_SPECTATOR
,
Constant Field Valuespublic static final java.lang.String ROOM_NAME_CHANGE
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room which was renamed. |
oldName | String | The previous name of the 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")); }
ChangeRoomNameRequest
,
Room
,
ROOM_NAME_CHANGE_ERROR
,
Constant Field Valuespublic static final java.lang.String ROOM_NAME_CHANGE_ERROR
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | short | The error code. |
ChangeRoomNameRequest
,
ROOM_NAME_CHANGE
,
Constant Field Valuespublic static final java.lang.String ROOM_PASSWORD_STATE_CHANGE
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room whose password was changed. |
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")); }
ChangeRoomPasswordStateRequest
,
Room
,
ROOM_PASSWORD_STATE_CHANGE_ERROR
,
Constant Field Valuespublic static final java.lang.String ROOM_PASSWORD_STATE_CHANGE_ERROR
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | short | The error code. |
ChangeRoomPasswordStateRequest
,
ROOM_PASSWORD_STATE_CHANGE
,
Constant Field Valuespublic static final java.lang.String ROOM_CAPACITY_CHANGE
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:
Property | Type | Description |
---|---|---|
room | Room | An object representing the Room whose capacity was changed. |
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)); }
ChangeRoomCapacityRequest
,
Room
,
ROOM_CAPACITY_CHANGE_ERROR
,
Constant Field Valuespublic static final java.lang.String ROOM_CAPACITY_CHANGE_ERROR
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | short | The error code. |
ChangeRoomCapacityRequest
,
ROOM_CAPACITY_CHANGE
,
Constant Field Valuespublic static final java.lang.String ROOM_FIND_RESULT
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:
Property | Type | Description |
---|---|---|
rooms | Array | A list of Room objects representing the Rooms matching the search criteria. If no Room is found, the list is empty |
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)); }
FindRoomsRequest
,
Constant Field Valuespublic static final java.lang.String USER_FIND_RESULT
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:
Property | Type | Description |
---|---|---|
users | Array | A list of User objects representing the Users matching the search criteria. If no User is found, the list is empty |
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)); }
FindUsersRequest
,
Constant Field Valuespublic static final java.lang.String INVITATION
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:
Property | Type | Description |
---|---|---|
invitation | Invitation | An object representing the invitation received by the current user. |
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")); } }); }
InviteUsersRequest
,
InvitationReplyRequest
,
Invitation
,
INVITATION_REPLY
,
Constant Field Valuespublic static final java.lang.String INVITATION_REPLY
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:
Property | Type | Description |
---|---|---|
invitee | User | An object representing the user who replied to the invitation. |
reply | int | The answer to the invitation among those available as constants in the InvitationReply class. |
data | ISFSObject | An object containing custom parameters, for example a message describing the reason of refusal. |
InvitationReplyRequest
,
InvitationReply
,
INVITATION
,
INVITATION_REPLY_ERROR
,
Constant Field Valuespublic static final java.lang.String INVITATION_REPLY_ERROR
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:
Property | Type | Description |
---|---|---|
errorMessage | String | A message containing the description of the error. |
errorCode | short | The error code. |
InvitationReplyRequest
,
INVITATION_REPLY
,
INVITATION
,
Constant Field Valuespublic static final java.lang.String PROXIMITY_LIST_UPDATE
The properties of the params object contained in the event object have the following values:
Property | Type | Description |
---|---|---|
room | Room | The Room where the event occurred. |
addedUsers | List<Users> | A list of User objects representing the users who entered the current user's Area of Interest. |
removedUsers | List<Users> | A list of User objects representing the users who left the current user's Area of Interest. |
addedItems | List<IMMOItem> | A list of MMOItem objects which entered the current user's Area of Interest. |
removedItems | List<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 ... } } }); }
SetUserPositionRequest
,
MMORoom
,
Constant Field Valuespublic static final java.lang.String MMOITEM_VARIABLES_UPDATE
The properties of the params object contained in the event have the following values:
Property | Type | Description |
---|---|---|
room | MMORoom | The MMORoom where the MMOItem whose Variables have been updated is located. |
mmoItem | MMOItem | The MMOItem whose variables have been updated. |
changedVars | List<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 ... } } }); }
MMORoom
,
MMOItem
,
MMOItemVariable
,
Constant Field Valuespublic static final java.lang.String CRYPTO_INIT
The properties of the params object contained in the event object have the following values:
Property | Type | Description |
---|---|---|
success | Boolean | true if a unique encryption key was successfully retrieved via HTTPS, false if the transaction failed. |
errorMsg | Boolean | May 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")); } } } }
SmartFox.initCrypto()
,
Constant Field ValuesConstructor Detail |
---|
public SFSEvent(java.lang.String type, java.util.Map<java.lang.String,java.lang.Object> args)
type
- The type of event.args
- An object containing the parameters of the event.public SFSEvent(java.lang.String type)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |