Class SFSApi
- All Implemented Interfaces:
ISFSApi
Overview
The SFSApi class provides central access to the server side API. Here you find the vast majority of the methods for interacting with the server: creating Rooms, joining, message handling, setting User/Room variables and many more...Specialized API
Additionally there are specialized API for specific tasks such as:- Game API: for quick games, challenges, invitations, etc...
- BuyddList API: for managing buddy lists
- MMO API: for MMO related functions, MMORoom creation, MMOItems etc...
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.smartfoxserver.entities.managers.IUserManagerprotected final org.slf4j.Loggerprotected final com.smartfoxserver.api.response.ISFSResponseApiprotected final SmartFoxServer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbanUser(User userToBan, User modUser, String banMessage, BanMode mode, int durationMinutes, int delaySeconds) Ban a User.voidbanUser(User userToBan, User modUser, String banMessage, String reason, BanMode mode, int durationMinutes, int delaySeconds) Ban a User.voidbanUserFromRoom(List<User> bannedUsers, Room theRoom, String message, int interval, TimeUnit timeUnit) Bans a User from a Room.voidchangeRoomCapacity(User owner, Room targetRoom, int maxUsers, int maxSpectators) Changes the capacity (max number of Users and Spectators) in the Room.voidchangeRoomName(User owner, Room targetRoom, String newName) Rename an existing Room.voidchangeRoomPassword(User owner, Room targetRoom, String newPassword) Changes the Room password and the Room password-state.booleancheckSecurePassword(ISession session, String originalPass, String encryptedPass) Check an encrypted password sent by the User at login time.Create a connection-less NPC (Non-Player Character).Create a connection-less NPC (Non-Player Character).createRoom(Zone zone, CreateRoomSettings params, User owner) Create a new RoomcreateRoom(Zone zone, CreateRoomSettings params, User owner, boolean joinIt, Room roomToLeave) Create a new RoomcreateRoom(Zone zone, CreateRoomSettings params, User owner, boolean joinIt, Room roomToLeave, boolean fireClientEvent, boolean fireServerEvent) voiddisconnect(ISession session) Removes a Session and the User connected with that session, if one existsvoiddisconnect(ISession session, int delaySeconds) Works likeISFSApi.disconnect(ISession)with an extra delay in secondsvoiddisconnectUser(User user) Disconnect the User abruptly.voiddisconnectUser(User user, IDisconnectionReason reason) Disconnect a User indicating a specific disconnection reason (for example because the User was Idle).voiddisconnectUser(User user, IDisconnectionReason reason, int delaySeconds) Works likeISFSApi.disconnectUser(User, IDisconnectionReason)with an extra delay in secondsvoidRemoves all Users from the target Room.voidRemoves all Users from the target Room.voidemptyRoom(Room targetRoom, boolean deactivateRoom, boolean fireClientEvent, boolean fireServerEvent) Removes all Users from the target Room.findRooms(Collection<Room> roomList, MatchExpression expression, int limit) Find one or more Room(s) in the specified collection of Rooms.findUsers(Collection<User> userList, MatchExpression expression, int limit) Find one or more User(s) in the specified collection of Users.Access theSFSPostOfficeto send email notifications and messagescom.smartfoxserver.api.response.ISFSResponseApiGets a reference to the global Task Scheduler.Provides the current SmartFoxServer versioncom.smartfoxserver.util.ServerUptimeProvides the server's uptimegetUserById(int userId) Finds a User from its unique IDgetUserByName(String name) Finds a User from its namegetUserBySession(ISession session) Finds a User from its SessionvoidJoin the user in a room.voidJoin the user in a room.
A client update and server side event will be also firedvoidjoinRoom(User user, Room roomToJoin, String password, boolean asSpectator, Room roomToLeave, boolean fireClientEvent, boolean fireServerEvent) Join the user in a Room.voidKicks the User out.voidkillConnection(User user) Simulates a sudden connection drop to test the reconnection system (HRC)voidRemoves a User from a previously joined RoomvoidRemoves a User from a previously joined Roomlogin(ISession sender, String name, String pass, String zoneName, ISFSObject paramsOut, boolean forceLogout) voidLog a User out of the current ZonevoidplayerToSpectator(User user, Room targetRoom, boolean fireClientEvent, boolean fireServerEvent) Turns a player in a Game Room to a spectator.voidquickJoinOrCreateRoom(User user, MatchExpression expression, Collection<String> groupList, CreateRoomSettings settings) Searches for a Room that matches the provided MatchExpression and joins the User in the first occurrence found.voidquickJoinOrCreateRoom(User user, MatchExpression expression, Collection<String> groupList, CreateRoomSettings settings, Room roomToLeave) Searches for a Room that matches the provided MatchExpression and joins the User in the first Room found.voidremoveRoom(Room room) Removes a Room from its Zone, provided the Room is empty.voidremoveRoom(Room room, boolean fireClientEvent, boolean fireServerEvent) Removes a Room from its ZoneFuture<?> runInSeparateThread(Runnable task) Runs a task in a separate (virtual) thread.<T> Future<T> runInSeparateThread(Callable<T> task) Similar to the above but uses a Callable which in turn can be used to return a result from the concurrent TaskvoidsendAdminMessage(User sender, String message, ISFSObject params, Collection<ISession> recipients) Sends a admin message to a number of Users.voidsendBuddyMessage(User sender, User recipient, String message, ISFSObject params) Sends a Buddy message to a specific user.voidsendExtensionResponse(String cmdName, ISFSObject params, User recipient, Room room, TransportType txType) voidsendExtensionResponse(String cmdName, ISFSObject params, List<User> recipients, Room room, TransportType txType) voidsendGenericMessage(com.smartfoxserver.api.GenericMessageType type, User sender, int targetRoomId, String message, ISFSObject params, Collection<ISession> recipients) voidsendModeratorMessage(User sender, String message, ISFSObject params, Collection<ISession> recipients) Sends a moderator message to a number of Users.voidsendObjectMessage(Room targetRoom, User sender, ISFSObject message, Collection<User> recipients) Send an Object message.voidsendPrivateMessage(User sender, User recipient, String message, ISFSObject params) Sends a private chat message.voidsendPublicMessage(Room targetRoom, User sender, String message, ISFSObject params) Sends a public chat message.voidsetRoomVariables(User user, Room targetRoom, List<RoomVariable> variables) Set Room Variables and update all clients.voidsetRoomVariables(User user, Room targetRoom, List<RoomVariable> variables, boolean fireClientEvent, boolean fireServerEvent, boolean overrideOwnership) Set Room Variables and update all clients.voidsetUserVariables(User owner, List<UserVariable> variables) Set User Variables.voidsetUserVariables(User owner, List<UserVariable> variables, boolean fireClientEvent, boolean fireServerEvent) Set User Variables.voidspectatorToPlayer(User user, Room targetRoom, boolean fireClientEvent, boolean fireServerEvent) Turns a spectator in a Game Room to a Player.voidsubscribeRoomGroup(User user, String groupId) Subscribe User to a Room Group.voidunsubscribeRoomGroup(User user, String groupId) Unsubscribe User to a Room Group.
-
Field Details
-
sfs
-
log
protected final org.slf4j.Logger log -
globalUserManager
protected com.smartfoxserver.entities.managers.IUserManager globalUserManager -
responseAPI
protected final com.smartfoxserver.api.response.ISFSResponseApi responseAPI
-
-
Constructor Details
-
SFSApi
-
-
Method Details
-
getScheduler
Gets a reference to the global Task Scheduler. With this you can run delayed or repetitive tasks in the Extension code. The Scheduler is backed by virtual threads, so you can add as many tasks as needed.- Specified by:
getSchedulerin interfaceISFSApi- Returns:
- a reference to server's Task Scheduler
- See Also:
-
getMailService
Access theSFSPostOfficeto send email notifications and messagesNOTE: before sending emails make sure the service is configured with a valid SMTP, via the AdminTool, under Server Configurator, Mailer
The service is based on the SimpleEmail API (included in SFS3) which can also be used stand-alone in Extensions if necessary. For example to implement more sophisticated email sending procedures. You can check their documentation for further details.
- Specified by:
getMailServicein interfaceISFSApi- Returns:
- the mail service
-
runInSeparateThread
Description copied from interface:ISFSApiRuns a task in a separate (virtual) thread. This doesn't add new threads in the system but rather uses the global virtual thread ExecutorService to run the task concurrently.This is especially useful for I/O bound tasks, such as reading from an external resources such as an HTTP service or remote database.
NOTE: always remember to catch all possible Exceptions inside your Runnable, otherwise they will silently escape with no notice.
NOTE 2: There should be very few casesin which you need to use this method. Extension calls are already handled by a separate virtual threads, so there is no penalty in running blocking code directly in the current Extension's thread.
- Specified by:
runInSeparateThreadin interfaceISFSApi- Parameters:
task- the Task to be run- Returns:
- the Future representing the running Task
-
runInSeparateThread
Description copied from interface:ISFSApiSimilar to the above but uses a Callable which in turn can be used to return a result from the concurrent TaskNOTE: always remember to catch all possible Exceptions inside your Callable, otherwise they will silently escape with no notice. NOTE 2: There should be very few casesin which you need to use this method. Extension calls are already handled by virtual threads, so there is no penalty in running blocking code directly in the Extension's thread.
Example:
class SlowCalculator implements Callable<Integer> { int x,y; public SlowCalculator(int x, int y) { this.x = x; this.y = y; } public Integer call() { Thread.sleep(1000L); return x + y; } } var future = getApi().runInSeparateThread(new SlowCalculator(5,10)); trace("Callable result: " + future.get());- Specified by:
runInSeparateThreadin interfaceISFSApi- Parameters:
task- the Task to be run- Returns:
- the Future representing the running Task
-
getResponseAPI
public com.smartfoxserver.api.response.ISFSResponseApi getResponseAPI()- Specified by:
getResponseAPIin interfaceISFSApi
-
getUserById
Finds a User from its unique ID- Specified by:
getUserByIdin interfaceISFSApi- Parameters:
userId- the User ID- Returns:
- the User. It can be null if no User was found with that ID
-
getUserByName
Finds a User from its name- Specified by:
getUserByNamein interfaceISFSApi- Parameters:
name- the User name- Returns:
- the User. It can be null if not User was found with that name (case sensitive)
-
getUserBySession
Finds a User from its Session- Specified by:
getUserBySessionin interfaceISFSApi- Parameters:
session- the Session- Returns:
- the User. It can be null if not User was found linked to that Session
-
kickUser
Kicks the User out. The operation allows to send a moderator message to the client prior to disconnecting it.- Specified by:
kickUserin interfaceISFSApi- Parameters:
userToKick- the User to be kickedmodUser- the mod/admin user, can be null to indicate generically the "Server"kickMessage- the moderator messagedelaySeconds- number of seconds before the disconnection is performed (recommended 5-10, to allow reading the message)
-
banUser
public void banUser(User userToBan, User modUser, String banMessage, BanMode mode, int durationMinutes, int delaySeconds) Ban a User. The operation allows to send a moderator message to the client prior to disconnecting it.The length of the ban and the rules under which the ban can be removed are specified in your Zone configuration.
- Specified by:
banUserin interfaceISFSApi- Parameters:
userToBan- the User to be bannedmodUser- the mod/admin user, can be null to indicate generically the "Server"banMessage- the moderator messagemode- choose between banning by ip address or by User namedurationMinutes- the duration of the ban in minutesdelaySeconds- number of seconds before the disconnection is performed
-
banUser
public void banUser(User userToBan, User modUser, String banMessage, String reason, BanMode mode, int durationMinutes, int delaySeconds) Ban a User. The operation allows to send a moderator message to the client prior to disconnecting it.The length of the ban and the rules under which the ban can be removed are specified in your Zone configuration.
- Specified by:
banUserin interfaceISFSApi- Parameters:
userToBan- the User to be bannedmodUser- the mod/admin user, can be null to indicate generically the "Server"banMessage- a moderator messagereason- the reason for the banishment (will appear in the AdminTool's BanManager but it's not sent to the User)mode- choose between banning by ip address or by User namedurationMinutes- the duration of the banishment in minutesdelaySeconds- number of seconds before the disconnection is performed
-
banUserFromRoom
public void banUserFromRoom(List<User> bannedUsers, Room theRoom, String message, int interval, TimeUnit timeUnit) Bans a User from a Room.NOTE:This is a soft ban compared to the other forms of banishment, as the this is volatile (i.e. it's not stored by the server so it doesn't survive server restarts) and short-lived.
The target User can be banned for a number of minutes (1..60) or hours (1..24). Afterwards they will be able to join again.
If a message is provided, it will be sent prior to kicking the User out of the Room. The message is received as Moderator Message, and coming from the Room's owner.
- Specified by:
banUserFromRoomin interfaceISFSApi- Parameters:
bannedUsers- a list of Users to be bannedtheRoom- the target Room (the Users must be joined here)message- a custom message, that is received as Moderator Message on the client sideinterval- the duration of the banishmenttimeUnit- the time unit to use (minutes or hours)
-
findRooms
Find one or more Room(s) in the specified collection of Rooms.- Specified by:
findRoomsin interfaceISFSApi- Parameters:
roomList- the Collection of Rooms to search (for instance the Zone's own User list)expression- the matching expressionlimit- stop the search after a certain amount of matches (e.g. limit = 10, will return the first 10 Rooms matching the expression). limit = 0 will return all matches.- Returns:
- the Rooms matching the passed expression
- See Also:
-
findUsers
Find one or more User(s) in the specified collection of Users.- Specified by:
findUsersin interfaceISFSApi- Parameters:
userList- the Collection of Users to search (for instance the Zone's own User list)expression- the matching expressionlimit- stop the search after a certain amount of matches (e.g. limit = 10, will return the first 10 Users matching the expression). limit = 0 will return all matches.- Returns:
- the Users matching the passed expression
- See Also:
-
disconnect
Description copied from interface:ISFSApiWorks likeISFSApi.disconnect(ISession)with an extra delay in seconds- Specified by:
disconnectin interfaceISFSApi- Parameters:
session- the SessiondelaySeconds- the delay before the disconnection
-
disconnect
Removes a Session and the User connected with that session, if one exists- Specified by:
disconnectin interfaceISFSApi- Parameters:
session- the session
-
disconnectUser
Works likeISFSApi.disconnectUser(User, IDisconnectionReason)with an extra delay in seconds- Specified by:
disconnectUserin interfaceISFSApi- Parameters:
user- the Userreason- the reason for disconnectiondelaySeconds- the delay before the disconnection- See Also:
-
disconnectUser
Disconnect a User indicating a specific disconnection reason (for example because the User was Idle). NOTE: Sending a disconnection reason to the client allow avoiding that the User attempts a transparent reconnection (when available)- Specified by:
disconnectUserin interfaceISFSApi- Parameters:
user- the Userreason- the reason for disconnection- See Also:
-
killConnection
Simulates a sudden connection drop to test the reconnection system (HRC)When the HRC is active in the current Zone the client API will attempt the reconnection For more info see this tutorial.
NOTE This will have no effect if the User's Zone is not enabled for reconnections
- Specified by:
killConnectionin interfaceISFSApi- Parameters:
user- The user to disconnect
-
disconnectUser
Disconnect the User abruptly.This will result in a sudden disconnection of the client with an Unknown disconnection reason. on the client side. If you want a more graceful disconnection see the
ISFSApi.kickUser(User, User, String, int)method.- Specified by:
disconnectUserin interfaceISFSApi- Parameters:
user- the User- See Also:
-
removeRoom
Removes a Room from its Zone, provided the Room is empty. If not you should invokeISFSApi.emptyRoom(Room)first or invite users to leave within a certain time frame.- Specified by:
removeRoomin interfaceISFSApi- Parameters:
room- the Room
-
removeRoom
Removes a Room from its Zone- Specified by:
removeRoomin interfaceISFSApi- Parameters:
room- the RoomfireClientEvent- fires client side EventfireServerEvent- fires server side Event
-
checkSecurePassword
Check an encrypted password sent by the User at login time.- Specified by:
checkSecurePasswordin interfaceISFSApi- Parameters:
session- the client sessionoriginalPass- the original un-encrypted password (typically coming from the user DB)encryptedPass- the encrypted password sent by the client- Returns:
- true if the password is correct, false otherwise. Always return false if any of the two password is null or its length == 0
-
login
-
login
-
logout
Log a User out of the current Zone -
createNPC
Create a connection-less NPC (Non-Player Character). The NPC will be seen in the system as a regular User although it can be recognized from theUser.isNpc()flag.NOTE: NPCs must be created once the server engine is up and running. The init() method of an Extension runs before the engine is ready so you will to add a listener to the
SFSEventType.SERVER_READYevent and wait for that event before instantiating any NPC.Example:
- Specified by:
createNPCin interfaceISFSApi- Parameters:
userName- the NPC namezone- the Zone- Returns:
- the User
- Throws:
SFSLoginException
-
createNPC
Create a connection-less NPC (Non-Player Character). The NPC will be seen in the system as a regular User although it can be recognized from theUser.isNpc()flag.NOTE: NPCs must be created once the server engine is up and running. The init() method of an Extension runs before the engine is ready so you will to add a listener to the
SFSEventType.SERVER_READYevent and wait for that event before instantiating any NPC.Example:
- Specified by:
createNPCin interfaceISFSApi- Parameters:
userName- the NPC namezone- the ZoneforceLogin- if a User already exists with that name, it will disconnect it first- Returns:
- the User
- Throws:
SFSLoginException
-
createRoom
public Room createRoom(Zone zone, CreateRoomSettings params, User owner) throws SFSCreateRoomException Create a new Room- Specified by:
createRoomin interfaceISFSApi- Parameters:
zone- the Zone in which the Room is going to be createdparams- the Room settingsowner- the Room owner, use null to indicate that the Room is owned by the Server itself- Returns:
- the Room
- Throws:
SFSCreateRoomException- See Also:
-
createRoom
public Room createRoom(Zone zone, CreateRoomSettings params, User owner, boolean joinIt, Room roomToLeave) throws SFSCreateRoomException Create a new Room- Specified by:
createRoomin interfaceISFSApi- Parameters:
zone- the Zone in which the Room is going to be createdparams- the Room settingsowner- the Room owner, use null to indicate that the Room is owned by the Server itselfjoinIt- if true the Room will be joined by the sender right after creationroomToLeave- a previous Room to leave after the join, or null to indicate no Room should be left- Returns:
- the Room
- Throws:
SFSCreateRoomException- See Also:
-
createRoom
public Room createRoom(Zone zone, CreateRoomSettings params, User owner, boolean joinIt, Room roomToLeave, boolean fireClientEvent, boolean fireServerEvent) throws SFSCreateRoomException - Specified by:
createRoomin interfaceISFSApi- Parameters:
zone- the Zone in which the Room is going to be createdparams- the Room settingsowner- the Room owner, when null it indicates that the Room is owned by the Server itselfjoinIt- if true the Room will be joined by the owner right after creationroomToLeave- a previous Room to leave after the join, or null to indicate no Room should be leftfireClientEvent- fire a client side EventfireServerEvent- fire a server side Event- Returns:
- the Room
- Throws:
SFSCreateRoomException- See Also:
-
joinRoom
Join the user in a room.This is the quickest way to join a User in non password-protected Rooms. By default the User leaves the previously joined Room (if any).
In game rooms the user is joined as player, meaning that he/she is assigned a player id. You can use the overloaded method
ISFSApi.joinRoom(User, Room, String, boolean, Room, boolean, boolean)for more options, e.g. for joining as a spectator.Thread safety notes: The same User can be in one join transaction at a time. If you need to join a player in multiple Rooms there are no concurrency concerns, as long as you're working in the same thread (which is expected). In case you have multiple threads attempting to join the same User in multiple Rooms make sure to synchronize the call.
- Specified by:
joinRoomin interfaceISFSApi- Parameters:
user- the Userroom- the Room in which to join the User- Throws:
SFSJoinRoomException
-
joinRoom
public void joinRoom(User user, Room roomToJoin, String password, boolean asSpectator, Room roomToLeave) throws SFSJoinRoomException Join the user in a room.
A client update and server side event will be also fired- Specified by:
joinRoomin interfaceISFSApi- Parameters:
user- the UserroomToJoin- the Room in which to join the Userpassword- an optional password if the room requires it. Use null if no password is neededasSpectator- join the room as spectator, in case of a game RoomroomToLeave- optionally specify a Room that should be left after a successful join. Pass null to indicate that no Room should be left, allowing the User to be joined in multiple Rooms at the same time- Throws:
SFSJoinRoomException
-
joinRoom
public void joinRoom(User user, Room roomToJoin, String password, boolean asSpectator, Room roomToLeave, boolean fireClientEvent, boolean fireServerEvent) throws SFSJoinRoomException Join the user in a Room.- Specified by:
joinRoomin interfaceISFSApi- Parameters:
user- the UserroomToJoin- the room to joinpassword- an optional password if the room requires it. Use null if no password is neededasSpectator- join the room as spectator, in case of a game roomroomToLeave- optional Room that should be left if the Join operation is successful. Pass null to indicate that no Room should be left, allowing the User to be joined in multiple Rooms at the same timefireClientEvent- fires client side EventfireServerEvent- fires server side Event- Throws:
SFSJoinRoomException
-
leaveRoom
Removes a User from a previously joined Room -
leaveRoom
Removes a User from a previously joined Room -
emptyRoom
Removes all Users from the target Room. The Room is deactivated first to block other join requests, then its emptied and left deactivated. The Room may be removed after this call if the relative SFSRoomRemoveMode attribute is configured to do so. -
emptyRoom
Removes all Users from the target Room. The Room can be deactivated first to block other join requests, and will remain in the required state. The Room may be removed after this call if the relative SFSRoomRemoveMode attribute is configured to do so. -
emptyRoom
public void emptyRoom(Room targetRoom, boolean deactivateRoom, boolean fireClientEvent, boolean fireServerEvent) Removes all Users from the target Room. The Room can be deactivated first to block other join requests, and will remain in the required state. The Room may be removed after this call if the relative SFSRoomRemoveMode attribute is configured to do so. -
quickJoinOrCreateRoom
public void quickJoinOrCreateRoom(User user, MatchExpression expression, Collection<String> groupList, CreateRoomSettings settings) throws SFSJoinRoomException, SFSCreateRoomException Searches for a Room that matches the provided MatchExpression and joins the User in the first occurrence found. If nothing is found proceeds with creating a Room with the provided configuration and joins the User there instead.- Specified by:
quickJoinOrCreateRoomin interfaceISFSApi- Parameters:
user- the User requesting to joinexpression- a MatchExpression to filter specific RoomsgroupList- one or more valid Room group names where to apply the MatchExpressionsettings- the room settings to use for creating a new Room if the search fails- Throws:
SFSJoinRoomExceptionSFSCreateRoomException- See Also:
-
quickJoinOrCreateRoom
public void quickJoinOrCreateRoom(User user, MatchExpression expression, Collection<String> groupList, CreateRoomSettings settings, Room roomToLeave) throws SFSJoinRoomException, SFSCreateRoomException Searches for a Room that matches the provided MatchExpression and joins the User in the first Room found. If nothing is found proceeds with creating a Room with the provided configuration and joins the User there.- Specified by:
quickJoinOrCreateRoomin interfaceISFSApi- Parameters:
user- the User requesting to joinexpression- a MatchExpression to filter specific RoomsgroupList- one or more valid Room group names where to apply the MatchExpressionsettings- the Room settings to create a new Room, if the search failsroomToLeave- a Room currently joined by the User that should be left upon successful joining- Throws:
SFSJoinRoomExceptionSFSCreateRoomException- See Also:
-
sendPublicMessage
Sends a public chat message. The message is broadcast to all Users in the same Room including the sender.- Specified by:
sendPublicMessagein interfaceISFSApi- Parameters:
targetRoom- the Room where the message is sentsender- the User sending the messagemessage- the messageparams- an optional object with additional parameters (e.g. text color, font size, etc...)- See Also:
-
sendPrivateMessage
Sends a private chat message. The message is sent to both the sender and receiver. The sender and receiver can be in any Rooms or even not joined in any rooms at all.- Specified by:
sendPrivateMessagein interfaceISFSApi- Parameters:
sender- the sender of the messagerecipient- the recipient of the messagemessage- the chat messageparams- an optional object with extra parameters (e.g. the font type, color etc...)- See Also:
-
sendBuddyMessage
public void sendBuddyMessage(User sender, User recipient, String message, ISFSObject params) throws SFSBuddyListException Sends a Buddy message to a specific user. The recipient must be in the sender's buddy list for this to work The message is sent to both the sender and receiver.- Specified by:
sendBuddyMessagein interfaceISFSApi- Parameters:
sender- the sender of the messagerecipient- the recipient of the messagemessage- the chat messageparams- a custom SFSObjects with extra parameters (e.g. the font type, color etc...)- Throws:
SFSBuddyListException- in case it's not possible to send the message
-
sendModeratorMessage
public void sendModeratorMessage(User sender, String message, ISFSObject params, Collection<ISession> recipients) Sends a moderator message to a number of Users. The sender parameter must be either a real User with "SuperUser" privileges or null. In the second case the sender becomes the "Server" itself.- Specified by:
sendModeratorMessagein interfaceISFSApi- Parameters:
sender- the moderator user sending this message or null, indicating a Server originated mod messagemessage- the messageparams- an optional object with custom parametersrecipients- the recipients of the message- See Also:
-
sendAdminMessage
public void sendAdminMessage(User sender, String message, ISFSObject params, Collection<ISession> recipients) Sends a admin message to a number of Users. The sender parameter must be either a real User with "SuperUser" privileges or null. In this last case the sender becomes the "Server" itself.- Specified by:
sendAdminMessagein interfaceISFSApi- Parameters:
sender- the admin user sending this message or null, indicating a Server originated admin messagemessage- the messageparams- an optional object with custom parametersrecipients- the recipients of the message- See Also:
-
sendObjectMessage
public void sendObjectMessage(Room targetRoom, User sender, ISFSObject message, Collection<User> recipients) Send an Object message. This message is an SFSObject populated any data. Typically this is used for sending game data (moves, state, updates etc.) to players or other game/app related updates. The message is sent to all users in the specified target room (sender excluded). It's also possible to pass a collection of recipients, provided they are joined in the same Room.
NOTE: The sender must be joined in the target Room.
- Specified by:
sendObjectMessagein interfaceISFSApi- Parameters:
targetRoom- the Room where the message will be sent tosender- the sender of the messagemessage- the message datarecipients- use null to send the message to all clients in the Room, or specify a collection of recipients
-
sendExtensionResponse
public void sendExtensionResponse(String cmdName, ISFSObject params, List<User> recipients, Room room, TransportType txType) - Specified by:
sendExtensionResponsein interfaceISFSApi
-
sendExtensionResponse
public void sendExtensionResponse(String cmdName, ISFSObject params, User recipient, Room room, TransportType txType) - Specified by:
sendExtensionResponsein interfaceISFSApi
-
setRoomVariables
Set Room Variables and update all clients.Only variables that change are broadcast to the other Users in the Room. Variables can be deleted using this request by setting their value to null.
- Specified by:
setRoomVariablesin interfaceISFSApi- Parameters:
user- the sender, null sets ownership of the variables to the Server itselftargetRoom- the Room in which variables should be setvariables- a list of Room variables- See Also:
-
setRoomVariables
public void setRoomVariables(User user, Room targetRoom, List<RoomVariable> variables, boolean fireClientEvent, boolean fireServerEvent, boolean overrideOwnership) Set Room Variables and update all clients.Only variables that change are broadcast to the other Users in the Room. Variables can be deleted using this request by setting their value to null.
- Specified by:
setRoomVariablesin interfaceISFSApi- Parameters:
user- the sender, null sets ownership of the variables to the Server itselftargetRoom- the Room in which variables should be setvariables- a list of RoomVariablesfireClientEvent- fires client side EventfireServerEvent- fires server side EventoverrideOwnership- allow to override the ownership of variables. This means that a User would be able to modify variables that he doesn't own.- See Also:
-
setUserVariables
Set User Variables.Only variables that change are broadcast to Users in the Room. Variables can be deleted by setting their value to null.
- Specified by:
setUserVariablesin interfaceISFSApi- Parameters:
owner- the User for which variables are setvariables- a list of UserVariables- See Also:
-
setUserVariables
public void setUserVariables(User owner, List<UserVariable> variables, boolean fireClientEvent, boolean fireServerEvent) Set User Variables.Only variables that change are broadcast to Users in the Room. Variables can be deleted by setting their value to null.
- Specified by:
setUserVariablesin interfaceISFSApi- Parameters:
owner- the User for which variables are setvariables- a list of UserVariablesfireClientEvent- fires client side EventfireServerEvent- fires server side Event- See Also:
-
changeRoomName
Rename an existing Room. Errors can be triggered in these cases:- the new name collides with another Room
- the new name length is out of the range allowed by the Zone configuration
- the new name contains bad words (if word filter is configured)
- Specified by:
changeRoomNamein interfaceISFSApi- Parameters:
owner- the User, it can be null if this is called on the server sidetargetRoom- the RoomnewName- the new Room name- Throws:
SFSRoomException
-
changeRoomPassword
public void changeRoomPassword(User owner, Room targetRoom, String newPassword) throws SFSRoomException Changes the Room password and the Room password-state. The password state indicates if a Room is private and requires a password for accessing it or not. Passing null or an empty string will make the Room public. Passing a valid string as the password will make the Room private.- Specified by:
changeRoomPasswordin interfaceISFSApi- Parameters:
owner- the User, it can be null if this is called on the server sidetargetRoom- the RoomnewPassword- the new password- Throws:
SFSRoomException
-
changeRoomCapacity
public void changeRoomCapacity(User owner, Room targetRoom, int maxUsers, int maxSpectators) throws SFSRoomException Changes the capacity (max number of Users and Spectators) in the Room. In case the Room size is shrunk extra players or spectators will not be kicked out of the Room.- Specified by:
changeRoomCapacityin interfaceISFSApi- Parameters:
owner- owner of the Room, null to indicate the Server itselftargetRoom- the RoommaxUsers- new maxUsers valuemaxSpectators- new maxSpectators value- Throws:
SFSRoomException
-
subscribeRoomGroup
Subscribe User to a Room Group. This enables the User to receive events for Rooms (new Room added/removed, Room count changes) in that Group- Specified by:
subscribeRoomGroupin interfaceISFSApi- Parameters:
user- the UsergroupId- the group name
-
unsubscribeRoomGroup
Unsubscribe User to a Room Group. Removes the subscription, therefore events from the Rooms in the Group will not trigger for the User- Specified by:
unsubscribeRoomGroupin interfaceISFSApi- Parameters:
user- the UsergroupId- the group name
-
sendGenericMessage
public void sendGenericMessage(com.smartfoxserver.api.GenericMessageType type, User sender, int targetRoomId, String message, ISFSObject params, Collection<ISession> recipients) - Specified by:
sendGenericMessagein interfaceISFSApi
-
spectatorToPlayer
public void spectatorToPlayer(User user, Room targetRoom, boolean fireClientEvent, boolean fireServerEvent) throws SFSRoomException Description copied from interface:ISFSApiTurns a spectator in a Game Room to a Player. The action will fail if no player slot is available.- Specified by:
spectatorToPlayerin interfaceISFSApi- Parameters:
user- the UsertargetRoom- the Room in which the spectator will be turned into a playerfireClientEvent- if true send an update to the client (recommended)fireServerEvent- if true fire a server side event- Throws:
SFSRoomException
-
playerToSpectator
public void playerToSpectator(User user, Room targetRoom, boolean fireClientEvent, boolean fireServerEvent) throws SFSRoomException Description copied from interface:ISFSApiTurns a player in a Game Room to a spectator. The action will fail if no spectator slot is available.- Specified by:
playerToSpectatorin interfaceISFSApi- Parameters:
user- the UsertargetRoom- the Room in which the player will be turned into a spectatorfireClientEvent- if true send an update to the client (recommended)fireServerEvent- if true fire a server side event- Throws:
SFSRoomException
-
getUptime
public com.smartfoxserver.util.ServerUptime getUptime()Description copied from interface:ISFSApiProvides the server's uptime -
getSFSVersion
Description copied from interface:ISFSApiProvides the current SmartFoxServer version- Specified by:
getSFSVersionin interfaceISFSApi- Returns:
- the server version
-