sfs2x.client.entities
Class SFSRoom

java.lang.Object
  extended by sfs2x.client.entities.SFSRoom
All Implemented Interfaces:
Room

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.

See Also:
CreateRoomRequest, JoinRoomRequest, SubscribeRoomGroupRequest, UnsubscribeRoomGroupRequest, ChangeRoomNameRequest, ChangeRoomPasswordStateRequest, ChangeRoomCapacityRequest, SmartFox.roomManager

Constructor Summary
SFSRoom(int id, java.lang.String name)
           
SFSRoom(int id, java.lang.String name, java.lang.String groupId)
          Creates a new SFSRoom instance.
 
Method Summary
 void addUser(User user)
          *Private*
 boolean containsUser(User user)
          *Private*
 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)
          *Private*
 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()
          *Private*
 IRoomManager getRoomManager()
          A reference to the RoomManager, managing 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)
          *Private*
 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)
          *Private*
 java.util.List<RoomVariable> getVariables()
          *Private*
 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()
          *Private*
 boolean isPasswordProtected()
          Indicates whether this Room requires a password to be joined or not.
 void merge(Room anotherRoom)
          *Private*
 void removeUser(User user)
          *Private*
 void setGame(boolean game)
          *Private*
 void setHidden(boolean hidden)
          *Private*
 void setJoined(boolean joined)
          *Private*
 void setManaged(boolean managed)
          *Private*
 void setMaxSpectators(int maxSpectators)
          *Private*
 void setMaxUsers(int maxUsers)
          *Private*
 void setName(java.lang.String name)
          *Private*
 void setPasswordProtected(boolean passwordProtected)
          *Private*
 void setProperties(java.util.Map<?,?> properties)
          *Private*
 void setRoomManager(IRoomManager manager)
          *Private*
 void setSpectatorCount(int spectatorCount)
          *Private*
 void setUserCount(int userCount)
          *Private*
 void setVariable(RoomVariable roomVariable)
          *Private*
 void setVariables(java.util.List<? extends RoomVariable> roomVariables)
          *Private*
 java.lang.String toString()
          Returns a string that contains the Room id, name and id of the Group to which it belongs.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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 istantiate 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)
*Private*


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.

Specified by:
getId in interface Room

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 interface Room
See Also:
ChangeRoomNameRequest

setName

public void setName(java.lang.String name)
*Private*

Specified by:
setName in interface Room

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.

Default: default

Specified by:
getGroupId in interface Room
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 interface Room
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.

Specified by:
isGame in interface 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.

Specified by:
isHidden in interface 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 interface Room
See Also:
ChangeRoomPasswordStateRequest

setPasswordProtected

public void setPasswordProtected(boolean passwordProtected)
*Private*

Specified by:
setPasswordProtected in interface Room

isManaged

public boolean isManaged()
*Private*

Specified by:
isManaged in interface Room

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 interface Room

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 interface Room

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 interface Room

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 interface Room

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 interface Room

setJoined

public void setJoined(boolean joined)
Description copied from interface: Room
*Private*

Specified by:
setJoined in interface Room

setGame

public void setGame(boolean game)
Description copied from interface: Room
*Private*

Specified by:
setGame in interface Room

setHidden

public void setHidden(boolean hidden)
*Private*

Specified by:
setHidden in interface Room

setManaged

public void setManaged(boolean managed)
*Private*

Specified by:
setManaged in interface Room

setUserCount

public void setUserCount(int userCount)
Description copied from interface: Room
*Private*

Specified by:
setUserCount in interface Room

setMaxUsers

public void setMaxUsers(int maxUsers)
Description copied from interface: Room
*Private*

Specified by:
setMaxUsers in interface Room

setSpectatorCount

public void setSpectatorCount(int spectatorCount)
Description copied from interface: Room
*Private*

Specified by:
setSpectatorCount in interface Room

setMaxSpectators

public void setMaxSpectators(int maxSpectators)
Description copied from interface: Room
*Private*

Specified by:
setMaxSpectators in interface Room

addUser

public void addUser(User user)
*Private*

Specified by:
addUser in interface Room

removeUser

public void removeUser(User user)
*Private*

Specified by:
removeUser in interface Room

containsUser

public boolean containsUser(User user)
*Private*

Specified by:
containsUser in interface Room
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)
*Private*

Specified by:
getUserByName in interface Room
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 interface Room
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 interface Room

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 interface Room

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 interface Room

getVariable

public RoomVariable getVariable(java.lang.String name)
*Private*

Specified by:
getVariable in interface Room
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()
*Private*

Specified by:
getVariables in interface Room
Returns:
The list of RoomVariable objects associated with this Room.
See Also:
RoomVariable, Room.getVariable(String)

setVariable

public void setVariable(RoomVariable roomVariable)
*Private*

Specified by:
setVariable in interface Room

setVariables

public void setVariables(java.util.List<? extends RoomVariable> roomVariables)
*Private*

Specified by:
setVariables in interface Room

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 interface Room
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()
*Private*

Specified by:
getProperties in interface Room

setProperties

public void setProperties(java.util.Map<?,?> properties)
*Private*

Specified by:
setProperties in interface Room

getRoomManager

public IRoomManager getRoomManager()
Description copied from interface: Room
A reference to the RoomManager, managing this Room

Specified by:
getRoomManager in interface Room

setRoomManager

public void setRoomManager(IRoomManager manager)
                    throws com.smartfoxserver.v2.exceptions.SFSException
*Private*

Specified by:
setRoomManager in interface Room
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 class java.lang.Object
Returns:
The string representation of the SFSRoom object.

merge

public void merge(Room anotherRoom)
Description copied from interface: Room
*Private*

Specified by:
merge in interface Room