Class SFSApi
- java.lang.Object
-
- com.smartfoxserver.v2.api.SFSApi
-
- All Implemented Interfaces:
ISFSApi
public class SFSApi extends java.lang.Object implements ISFSApi
Overview
The SFSApi class provides the central access to the main SFS2X Server side API. Here you find all basic methods for interacting with the server: creating Rooms, joining, log in/out, message handling, User/Room variables and many more...Specialized API
Additionally there are specialized API such as- Game API: for quick games, challenges, invitations, etc...
- BuyddList API: for managing buddy lists
- MMO API: for MMO related functions, MMORoom creation etc...
- See Also:
APIManager
,SmartFoxServer.getAPIManager()
,SFSBuddyApi
,SFSGameApi
,SFSMMOApi
-
-
Field Summary
Fields Modifier and Type Field Description protected com.smartfoxserver.v2.entities.managers.IUserManager
globalUserManager
protected org.slf4j.Logger
log
protected com.smartfoxserver.v2.api.response.ISFSResponseApi
responseAPI
protected SmartFoxServer
sfs
-
Constructor Summary
Constructors Constructor Description SFSApi(SmartFoxServer sfs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
banUser(User userToBan, User modUser, java.lang.String banMessage, BanMode mode, int durationMinutes, int delaySeconds)
Ban a User.void
banUser(User userToBan, User modUser, java.lang.String banMessage, java.lang.String reason, BanMode mode, int durationMinutes, int delaySeconds)
Ban a User.void
changeRoomCapacity(User owner, Room targetRoom, int maxUsers, int maxSpectators)
Changes the capacity (max number of Users and Spectators) in the Room.void
changeRoomName(User owner, Room targetRoom, java.lang.String newName)
Rename a Room.void
changeRoomPassword(User owner, Room targetRoom, java.lang.String newPassword)
Changes the Room password and the Room password-state.boolean
checkSecurePassword(ISession session, java.lang.String originalPass, java.lang.String encryptedPass)
Check an encrypted password sent by the User at login time.User
createNPC(java.lang.String userName, Zone zone, boolean forceLogin)
Create connection-less NPC (Non-Player Character).Room
createRoom(Zone zone, CreateRoomSettings params, User owner)
Create a new RoomRoom
createRoom(Zone zone, CreateRoomSettings params, User owner, boolean joinIt, Room roomToLeave)
Create a new RoomRoom
createRoom(Zone zone, CreateRoomSettings params, User owner, boolean joinIt, Room roomToLeave, boolean fireClientEvent, boolean fireServerEvent)
void
disconnect(ISession session)
Removes a Session and the User connected with that session, if one existsvoid
disconnectUser(User user)
Disconnect a User from the server.void
disconnectUser(User user, IDisconnectionReason reason)
Disconnect a User indicating one specific reason (for example because the User was Idle).void
emptyRoom(Room targetRoom)
Removes all Users from the target Room.void
emptyRoom(Room targetRoom, boolean deactivateRoom)
Removes all Users from the target Room.void
emptyRoom(Room targetRoom, boolean deactivateRoom, boolean fireClientEvent, boolean fireServerEvent)
Removes all Users from the target Room.java.util.List<Room>
findRooms(java.util.Collection<Room> roomList, MatchExpression expression, int limit)
Find one or more Room(s) in the specified collection of Users.java.util.List<User>
findUsers(java.util.Collection<User> userList, MatchExpression expression, int limit)
Find one or more User(s) in the specified collection of Users.TaskScheduler
getNewScheduler(int threadPoolSize)
Creates a new TaskScheduler.com.smartfoxserver.v2.api.response.ISFSResponseApi
getResponseAPI()
TaskScheduler
getSystemScheduler()
Gets a reference to the global SFS Task Scheduler.User
getUserById(int userId)
Finds a User from its unique IDUser
getUserByName(java.lang.String name)
Finds a User from its nameUser
getUserBySession(ISession session)
Finds a User from its Sessionvoid
joinRoom(User user, Room room)
Join the user in a room.
This is the quickest way to join a User in non password-protected Room.void
joinRoom(User user, Room roomToJoin, java.lang.String password, boolean asSpectator, Room roomToLeave)
Join the user in a room.
A client update and server side event will be also firedvoid
joinRoom(User user, Room roomToJoin, java.lang.String password, boolean asSpectator, Room roomToLeave, boolean fireClientEvent, boolean fireServerEvent)
Join the user in a room.void
kickUser(User userToKick, User modUser, java.lang.String kickMessage, int delaySeconds)
Kicks the User out.void
leaveRoom(User user, Room room)
Makes a user leave a room that he has joinedvoid
leaveRoom(User user, Room room, boolean fireClientEvent, boolean fireServerEvent)
Removes a User from a previously joined RoomUser
login(ISession sender, java.lang.String name, java.lang.String pass, java.lang.String zoneName, ISFSObject paramsOut)
Logs a client into a Zone, allowing it to become a UserUser
login(ISession sender, java.lang.String name, java.lang.String pass, java.lang.String zoneName, ISFSObject paramsOut, boolean forceLogout)
Uses additional flag to disconnect previous user with same usernamevoid
logout(User user)
Log a User out of the current Zonevoid
playerToSpectator(User user, Room targetRoom, boolean fireClientEvent, boolean fireServerEvent)
Turns a player in a Game Room to a spectator.void
quickJoinOrCreateRoom(User user, MatchExpression expression, java.util.Collection<java.lang.String> groupList, CreateRoomSettings settings)
Searches for a Room that matches the provided MatchExpression and joins the User in the first occurrence found.void
quickJoinOrCreateRoom(User user, MatchExpression expression, java.util.Collection<java.lang.String> groupList, CreateRoomSettings settings, Room roomToLeave)
Searches for a Room that matches the provided MatchExpression and joins the User in the first occurrence found.void
removeRoom(Room room)
Removes a Room from its Zonevoid
removeRoom(Room room, boolean fireClientEvent, boolean fireServerEvent)
Removes a Room from its Zonevoid
sendAdminMessage(User sender, java.lang.String message, ISFSObject params, java.util.Collection<ISession> recipients)
Sends a administrator message to a number of Users.void
sendBuddyMessage(User sender, User recipient, java.lang.String message, ISFSObject params)
void
sendExtensionResponse(java.lang.String cmdName, ISFSObject params, User recipient, Room room, boolean useUDP)
void
sendExtensionResponse(java.lang.String cmdName, ISFSObject params, java.util.List<User> recipients, Room room, boolean useUDP)
void
sendGenericMessage(com.smartfoxserver.v2.api.GenericMessageType type, User sender, int targetRoomId, java.lang.String message, ISFSObject params, java.util.Collection<ISession> recipients)
void
sendModeratorMessage(User sender, java.lang.String message, ISFSObject params, java.util.Collection<ISession> recipients)
Sends a moderator message to a number of Users.void
sendObjectMessage(Room targetRoom, User sender, ISFSObject message, java.util.Collection<User> recipients)
Send an Object message.void
sendPrivateMessage(User sender, User recipient, java.lang.String message, ISFSObject params)
Sends a private chat message.void
sendPublicMessage(Room targetRoom, User sender, java.lang.String message, ISFSObject params)
Sends a public chat message.void
setRoomVariables(User user, Room targetRoom, java.util.List<RoomVariable> variables)
Set Room Variables.void
setRoomVariables(User user, Room targetRoom, java.util.List<RoomVariable> variables, boolean fireClientEvent, boolean fireServerEvent, boolean overrideOwnership)
Set Room Variables.void
setUserVariables(User owner, java.util.List<UserVariable> variables)
Set User Variables.void
setUserVariables(User owner, java.util.List<UserVariable> variables, boolean fireClientEvent, boolean fireServerEvent)
Set User Variables.void
spectatorToPlayer(User user, Room targetRoom, boolean fireClientEvent, boolean fireServerEvent)
Turns a spectator in a Game Room to a Player.void
subscribeRoomGroup(User user, java.lang.String groupId)
Subscribe User to a Room Group.void
unsubscribeRoomGroup(User user, java.lang.String groupId)
Unsubscribe User to a Room Group.
-
-
-
Field Detail
-
sfs
protected final SmartFoxServer sfs
-
log
protected final org.slf4j.Logger log
-
globalUserManager
protected com.smartfoxserver.v2.entities.managers.IUserManager globalUserManager
-
responseAPI
protected final com.smartfoxserver.v2.api.response.ISFSResponseApi responseAPI
-
-
Constructor Detail
-
SFSApi
public SFSApi(SmartFoxServer sfs)
-
-
Method Detail
-
getSystemScheduler
public TaskScheduler getSystemScheduler()
Gets a reference to the global SFS Task Scheduler. This is useful to run delayed or repetitive tasks in one's Extension code.- Specified by:
getSystemScheduler
in interfaceISFSApi
- Returns:
- a reference to SmartFox's system Task Scheduler
- See Also:
TaskScheduler
-
getNewScheduler
public TaskScheduler getNewScheduler(int threadPoolSize)
Creates a new TaskScheduler. This is useful if one wants a dedicated scheduler for their extension, especially when it is used to handle hundreds or thousands of task, offloading the System scheduler.- Specified by:
getNewScheduler
in interfaceISFSApi
- Parameters:
threadPoolSize
- the size of the thread pool backing the Scheduler- Returns:
- a new Task Scheduler
- See Also:
TaskScheduler
-
getResponseAPI
public com.smartfoxserver.v2.api.response.ISFSResponseApi getResponseAPI()
- Specified by:
getResponseAPI
in interfaceISFSApi
-
getUserById
public User getUserById(int userId)
Finds a User from its unique ID- Specified by:
getUserById
in interfaceISFSApi
- Parameters:
userId
- the User ID- Returns:
- the User. It can be null if no User was found with that ID
-
getUserByName
public User getUserByName(java.lang.String name)
Finds a User from its name- Specified by:
getUserByName
in interfaceISFSApi
- Parameters:
name
- the User name- Returns:
- the User. It can be null if not User was found with that name (case sensitive)
-
getUserBySession
public User getUserBySession(ISession session)
Finds a User from its Session- Specified by:
getUserBySession
in interfaceISFSApi
- Parameters:
session
- the Session- Returns:
- the User. It can be null if not User was found with that Session
-
kickUser
public void kickUser(User userToKick, User modUser, java.lang.String kickMessage, int delaySeconds)
Kicks the User out. The operation allows to send a moderator message to the client and allow a number of seconds for reading it before the connection is closed.
-
banUser
public void banUser(User userToBan, User modUser, java.lang.String banMessage, BanMode mode, int durationMinutes, int delaySeconds)
Ban a User. The operation allows to send a moderator message to the client and allow a number of seconds for reading it before the connection is closed.The length of the banishment and the rules under which the ban can be removed are specified in your Zone configuration
- Specified by:
banUser
in interfaceISFSApi
- Parameters:
userToBan
- the User to be bannedmodUser
- the mod/admin user, can be null to indicate generically the "Server"banMessage
- a moderator messagemode
- choose between banning by Ip Address or by User namedurationMinutes
- the duration of the banishment in minutesdelaySeconds
- delay before the disconnection is performed
-
banUser
public void banUser(User userToBan, User modUser, java.lang.String banMessage, java.lang.String reason, BanMode mode, int durationMinutes, int delaySeconds)
Ban a User. The operation allows to send a moderator message to the client and allow a number of seconds for reading it before the connection is closed.The length of the banishment and the rules under which the ban can be removed are specified in your Zone configuration
- Specified by:
banUser
in 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
- delay before the disconnection is performed
-
findRooms
public java.util.List<Room> findRooms(java.util.Collection<Room> roomList, MatchExpression expression, int limit)
Find one or more Room(s) in the specified collection of Users.- Specified by:
findRooms
in interfaceISFSApi
- Parameters:
roomList
- the list of Rooms to searchexpression
- 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
-
findUsers
public java.util.List<User> findUsers(java.util.Collection<User> userList, MatchExpression expression, int limit)
Find one or more User(s) in the specified collection of Users.- Specified by:
findUsers
in interfaceISFSApi
- Parameters:
userList
- the collection of Users to searchexpression
- 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
-
disconnect
public void disconnect(ISession session)
Removes a Session and the User connected with that session, if one exists- Specified by:
disconnect
in interfaceISFSApi
- Parameters:
session
- the session
-
disconnectUser
public void disconnectUser(User user, IDisconnectionReason reason)
Disconnect a User indicating one specific reason (for example because the User was Idle). Sending a disconnection reason to the client allow avoiding that the User attempts a transparent reconnection (when available)- Specified by:
disconnectUser
in interfaceISFSApi
- Parameters:
user
- the Userreason
- the reason for disconnection- See Also:
ClientDisconnectionReason
-
disconnectUser
public void disconnectUser(User user)
Disconnect a User from the server.- Specified by:
disconnectUser
in interfaceISFSApi
- Parameters:
user
- the user- See Also:
ISFSApi.disconnectUser(User, IDisconnectionReason)
-
removeRoom
public void removeRoom(Room room)
Removes a Room from its Zone- Specified by:
removeRoom
in interfaceISFSApi
- Parameters:
room
- the Room
-
removeRoom
public void removeRoom(Room room, boolean fireClientEvent, boolean fireServerEvent)
Removes a Room from its Zone- Specified by:
removeRoom
in interfaceISFSApi
- Parameters:
room
- the RoomfireClientEvent
- fires client side EventfireServerEvent
- fires server side Event
-
checkSecurePassword
public boolean checkSecurePassword(ISession session, java.lang.String originalPass, java.lang.String encryptedPass)
Check an encrypted password sent by the User at login time.- Specified by:
checkSecurePassword
in 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
public User login(ISession sender, java.lang.String name, java.lang.String pass, java.lang.String zoneName, ISFSObject paramsOut)
Logs a client into a Zone, allowing it to become a UserThe login process is central to SmartFoxServer because it generates a User object. Only Users can interact with the Server and the other connected clients.
The initial process of connection and login is actually very simple:
- Establish socket connection: the client starts a new Session (TCP connection) followed by an API handshake
- Log into a Zone: using its Session the client can finally join an Application (Zone) and start the interaction
Custom Login
Activating the customLogin feature in the Zone allows developers to listen for login events such asSFSEventType.USER_LOGIN
andSFSEventType.USER_JOIN_ZONE
and perform custom operations.- USER_LOGIN: fired when a client requests to join a Zone. Here you can perform a check on their credentials.
- USER_JOIN_ZONE: fired when a client has successfully joined a Zone (and turned into a User)
Security
The User password is never transmitted in clear. A CHAP (Challenge Handshake Authentication Protocol) protocol is used instead to ensure a high standard of security.- Specified by:
login
in interfaceISFSApi
- Parameters:
sender
- the client sessionname
- the user namepass
- the user passwordzoneName
- the name of the Zone to joinparamsOut
- (optional) custom params to send back in the client onLogin event- Returns:
- the User object assigned to this user.
- See Also:
User
,Zone
,SFSEventType.USER_LOGIN
,SFSEventType.USER_JOIN_ZONE
-
login
public User login(ISession sender, java.lang.String name, java.lang.String pass, java.lang.String zoneName, ISFSObject paramsOut, boolean forceLogout)
Uses additional flag to disconnect previous user with same username- Specified by:
login
in interfaceISFSApi
forceLogout
- forces a previous connection out- Returns:
- the User
- See Also:
ISFSApi.login(ISession, String, String, String, ISFSObject)
-
logout
public void logout(User user)
Log a User out of the current Zone- Specified by:
logout
in interfaceISFSApi
- Parameters:
user
- the User- See Also:
ISFSApi.login(ISession, String, String, String, ISFSObject)
-
createNPC
public User createNPC(java.lang.String userName, Zone zone, boolean forceLogin) throws SFSLoginException
Create connection-less NPC (Non-Player Character). The NPC will be seen in the system as any other regular User although he can be recognized from itsUser.isNpc()
flag. There is no real, physical connection to the Server (no TCP connection is used)NOTE: NPCs must be created once the server engine is up and running. The init() method of your Extension runs before the engine is ready so you will need to do is adding a listener to the
SFSEventType.SERVER_READY
event and wait for that event before instantiating any NPC.- Specified by:
createNPC
in 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:
createRoom
in 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 itself- Returns:
- the Room
- Throws:
SFSCreateRoomException
- See Also:
CreateRoomSettings
-
createRoom
public Room createRoom(Zone zone, CreateRoomSettings params, User owner, boolean joinIt, Room roomToLeave) throws SFSCreateRoomException
Create a new Room- Specified by:
createRoom
in 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- Returns:
- the Room
- Throws:
SFSCreateRoomException
- See Also:
CreateRoomSettings
-
createRoom
public Room createRoom(Zone zone, CreateRoomSettings params, User owner, boolean joinIt, Room roomToLeave, boolean fireClientEvent, boolean fireServerEvent) throws SFSCreateRoomException
- Specified by:
createRoom
in 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 nullfireClientEvent
- fire a client side EventfireServerEvent
- fire a server side Event- Returns:
- the Room
- Throws:
SFSCreateRoomException
- See Also:
CreateRoomSettings
-
joinRoom
public void joinRoom(User user, Room room) throws SFSJoinRoomException
Join the user in a room.
This is the quickest way to join a User in non password-protected Room. By default the User will leave the old Room (if any) after joining the new one and both client and server events will be fired.In game rooms the user will be joined as player, if you need to join as spectator you will need to use one of the other overloaded methods.
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:
joinRoom
in interfaceISFSApi
- Throws:
SFSJoinRoomException
-
joinRoom
public void joinRoom(User user, Room roomToJoin, java.lang.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:
joinRoom
in 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
- optionally specify a Room that should be left if roomToJoin is successfully joined.- Throws:
SFSJoinRoomException
-
joinRoom
public void joinRoom(User user, Room roomToJoin, java.lang.String password, boolean asSpectator, Room roomToLeave, boolean fireClientEvent, boolean fireServerEvent) throws SFSJoinRoomException
Join the user in a room.- Specified by:
joinRoom
in 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
- optionally specify a Room that should be left if roomToJoin is successfully joined.fireClientEvent
- fires client side EventfireServerEvent
- fires server side Event- Throws:
SFSJoinRoomException
-
leaveRoom
public void leaveRoom(User user, Room room, boolean fireClientEvent, boolean fireServerEvent)
Removes a User from a previously joined Room
-
emptyRoom
public void emptyRoom(Room targetRoom)
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.- Specified by:
emptyRoom
in interfaceISFSApi
- Parameters:
targetRoom
- the Room to be emptied- See Also:
SFSRoomRemoveMode
-
emptyRoom
public void emptyRoom(Room targetRoom, boolean deactivateRoom)
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.- Specified by:
emptyRoom
in interfaceISFSApi
- Parameters:
targetRoom
- the Room to be emptieddeactivateRoom
- use true to deactivate the Room and avoid concurrent and/or subsequent join operations- See Also:
SFSRoomRemoveMode
-
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.- Specified by:
emptyRoom
in interfaceISFSApi
- Parameters:
targetRoom
- the Room to be emptieddeactivateRoom
- use true to deactivate the Room and avoid concurrent and/or subsequent join operationsfireClientEvent
- fires client side EventfireServerEvent
- fires server side Event- See Also:
SFSRoomRemoveMode
-
quickJoinOrCreateRoom
public void quickJoinOrCreateRoom(User user, MatchExpression expression, java.util.Collection<java.lang.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:
quickJoinOrCreateRoom
in 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:
SFSJoinRoomException
SFSCreateRoomException
-
quickJoinOrCreateRoom
public void quickJoinOrCreateRoom(User user, MatchExpression expression, java.util.Collection<java.lang.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 occurrence found. If nothing is found proceeds with creating a Room with the provided configuration and joins the User there instead.- Specified by:
quickJoinOrCreateRoom
in 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 failsroomToLeave
- a Room currently joined by the User that should be left upon successful joining- Throws:
SFSJoinRoomException
SFSCreateRoomException
-
sendPublicMessage
public void sendPublicMessage(Room targetRoom, User sender, java.lang.String message, ISFSObject params)
Sends a public chat message. The message is broadcast to all Users in the same Room including the sender.- Specified by:
sendPublicMessage
in interfaceISFSApi
- Parameters:
targetRoom
- the Room where the message is sentsender
- the User sending the messagemessage
- the chat messageparams
- a custom object with additional parameters (e.g. text color, font size, etc...)
-
sendPrivateMessage
public void sendPrivateMessage(User sender, User recipient, java.lang.String message, ISFSObject params)
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:
sendPrivateMessage
in 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...)
-
sendBuddyMessage
public void sendBuddyMessage(User sender, User recipient, java.lang.String message, ISFSObject params) throws SFSBuddyListException
- Specified by:
sendBuddyMessage
in interfaceISFSApi
- Throws:
SFSBuddyListException
-
sendModeratorMessage
public void sendModeratorMessage(User sender, java.lang.String message, ISFSObject params, java.util.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 this last case the sender becomes the "Server" itself.- Specified by:
sendModeratorMessage
in interfaceISFSApi
- Parameters:
sender
- the moderator user sending this message or null, indicating a Server originated mod messagemessage
- the messageparams
- an SFSObject with custom parametersrecipients
- the recipients of the message
-
sendAdminMessage
public void sendAdminMessage(User sender, java.lang.String message, ISFSObject params, java.util.Collection<ISession> recipients)
Sends a administrator 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:
sendAdminMessage
in interfaceISFSApi
- Parameters:
sender
- the admin user sending this message or null, indicating a Server originated admin messagemessage
- the messageparams
- an SFSObject with custom parametersrecipients
- the recipients of the message
-
sendObjectMessage
public void sendObjectMessage(Room targetRoom, User sender, ISFSObject message, java.util.Collection<User> recipients)
Send an Object message. This message is based on a custom SFSObject that can contain any data. Typically this is used for sending game moves to players or other game/app related updates. The message is sent to all users in the specified target room (with the exclusion of the sender) but you can also pass a collection of Users to specify which clients in that Room should receive the message.
NOTE: The sender must be joined in the target Room.
- Specified by:
sendObjectMessage
in interfaceISFSApi
- Parameters:
targetRoom
- the room where the message will be sent tosender
- the sender of the messagemessage
- a custom SFSObjectrecipients
- use null to send the message to all clients in the Room, or specify a collection of users that should receive the message
-
sendExtensionResponse
public void sendExtensionResponse(java.lang.String cmdName, ISFSObject params, java.util.List<User> recipients, Room room, boolean useUDP)
- Specified by:
sendExtensionResponse
in interfaceISFSApi
-
sendExtensionResponse
public void sendExtensionResponse(java.lang.String cmdName, ISFSObject params, User recipient, Room room, boolean useUDP)
- Specified by:
sendExtensionResponse
in interfaceISFSApi
-
setRoomVariables
public void setRoomVariables(User user, Room targetRoom, java.util.List<RoomVariable> variables)
Set Room Variables. Only variables that change are broadcast to the Users in the target Room. In order to delete a variable you can set it to null.- Specified by:
setRoomVariables
in interfaceISFSApi
- Parameters:
user
- the sender (null == sets ownership of the variables to the Server itself)targetRoom
- the Room in which variables should be setvariables
- a list of Room variables- See Also:
RoomVariable
-
setRoomVariables
public void setRoomVariables(User user, Room targetRoom, java.util.List<RoomVariable> variables, boolean fireClientEvent, boolean fireServerEvent, boolean overrideOwnership)
Set Room Variables. Only variables that change are broadcast to the Users in the target Room. In order to delete a variable you can set it to null.- Specified by:
setRoomVariables
in interfaceISFSApi
- Parameters:
user
- the sender (null == sets ownership of the variables to the Server itself)targetRoom
- 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- See Also:
RoomVariable
-
setUserVariables
public void setUserVariables(User owner, java.util.List<UserVariable> variables)
Set User Variables. Only variables that change are broadcast to the Users that can "see" the owner. In order to delete a variable you can set it to null.- Specified by:
setUserVariables
in interfaceISFSApi
- Parameters:
owner
- the User for which variables are setvariables
- a list of UserVariables- See Also:
UserVariable
-
setUserVariables
public void setUserVariables(User owner, java.util.List<UserVariable> variables, boolean fireClientEvent, boolean fireServerEvent)
Set User Variables. Only variables that change are broadcast to the Users that can "see" the sender. In order to delete a variable you can set it to null.- Specified by:
setUserVariables
in interfaceISFSApi
- Parameters:
owner
- the User for which variables are setvariables
- a list of UserVariablesfireClientEvent
- fires client side EventfireServerEvent
- fires server side Event- See Also:
UserVariable
-
changeRoomName
public void changeRoomName(User owner, Room targetRoom, java.lang.String newName) throws SFSRoomException
Rename a Room. Errors can be fired if:- the new name is already in use
- 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:
changeRoomName
in 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, java.lang.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 a null or empty string as the password will make room public. Passing a valid string as the password will make the Room private.- Specified by:
changeRoomPassword
in 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:
changeRoomCapacity
in interfaceISFSApi
- Parameters:
owner
- owner of the Room, the requester must be owner of the Room or SuperUsertargetRoom
- the roommaxUsers
- new maxUsers valuemaxSpectators
- new maxSpectators value- Throws:
SFSRoomException
-
subscribeRoomGroup
public void subscribeRoomGroup(User user, java.lang.String groupId)
Subscribe User to a Room Group. This will enable the User to receive events for Rooms in that Group- Specified by:
subscribeRoomGroup
in interfaceISFSApi
- Parameters:
user
- the UsergroupId
- the group name
-
unsubscribeRoomGroup
public void unsubscribeRoomGroup(User user, java.lang.String groupId)
Unsubscribe User to a Room Group.- Specified by:
unsubscribeRoomGroup
in interfaceISFSApi
- Parameters:
user
- the UsergroupId
- the group name
-
sendGenericMessage
public void sendGenericMessage(com.smartfoxserver.v2.api.GenericMessageType type, User sender, int targetRoomId, java.lang.String message, ISFSObject params, java.util.Collection<ISession> recipients)
- Specified by:
sendGenericMessage
in interfaceISFSApi
-
spectatorToPlayer
public void spectatorToPlayer(User user, Room targetRoom, boolean fireClientEvent, boolean fireServerEvent) throws SFSRoomException
Description copied from interface:ISFSApi
Turns a spectator in a Game Room to a Player. The action will fail if no player slot is available.- Specified by:
spectatorToPlayer
in 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:ISFSApi
Turns a player in a Game Room to a spectator. The action will fail if no spectator slot is available.- Specified by:
playerToSpectator
in 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
-
-