Class SFSRoom
- All Implemented Interfaces:
Room
Overview
The Room object is used to organize and group Users in the the current Zone. Rooms can be created for chatting, playing games, exchanging images and documents, collaborate on shared projects etc ...Users can join one or more Room and start interacting with other people and players in those same Rooms. Rooms can be organized in Room Groups. A Group is nothing more than a unique (String) tag that is assigned to each Room. By assigning a Room to a specific Room Group you will be able to separate Rooms in different categories and avoiding to mix all of them together, especially when the application has thousands of Rooms.
An example of grouping Rooms is separating the lobby Rooms from the chat and game Rooms. One could define three different groups called "Lobby", "Chat", "Game" and assign Rooms to one of these groups at creation time.
Services
There are several different types of Rooms:- SFSRoom: the most basic type of Room, allows to chat and play games. Players can join freely unless the Room is configured to be private.
- SFSGame: a more advanced Room type dedicate to games, allows to use Invitations and the match-making system to find the appropriate players for the specific requirements of the Game. E.g.: you can define specific criteria such as ranking or experience level or any other custom parameter and the use these to match Users that could play in the Room
- MMORoom a special type of Room where events are only propagated in an Area-Of-Interest (AoI) around the player using a coordinate system. This allows to have 100s or 1000s of players in the same Room interacting and playing, while optimizing the traffic from all the event updates.
Rooms provide lots of useful services for the application security:
- User management with auto-banning and kicking with specific rules
- Bad Words filtering
- Anti-Flood filtering
- Manager player IDs for Game Rooms
- State synchronization across all players
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoidbooleancontainsProperty(Object key) Checks whether a custom property exists or notbooleancontainsUser(User user) Checks if the specified User is joined in the RoombooleancontainsUser(String name) Checks if the specified User is joined in the RoombooleancontainsVariable(String varName) Checks if a certain Room Variable name existsvoiddestroy()voidbooleancom.smartfoxserver.util.IAdminHelpercom.smartfoxserver.entities.managers.IAudioManagerReturn the auto-remove mode of the RoomReturns the id of every User currently banned in this Room.intReturn the capacity of the Room (maximum number of clients that can be contained).getDump()Get the extension connected to this Room, if anyGet the Room Group Id.intgetId()Return the unique Room IdlongObtain the time of existence of the RoomintReturn the maximum number of Room Variables allowed in the Room.intReturn the maximum number of Spectators allowed in the Room.intReturn the maximum number of Users allowed in the Room.getName()Get the room namegetOwner()Get the owner of the Room (the user that created it)Returns the name of user that created the Room.Get the Room password.For Game Rooms: get all Players in the Room (same as all User without the Spectators)Get the map with all Room propertiesgetProperty(Object key) Get any custom property attached to this Room.getRoomVariablesData(boolean globalsOnly) Get all the User Sessions in the RoomgetSize()Return the current Room sizeFor Game Rooms: get all Spectators in the Room (same as all User without the Players)getUserById(int id) getUserByName(String name) getUserByPlayerId(int playerId) Get the User currently having the specified playerId (Game Room only)getUserBySession(ISession session) Get all Users in the Roomcom.smartfoxserver.entities.managers.IUserManagergetVariable(String varName) Get a Room VariableGet the full list of Room Variables in the RoomintGet the total amount of Room Variables for this RoomGet a list of Room Variables created by a specific UsergetZone()Get the Zone managing this Room.booleanisActive()Return true if the Room is active in the Zone.booleanTrue if the Room allows only its creator to send JoinRoomInvitations.booleanReturns true if audio streaming is allowed in the current Room.booleanChecks if the Room was created dynamically (at runtime)booleanisEmpty()Checks whether the Room is emptybooleanisFlagSet(SFSRoomSettings flag) Checks whether a certain Room Setting is setbooleanisFull()Checks whether the Room is full.booleanisGame()Checks if this is a Game RoombooleanisHidden()Checks if the Game is hidden.booleanisJoinAllowed(User user) Returns false if the provided User is not allowed to join this Room.booleanReturn true if the Room is owned by the provided User object.booleanChecks if the Room requires a password for joining itbooleanisPublic()Returns true if the Room has public access, in other words it doesn't require a password.booleanbooleanCheck if the word filter is used in this Room (applied to Public Messages)voidremoveProperty(Object key) Removes a custom propertyvoidremoveUser(User user) voidremoveVariable(String varName) removeVariablesCreatedByUser(User user, boolean isLeaveRoom) voidsetActive(boolean flag) voidsetAdminHelper(com.smartfoxserver.util.IAdminHelper helper) voidsetAllowOwnerInvitations(boolean flag) Set to true if the Room allows only its creator to send JoinRoomInvitations.voidsetAutoRemoveMode(SFSRoomRemoveMode autoRemoveMode) voidsetCapacity(int maxUser, int maxSpectators) voidsetDynamic(boolean dynamic) voidsetExtension(ISFSExtension extension) voidsetFlag(SFSRoomSettings flag, boolean state) voidsetFlags(Set<SFSRoomSettings> settings) voidsetGame(boolean game) voidsetGame(boolean game, Class<? extends IPlayerIdGenerator> customPlayerIdGeneratorClass) voidsetGroupId(String groupId) voidsetHidden(boolean hidden) voidsetMaxRoomVariablesAllowed(int max) voidsetMaxSpectators(int maxSpectators) voidsetMaxUsers(int maxUsers) voidvoidvoidsetPassword(String password) voidsetProperties(Map<Object, Object> props) voidsetProperty(Object key, Object value) Attach a custom (server-side only) property to the Room objectvoidsetSuppressUserList(boolean value) voidsetUserManager(com.smartfoxserver.entities.managers.IUserManager userManager) voidsetUseWordsFilter(boolean useWordsFilter) Toggle the word filter in this Room (applied to Public Messages)voidsetVariable(RoomVariable roomVariable) voidsetVariable(RoomVariable roomVariable, boolean overrideOwnership) voidsetVariables(List<RoomVariable> variables) voidsetVariables(List<RoomVariable> variables, boolean overrideOwnership) voidvoidswitchPlayerToSpectator(User user) voidswitchSpectatorToPlayer(User user) toSFSArray(boolean globalRoomVarsOnly) toString()void
-
Field Details
-
logger
protected org.slf4j.Logger logger
-
-
Constructor Details
-
SFSRoom
-
SFSRoom
-
-
Method Details
-
getId
public int getId()Return the unique Room Id -
getGroupId
Get the Room Group Id.- Specified by:
getGroupIdin interfaceRoom- Returns:
- the group Id
-
setGroupId
- Specified by:
setGroupIdin interfaceRoom
-
getName
Get the room name -
setName
-
getPassword
Get the Room password.- Specified by:
getPasswordin interfaceRoom- Returns:
- the room password, null if no password is used
- See Also:
-
setPassword
- Specified by:
setPasswordin interfaceRoom
-
isPasswordProtected
public boolean isPasswordProtected()Checks if the Room requires a password for joining it- Specified by:
isPasswordProtectedin interfaceRoom- Returns:
- true if the Room requires a password
-
isPublic
public boolean isPublic()Returns true if the Room has public access, in other words it doesn't require a password. -
getMaxUsers
public int getMaxUsers()Return the maximum number of Users allowed in the Room.- Specified by:
getMaxUsersin interfaceRoom- Returns:
- the max number of users allowed in the Room
-
setMaxUsers
public void setMaxUsers(int maxUsers) - Specified by:
setMaxUsersin interfaceRoom
-
getMaxSpectators
public int getMaxSpectators()Return the maximum number of Spectators allowed in the Room.- Specified by:
getMaxSpectatorsin interfaceRoom- Returns:
- the max number of spectators allowed in the Room
-
setMaxSpectators
public void setMaxSpectators(int maxSpectators) - Specified by:
setMaxSpectatorsin interfaceRoom
-
getOwner
Get the owner of the Room (the user that created it) -
getOwnerName
Description copied from interface:RoomReturns the name of user that created the Room.If the owner is the server itself the name will be "[server]"
- Specified by:
getOwnerNamein interfaceRoom- Returns:
-
isOwnedBy
Description copied from interface:RoomReturn true if the Room is owned by the provided User object.The owner of a Room is the User that created it. Rooms created by the server will always return false;
-
setOwner
-
getUserManager
public com.smartfoxserver.entities.managers.IUserManager getUserManager()- Specified by:
getUserManagerin interfaceRoom
-
setUserManager
public void setUserManager(com.smartfoxserver.entities.managers.IUserManager userManager) - Specified by:
setUserManagerin interfaceRoom
-
getZone
Get the Zone managing this Room. -
setZone
-
isDynamic
public boolean isDynamic()Checks if the Room was created dynamically (at runtime) -
setDynamic
public void setDynamic(boolean dynamic) - Specified by:
setDynamicin interfaceRoom
-
isGame
public boolean isGame()Checks if this is a Game Room -
setGame
-
setGame
public void setGame(boolean game) -
isHidden
public boolean isHidden()Checks if the Game is hidden. The hidden attribute doesn't change the Room normal behavior however it provides a flag that can be used on the client side to hide it from the Room List -
setHidden
public void setHidden(boolean hidden) -
isActive
public boolean isActive()Return true if the Room is active in the Zone. When a Room is not active it will refuse any join request -
setActive
public void setActive(boolean flag) -
getAutoRemoveMode
Return the auto-remove mode of the Room- Specified by:
getAutoRemoveModein interfaceRoom- Returns:
- the auto-remove mode of the Room
- See Also:
-
setAutoRemoveMode
- Specified by:
setAutoRemoveModein interfaceRoom
-
getPlayersList
For Game Rooms: get all Players in the Room (same as all User without the Spectators)- Specified by:
getPlayersListin interfaceRoom- Returns:
- all Players in the Room
-
getProperty
Get any custom property attached to this Room.- Specified by:
getPropertyin interfaceRoom- Parameters:
key-- Returns:
- the value
-
getProperties
Get the map with all Room properties- Specified by:
getPropertiesin interfaceRoom- Returns:
- the map with all User properties
-
getSize
Return the current Room size -
removeProperty
Removes a custom property- Specified by:
removePropertyin interfaceRoom- Parameters:
key- the name of the property
-
getSpectatorsList
For Game Rooms: get all Spectators in the Room (same as all User without the Players)- Specified by:
getSpectatorsListin interfaceRoom- Returns:
- all Spectators in the Room
-
getUserById
- Specified by:
getUserByIdin interfaceRoom- Parameters:
id- the User id- Returns:
- the User with the provided id, null if no User was found in the Room
-
getUserByName
- Specified by:
getUserByNamein interfaceRoom- Parameters:
name- the User name- Returns:
- the User with the provided name, null if no User was found in the Room
-
getUserBySession
- Specified by:
getUserBySessionin interfaceRoom- Parameters:
session- the User session- Returns:
- the User with the provided session, null if no User was found in the Room
-
getUserByPlayerId
Get the User currently having the specified playerId (Game Room only)- Specified by:
getUserByPlayerIdin interfaceRoom- Parameters:
playerId- the player id- Returns:
- the User, null if no User exists with that player id
-
getUserList
Get all Users in the Room- Specified by:
getUserListin interfaceRoom- Returns:
- all Users in the Room
-
getSessionList
Get all the User Sessions in the Room- Specified by:
getSessionListin interfaceRoom- Returns:
- all the User Sessions in the Room
-
getVariablesCount
public int getVariablesCount()Get the total amount of Room Variables for this Room- Specified by:
getVariablesCountin interfaceRoom- Returns:
- the total amount of Room Variables for this Room
-
getVariable
Get a Room Variable- Specified by:
getVariablein interfaceRoom- Parameters:
varName- the name of the variable- Returns:
- the variable
- See Also:
-
getVariables
Get the full list of Room Variables in the Room- Specified by:
getVariablesin interfaceRoom- Returns:
- the complete list of Room Variables in the Room
-
getVariablesCreatedByUser
Get a list of Room Variables created by a specific User- Specified by:
getVariablesCreatedByUserin interfaceRoom- Parameters:
user- the User- Returns:
- list of Room Variables created by the provided User
-
containsProperty
Checks whether a custom property exists or not- Specified by:
containsPropertyin interfaceRoom- Parameters:
key- the name of the property- Returns:
- true if the property exists
-
removeVariable
- Specified by:
removeVariablein interfaceRoom
-
removeVariablesCreatedByUser
- Specified by:
removeVariablesCreatedByUserin interfaceRoom
-
removeVariablesCreatedByUser
- Specified by:
removeVariablesCreatedByUserin interfaceRoom
-
getCapacity
public int getCapacity()Return the capacity of the Room (maximum number of clients that can be contained). In a Game Room this value is the sum of the maxUser + maxSpectators- Specified by:
getCapacityin interfaceRoom- Returns:
- the Room capacity
-
setCapacity
public void setCapacity(int maxUser, int maxSpectators) - Specified by:
setCapacityin interfaceRoom
-
setMaxRoomVariablesAllowed
public void setMaxRoomVariablesAllowed(int max) - Specified by:
setMaxRoomVariablesAllowedin interfaceRoom
-
getMaxRoomVariablesAllowed
public int getMaxRoomVariablesAllowed()Return the maximum number of Room Variables allowed in the Room.- Specified by:
getMaxRoomVariablesAllowedin interfaceRoom- Returns:
- the max number of Room Variables allowed in the Room
-
setFlags
-
isFlagSet
Checks whether a certain Room Setting is set -
setFlag
-
isUseWordsFilter
public boolean isUseWordsFilter()Check if the word filter is used in this Room (applied to Public Messages)- Specified by:
isUseWordsFilterin interfaceRoom- Returns:
- true if the word filter is used in this Room (applied to Public Messages)
-
setUseWordsFilter
public void setUseWordsFilter(boolean useWordsFilter) Toggle the word filter in this Room (applied to Public Messages)- Specified by:
setUseWordsFilterin interfaceRoom- Parameters:
useWordsFilter-
-
setProperty
Attach a custom (server-side only) property to the Room object- Specified by:
setPropertyin interfaceRoom- Parameters:
key- the property namevalue- the property value
-
setVariables
- Specified by:
setVariablesin interfaceRoom
-
setVariables
- Specified by:
setVariablesin interfaceRoom
-
setVariable
- Specified by:
setVariablein interfaceRoom- Throws:
SFSVariableException
-
isAllowOwnerInvitations
public boolean isAllowOwnerInvitations()True if the Room allows only its creator to send JoinRoomInvitations. If false, any non spectator User joined in the Room can invite other people.- Specified by:
isAllowOwnerInvitationsin interfaceRoom- Returns:
- True if the Room allows only its creator to send JoinRoomInvitations. If false, any non spectator User joined in the Room can invite other people.
-
setAllowOwnerInvitations
public void setAllowOwnerInvitations(boolean flag) Set to true if the Room allows only its creator to send JoinRoomInvitations. Use false if any non spectator User joined in the Room can invite other people.- Specified by:
setAllowOwnerInvitationsin interfaceRoom- Parameters:
flag- true if the Room allows only its creator to send JoinRoomInvitations. Use false if any non spectator User joined in the Room can invite other people.
-
isSuppressUserList
public boolean isSuppressUserList()- Specified by:
isSuppressUserListin interfaceRoom
-
setSuppressUserList
public void setSuppressUserList(boolean value) - Specified by:
setSuppressUserListin interfaceRoom
-
enableAudioManager
public void enableAudioManager()- Specified by:
enableAudioManagerin interfaceRoom
-
getAudioManager
public com.smartfoxserver.entities.managers.IAudioManager getAudioManager()- Specified by:
getAudioManagerin interfaceRoom
-
isAudioStreamingAllowed
public boolean isAudioStreamingAllowed()Returns true if audio streaming is allowed in the current Room.- Specified by:
isAudioStreamingAllowedin interfaceRoom- Returns:
- true if audio streaming is allowed
-
destroy
public void destroy() -
setVariable
public void setVariable(RoomVariable roomVariable, boolean overrideOwnership) throws SFSVariableException - Specified by:
setVariablein interfaceRoom- Throws:
SFSVariableException
-
containsVariable
Checks if a certain Room Variable name exists- Specified by:
containsVariablein interfaceRoom- Parameters:
varName- the variable name- Returns:
- true if a Room Variable with the provided name exists
-
containsUser
Checks if the specified User is joined in the Room- Specified by:
containsUserin interfaceRoom- Parameters:
name- the User name- Returns:
- true if the User is present (joined) in this Room
-
containsUser
Checks if the specified User is joined in the Room- Specified by:
containsUserin interfaceRoom- Parameters:
user- the User- Returns:
- true if the User is present (joined) in this Room
-
addUser
- Specified by:
addUserin interfaceRoom- Throws:
SFSJoinRoomException
-
addUser
- Specified by:
addUserin interfaceRoom- Throws:
SFSJoinRoomException
-
removeUser
- Specified by:
removeUserin interfaceRoom
-
banUser
-
isJoinAllowed
Description copied from interface:RoomReturns false if the provided User is not allowed to join this Room. In such case the User must have been previously banned from this Room and the ban is not expired yet.- Specified by:
isJoinAllowedin interfaceRoom- Parameters:
user- the User to check- Returns:
- false if the User is not allowed to join, true otherwise
-
unbanUser
-
getBannedUserIds
Returns the id of every User currently banned in this Room.By default the 'user id' is the User's name, which is unique in the Zone. However certain application do not consistently associate the same User name to the same User when they login. For example, this happens when an email address is used for logging in rather than the user name. In those case the User name might be different on every Session and thus the banning system would not work.
- Specified by:
getBannedUserIdsin interfaceRoom- Returns:
- the User id (default is the user name)
-
switchPlayerToSpectator
- Specified by:
switchPlayerToSpectatorin interfaceRoom- Throws:
SFSRoomException
-
switchSpectatorToPlayer
- Specified by:
switchSpectatorToPlayerin interfaceRoom- Throws:
SFSRoomException
-
getLifeTime
public long getLifeTime()Obtain the time of existence of the Room- Specified by:
getLifeTimein interfaceRoom- Returns:
- the time of existence of the Room in milliseconds
-
isEmpty
public boolean isEmpty()Checks whether the Room is empty -
isFull
public boolean isFull()Checks whether the Room is full. In game rooms this check will return true only if all player slots are taken. -
getUserListData
- Specified by:
getUserListDatain interfaceRoom
-
getRoomVariablesData
- Specified by:
getRoomVariablesDatain interfaceRoom
-
toString
-
equals
-
getExtension
Get the extension connected to this Room, if any- Specified by:
getExtensionin interfaceRoom- Returns:
- the extension attached to this Room, null if no extension exists
-
setExtension
- Specified by:
setExtensionin interfaceRoom
-
toSFSArray
- Specified by:
toSFSArrayin interfaceRoom
-
getDump
-
getAdminHelper
public com.smartfoxserver.util.IAdminHelper getAdminHelper() -
setAdminHelper
public void setAdminHelper(com.smartfoxserver.util.IAdminHelper helper) -
getPlayerIdGeneratorClassName
- Specified by:
getPlayerIdGeneratorClassNamein interfaceRoom
-
setProperties
-