public class SFSRoom extends java.lang.Object implements Room
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.
Also each Room provides a number of essential services:
User
,
SFSGame
,
SFSApi
,
BaseSFSExtension
,
SFSExtension
Modifier and Type | Field and Description |
---|---|
protected org.slf4j.Logger |
logger |
Constructor and Description |
---|
SFSRoom(java.lang.String name) |
SFSRoom(java.lang.String name,
java.lang.Class<?> customPlayerIdGeneratorClass) |
Modifier and Type | Method and Description |
---|---|
void |
addUser(User user) |
void |
addUser(User user,
boolean asSpectator) |
boolean |
containsProperty(java.lang.Object key)
Checks whether a custom property exists or not
|
boolean |
containsUser(java.lang.String name)
Checks if the specified User is joined in the Room
|
boolean |
containsUser(User user)
Checks if the specified User is joined in the Room
|
boolean |
containsVariable(java.lang.String varName)
Checks if a certain Room Variable name exists
|
void |
destroy() |
boolean |
equals(java.lang.Object obj) |
com.smartfoxserver.v2.util.IAdminHelper |
getAdminHelper() |
SFSRoomRemoveMode |
getAutoRemoveMode()
Return the auto-remove mode of the Room
|
int |
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 any
|
java.lang.String |
getGroupId()
Get the Room Group Id.
|
int |
getId()
Return the unique Room Id
|
long |
getLifeTime()
Obtain the time of existence of the Room
|
int |
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 name
|
User |
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 properties
|
java.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 Room
|
RoomSize |
getSize()
Return the current Room size
|
java.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 Room
|
ISFSArray |
getUserListData() |
com.smartfoxserver.v2.entities.managers.IUserManager |
getUserManager() |
RoomVariable |
getVariable(java.lang.String varName)
Get a Room Variable
|
java.util.List<RoomVariable> |
getVariables()
Get the full list of Room Variables in the Room
|
int |
getVariablesCount()
Get the total amount of Room Variables for this Room
|
java.util.List<RoomVariable> |
getVariablesCreatedByUser(User user)
Get a list of Room Variables created by a specific User
|
Zone |
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 empty
|
boolean |
isFlagSet(SFSRoomSettings flag)
Checks whether a certain Room Setting is set
|
boolean |
isFull()
Checks whether the Room is full.
|
boolean |
isGame()
Checks if this is a Game Room
|
boolean |
isHidden()
Checks if the Game is hidden.
|
boolean |
isPasswordProtected()
Checks if the Room requires a password for joining it
|
boolean |
isPublic()
Returns true if the Room has public access, in other words it doesn't require a password.
|
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 property
|
void |
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 object
|
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() |
public SFSRoom(java.lang.String name)
public SFSRoom(java.lang.String name, java.lang.Class<?> customPlayerIdGeneratorClass)
public int getId()
public java.lang.String getGroupId()
getGroupId
in interface Room
public void setGroupId(java.lang.String groupId)
setGroupId
in interface Room
public java.lang.String getName()
public java.lang.String getPassword()
getPassword
in interface Room
Room.isPasswordProtected()
public void setPassword(java.lang.String password)
setPassword
in interface Room
public boolean isPasswordProtected()
isPasswordProtected
in interface Room
public boolean isPublic()
public int getMaxUsers()
getMaxUsers
in interface Room
public void setMaxUsers(int maxUsers)
setMaxUsers
in interface Room
public int getMaxSpectators()
getMaxSpectators
in interface Room
public void setMaxSpectators(int maxSpectators)
setMaxSpectators
in interface Room
public User getOwner()
public com.smartfoxserver.v2.entities.managers.IUserManager getUserManager()
getUserManager
in interface Room
public void setUserManager(com.smartfoxserver.v2.entities.managers.IUserManager userManager)
setUserManager
in interface Room
public Zone getZone()
public boolean isDynamic()
public void setDynamic(boolean dynamic)
setDynamic
in interface Room
public boolean isGame()
public void setGame(boolean game, java.lang.Class<? extends IPlayerIdGenerator> customPlayerIdGeneratorClass)
public boolean isHidden()
public boolean isActive()
public SFSRoomRemoveMode getAutoRemoveMode()
getAutoRemoveMode
in interface Room
SFSRoomRemoveMode
public void setAutoRemoveMode(SFSRoomRemoveMode autoRemoveMode)
setAutoRemoveMode
in interface Room
public java.util.List<User> getPlayersList()
getPlayersList
in interface Room
public java.lang.Object getProperty(java.lang.Object key)
getProperty
in interface Room
public java.util.concurrent.ConcurrentMap<java.lang.Object,java.lang.Object> getProperties()
getProperties
in interface Room
public RoomSize getSize()
public void removeProperty(java.lang.Object key)
removeProperty
in interface Room
key
- the name of the propertypublic java.util.List<User> getSpectatorsList()
getSpectatorsList
in interface Room
public User getUserById(int id)
getUserById
in interface Room
id
- the User idpublic User getUserByName(java.lang.String name)
getUserByName
in interface Room
name
- the User namepublic User getUserBySession(ISession session)
getUserBySession
in interface Room
session
- the User sessionpublic User getUserByPlayerId(int playerId)
getUserByPlayerId
in interface Room
playerId
- the player idpublic java.util.List<User> getUserList()
getUserList
in interface Room
public java.util.List<ISession> getSessionList()
getSessionList
in interface Room
public int getVariablesCount()
getVariablesCount
in interface Room
public RoomVariable getVariable(java.lang.String varName)
getVariable
in interface Room
varName
- the name of the variableSFSRoomVariable
public java.util.List<RoomVariable> getVariables()
getVariables
in interface Room
public java.util.List<RoomVariable> getVariablesCreatedByUser(User user)
getVariablesCreatedByUser
in interface Room
user
- the Userpublic boolean containsProperty(java.lang.Object key)
containsProperty
in interface Room
key
- the name of the propertypublic void removeVariable(java.lang.String varName)
removeVariable
in interface Room
public java.util.List<RoomVariable> removeVariablesCreatedByUser(User user)
removeVariablesCreatedByUser
in interface Room
public java.util.List<RoomVariable> removeVariablesCreatedByUser(User user, boolean isLeaveRoom)
removeVariablesCreatedByUser
in interface Room
public int getCapacity()
getCapacity
in interface Room
public void setCapacity(int maxUser, int maxSpectators)
setCapacity
in interface Room
public void setMaxRoomVariablesAllowed(int max)
setMaxRoomVariablesAllowed
in interface Room
public int getMaxRoomVariablesAllowed()
getMaxRoomVariablesAllowed
in interface Room
public void setFlags(java.util.Set<SFSRoomSettings> settings)
public boolean isFlagSet(SFSRoomSettings flag)
isFlagSet
in interface Room
flag
- the flagSFSRoomSettings
public void setFlag(SFSRoomSettings flag, boolean state)
public boolean isUseWordsFilter()
isUseWordsFilter
in interface Room
public void setUseWordsFilter(boolean useWordsFilter)
setUseWordsFilter
in interface Room
public void setProperty(java.lang.Object key, java.lang.Object value)
setProperty
in interface Room
key
- the property namevalue
- the property valuepublic void setVariables(java.util.List<RoomVariable> variables)
setVariables
in interface Room
public void setVariables(java.util.List<RoomVariable> variables, boolean overrideOwnership)
setVariables
in interface Room
public void setVariable(RoomVariable roomVariable) throws SFSVariableException
setVariable
in interface Room
SFSVariableException
public boolean isAllowOwnerInvitations()
isAllowOwnerInvitations
in interface Room
public void setAllowOwnerInvitations(boolean flag)
setAllowOwnerInvitations
in interface Room
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.public void setVariable(RoomVariable roomVariable, boolean overrideOwnership) throws SFSVariableException
setVariable
in interface Room
SFSVariableException
public boolean containsVariable(java.lang.String varName)
containsVariable
in interface Room
varName
- the variable namepublic boolean containsUser(java.lang.String name)
containsUser
in interface Room
name
- the User namepublic boolean containsUser(User user)
containsUser
in interface Room
user
- the Userpublic void addUser(User user) throws SFSJoinRoomException
addUser
in interface Room
SFSJoinRoomException
public void addUser(User user, boolean asSpectator) throws SFSJoinRoomException
addUser
in interface Room
SFSJoinRoomException
public void removeUser(User user)
removeUser
in interface Room
public void switchPlayerToSpectator(User user) throws SFSRoomException
switchPlayerToSpectator
in interface Room
SFSRoomException
public void switchSpectatorToPlayer(User user) throws SFSRoomException
switchSpectatorToPlayer
in interface Room
SFSRoomException
public long getLifeTime()
getLifeTime
in interface Room
public boolean isEmpty()
public boolean isFull()
public ISFSArray getUserListData()
getUserListData
in interface Room
public ISFSArray getRoomVariablesData(boolean globalsOnly)
getRoomVariablesData
in interface Room
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public ISFSExtension getExtension()
getExtension
in interface Room
public void setExtension(ISFSExtension extension)
setExtension
in interface Room
public ISFSArray toSFSArray(boolean globalRoomVarsOnly)
toSFSArray
in interface Room
public java.lang.String getDump()
public com.smartfoxserver.v2.util.IAdminHelper getAdminHelper()
public void setAdminHelper(com.smartfoxserver.v2.util.IAdminHelper helper)
public java.lang.String getPlayerIdGeneratorClassName()
getPlayerIdGeneratorClassName
in interface Room
public void setProperties(java.util.Map<java.lang.Object,java.lang.Object> props)