Class SFSEvent
The SFSEvent parent class (ApiEvent) provides a public property called params which contains different parameters depending on the event type.
Example of usage:
import sfs3.client.*;
import sfs3.client.requests.*;
import sfs3.client.util.ConfigData;
public class SFS3Connector
{
SmartFox sfs;
ConfigData cfg;
public SFS3Connector()
{
// Configure client connection settings
cfg = new ConfigData();
cfg.host = "localhost";
cfg.zone = "Playground";
// Set up event handlers
sfs = new SmartFox();
sfs.addEventListener(SFSEvent.CONNECTION, this::onConnection);
sfs.addEventListener(SFSEvent.CONNECTION_LOST, this::onConnectionLost);
sfs.addEventListener(SFSEvent.LOGIN, this::onLogin);
sfs.addEventListener(SFSEvent.LOGIN_ERROR, this::onLoginError);
System.out.println("API Ver: " + sfs.getVersion());
// Connect to the server
sfs.connect(cfg);
}
// ----------------------------------------------------------------------
// Event Handlers
// ----------------------------------------------------------------------
private void onConnection(ApiEvent evt)
{
var success = (Boolean) evt.getParam(EventParam.Success);
if (success)
{
System.out.println("Connection success");
// Login as guest
sfs.send(new LoginRequest(""));
}
else
System.out.println("Connection Failed. Is the server running?");
}
private void onConnectionLost(ApiEvent evt)
{
System.out.println("Connection was lost");
}
private void onLogin(ApiEvent evt)
{
System.out.println("Logged in as: " + sfs.getMySelf().getName());
}
private void onLoginError(ApiEvent evt)
{
var message = (String) evt.getParam(EventParam.ErrorMessage);
System.out.println("Login failed. Error: " + message);
}
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDispatched when the current user receives a message from an administrator user.static final StringDispatched when a connection between the client and a SmartFoxServer 3 instance is attempted.static final StringDispatched when the connection between the client and the SmartFoxServer 3 instance is interrupted.static final StringDispatched when the connection between the client and the SmartFoxServer 3 instance is re-established after a temporary disconnection, while the SmartFoxServer 3 HRC system is available in the Zone.static final StringDispatched when the connection between the client and the SmartFoxServer 3 instance is interrupted abruptly while the SmartFoxServer 3 HRC system is available in the Zone.static final StringDispatched when data coming from a server-side Extension is received by the current user.static final Stringstatic final StringDispatched when the current user receives an invitation from another user.static final StringDispatched when the current user receives a reply to an invitation sent previously.static final StringDispatched when an error occurs while the current user is sending a reply to an invitation.static final StringDispatched in response to a LoginRequest and signaling a successful login in the selected Zone.static final StringDispatched if an error occurs while the user login is being performed.static final StringDispatched when the current user logs out of the server Zone.static final StringDispatched to notify about MMOItemVariables updates in the current MMORoom.static final StringDispatched when the current user receives a message from a moderator user.static final StringDispatched when an object containing custom data is received by the current user.static final StringDispatched when a new lag value measurement is available.static final StringDispatched when a player is turned to a spectator inside a Game Room.static final StringDispatched when an error occurs while the current user is being turned from player to spectator in a Game Room.static final StringDispatched when a private message is received by the current user.static final StringDispatched to notify about Users and MMOItem changes in the players' AoI of a joined MMORoom, typically in response to a SetUserPositionRequest request.static final StringDispatched when a public message is received by the current user.static final StringDispatched when a new Room is created inside the Zone under any of the Room Groups that the client is subscribed to.static final StringDispatched when the capacity of a Room is changed.static final StringDispatched when an error occurs while attempting to change the capacity of a Room.static final StringDispatched if an error occurs while creating a new Room.static final StringDispatched when a Rooms search is completed.static final StringDispatched when a Room Group is subscribed by the current user.static final StringThis event is fired in response to the SubscribeRoomGroupRequest request in case the operation failed.static final StringDispatched when a Group is unsubscribed by the current user.static final StringThis event is fired in response to the UnsubscribeRoomGroupRequest request in case the operation failed.static final StringDispatched when a Room is joined by the current user.static final StringDispatched when an error occurs while the current user is trying to join a Room.static final StringDispatched when the name of a Room is changed.static final StringDispatched when an error occurs while attempting to change the name of a Room.static final StringDispatched when the password of a Room is set, changed or removed.static final StringDispatched when an error occurs while attempting to set, change or remove the password of a Room.static final StringDispatched when a Room belonging to one of the Groups subscribed by the client is removed from the Zone.static final StringDispatched when a Room Variable is updated.static final StringThis event is fired in response to the SpectatorToPlayerRequest request if the operation is executed successfully.static final StringDispatched when an error occurs while the current user is being turned from spectator to player in a Game Room.static final StringDispatched when the result of the UDP handshake is notified.static final StringDispatched when an active UDP connection is lost.static final StringDispatched when the number of users/players or spectators inside a Room changes.static final StringDispatched when one of the Rooms joined by the current user is entered by another user.static final StringDispatched when one of the Rooms joined by the current user is left by another user, or by the current user himself.static final StringDispatched when a Users search is completed.static final StringDispatched when a User Variable is updated. -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
HANDSHAKE
- See Also:
- Internal
-
UDP_CONNECTION
Dispatched when the result of the UDP handshake is notified. This event is fired in response to a call to the connectUdp() method.
The properties of the params object contained in the event object have the following values:
Property Type Description Success Boolean The connection result: trueif a connection was established,falseotherwise.- See Also:
-
UDP_CONNECTION_LOST
Dispatched when an active UDP connection is lost.
The properties of the params object contained in the event object have the following values:
Property Type Description ErrorMessage String Provides extra info on what went wrong. Can be null if no specific error occurred. - See Also:
-
CONNECTION
Dispatched when a connection between the client and a SmartFoxServer 3 instance is attempted. This event is fired in response to a call to the connect() method.
The properties of the params object contained in the event object have the following values:
Property Type Description Success Boolean The connection result: trueif a connection was established,falseotherwise.- See Also:
-
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
trueto the enableLagMonitor() method.The properties of the params object contained in the event object have the following values:
Property Type Description LagValue LagValue Object providing the average of the last ten measured lag values (milliseconds) as well as the min. and max. values ever recorded - See Also:
-
CONNECTION_LOST
Dispatched when the connection between the client and the SmartFoxServer 3 instance is interrupted. This event is also fired in response to a call to the disconnect() method.
The properties of the params object contained in the event object have the following values:
Property Type Description DisconnectionReason String The reason of the disconnection, among those available in the ClientDisconnectionReason class. - See Also:
-
CONNECTION_RETRY
Dispatched when the connection between the client and the SmartFoxServer 3 instance is interrupted abruptly while the SmartFoxServer 3 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 into a game without loosing the match because of an unstable connection.
When this event is dispatched the API enters a "frozen" 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.
- See Also:
-
CONNECTION_RESUME
Dispatched when the connection between the client and the SmartFoxServer 3 instance is re-established after a temporary disconnection, while the SmartFoxServer 3 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 a player to get back into a game without loosing the match because of an unstable connection.
When this event is dispatched the application interface should be reverted to the state it had before the disconnection. In case the reconnection attempt fails, the CONNECTION_LOST event is fired.
No parameters are available for this event object.
- See Also:
-
LOGIN
Dispatched in response to a LoginRequest and signaling a successful login in the selected Zone.
The properties of the params 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. - See Also:
-
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 params 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. - See Also:
-
LOGOUT
Dispatched when the current user logs out of the server Zone. This event is fired in response to the LogoutRequest request.
No parameters are available for this event object.
- See Also:
-
ROOM_ADD
Dispatched when a new Room is created inside the Zone under any of the Room Groups that the client is subscribed to. This event is fired in response to the CreateRoomRequest / CreateSFSGameRequest requests in case the operation is executed successfully.
The properties of the params object contained in the event object have the following values:
Property Type Description Room Room An object representing the Room that was created. - See Also:
-
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 params object contained in the event object have the following values:
Property Type Description Room Room An object representing the Room that was removed. - See Also:
-
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 params 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. - See Also:
-
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 params object contained in the event object have the following values:
Property Type Description Room Room An object representing the Room that was joined. - See Also:
-
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 params 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. - See Also:
-
USER_ENTER_ROOM
Dispatched when one of the Rooms joined by the current user is entered by another user. This event is triggered 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 params 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. - See Also:
-
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 triggered 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 params 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. - See Also:
-
USER_COUNT_CHANGE
Dispatched when the number of users/players or spectators inside a Room changes. This event can be triggered 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 params 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. UserCount int The new users count (players in case of Game Room). SpecCount int The new spectators count (Game Room only). - See Also:
-
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 params 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. - See Also:
-
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 also fired by the sender's client, so that the user is aware that the message was delivered successfully to the recipient, and it can be displayed in the private chat UI 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 params 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. - See Also:
-
OBJECT_MESSAGE
Dispatched when an object containing custom data is received by the current user. This event is triggered by an ObjectMessageRequest request sent by any user in the target Room.
The properties of the params 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. - See Also:
-
MODERATOR_MESSAGE
Dispatched when the current user receives a message from a moderator user. This event can be triggered by either a ModeratorMessageRequest, KickUserRequest or a BanUserRequest request. Also, this event can be triggered by a kick/ban action performed through the SmartFoxServer 3 Administration Tool.
The properties of the params 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. - See Also:
-
ADMIN_MESSAGE
Dispatched when the current user receives a message from an administrator user. This event is triggered by the AdminMessageRequest request sent by a user with administration privileges.
The properties of the params 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. - See Also:
-
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.
The properties of the params object contained in the event object have the following values:
Property Type Description Cmd String The name of a custom command to be processed. 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 sent in the request ExtParams ISFSObject An object containing the data sent by the Extension. Room Room An object representing the Room which the Extension is attached to (null if it's not a Room Extension) RoomId int The id of the Room Extension (null if it's not a Room Extension) TxType TransportType The transport type used by the Extensions (TCP, UDP_RELIABLE, UDP_UNRELIABLE etc...) - See Also:
-
ROOM_VARIABLES_UPDATE
Dispatched when a Room Variable is updated. This event is triggered by the SetRoomVariablesRequest request, which could have been sent by a user in the same Room or, in case of a global Room Variable, in a Room belonging to one of the subscribed Groups.
The properties of the params 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 List<String> The list of names of the Room Variables that were updated (or created for the first time). - See Also:
-
USER_VARIABLES_UPDATE
Dispatched when a User Variable is updated. This event is triggered by the SetUserVariablesRequest request sent by a user in one of the currently joined Rooms.
The properties of the params 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 List<String> The list of names of the User Variables that were updated (or created for the first time). - See Also:
-
ROOM_GROUP_SUBSCRIBE
Dispatched when a Room 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 params object contained in the event object have the following values:
Property Type Description GroupId String The name of the Group that was subscribed. NewRooms List<Room> A list of Room objects representing the Rooms belonging to the subscribed Group. - See Also:
-
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 params object contained in the event object have the following values:
Property Type Description GroupId String The name of the Group that was unsubscribed. - See Also:
-
ROOM_GROUP_SUBSCRIBE_ERROR
This event is fired in response to the SubscribeRoomGroupRequest request in case the operation failed.
The properties of the params 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. - See Also:
-
ROOM_GROUP_UNSUBSCRIBE_ERROR
This event is fired in response to the UnsubscribeRoomGroupRequest request in case the operation failed.
The properties of the params 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. - See Also:
-
SPECTATOR_TO_PLAYER
This event is fired in response to the SpectatorToPlayerRequest request if the operation is executed successfully.
The properties of the params 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. - See Also:
-
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 params 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. - See Also:
-
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 params 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. - See Also:
-
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 params 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. - See Also:
-
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 params 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. - See Also:
-
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 params 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. - See Also:
-
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 params object contained in the event object have the following values:
Property Type Description Room Room An object representing the Room whose password was changed. - See Also:
-
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 params 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. - See Also:
-
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 params object contained in the event object have the following values:
Property Type Description Room Room An object representing the Room whose capacity was changed. - See Also:
-
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 params 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. - See Also:
-
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 params object contained in the event object have the following values:
Property Type Description RoomList List<Room> A list of Room objects representing the Rooms matching the search criteria. If no Room is found, the list is empty - See Also:
-
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 params object contained in the event object have the following values:
Property Type Description UserList List<User> A list of User objects representing the Users matching the search criteria. If no User is found, the list is empty - See Also:
-
INVITATION
Dispatched when the current user receives an invitation from another user. This event is triggered by the InviteUsersRequest request; the user is supposed to reply using the InvitationReplyRequest request.
The properties of the params 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. - See Also:
-
INVITATION_REPLY
Dispatched when the current user receives a reply to an invitation sent previously. This event is triggered by the InvitationReplyRequest request sent by the invitee.
The properties of the params 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 InvitationReply The response from the invitee (ACCEPT, REFUSE or EXPIRED) InvitationReply class. Data ISFSObject An optional object containing custom parameters, for example a message describing the reason of the refusal. - See Also:
-
INVITATION_REPLY_ERROR
Dispatched when an error occurs while the current user is sending a reply to an invitation. This event is fired in response to the InvitationReplyRequest request in case the operation failed.
The properties of the params 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. - See Also:
-
PROXIMITY_LIST_UPDATE
Dispatched to notify about Users and MMOItem changes in the players' AoI of a joined MMORoom, typically in response to a SetUserPositionRequest request.
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. - See Also:
-
MMOITEM_VARIABLES_UPDATE
Dispatched to notify about MMOItemVariables updates in the current MMORoom.
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). - See Also:
-
-
Constructor Details
-
SFSEvent
Creates a new SFSEvent instance.- Parameters:
type- The type of event.args- An object containing the parameters of the event.
-
SFSEvent
-