Class SFSRoom

  • All Implemented Interfaces:
    Room
    Direct Known Subclasses:
    MMORoom, SFSGame

    public class SFSRoom
    extends java.lang.Object
    implements Room

    Overview

    The Room object is the main tool to organize and group Users in the application. Rooms can be created for chatting, playing games, exchanging images and audio files, sharing documents, collaboratively work on shared resources and a lot more.

    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.

    Services

    In SmartFoxServer 2X Rooms are extremely versatile. They offer the same basic features already known in SmartFoxServer 1.x plus they add dozens of new fine-tuning option that will help you configure them exactly the way you need them. The new features allow you to:
    • Organize Rooms in Room Groups
    • Rename Rooms at runtime
    • Resize Rooms at runtime
    • Lock/Unlock Rooms at runtime with a password
    • Hide Room visibility
    • Broadcast Room Variables outside of the Room itself
    • Decide which Room Variables are server-side only and which will be auto-updated to each client
    • Configure Events and Permissions for each Room on a fine-grained level.
    • Configure the life-cycle of a Room (when it gets removed and how)
    • Join any Room from client side without the need of having it in the local room list
    • Optimize the client room list by deciding which Room Groups the User will listen event for

    Also each Room provides a number of essential services:

    • User management
    • Words filtering
    • Anti-Flood filtering
    • Manager player IDs for Game ROoms
    • Event dispatching
    Finally each Room is fully extensible via the use of a server side Extension which allow to process client requests, server events and more. The Extension is attached to the Room itself and initialized as soon as the Room is ready. The Extension can take control of the Room and interact with the server via the server side API.

    Advanced Game features

    Room objects provide the ability to manage games with custom logic very easily by plugging custom logic via Extensions. The new SFS2X framework also provides a new type of Room called SFSGame which delivers advanced gaming features, such as an invitation system, game matching, user matching, game start/stop auto-notifications and more...
    See Also:
    User, SFSGame, SFSApi, BaseSFSExtension, SFSExtension
    • Field Detail

      • logger

        protected org.slf4j.Logger logger
    • Constructor Detail

      • SFSRoom

        public SFSRoom​(java.lang.String name)
      • SFSRoom

        public SFSRoom​(java.lang.String name,
                       java.lang.Class<?> customPlayerIdGeneratorClass)
    • Method Detail

      • getId

        public int getId()
        Return the unique Room Id
        Specified by:
        getId in interface Room
        Returns:
        the unique Room id
      • getGroupId

        public java.lang.String getGroupId()
        Get the Room Group Id.
        Specified by:
        getGroupId in interface Room
        Returns:
        the group Id
      • setGroupId

        public void setGroupId​(java.lang.String groupId)
        Specified by:
        setGroupId in interface Room
      • getName

        public java.lang.String getName()
        Get the room name
        Specified by:
        getName in interface Room
        Returns:
        the room name
      • setName

        public void setName​(java.lang.String name)
        Specified by:
        setName in interface Room
      • getPassword

        public java.lang.String getPassword()
        Get the Room password.
        Specified by:
        getPassword in interface Room
        Returns:
        the room password, null if no password is used
        See Also:
        Room.isPasswordProtected()
      • setPassword

        public void setPassword​(java.lang.String password)
        Specified by:
        setPassword in interface Room
      • isPasswordProtected

        public boolean isPasswordProtected()
        Checks if the Room requires a password for joining it
        Specified by:
        isPasswordProtected in interface Room
        Returns:
        true if the Room requires a password
      • isPublic

        public boolean isPublic()
        Returns true if the Room has public access, in other words it doesn't require a password.
        Specified by:
        isPublic in interface Room
        Returns:
        true id the Room is public and doesn't require a password
      • getMaxUsers

        public int getMaxUsers()
        Return the maximum number of Users allowed in the Room.
        Specified by:
        getMaxUsers in interface Room
        Returns:
        the max number of users allowed in the Room
      • setMaxUsers

        public void setMaxUsers​(int maxUsers)
        Specified by:
        setMaxUsers in interface Room
      • getMaxSpectators

        public int getMaxSpectators()
        Return the maximum number of Spectators allowed in the Room.
        Specified by:
        getMaxSpectators in interface Room
        Returns:
        the max number of spectators allowed in the Room
      • setMaxSpectators

        public void setMaxSpectators​(int maxSpectators)
        Specified by:
        setMaxSpectators in interface Room
      • getOwner

        public User getOwner()
        Get the owner of the Room (the user that created it)
        Specified by:
        getOwner in interface Room
        Returns:
        the owner of the Room, it can be null if the Room was created by the Server itself
      • setOwner

        public void setOwner​(User owner)
        Specified by:
        setOwner in interface Room
      • getUserManager

        public com.smartfoxserver.v2.entities.managers.IUserManager getUserManager()
        Specified by:
        getUserManager in interface Room
      • setUserManager

        public void setUserManager​(com.smartfoxserver.v2.entities.managers.IUserManager userManager)
        Specified by:
        setUserManager in interface Room
      • getZone

        public Zone getZone()
        Get the Zone managing this Room.
        Specified by:
        getZone in interface Room
        Returns:
        the Zone that contains the Room
      • setZone

        public void setZone​(Zone zone)
        Specified by:
        setZone in interface Room
      • isDynamic

        public boolean isDynamic()
        Checks if the Room was created dynamically (at runtime)
        Specified by:
        isDynamic in interface Room
        Returns:
        true if the Room was created dynamically
      • setDynamic

        public void setDynamic​(boolean dynamic)
        Specified by:
        setDynamic in interface Room
      • isGame

        public boolean isGame()
        Checks if this is a Game Room
        Specified by:
        isGame in interface Room
        Returns:
        true if this is a Game Room
      • setGame

        public void setGame​(boolean game,
                            java.lang.Class<? extends IPlayerIdGenerator> customPlayerIdGeneratorClass)
        Specified by:
        setGame in interface Room
      • setGame

        public void setGame​(boolean game)
        Specified by:
        setGame in interface Room
      • isHidden

        public boolean isHidden()
        Checks if the Game is hidden. The hidden attribute doesn't change the Room normal behavior however it provides a flag that can be used on the client side to hide it from the Room List
        Specified by:
        isHidden in interface Room
        Returns:
        true if the Room is 'hidden'
      • setHidden

        public void setHidden​(boolean hidden)
        Specified by:
        setHidden in interface Room
      • isActive

        public boolean isActive()
        Return true if the Room is active in the Zone. When a Room is not active it will refuse any join request
        Specified by:
        isActive in interface Room
        Returns:
        true if the Room is active
      • setActive

        public void setActive​(boolean flag)
        Specified by:
        setActive in interface Room
      • getPlayersList

        public java.util.List<User> getPlayersList()
        For Game Rooms: get all Players in the Room (same as all User without the Spectators)
        Specified by:
        getPlayersList in interface Room
        Returns:
        all Players in the Room
      • getProperty

        public java.lang.Object getProperty​(java.lang.Object key)
        Get any custom property attached to this Room.
        Specified by:
        getProperty in interface Room
        Returns:
        the value
      • getProperties

        public java.util.concurrent.ConcurrentMap<java.lang.Object,​java.lang.Object> getProperties()
        Get the map with all Room properties
        Specified by:
        getProperties in interface Room
        Returns:
        the map with all User properties
      • getSize

        public RoomSize getSize()
        Return the current Room size
        Specified by:
        getSize in interface Room
        Returns:
        the current Room size
        See Also:
        RoomSize
      • removeProperty

        public void removeProperty​(java.lang.Object key)
        Removes a custom property
        Specified by:
        removeProperty in interface Room
        Parameters:
        key - the name of the property
      • getSpectatorsList

        public java.util.List<User> getSpectatorsList()
        For Game Rooms: get all Spectators in the Room (same as all User without the Players)
        Specified by:
        getSpectatorsList in interface Room
        Returns:
        all Spectators in the Room
      • getUserById

        public User getUserById​(int id)
        Specified by:
        getUserById in interface Room
        Parameters:
        id - the User id
        Returns:
        the User with the provided id, null if no User was found in the Room
      • getUserByName

        public User getUserByName​(java.lang.String name)
        Specified by:
        getUserByName in interface Room
        Parameters:
        name - the User name
        Returns:
        the User with the provided name, null if no User was found in the Room
      • getUserBySession

        public User getUserBySession​(ISession session)
        Specified by:
        getUserBySession in interface Room
        Parameters:
        session - the User session
        Returns:
        the User with the provided session, null if no User was found in the Room
      • getUserByPlayerId

        public User getUserByPlayerId​(int playerId)
        Get the User currently having the specified playerId (Game Room only)
        Specified by:
        getUserByPlayerId in interface Room
        Parameters:
        playerId - the player id
        Returns:
        the User, null if no User exists with that player id
      • getUserList

        public java.util.List<User> getUserList()
        Get all Users in the Room
        Specified by:
        getUserList in interface Room
        Returns:
        all Users in the Room
      • getSessionList

        public java.util.List<ISession> getSessionList()
        Get all the User Sessions in the Room
        Specified by:
        getSessionList in interface Room
        Returns:
        all the User Sessions in the Room
      • getVariablesCount

        public int getVariablesCount()
        Get the total amount of Room Variables for this Room
        Specified by:
        getVariablesCount in interface Room
        Returns:
        the total amount of Room Variables for this Room
      • getVariable

        public RoomVariable getVariable​(java.lang.String varName)
        Get a Room Variable
        Specified by:
        getVariable in interface Room
        Parameters:
        varName - the name of the variable
        Returns:
        the variable
        See Also:
        SFSRoomVariable
      • getVariables

        public java.util.List<RoomVariable> getVariables()
        Get the full list of Room Variables in the Room
        Specified by:
        getVariables in interface Room
        Returns:
        the complete list of Room Variables in the Room
      • getVariablesCreatedByUser

        public java.util.List<RoomVariable> getVariablesCreatedByUser​(User user)
        Get a list of Room Variables created by a specific User
        Specified by:
        getVariablesCreatedByUser in interface Room
        Parameters:
        user - the User
        Returns:
        list of Room Variables created by the provided User
      • containsProperty

        public boolean containsProperty​(java.lang.Object key)
        Checks whether a custom property exists or not
        Specified by:
        containsProperty in interface Room
        Parameters:
        key - the name of the property
        Returns:
        true if the property exists
      • removeVariable

        public void removeVariable​(java.lang.String varName)
        Specified by:
        removeVariable in interface Room
      • getCapacity

        public int getCapacity()
        Return the capacity of the Room (maximum number of clients that can be contained). In a Game Room this value is the sum of the maxUser + maxSpectators
        Specified by:
        getCapacity in interface Room
        Returns:
        the Room capacity
      • setCapacity

        public void setCapacity​(int maxUser,
                                int maxSpectators)
        Specified by:
        setCapacity in interface Room
      • getMaxRoomVariablesAllowed

        public int getMaxRoomVariablesAllowed()
        Return the maximum number of Room Variables allowed in the Room.
        Specified by:
        getMaxRoomVariablesAllowed in interface Room
        Returns:
        the max number of Room Variables allowed in the Room
      • isFlagSet

        public boolean isFlagSet​(SFSRoomSettings flag)
        Checks whether a certain Room Setting is set
        Specified by:
        isFlagSet in interface Room
        Parameters:
        flag - the flag
        Returns:
        true if the flag is set
        See Also:
        SFSRoomSettings
      • isUseWordsFilter

        public boolean isUseWordsFilter()
        Check if the word filter is used in this Room (applied to Public Messages)
        Specified by:
        isUseWordsFilter in interface Room
        Returns:
        true if the word filter is used in this Room (applied to Public Messages)
      • setUseWordsFilter

        public void setUseWordsFilter​(boolean useWordsFilter)
        Toggle the word filter in this Room (applied to Public Messages)
        Specified by:
        setUseWordsFilter in interface Room
      • setProperty

        public void setProperty​(java.lang.Object key,
                                java.lang.Object value)
        Attach a custom (server-side only) property to the Room object
        Specified by:
        setProperty in interface Room
        Parameters:
        key - the property name
        value - the property value
      • setVariables

        public void setVariables​(java.util.List<RoomVariable> variables,
                                 boolean overrideOwnership)
        Specified by:
        setVariables in interface Room
      • isAllowOwnerInvitations

        public boolean isAllowOwnerInvitations()
        True if the Room allows only its creator to send JoinRoomInvitations. If false, any non spectator User joined in the Room can invite other people.
        Specified by:
        isAllowOwnerInvitations in interface Room
        Returns:
        True if the Room allows only its creator to send JoinRoomInvitations. If false, any non spectator User joined in the Room can invite other people.
      • setAllowOwnerInvitations

        public void setAllowOwnerInvitations​(boolean flag)
        Set to 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.
        Specified by:
        setAllowOwnerInvitations in interface Room
        Parameters:
        flag - 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.
      • isSuppressUserList

        public boolean isSuppressUserList()
        Specified by:
        isSuppressUserList in interface Room
      • setSuppressUserList

        public void setSuppressUserList​(boolean value)
        Specified by:
        setSuppressUserList in interface Room
      • destroy

        public void destroy()
        Specified by:
        destroy in interface Room
      • containsVariable

        public boolean containsVariable​(java.lang.String varName)
        Checks if a certain Room Variable name exists
        Specified by:
        containsVariable in interface Room
        Parameters:
        varName - the variable name
        Returns:
        true if a Room Variable with the provided name exists
      • containsUser

        public boolean containsUser​(java.lang.String name)
        Checks if the specified User is joined in the Room
        Specified by:
        containsUser in interface Room
        Parameters:
        name - the User name
        Returns:
        true if the User is present (joined) in this Room
      • containsUser

        public boolean containsUser​(User user)
        Checks if the specified User is joined in the Room
        Specified by:
        containsUser in interface Room
        Parameters:
        user - the User
        Returns:
        true if the User is present (joined) in this Room
      • removeUser

        public void removeUser​(User user)
        Specified by:
        removeUser in interface Room
      • getLifeTime

        public long getLifeTime()
        Obtain the time of existence of the Room
        Specified by:
        getLifeTime in interface Room
        Returns:
        the time of existence of the Room in milliseconds
      • isEmpty

        public boolean isEmpty()
        Checks whether the Room is empty
        Specified by:
        isEmpty in interface Room
        Returns:
        true if the Room is empty
      • isFull

        public boolean isFull()
        Checks whether the Room is full. In game rooms this check will return true only if all player slots are taken.
        Specified by:
        isFull in interface Room
        Returns:
        true if the Room is full
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • getExtension

        public ISFSExtension getExtension()
        Get the extension connected to this Room, if any
        Specified by:
        getExtension in interface Room
        Returns:
        the extension attached to this Room, null if no extension exists
      • toSFSArray

        public ISFSArray toSFSArray​(boolean globalRoomVarsOnly)
        Specified by:
        toSFSArray in interface Room
      • getDump

        public java.lang.String getDump()
        Get a dump of all Room attributes/settings. Useful for debugging
        Specified by:
        getDump in interface Room
        Returns:
        a dump of all Room attributes/settings
      • getAdminHelper

        public com.smartfoxserver.v2.util.IAdminHelper getAdminHelper()
      • setAdminHelper

        public void setAdminHelper​(com.smartfoxserver.v2.util.IAdminHelper helper)
      • setProperties

        public void setProperties​(java.util.Map<java.lang.Object,​java.lang.Object> props)