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.Logger
logger
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addUser(User user)
void
addUser(User user, boolean asSpectator)
boolean
containsProperty(java.lang.Object key)
Checks whether a custom property exists or notboolean
containsUser(User user)
Checks if the specified User is joined in the Roomboolean
containsUser(java.lang.String name)
Checks if the specified User is joined in the Roomboolean
containsVariable(java.lang.String varName)
Checks if a certain Room Variable name existsvoid
destroy()
boolean
equals(java.lang.Object obj)
com.smartfoxserver.v2.util.IAdminHelper
getAdminHelper()
SFSRoomRemoveMode
getAutoRemoveMode()
Return the auto-remove mode of the Roomint
getCapacity()
Return the capacity of the Room (maximum number of clients that can be contained).java.lang.String
getDump()
Get a dump of all Room attributes/settings.ISFSExtension
getExtension()
Get the extension connected to this Room, if anyjava.lang.String
getGroupId()
Get the Room Group Id.int
getId()
Return the unique Room Idlong
getLifeTime()
Obtain the time of existence of the Roomint
getMaxRoomVariablesAllowed()
Return the maximum number of Room Variables allowed in the Room.int
getMaxSpectators()
Return the maximum number of Spectators allowed in the Room.int
getMaxUsers()
Return the maximum number of Users allowed in the Room.java.lang.String
getName()
Get the room nameUser
getOwner()
Get the owner of the Room (the user that created it)java.lang.String
getPassword()
Get the Room password.java.lang.String
getPlayerIdGeneratorClassName()
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.Object
getProperty(java.lang.Object key)
Get any custom property attached to this Room.ISFSArray
getRoomVariablesData(boolean globalsOnly)
java.util.List<ISession>
getSessionList()
Get all the User Sessions in the RoomRoomSize
getSize()
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)User
getUserById(int id)
User
getUserByName(java.lang.String name)
User
getUserByPlayerId(int playerId)
Get the User currently having the specified playerId (Game Room only)User
getUserBySession(ISession session)
java.util.List<User>
getUserList()
Get all Users in the RoomISFSArray
getUserListData()
com.smartfoxserver.v2.entities.managers.IUserManager
getUserManager()
RoomVariable
getVariable(java.lang.String varName)
Get a Room Variablejava.util.List<RoomVariable>
getVariables()
Get the full list of Room Variables in the Roomint
getVariablesCount()
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 UserZone
getZone()
Get the Zone managing this Room.boolean
isActive()
Return true if the Room is active in the Zone.boolean
isAllowOwnerInvitations()
True if the Room allows only its creator to send JoinRoomInvitations.boolean
isDynamic()
Checks if the Room was created dynamically (at runtime)boolean
isEmpty()
Checks whether the Room is emptyboolean
isFlagSet(SFSRoomSettings flag)
Checks whether a certain Room Setting is setboolean
isFull()
Checks whether the Room is full.boolean
isGame()
Checks if this is a Game Roomboolean
isHidden()
Checks if the Game is hidden.boolean
isPasswordProtected()
Checks if the Room requires a password for joining itboolean
isPublic()
Returns true if the Room has public access, in other words it doesn't require a password.boolean
isSuppressUserList()
boolean
isUseWordsFilter()
Check if the word filter is used in this Room (applied to Public Messages)void
removeProperty(java.lang.Object key)
Removes a custom propertyvoid
removeUser(User user)
void
removeVariable(java.lang.String varName)
java.util.List<RoomVariable>
removeVariablesCreatedByUser(User user)
java.util.List<RoomVariable>
removeVariablesCreatedByUser(User user, boolean isLeaveRoom)
void
setActive(boolean flag)
void
setAdminHelper(com.smartfoxserver.v2.util.IAdminHelper helper)
void
setAllowOwnerInvitations(boolean flag)
Set to true if the Room allows only its creator to send JoinRoomInvitations.void
setAutoRemoveMode(SFSRoomRemoveMode autoRemoveMode)
void
setCapacity(int maxUser, int maxSpectators)
void
setDynamic(boolean dynamic)
void
setExtension(ISFSExtension extension)
void
setFlag(SFSRoomSettings flag, boolean state)
void
setFlags(java.util.Set<SFSRoomSettings> settings)
void
setGame(boolean game)
void
setGame(boolean game, java.lang.Class<? extends IPlayerIdGenerator> customPlayerIdGeneratorClass)
void
setGroupId(java.lang.String groupId)
void
setHidden(boolean hidden)
void
setMaxRoomVariablesAllowed(int max)
void
setMaxSpectators(int maxSpectators)
void
setMaxUsers(int maxUsers)
void
setName(java.lang.String name)
void
setOwner(User owner)
void
setPassword(java.lang.String password)
void
setProperties(java.util.Map<java.lang.Object,java.lang.Object> props)
void
setProperty(java.lang.Object key, java.lang.Object value)
Attach a custom (server-side only) property to the Room objectvoid
setSuppressUserList(boolean value)
void
setUserManager(com.smartfoxserver.v2.entities.managers.IUserManager userManager)
void
setUseWordsFilter(boolean useWordsFilter)
Toggle the word filter in this Room (applied to Public Messages)void
setVariable(RoomVariable roomVariable)
void
setVariable(RoomVariable roomVariable, boolean overrideOwnership)
void
setVariables(java.util.List<RoomVariable> variables)
void
setVariables(java.util.List<RoomVariable> variables, boolean overrideOwnership)
void
setZone(Zone zone)
void
switchPlayerToSpectator(User user)
void
switchSpectatorToPlayer(User user)
ISFSArray
toSFSArray(boolean globalRoomVarsOnly)
java.lang.String
toString()
-
-
-
Method Detail
-
getId
public int getId()
Return the unique Room Id
-
getGroupId
public java.lang.String getGroupId()
Get the Room Group Id.- Specified by:
getGroupId
in interfaceRoom
- Returns:
- the group Id
-
setGroupId
public void setGroupId(java.lang.String groupId)
- Specified by:
setGroupId
in interfaceRoom
-
getName
public java.lang.String getName()
Get the room name
-
getPassword
public java.lang.String getPassword()
Get the Room password.- Specified by:
getPassword
in 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:
setPassword
in interfaceRoom
-
isPasswordProtected
public boolean isPasswordProtected()
Checks if the Room requires a password for joining it- Specified by:
isPasswordProtected
in 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:
getMaxUsers
in interfaceRoom
- Returns:
- the max number of users allowed in the Room
-
setMaxUsers
public void setMaxUsers(int maxUsers)
- Specified by:
setMaxUsers
in interfaceRoom
-
getMaxSpectators
public int getMaxSpectators()
Return the maximum number of Spectators allowed in the Room.- Specified by:
getMaxSpectators
in interfaceRoom
- Returns:
- the max number of spectators allowed in the Room
-
setMaxSpectators
public void setMaxSpectators(int maxSpectators)
- Specified by:
setMaxSpectators
in 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:
getUserManager
in interfaceRoom
-
setUserManager
public void setUserManager(com.smartfoxserver.v2.entities.managers.IUserManager userManager)
- Specified by:
setUserManager
in 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:
setDynamic
in 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:
getAutoRemoveMode
in interfaceRoom
- Returns:
- the auto-remove mode of the Room
- See Also:
SFSRoomRemoveMode
-
setAutoRemoveMode
public void setAutoRemoveMode(SFSRoomRemoveMode autoRemoveMode)
- Specified by:
setAutoRemoveMode
in 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:
getPlayersList
in 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:
getProperty
in 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:
getProperties
in 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:
removeProperty
in 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:
getSpectatorsList
in interfaceRoom
- Returns:
- all Spectators in the Room
-
getUserById
public User getUserById(int id)
- Specified by:
getUserById
in 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:
getUserByName
in 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:
getUserBySession
in 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:
getUserByPlayerId
in 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:
getUserList
in interfaceRoom
- Returns:
- all Users in the Room
-
getSessionList
public java.util.List<ISession> getSessionList()
Get all the User Sessions in the Room- Specified by:
getSessionList
in 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:
getVariablesCount
in 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:
getVariable
in 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:
getVariables
in 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:
getVariablesCreatedByUser
in 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:
containsProperty
in interfaceRoom
- Parameters:
key
- the name of the property- Returns:
- true if the property exists
-
removeVariable
public void removeVariable(java.lang.String varName)
- Specified by:
removeVariable
in interfaceRoom
-
removeVariablesCreatedByUser
public java.util.List<RoomVariable> removeVariablesCreatedByUser(User user)
- Specified by:
removeVariablesCreatedByUser
in interfaceRoom
-
removeVariablesCreatedByUser
public java.util.List<RoomVariable> removeVariablesCreatedByUser(User user, boolean isLeaveRoom)
- Specified by:
removeVariablesCreatedByUser
in 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:
getCapacity
in interfaceRoom
- Returns:
- the Room capacity
-
setCapacity
public void setCapacity(int maxUser, int maxSpectators)
- Specified by:
setCapacity
in interfaceRoom
-
setMaxRoomVariablesAllowed
public void setMaxRoomVariablesAllowed(int max)
- Specified by:
setMaxRoomVariablesAllowed
in interfaceRoom
-
getMaxRoomVariablesAllowed
public int getMaxRoomVariablesAllowed()
Return the maximum number of Room Variables allowed in the Room.- Specified by:
getMaxRoomVariablesAllowed
in 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:
isFlagSet
in 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:
isUseWordsFilter
in 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:
setUseWordsFilter
in 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:
setProperty
in interfaceRoom
- Parameters:
key
- the property namevalue
- the property value
-
setVariables
public void setVariables(java.util.List<RoomVariable> variables)
- Specified by:
setVariables
in interfaceRoom
-
setVariables
public void setVariables(java.util.List<RoomVariable> variables, boolean overrideOwnership)
- Specified by:
setVariables
in interfaceRoom
-
setVariable
public void setVariable(RoomVariable roomVariable) throws SFSVariableException
- Specified by:
setVariable
in 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:
isAllowOwnerInvitations
in 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:
setAllowOwnerInvitations
in 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:
isSuppressUserList
in interfaceRoom
-
setSuppressUserList
public void setSuppressUserList(boolean value)
- Specified by:
setSuppressUserList
in interfaceRoom
-
setVariable
public void setVariable(RoomVariable roomVariable, boolean overrideOwnership) throws SFSVariableException
- Specified by:
setVariable
in interfaceRoom
- Throws:
SFSVariableException
-
containsVariable
public boolean containsVariable(java.lang.String varName)
Checks if a certain Room Variable name exists- Specified by:
containsVariable
in 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:
containsUser
in 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:
containsUser
in 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:
addUser
in interfaceRoom
- Throws:
SFSJoinRoomException
-
addUser
public void addUser(User user, boolean asSpectator) throws SFSJoinRoomException
- Specified by:
addUser
in interfaceRoom
- Throws:
SFSJoinRoomException
-
removeUser
public void removeUser(User user)
- Specified by:
removeUser
in interfaceRoom
-
switchPlayerToSpectator
public void switchPlayerToSpectator(User user) throws SFSRoomException
- Specified by:
switchPlayerToSpectator
in interfaceRoom
- Throws:
SFSRoomException
-
switchSpectatorToPlayer
public void switchSpectatorToPlayer(User user) throws SFSRoomException
- Specified by:
switchSpectatorToPlayer
in interfaceRoom
- Throws:
SFSRoomException
-
getLifeTime
public long getLifeTime()
Obtain the time of existence of the Room- Specified by:
getLifeTime
in 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:
getUserListData
in interfaceRoom
-
getRoomVariablesData
public ISFSArray getRoomVariablesData(boolean globalsOnly)
- Specified by:
getRoomVariablesData
in interfaceRoom
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
getExtension
public ISFSExtension getExtension()
Get the extension connected to this Room, if any- Specified by:
getExtension
in interfaceRoom
- Returns:
- the extension attached to this Room, null if no extension exists
-
setExtension
public void setExtension(ISFSExtension extension)
- Specified by:
setExtension
in interfaceRoom
-
toSFSArray
public ISFSArray toSFSArray(boolean globalRoomVarsOnly)
- Specified by:
toSFSArray
in 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:
getPlayerIdGeneratorClassName
in interfaceRoom
-
setProperties
public void setProperties(java.util.Map<java.lang.Object,java.lang.Object> props)
-
-