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 void
addUser(User user)
* API internal usage only *boolean
containsUser(User user)
Indicates whether the specified user is currently inside this Room or not.boolean
containsVariable(java.lang.String name)
Indicates whether this Room has the specified Room Variable set or not.static Room
fromSFSArray(com.smartfoxserver.v2.entities.data.ISFSArray sfsa)
* API internal usage only *int
getCapacity()
Returns the maximum amount of users, including spectators, that can be contained in this Room.java.lang.String
getGroupId()
Returns the Room Group name.int
getId()
Indicates the id of this Room.int
getMaxSpectators()
Returns the maximum number of spectators allowed in this Room (Game Rooms only).int
getMaxUsers()
Returns the maximum number of users allowed in this Room.java.lang.String
getName()
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.IRoomManager
getRoomManager()
Returns a reference to the Room Manager which manages this Room.int
getSpectatorCount()
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).User
getUserById(int id)
Retrieves a User object from its id property.User
getUserByName(java.lang.String name)
Retrieves a User object from its name property.int
getUserCount()
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.RoomVariable
getVariable(java.lang.String name)
Retrieves a Room Variable from its name.java.util.List<RoomVariable>
getVariables()
Retrieves all the Room Variables of this Room.boolean
isGame()
Indicates whether this is a Game Room or not.boolean
isHidden()
Indicates whether this Room is hidden or not.boolean
isJoined()
Indicates whether the client joined this Room or not.boolean
isManaged()
* API internal usage only *boolean
isPasswordProtected()
Indicates whether this Room requires a password to be joined or not.void
merge(Room anotherRoom)
* API internal usage only *void
removeUser(User user)
* API internal usage only *void
setGame(boolean game)
* API internal usage only *void
setHidden(boolean hidden)
* API internal usage only *void
setJoined(boolean joined)
* API internal usage only *void
setManaged(boolean managed)
* API internal usage only *void
setMaxSpectators(int maxSpectators)
* API internal usage only *void
setMaxUsers(int maxUsers)
* API internal usage only *void
setName(java.lang.String name)
* API internal usage only *void
setPasswordProtected(boolean passwordProtected)
* API internal usage only *void
setProperties(java.util.Map<?,?> properties)
Defines a generic utility object that can be used to store custom Room data.void
setRoomManager(IRoomManager manager)
* API internal usage only *void
setSpectatorCount(int spectatorCount)
* API internal usage only *void
setUserCount(int userCount)
* API internal usage only *void
setVariable(RoomVariable roomVariable)
* API internal usage only *void
setVariables(java.util.List<? extends RoomVariable> roomVariables)
* API internal usage only *java.lang.String
toString()
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:Room
Indicates 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:Room
Indicates 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:
getName
in 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:Room
Returns 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:
getGroupId
in interfaceRoom
- See Also:
SubscribeRoomGroupRequest
,UnsubscribeRoomGroupRequest
-
isJoined
public boolean isJoined()
Description copied from interface:Room
Indicates 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:
isJoined
in interfaceRoom
- See Also:
JoinRoomRequest
-
isGame
public boolean isGame()
Description copied from interface:Room
Indicates 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:Room
Indicates 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:Room
Indicates 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:
isPasswordProtected
in interfaceRoom
- See Also:
ChangeRoomPasswordStateRequest
-
setPasswordProtected
public void setPasswordProtected(boolean passwordProtected)
* API internal usage only *- Specified by:
setPasswordProtected
in interfaceRoom
-
isManaged
public boolean isManaged()
* API internal usage only *
-
getUserCount
public int getUserCount()
Description copied from interface:Room
Returns 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:
getUserCount
in interfaceRoom
-
getMaxUsers
public int getMaxUsers()
Description copied from interface:Room
Returns 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:
getMaxUsers
in interfaceRoom
-
getSpectatorCount
public int getSpectatorCount()
Description copied from interface:Room
Returns 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:
getSpectatorCount
in interfaceRoom
-
getMaxSpectators
public int getMaxSpectators()
Description copied from interface:Room
Returns 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:
getMaxSpectators
in interfaceRoom
-
getCapacity
public int getCapacity()
Description copied from interface:Room
Returns the maximum amount of users, including spectators, that can be contained in this Room.- Specified by:
getCapacity
in 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:
setManaged
in interfaceRoom
-
setUserCount
public void setUserCount(int userCount)
* API internal usage only *- Specified by:
setUserCount
in interfaceRoom
-
setMaxUsers
public void setMaxUsers(int maxUsers)
* API internal usage only *- Specified by:
setMaxUsers
in interfaceRoom
-
setSpectatorCount
public void setSpectatorCount(int spectatorCount)
* API internal usage only *- Specified by:
setSpectatorCount
in interfaceRoom
-
setMaxSpectators
public void setMaxSpectators(int maxSpectators)
* API internal usage only *- Specified by:
setMaxSpectators
in interfaceRoom
-
addUser
public void addUser(User user)
* API internal usage only *
-
removeUser
public void removeUser(User user)
* API internal usage only *- Specified by:
removeUser
in interfaceRoom
-
containsUser
public boolean containsUser(User user)
Description copied from interface:Room
Indicates whether the specified user is currently inside this Room or not.- Specified by:
containsUser
in interfaceRoom
- Parameters:
user
- The User object representing the user whose presence in this Room must be checked.- Returns:
true
if the user is inside this Room;false
otherwise.
-
getUserByName
public User getUserByName(java.lang.String name)
Description copied from interface:Room
Retrieves a User object from its name property.- Specified by:
getUserByName
in interfaceRoom
- Parameters:
name
- The name of the user to be found.- Returns:
- The User object representing the user, or
null
if 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:Room
Retrieves a User object from its id property.- Specified by:
getUserById
in interfaceRoom
- Parameters:
id
- The id of the user to be found.- Returns:
- The User object representing the user, or
null
if 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:Room
Returns a list of User objects representing all the users currently inside this Room.- Specified by:
getUserList
in interfaceRoom
-
getPlayerList
public java.util.List<User> getPlayerList()
Description copied from interface:Room
Returns a list of User objects representing the players currently inside this Room (Game Rooms only).- Specified by:
getPlayerList
in interfaceRoom
-
getSpectatorList
public java.util.List<User> getSpectatorList()
Description copied from interface:Room
Returns a list of User objects representing the spectators currently inside this Room (Game Rooms only).- Specified by:
getSpectatorList
in interfaceRoom
-
getVariable
public RoomVariable getVariable(java.lang.String name)
Description copied from interface:Room
Retrieves a Room Variable from its name.- Specified by:
getVariable
in interfaceRoom
- Parameters:
name
- The name of the Room Variable to be retrieved.- Returns:
- The RoomVariable object representing the Room Variable, or
null
if 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:Room
Retrieves all the Room Variables of this Room.- Specified by:
getVariables
in 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:
setVariable
in interfaceRoom
-
setVariables
public void setVariables(java.util.List<? extends RoomVariable> roomVariables)
* API internal usage only *- Specified by:
setVariables
in interfaceRoom
-
containsVariable
public boolean containsVariable(java.lang.String name)
Description copied from interface:Room
Indicates whether this Room has the specified Room Variable set or not.- Specified by:
containsVariable
in interfaceRoom
- Parameters:
name
- The name of the Room Variable whose existance in this Room must be checked.- Returns:
true
if a Room Variable with the passed name exists in this Room.
-
getProperties
public java.util.Map<?,?> getProperties()
Description copied from interface:Room
Defines 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:
getProperties
in interfaceRoom
- See Also:
Room.setProperties(Map)
-
setProperties
public void setProperties(java.util.Map<?,?> properties)
Description copied from interface:Room
Defines 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:
setProperties
in interfaceRoom
- See Also:
Room.getProperties()
-
getRoomManager
public IRoomManager getRoomManager()
Description copied from interface:Room
Returns 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:
getRoomManager
in interfaceRoom
-
setRoomManager
public void setRoomManager(IRoomManager manager) throws com.smartfoxserver.v2.exceptions.SFSException
* API internal usage only *- Specified by:
setRoomManager
in 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:
toString
in classjava.lang.Object
- Returns:
- The string representation of the SFSRoom object.
-
-