Class SFSRoom
- java.lang.Object
-
- sfs2x.client.entities.SFSRoom
-
- All Implemented Interfaces:
Room
- Direct Known Subclasses:
MMORoom
public class SFSRoom extends java.lang.Object implements Room
The SFSRoom object represents a SmartFoxServer Room entity on the client.The SmartFoxServer 2X client API are not aware of all the Rooms which exist on the server side, but only of those that are joined by the user and those in the Room Groups that have been subscribed. Subscribing to one or more Groups allows the client to listen to Room events in specific "areas" of the Zone, without having to retrieve and keep synchronized the details of all available Rooms, thus reducing the traffic between the client and the server considerably.
The list of available Rooms is created after a successful login and it is kept updated continuously by the server.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddUser(User user)* API internal usage only *booleancontainsUser(User user)Indicates whether the specified user is currently inside this Room or not.booleancontainsVariable(java.lang.String name)Indicates whether this Room has the specified Room Variable set or not.static RoomfromSFSArray(com.smartfoxserver.v2.entities.data.ISFSArray sfsa)* API internal usage only *intgetCapacity()Returns the maximum amount of users, including spectators, that can be contained in this Room.java.lang.StringgetGroupId()Returns the Room Group name.intgetId()Indicates the id of this Room.intgetMaxSpectators()Returns the maximum number of spectators allowed in this Room (Game Rooms only).intgetMaxUsers()Returns the maximum number of users allowed in this Room.java.lang.StringgetName()Indicates the name of this Room.java.util.List<User>getPlayerList()Returns a list of User objects representing the players currently inside this Room (Game Rooms only).java.util.Map<?,?>getProperties()Defines a generic utility object that can be used to store custom Room data.IRoomManagergetRoomManager()Returns a reference to the Room Manager which manages this Room.intgetSpectatorCount()Returns the current number of spectators in this Room (Game Rooms only).java.util.List<User>getSpectatorList()Returns a list of User objects representing the spectators currently inside this Room (Game Rooms only).UsergetUserById(int id)Retrieves a User object from its id property.UsergetUserByName(java.lang.String name)Retrieves a User object from its name property.intgetUserCount()Returns the current number of users in this Room.java.util.List<User>getUserList()Returns a list of User objects representing all the users currently inside this Room.RoomVariablegetVariable(java.lang.String name)Retrieves a Room Variable from its name.java.util.List<RoomVariable>getVariables()Retrieves all the Room Variables of this Room.booleanisGame()Indicates whether this is a Game Room or not.booleanisHidden()Indicates whether this Room is hidden or not.booleanisJoined()Indicates whether the client joined this Room or not.booleanisManaged()* API internal usage only *booleanisPasswordProtected()Indicates whether this Room requires a password to be joined or not.voidmerge(Room anotherRoom)* API internal usage only *voidremoveUser(User user)* API internal usage only *voidsetGame(boolean game)* API internal usage only *voidsetHidden(boolean hidden)* API internal usage only *voidsetJoined(boolean joined)* API internal usage only *voidsetManaged(boolean managed)* API internal usage only *voidsetMaxSpectators(int maxSpectators)* API internal usage only *voidsetMaxUsers(int maxUsers)* API internal usage only *voidsetName(java.lang.String name)* API internal usage only *voidsetPasswordProtected(boolean passwordProtected)* API internal usage only *voidsetProperties(java.util.Map<?,?> properties)Defines a generic utility object that can be used to store custom Room data.voidsetRoomManager(IRoomManager manager)* API internal usage only *voidsetSpectatorCount(int spectatorCount)* API internal usage only *voidsetUserCount(int userCount)* API internal usage only *voidsetVariable(RoomVariable roomVariable)* API internal usage only *voidsetVariables(java.util.List<? extends RoomVariable> roomVariables)* API internal usage only *java.lang.StringtoString()Returns a string that contains the Room id, name and id of the Group to which it belongs.
-
-
-
Constructor Detail
-
SFSRoom
public SFSRoom(int id, java.lang.String name)
-
SFSRoom
public SFSRoom(int id, java.lang.String name, java.lang.String groupId)Creates a new SFSRoom instance.NOTE: developers never instantiate a SFSRoom manually: this is done by the SmartFoxServer 2X API internally.
- Parameters:
id- The Room id.name- The Room name.groupId- The id of the Group to which the Room belongs.
-
-
Method Detail
-
fromSFSArray
public static Room fromSFSArray(com.smartfoxserver.v2.entities.data.ISFSArray sfsa)
* API internal usage only *
-
getId
public int getId()
Description copied from interface:RoomIndicates the id of this Room. It is unique and it is generated by the server when the Room is created.
-
getName
public java.lang.String getName()
Description copied from interface:RoomIndicates the name of this Room. Two Rooms in the same Zone can't have the same name.NOTE: setting the name property manually has no effect on the server and can disrupt the API functioning. Use the ChangeRoomNameRequest request instead.
- Specified by:
getNamein interfaceRoom- See Also:
ChangeRoomNameRequest
-
setName
public void setName(java.lang.String name)
* API internal usage only *
-
getGroupId
public java.lang.String getGroupId()
Description copied from interface:RoomReturns the Room Group name. Each Group is identified by a unique string (its name or id) and it represents a different "container" for Rooms.Room Groups enable developers to organize Rooms under different types or categories and let clients select only those Groups they are interested in, in order to receive their events only. This is done via the SubscribeRoomGroupRequest and UnsubscribeRoomGroupRequest requests.
The default value is
default.- Specified by:
getGroupIdin interfaceRoom- See Also:
SubscribeRoomGroupRequest,UnsubscribeRoomGroupRequest
-
isJoined
public boolean isJoined()
Description copied from interface:RoomIndicates whether the client joined this Room or not.NOTE: setting the isJoined property manually has no effect on the server and can disrupt the API functioning. Use the JoinRoomRequest request to join a new Room instead.
- Specified by:
isJoinedin interfaceRoom- See Also:
JoinRoomRequest
-
isGame
public boolean isGame()
Description copied from interface:RoomIndicates whether this is a Game Room or not.NOTE: setting the isGame property manually has no effect on the server and can disrupt the API functioning. This flag must be set when creating the Room.
-
isHidden
public boolean isHidden()
Description copied from interface:RoomIndicates whether this Room is hidden or not. This is a utility flag that can be used by developers to hide certain Rooms from the interface of their application.NOTE: setting the isHidden property manually has no effect on the server and can disrupt the API functioning. This flag must be set when creating the Room.
-
isPasswordProtected
public boolean isPasswordProtected()
Description copied from interface:RoomIndicates whether this Room requires a password to be joined or not.NOTE: setting the isPasswordProtected property manually has no effect on the server and can disrupt the API functioning. This flag depends on the Room's password set when the Room is created or by means of the ChangeRoomPasswordStateRequest request.
- Specified by:
isPasswordProtectedin interfaceRoom- See Also:
ChangeRoomPasswordStateRequest
-
setPasswordProtected
public void setPasswordProtected(boolean passwordProtected)
* API internal usage only *- Specified by:
setPasswordProtectedin interfaceRoom
-
isManaged
public boolean isManaged()
* API internal usage only *
-
getUserCount
public int getUserCount()
Description copied from interface:RoomReturns the current number of users in this Room. In case of Game Rooms, this is the number of players.NOTE: setting the userCount property manually has no effect on the server and can disrupt the API functioning. This flag depends on the Room state.
- Specified by:
getUserCountin interfaceRoom
-
getMaxUsers
public int getMaxUsers()
Description copied from interface:RoomReturns the maximum number of users allowed in this Room. In case of Game Rooms, this is the maximum number of players.NOTE: setting the maxUsers property manually has no effect on the server and can disrupt the API functioning. This flag must be set when creating the Room.
- Specified by:
getMaxUsersin interfaceRoom
-
getSpectatorCount
public int getSpectatorCount()
Description copied from interface:RoomReturns the current number of spectators in this Room (Game Rooms only).NOTE: setting the spectatorCount property manually has no effect on the server and can disrupt the API functioning. This flag depends on the Room state.
- Specified by:
getSpectatorCountin interfaceRoom
-
getMaxSpectators
public int getMaxSpectators()
Description copied from interface:RoomReturns the maximum number of spectators allowed in this Room (Game Rooms only).NOTE: setting the maxSpectators property manually has no effect on the server and can disrupt the API functioning. This flag must be set when creating the Game Room.
- Specified by:
getMaxSpectatorsin interfaceRoom
-
getCapacity
public int getCapacity()
Description copied from interface:RoomReturns the maximum amount of users, including spectators, that can be contained in this Room.- Specified by:
getCapacityin interfaceRoom
-
setJoined
public void setJoined(boolean joined)
* API internal usage only *
-
setGame
public void setGame(boolean game)
* API internal usage only *
-
setHidden
public void setHidden(boolean hidden)
* API internal usage only *
-
setManaged
public void setManaged(boolean managed)
* API internal usage only *- Specified by:
setManagedin interfaceRoom
-
setUserCount
public void setUserCount(int userCount)
* API internal usage only *- Specified by:
setUserCountin interfaceRoom
-
setMaxUsers
public void setMaxUsers(int maxUsers)
* API internal usage only *- Specified by:
setMaxUsersin interfaceRoom
-
setSpectatorCount
public void setSpectatorCount(int spectatorCount)
* API internal usage only *- Specified by:
setSpectatorCountin interfaceRoom
-
setMaxSpectators
public void setMaxSpectators(int maxSpectators)
* API internal usage only *- Specified by:
setMaxSpectatorsin interfaceRoom
-
addUser
public void addUser(User user)
* API internal usage only *
-
removeUser
public void removeUser(User user)
* API internal usage only *- Specified by:
removeUserin interfaceRoom
-
containsUser
public boolean containsUser(User user)
Description copied from interface:RoomIndicates whether the specified user is currently inside this Room or not.- Specified by:
containsUserin interfaceRoom- Parameters:
user- The User object representing the user whose presence in this Room must be checked.- Returns:
trueif the user is inside this Room;falseotherwise.
-
getUserByName
public User getUserByName(java.lang.String name)
Description copied from interface:RoomRetrieves a User object from its name property.- Specified by:
getUserByNamein interfaceRoom- Parameters:
name- The name of the user to be found.- Returns:
- The User object representing the user, or
nullif no user with the passed name exists in this Room. - See Also:
Room.getUserById(int)
-
getUserById
public User getUserById(int id)
Description copied from interface:RoomRetrieves a User object from its id property.- Specified by:
getUserByIdin interfaceRoom- Parameters:
id- The id of the user to be found.- Returns:
- The User object representing the user, or
nullif no user with the passed id exists in this Room. - See Also:
Room.getUserByName(String)
-
getUserList
public java.util.List<User> getUserList()
Description copied from interface:RoomReturns a list of User objects representing all the users currently inside this Room.- Specified by:
getUserListin interfaceRoom
-
getPlayerList
public java.util.List<User> getPlayerList()
Description copied from interface:RoomReturns a list of User objects representing the players currently inside this Room (Game Rooms only).- Specified by:
getPlayerListin interfaceRoom
-
getSpectatorList
public java.util.List<User> getSpectatorList()
Description copied from interface:RoomReturns a list of User objects representing the spectators currently inside this Room (Game Rooms only).- Specified by:
getSpectatorListin interfaceRoom
-
getVariable
public RoomVariable getVariable(java.lang.String name)
Description copied from interface:RoomRetrieves a Room Variable from its name.- Specified by:
getVariablein interfaceRoom- Parameters:
name- The name of the Room Variable to be retrieved.- Returns:
- The RoomVariable object representing the Room Variable, or
nullif no Room Variable with the passed name exists in this Room. - See Also:
Room.getVariables(),SetRoomVariablesRequest
-
getVariables
public java.util.List<RoomVariable> getVariables()
Description copied from interface:RoomRetrieves all the Room Variables of this Room.- Specified by:
getVariablesin interfaceRoom- Returns:
- The list of RoomVariable objects associated with this Room.
- See Also:
Room.getVariable(String),RoomVariable
-
setVariable
public void setVariable(RoomVariable roomVariable)
* API internal usage only *- Specified by:
setVariablein interfaceRoom
-
setVariables
public void setVariables(java.util.List<? extends RoomVariable> roomVariables)
* API internal usage only *- Specified by:
setVariablesin interfaceRoom
-
containsVariable
public boolean containsVariable(java.lang.String name)
Description copied from interface:RoomIndicates whether this Room has the specified Room Variable set or not.- Specified by:
containsVariablein interfaceRoom- Parameters:
name- The name of the Room Variable whose existance in this Room must be checked.- Returns:
trueif a Room Variable with the passed name exists in this Room.
-
getProperties
public java.util.Map<?,?> getProperties()
Description copied from interface:RoomDefines a generic utility object that can be used to store custom Room data. The values added to this object are for client-side use only and are never transmitted to the server or to the other clients.- Specified by:
getPropertiesin interfaceRoom- See Also:
Room.setProperties(Map)
-
setProperties
public void setProperties(java.util.Map<?,?> properties)
Description copied from interface:RoomDefines a generic utility object that can be used to store custom Room data. The values added to this object are for client-side use only and are never transmitted to the server or to the other clients.- Specified by:
setPropertiesin interfaceRoom- See Also:
Room.getProperties()
-
getRoomManager
public IRoomManager getRoomManager()
Description copied from interface:RoomReturns a reference to the Room Manager which manages this Room.NOTE: setting the roomManager property manually has no effect on the server and can disrupt the API functioning.
- Specified by:
getRoomManagerin interfaceRoom
-
setRoomManager
public void setRoomManager(IRoomManager manager) throws com.smartfoxserver.v2.exceptions.SFSException
* API internal usage only *- Specified by:
setRoomManagerin interfaceRoom- Throws:
com.smartfoxserver.v2.exceptions.SFSException
-
toString
public java.lang.String toString()
Returns a string that contains the Room id, name and id of the Group to which it belongs.- Overrides:
toStringin classjava.lang.Object- Returns:
- The string representation of the SFSRoom object.
-
-