Package com.smartfoxserver.v2.entities
Class SFSRoom
- java.lang.Object
-
- com.smartfoxserver.v2.entities.SFSRoom
-
- All Implemented Interfaces:
Room
public class SFSRoom extends java.lang.Object implements Room
Overview
The Room object is the main tool to organize and group Users in the application. Rooms can be created for chatting, playing games, exchanging images and audio files, sharing documents, collaboratively work on shared resources and a lot more.Each Room can contain any number of Users and can be organized in Room Groups. A Group is nothing more than a unique String ID that is assigned to each Room. By assigning different Group IDs to different Rooms you will be able to separate Rooms in different "departments" avoiding to mix all Rooms together, especially when the application will create thousands of Rooms.
An example of grouping Rooms is separating the lobby Rooms from the chat and game Rooms. You could define three different groups called "Lobby", "Chat", "Game" and assign your Rooms to one of these groups at the time of the Room creation.
Services
In SmartFoxServer 2X Rooms are extremely versatile. They offer the same basic features already known in SmartFoxServer 1.x plus they add dozens of new fine-tuning option that will help you configure them exactly the way you need them. The new features allow you to:- Organize Rooms in Room Groups
- Rename Rooms at runtime
- Resize Rooms at runtime
- Lock/Unlock Rooms at runtime with a password
- Hide Room visibility
- Broadcast Room Variables outside of the Room itself
- Decide which Room Variables are server-side only and which will be auto-updated to each client
- Configure Events and Permissions for each Room on a fine-grained level.
- Configure the life-cycle of a Room (when it gets removed and how)
- Join any Room from client side without the need of having it in the local room list
- Optimize the client room list by deciding which Room Groups the User will listen event for
Also each Room provides a number of essential services:
- User management
- Words filtering
- Anti-Flood filtering
- Manager player IDs for Game ROoms
- Event dispatching
Advanced Game features
Room objects provide the ability to manage games with custom logic very easily by plugging custom logic via Extensions. The new SFS2X framework also provides a new type of Room called SFSGame which delivers advanced gaming features, such as an invitation system, game matching, user matching, game start/stop auto-notifications and more...- See Also:
User,SFSGame,SFSApi,BaseSFSExtension,SFSExtension
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Loggerlogger
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddUser(User user)voidaddUser(User user, boolean asSpectator)booleancontainsProperty(java.lang.Object key)Checks whether a custom property exists or notbooleancontainsUser(User user)Checks if the specified User is joined in the RoombooleancontainsUser(java.lang.String name)Checks if the specified User is joined in the RoombooleancontainsVariable(java.lang.String varName)Checks if a certain Room Variable name existsvoiddestroy()booleanequals(java.lang.Object obj)com.smartfoxserver.v2.util.IAdminHelpergetAdminHelper()SFSRoomRemoveModegetAutoRemoveMode()Return the auto-remove mode of the RoomintgetCapacity()Return the capacity of the Room (maximum number of clients that can be contained).java.lang.StringgetDump()Get a dump of all Room attributes/settings.ISFSExtensiongetExtension()Get the extension connected to this Room, if anyjava.lang.StringgetGroupId()Get the Room Group Id.intgetId()Return the unique Room IdlonggetLifeTime()Obtain the time of existence of the RoomintgetMaxRoomVariablesAllowed()Return the maximum number of Room Variables allowed in the Room.intgetMaxSpectators()Return the maximum number of Spectators allowed in the Room.intgetMaxUsers()Return the maximum number of Users allowed in the Room.java.lang.StringgetName()Get the room nameUsergetOwner()Get the owner of the Room (the user that created it)java.lang.StringgetPassword()Get the Room password.java.lang.StringgetPlayerIdGeneratorClassName()java.util.List<User>getPlayersList()For Game Rooms: get all Players in the Room (same as all User without the Spectators)java.util.concurrent.ConcurrentMap<java.lang.Object,java.lang.Object>getProperties()Get the map with all Room propertiesjava.lang.ObjectgetProperty(java.lang.Object key)Get any custom property attached to this Room.ISFSArraygetRoomVariablesData(boolean globalsOnly)java.util.List<ISession>getSessionList()Get all the User Sessions in the RoomRoomSizegetSize()Return the current Room sizejava.util.List<User>getSpectatorsList()For Game Rooms: get all Spectators in the Room (same as all User without the Players)UsergetUserById(int id)UsergetUserByName(java.lang.String name)UsergetUserByPlayerId(int playerId)Get the User currently having the specified playerId (Game Room only)UsergetUserBySession(ISession session)java.util.List<User>getUserList()Get all Users in the RoomISFSArraygetUserListData()com.smartfoxserver.v2.entities.managers.IUserManagergetUserManager()RoomVariablegetVariable(java.lang.String varName)Get a Room Variablejava.util.List<RoomVariable>getVariables()Get the full list of Room Variables in the RoomintgetVariablesCount()Get the total amount of Room Variables for this Roomjava.util.List<RoomVariable>getVariablesCreatedByUser(User user)Get a list of Room Variables created by a specific UserZonegetZone()Get the Zone managing this Room.booleanisActive()Return true if the Room is active in the Zone.booleanisAllowOwnerInvitations()True if the Room allows only its creator to send JoinRoomInvitations.booleanisDynamic()Checks 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.booleanisPasswordProtected()Checks 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.booleanisSuppressUserList()booleanisUseWordsFilter()Check if the word filter is used in this Room (applied to Public Messages)voidremoveProperty(java.lang.Object key)Removes a custom propertyvoidremoveUser(User user)voidremoveVariable(java.lang.String varName)java.util.List<RoomVariable>removeVariablesCreatedByUser(User user)java.util.List<RoomVariable>removeVariablesCreatedByUser(User user, boolean isLeaveRoom)voidsetActive(boolean flag)voidsetAdminHelper(com.smartfoxserver.v2.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(java.util.Set<SFSRoomSettings> settings)voidsetGame(boolean game)voidsetGame(boolean game, java.lang.Class<? extends IPlayerIdGenerator> customPlayerIdGeneratorClass)voidsetGroupId(java.lang.String groupId)voidsetHidden(boolean hidden)voidsetMaxRoomVariablesAllowed(int max)voidsetMaxSpectators(int maxSpectators)voidsetMaxUsers(int maxUsers)voidsetName(java.lang.String name)voidsetOwner(User owner)voidsetPassword(java.lang.String password)voidsetProperties(java.util.Map<java.lang.Object,java.lang.Object> props)voidsetProperty(java.lang.Object key, java.lang.Object value)Attach a custom (server-side only) property to the Room objectvoidsetSuppressUserList(boolean value)voidsetUserManager(com.smartfoxserver.v2.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(java.util.List<RoomVariable> variables)voidsetVariables(java.util.List<RoomVariable> variables, boolean overrideOwnership)voidsetZone(Zone zone)voidswitchPlayerToSpectator(User user)voidswitchSpectatorToPlayer(User user)ISFSArraytoSFSArray(boolean globalRoomVarsOnly)java.lang.StringtoString()
-
-
-
Method Detail
-
getId
public int getId()
Return the unique Room Id
-
getGroupId
public java.lang.String getGroupId()
Get the Room Group Id.- Specified by:
getGroupIdin interfaceRoom- Returns:
- the group Id
-
setGroupId
public void setGroupId(java.lang.String groupId)
- Specified by:
setGroupIdin interfaceRoom
-
getName
public java.lang.String getName()
Get the room name
-
getPassword
public java.lang.String getPassword()
Get the Room password.- Specified by:
getPasswordin interfaceRoom- Returns:
- the room password, null if no password is used
- See Also:
Room.isPasswordProtected()
-
setPassword
public void setPassword(java.lang.String password)
- 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
public User getOwner()
Get the owner of the Room (the user that created it)
-
getUserManager
public com.smartfoxserver.v2.entities.managers.IUserManager getUserManager()
- Specified by:
getUserManagerin interfaceRoom
-
setUserManager
public void setUserManager(com.smartfoxserver.v2.entities.managers.IUserManager userManager)
- Specified by:
setUserManagerin interfaceRoom
-
getZone
public Zone getZone()
Get the Zone managing this Room.
-
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
public void setGame(boolean game, java.lang.Class<? extends IPlayerIdGenerator> customPlayerIdGeneratorClass)
-
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
-
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
-
getAutoRemoveMode
public SFSRoomRemoveMode getAutoRemoveMode()
Return the auto-remove mode of the Room- Specified by:
getAutoRemoveModein interfaceRoom- Returns:
- the auto-remove mode of the Room
- See Also:
SFSRoomRemoveMode
-
setAutoRemoveMode
public void setAutoRemoveMode(SFSRoomRemoveMode autoRemoveMode)
- Specified by:
setAutoRemoveModein interfaceRoom
-
getPlayersList
public java.util.List<User> 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
public java.lang.Object getProperty(java.lang.Object key)
Get any custom property attached to this Room.- Specified by:
getPropertyin interfaceRoom- Returns:
- the value
-
getProperties
public java.util.concurrent.ConcurrentMap<java.lang.Object,java.lang.Object> getProperties()
Get the map with all Room properties- Specified by:
getPropertiesin interfaceRoom- Returns:
- the map with all User properties
-
getSize
public RoomSize getSize()
Return the current Room size
-
removeProperty
public void removeProperty(java.lang.Object key)
Removes a custom property- Specified by:
removePropertyin interfaceRoom- Parameters:
key- the name of the property
-
getSpectatorsList
public java.util.List<User> 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
public User getUserById(int id)
- 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
public User getUserByName(java.lang.String name)
- 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
public User getUserBySession(ISession session)
- 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
public User getUserByPlayerId(int playerId)
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
public java.util.List<User> getUserList()
Get all Users in the Room- Specified by:
getUserListin interfaceRoom- Returns:
- all Users in the Room
-
getSessionList
public java.util.List<ISession> 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
public RoomVariable getVariable(java.lang.String varName)
Get a Room Variable- Specified by:
getVariablein interfaceRoom- Parameters:
varName- the name of the variable- Returns:
- the variable
- See Also:
SFSRoomVariable
-
getVariables
public java.util.List<RoomVariable> 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
public java.util.List<RoomVariable> getVariablesCreatedByUser(User user)
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
public boolean containsProperty(java.lang.Object key)
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
public void removeVariable(java.lang.String varName)
- Specified by:
removeVariablein interfaceRoom
-
removeVariablesCreatedByUser
public java.util.List<RoomVariable> removeVariablesCreatedByUser(User user)
- Specified by:
removeVariablesCreatedByUserin interfaceRoom
-
removeVariablesCreatedByUser
public java.util.List<RoomVariable> removeVariablesCreatedByUser(User user, boolean isLeaveRoom)
- 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
public void setFlags(java.util.Set<SFSRoomSettings> settings)
-
isFlagSet
public boolean isFlagSet(SFSRoomSettings flag)
Checks whether a certain Room Setting is set- Specified by:
isFlagSetin interfaceRoom- Parameters:
flag- the flag- Returns:
- true if the flag is set
- See Also:
SFSRoomSettings
-
setFlag
public void setFlag(SFSRoomSettings flag, boolean state)
-
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
-
setProperty
public void setProperty(java.lang.Object key, java.lang.Object value)Attach a custom (server-side only) property to the Room object- Specified by:
setPropertyin interfaceRoom- Parameters:
key- the property namevalue- the property value
-
setVariables
public void setVariables(java.util.List<RoomVariable> variables)
- Specified by:
setVariablesin interfaceRoom
-
setVariables
public void setVariables(java.util.List<RoomVariable> variables, boolean overrideOwnership)
- Specified by:
setVariablesin interfaceRoom
-
setVariable
public void setVariable(RoomVariable roomVariable) throws SFSVariableException
- 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
-
setVariable
public void setVariable(RoomVariable roomVariable, boolean overrideOwnership) throws SFSVariableException
- Specified by:
setVariablein interfaceRoom- Throws:
SFSVariableException
-
containsVariable
public boolean containsVariable(java.lang.String varName)
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
public boolean containsUser(java.lang.String name)
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
public boolean containsUser(User user)
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
public void addUser(User user) throws SFSJoinRoomException
- Specified by:
addUserin interfaceRoom- Throws:
SFSJoinRoomException
-
addUser
public void addUser(User user, boolean asSpectator) throws SFSJoinRoomException
- Specified by:
addUserin interfaceRoom- Throws:
SFSJoinRoomException
-
removeUser
public void removeUser(User user)
- Specified by:
removeUserin interfaceRoom
-
switchPlayerToSpectator
public void switchPlayerToSpectator(User user) throws SFSRoomException
- Specified by:
switchPlayerToSpectatorin interfaceRoom- Throws:
SFSRoomException
-
switchSpectatorToPlayer
public void switchSpectatorToPlayer(User user) throws SFSRoomException
- 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
public ISFSArray getUserListData()
- Specified by:
getUserListDatain interfaceRoom
-
getRoomVariablesData
public ISFSArray getRoomVariablesData(boolean globalsOnly)
- Specified by:
getRoomVariablesDatain interfaceRoom
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
getExtension
public ISFSExtension 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
public void setExtension(ISFSExtension extension)
- Specified by:
setExtensionin interfaceRoom
-
toSFSArray
public ISFSArray toSFSArray(boolean globalRoomVarsOnly)
- Specified by:
toSFSArrayin interfaceRoom
-
getDump
public java.lang.String getDump()
Get a dump of all Room attributes/settings. Useful for debugging
-
getAdminHelper
public com.smartfoxserver.v2.util.IAdminHelper getAdminHelper()
-
setAdminHelper
public void setAdminHelper(com.smartfoxserver.v2.util.IAdminHelper helper)
-
getPlayerIdGeneratorClassName
public java.lang.String getPlayerIdGeneratorClassName()
- Specified by:
getPlayerIdGeneratorClassNamein interfaceRoom
-
setProperties
public void setProperties(java.util.Map<java.lang.Object,java.lang.Object> props)
-
-