Class SFSRoom

java.lang.Object
sfs3.client.entities.SFSRoom
All Implemented Interfaces:
Room
Direct Known Subclasses:
MMORoom

public class SFSRoom extends Object implements Room
The SFSRoom object represents a SmartFoxServer Room on the client.

The SmartFoxServer 3 client API doesn't know all of the Rooms existing on the server side, but only those that are joined by the user and those in the Room Groups that have been subscribed.

Subscribing to one or more Groups allows to listen to Room events for all Rooms belonging to that Group.

A list of available Rooms is created after a successful login and it is kept updated by the server.

See Also:
  • Field Details

    • DEFAULT_GROUP_ID

      public static final String DEFAULT_GROUP_ID
      See Also:
    • id

      protected int id
    • name

      protected String name
    • groupId

      protected String groupId
    • isGame

      protected boolean isGame
    • isHidden

      protected boolean isHidden
    • isJoined

      protected boolean isJoined
    • isPasswordProtected

      protected boolean isPasswordProtected
    • isManaged

      protected boolean isManaged
    • isAudioStreamingAllowed

      protected boolean isAudioStreamingAllowed
    • variables

      protected Map<String,RoomVariable> variables
    • userManager

      protected IUserManager userManager
    • maxUsers

      protected int maxUsers
    • maxSpectators

      protected int maxSpectators
    • userCount

      protected int userCount
    • specCount

      protected int specCount
    • roomManager

      protected IRoomManager roomManager
  • Constructor Details

    • SFSRoom

      public SFSRoom(int id, String name)
    • SFSRoom

      public SFSRoom(int id, String name, String groupId)

      NOTE: never instantiate a SFSRoom manually: this is done by the SmartFoxServer 3 API internally.

  • Method Details

    • fromSFSArray

      public static Room fromSFSArray(ISFSArray sfsa)
      Internal
    • getId

      public int getId()
      Description copied from interface: Room
      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 String getName()
      Description copied from interface: Room
      The unique name of this Room. Two Rooms in the same Zone can't have the same name (in a case sensitive way)

      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:
    • setName

      public void setName(String name)
      Specified by:
      setName in interface Room
      Internal
    • getGroupId

      public 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 interface Room
      See Also:
    • 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:
    • 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:
    • setPasswordProtected

      public void setPasswordProtected(boolean passwordProtected)
      Specified by:
      setPasswordProtected in interface Room
      Internal
    • isManaged

      public boolean isManaged()
      Specified by:
      isManaged in interface Room
      Internal
    • isAudioStreamingAllowed

      public boolean isAudioStreamingAllowed()
      Description copied from interface: Room
      Indicates whether audio streaming is allowed in the Room.
      Specified by:
      isAudioStreamingAllowed in interface Room
      Returns:
      true if streaming is allowed
    • setAudioStreamingAllowed

      public void setAudioStreamingAllowed(boolean value)
      Specified by:
      setAudioStreamingAllowed in interface Room
      See Also:
    • 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)
      Specified by:
      setJoined in interface Room
      Internal
    • setGame

      public void setGame(boolean game)
      Specified by:
      setGame in interface Room
      Internal
    • setHidden

      public void setHidden(boolean hidden)
      Specified by:
      setHidden in interface Room
      Internal
    • setManaged

      public void setManaged(boolean managed)
      Specified by:
      setManaged in interface Room
      Internal
    • setUserCount

      public void setUserCount(int userCount)
      Specified by:
      setUserCount in interface Room
      Internal
    • setMaxUsers

      public void setMaxUsers(int maxUsers)
      Specified by:
      setMaxUsers in interface Room
      Internal
    • setSpectatorCount

      public void setSpectatorCount(int spectatorCount)
      Specified by:
      setSpectatorCount in interface Room
      Internal
    • setMaxSpectators

      public void setMaxSpectators(int maxSpectators)
      Specified by:
      setMaxSpectators in interface Room
      Internal
    • addUser

      public void addUser(User user)
      Specified by:
      addUser in interface Room
      Internal
    • removeUser

      public void removeUser(User user)
      Specified by:
      removeUser in interface Room
      Internal
    • 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 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(String name)
      Description copied from interface: Room
      Retrieves a User object from its name property.
      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:
    • 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:
    • getUserList

      public 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 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 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(String name)
      Description copied from interface: Room
      Retrieves a Room Variable from its name.
      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:
    • getVariables

      public List<RoomVariable> getVariables()
      Description copied from interface: Room
      Retrieves all the Room Variables of this Room.
      Specified by:
      getVariables in interface Room
      Returns:
      The list of RoomVariable objects associated with this Room.
      See Also:
    • setVariable

      public void setVariable(RoomVariable roomVariable)
      Specified by:
      setVariable in interface Room
      Internal
    • setVariables

      public void setVariables(List<? extends RoomVariable> roomVariables)
      Specified by:
      setVariables in interface Room
      Internal
    • containsVariable

      public boolean containsVariable(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.
    • 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 interface Room
    • setRoomManager

      public void setRoomManager(IRoomManager manager) throws SFSException
      Specified by:
      setRoomManager in interface Room
      Throws:
      SFSException
      Internal
    • equals

      public boolean equals(Object that)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns a string that contains the Room id, name and id of the Group to which it belongs.
      Overrides:
      toString in class Object
      Returns:
      The string representation of the SFSRoom object.