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 Roompublic void setGroupId(java.lang.String groupId)
setGroupId in interface Roompublic java.lang.String getName()
public java.lang.String getPassword()
getPassword in interface RoomRoom.isPasswordProtected()public void setPassword(java.lang.String password)
setPassword in interface Roompublic boolean isPasswordProtected()
isPasswordProtected in interface Roompublic boolean isPublic()
public int getMaxUsers()
getMaxUsers in interface Roompublic void setMaxUsers(int maxUsers)
setMaxUsers in interface Roompublic int getMaxSpectators()
getMaxSpectators in interface Roompublic void setMaxSpectators(int maxSpectators)
setMaxSpectators in interface Roompublic User getOwner()
public com.smartfoxserver.v2.entities.managers.IUserManager getUserManager()
getUserManager in interface Roompublic void setUserManager(com.smartfoxserver.v2.entities.managers.IUserManager userManager)
setUserManager in interface Roompublic Zone getZone()
public boolean isDynamic()
public void setDynamic(boolean dynamic)
setDynamic in interface Roompublic 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 RoomSFSRoomRemoveModepublic void setAutoRemoveMode(SFSRoomRemoveMode autoRemoveMode)
setAutoRemoveMode in interface Roompublic java.util.List<User> getPlayersList()
getPlayersList in interface Roompublic java.lang.Object getProperty(java.lang.Object key)
getProperty in interface Roompublic java.util.concurrent.ConcurrentMap<java.lang.Object,java.lang.Object> getProperties()
getProperties in interface Roompublic RoomSize getSize()
public void removeProperty(java.lang.Object key)
removeProperty in interface Roomkey - the name of the propertypublic java.util.List<User> getSpectatorsList()
getSpectatorsList in interface Roompublic User getUserById(int id)
getUserById in interface Roomid - the User idpublic User getUserByName(java.lang.String name)
getUserByName in interface Roomname - the User namepublic User getUserBySession(ISession session)
getUserBySession in interface Roomsession - the User sessionpublic User getUserByPlayerId(int playerId)
getUserByPlayerId in interface RoomplayerId - the player idpublic java.util.List<User> getUserList()
getUserList in interface Roompublic java.util.List<ISession> getSessionList()
getSessionList in interface Roompublic int getVariablesCount()
getVariablesCount in interface Roompublic RoomVariable getVariable(java.lang.String varName)
getVariable in interface RoomvarName - the name of the variableSFSRoomVariablepublic java.util.List<RoomVariable> getVariables()
getVariables in interface Roompublic java.util.List<RoomVariable> getVariablesCreatedByUser(User user)
getVariablesCreatedByUser in interface Roomuser - the Userpublic boolean containsProperty(java.lang.Object key)
containsProperty in interface Roomkey - the name of the propertypublic void removeVariable(java.lang.String varName)
removeVariable in interface Roompublic java.util.List<RoomVariable> removeVariablesCreatedByUser(User user)
removeVariablesCreatedByUser in interface Roompublic java.util.List<RoomVariable> removeVariablesCreatedByUser(User user, boolean isLeaveRoom)
removeVariablesCreatedByUser in interface Roompublic int getCapacity()
getCapacity in interface Roompublic void setCapacity(int maxUser,
int maxSpectators)
setCapacity in interface Roompublic void setMaxRoomVariablesAllowed(int max)
setMaxRoomVariablesAllowed in interface Roompublic int getMaxRoomVariablesAllowed()
getMaxRoomVariablesAllowed in interface Roompublic void setFlags(java.util.Set<SFSRoomSettings> settings)
public boolean isFlagSet(SFSRoomSettings flag)
isFlagSet in interface Roomflag - the flagSFSRoomSettingspublic void setFlag(SFSRoomSettings flag, boolean state)
public boolean isUseWordsFilter()
isUseWordsFilter in interface Roompublic void setUseWordsFilter(boolean useWordsFilter)
setUseWordsFilter in interface Roompublic void setProperty(java.lang.Object key,
java.lang.Object value)
setProperty in interface Roomkey - the property namevalue - the property valuepublic void setVariables(java.util.List<RoomVariable> variables)
setVariables in interface Roompublic void setVariables(java.util.List<RoomVariable> variables, boolean overrideOwnership)
setVariables in interface Roompublic void setVariable(RoomVariable roomVariable) throws SFSVariableException
setVariable in interface RoomSFSVariableExceptionpublic boolean isAllowOwnerInvitations()
isAllowOwnerInvitations in interface Roompublic void setAllowOwnerInvitations(boolean flag)
setAllowOwnerInvitations in interface Roomflag - 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 RoomSFSVariableExceptionpublic boolean containsVariable(java.lang.String varName)
containsVariable in interface RoomvarName - the variable namepublic boolean containsUser(java.lang.String name)
containsUser in interface Roomname - the User namepublic boolean containsUser(User user)
containsUser in interface Roomuser - the Userpublic void addUser(User user) throws SFSJoinRoomException
addUser in interface RoomSFSJoinRoomExceptionpublic void addUser(User user, boolean asSpectator) throws SFSJoinRoomException
addUser in interface RoomSFSJoinRoomExceptionpublic void removeUser(User user)
removeUser in interface Roompublic void switchPlayerToSpectator(User user) throws SFSRoomException
switchPlayerToSpectator in interface RoomSFSRoomExceptionpublic void switchSpectatorToPlayer(User user) throws SFSRoomException
switchSpectatorToPlayer in interface RoomSFSRoomExceptionpublic long getLifeTime()
getLifeTime in interface Roompublic boolean isEmpty()
public boolean isFull()
public ISFSArray getUserListData()
getUserListData in interface Roompublic ISFSArray getRoomVariablesData(boolean globalsOnly)
getRoomVariablesData in interface Roompublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic ISFSExtension getExtension()
getExtension in interface Roompublic void setExtension(ISFSExtension extension)
setExtension in interface Roompublic ISFSArray toSFSArray(boolean globalRoomVarsOnly)
toSFSArray in interface Roompublic 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 Roompublic void setProperties(java.util.Map<java.lang.Object,java.lang.Object> props)