Class SFSUser

  • All Implemented Interfaces:
    User

    public class SFSUser
    extends java.lang.Object
    implements User

    Overview

    The User object represents a connected and logged in client in the system. Each User carries a Session object which represents his connection to the server, including many utility methods for determining what kind of User this is (real User, NPC), the type of connection, the amount of data transferred and more.

    Also each User provides a number of essential services:

    • Keep track of the User's created and joined Room(s)
    • Keep track of Group event subscriptions
    • Store User Variables and Buddy Variables and settings
    • Keep track of every playerId of the User for each Game Room joined
    In order to generate a User object in the system the client must execute two steps:
    1. Establish a connection to the server and perform a successful handshake via the client API. This will create a new Session in the system.
    2. Perform a successful Login request which will in turn generate the new User in the chosen Zone.
    Once the User is successfully added to the system the client is able to perform any request to the Server API or the custom user Extensions.
    See Also:
    Zone, SFSApi, Session
    • Constructor Detail

      • SFSUser

        public SFSUser​(ISession session)
      • SFSUser

        public SFSUser​(java.lang.String name,
                       ISession session)
    • Method Detail

      • getBuddyProperties

        public BuddyProperties getBuddyProperties()
        Description copied from interface: User
        Get the BuddyProperty object
        Specified by:
        getBuddyProperties in interface User
        Returns:
        the buddy properties
      • getId

        public int getId()
        Description copied from interface: User
        Get the unique user ID
        Specified by:
        getId in interface User
        Returns:
        the user id
      • getPrivilegeId

        public short getPrivilegeId()
        Description copied from interface: User
        Return the Privilege ID of the User. Default privilege IDs are:
        • 0: guest
        • 1: regular user
        • 2: moderator
        • 3: administrator
        Specified by:
        getPrivilegeId in interface User
        Returns:
        the privilege id
      • setPrivilegeId

        public void setPrivilegeId​(short id)
        Specified by:
        setPrivilegeId in interface User
      • isSuperUser

        public boolean isSuperUser()
        Description copied from interface: User
        Check if the User has SuperUser capabilities (kicking/banning etc...)
        Specified by:
        isSuperUser in interface User
        Returns:
        true if the User has SuperUser capabilities
      • isConnected

        public boolean isConnected()
        Description copied from interface: User
        Check if the User is connected
        Specified by:
        isConnected in interface User
        Returns:
        true if the user has an active connection
      • isLocal

        public boolean isLocal()
        Description copied from interface: User
        Returns true if the User is connected to the local cluster node
        Specified by:
        isLocal in interface User
        Returns:
        true if the user is local to the cluster node
      • setConnected

        public void setConnected​(boolean flag)
        Specified by:
        setConnected in interface User
      • isJoining

        public boolean isJoining()
        Specified by:
        isJoining in interface User
      • setJoining

        public void setJoining​(boolean flag)
        Specified by:
        setJoining in interface User
      • getIpAddress

        public java.lang.String getIpAddress()
        Description copied from interface: User
        Return the User IP address
        Specified by:
        getIpAddress in interface User
        Returns:
        the IP address
      • getMaxAllowedVariables

        public int getMaxAllowedVariables()
        Description copied from interface: User
        Get the maximum allowed User Variables for this User
        Specified by:
        getMaxAllowedVariables in interface User
        Returns:
        the number of variables
      • setMaxAllowedVariables

        public void setMaxAllowedVariables​(int max)
        Specified by:
        setMaxAllowedVariables in interface User
      • getCreatedRooms

        public java.util.List<Room> getCreatedRooms()
        Description copied from interface: User
        Get a list of Rooms created by this User
        Specified by:
        getCreatedRooms in interface User
        Returns:
        the list of Rooms (if any)
      • addJoinedRoom

        public void addJoinedRoom​(Room room)
        Specified by:
        addJoinedRoom in interface User
      • getOwnedRoomsCount

        public int getOwnedRoomsCount()
        Description copied from interface: User
        Get the number of Rooms created by the User
        Specified by:
        getOwnedRoomsCount in interface User
        Returns:
        the number of Rooms created by the User
      • subscribeGroup

        public void subscribeGroup​(java.lang.String id)
        Specified by:
        subscribeGroup in interface User
      • unsubscribeGroup

        public void unsubscribeGroup​(java.lang.String id)
        Specified by:
        unsubscribeGroup in interface User
      • getSubscribedGroups

        public java.util.List<java.lang.String> getSubscribedGroups()
        Description copied from interface: User
        Get a list of Room Groups subscribed by the User
        Specified by:
        getSubscribedGroups in interface User
        Returns:
        the list of groups
      • isSubscribedToGroup

        public boolean isSubscribedToGroup​(java.lang.String id)
        Description copied from interface: User
        Check if the User is subscribed to a certain Room Group
        Specified by:
        isSubscribedToGroup in interface User
        Parameters:
        id - the id of the group
        Returns:
        true if the User is currently subscribed to the group
      • isNpc

        public boolean isNpc()
        Description copied from interface: User
        Returns the NPC flag
        Specified by:
        isNpc in interface User
        Returns:
        true if the user is an NPC
      • getJoinedRooms

        public java.util.List<Room> getJoinedRooms()
        Description copied from interface: User
        A list of Rooms currently joined by the User
        Specified by:
        getJoinedRooms in interface User
        Returns:
        the list of Rooms
      • getZone

        public Zone getZone()
        Description copied from interface: User
        Get the Zone where the User is currently logged in
        Specified by:
        getZone in interface User
        Returns:
        the Zone
      • setZone

        public void setZone​(Zone currentZone)
        Specified by:
        setZone in interface User
      • getLastJoinedRoom

        public Room getLastJoinedRoom()
        Description copied from interface: User
        A reference to the last Room that was joined by this User
        Specified by:
        getLastJoinedRoom in interface User
        Returns:
        the last joined Room
      • isJoinedInRoom

        public boolean isJoinedInRoom​(Room room)
        Description copied from interface: User
        Check if a User is joined in a Room
        Specified by:
        isJoinedInRoom in interface User
        Parameters:
        room - the Room
        Returns:
        true if the User is joined in the passed Room
      • getLoginTime

        public long getLoginTime()
        Description copied from interface: User
        Get the user login time (Unix timestamp)
        Specified by:
        getLoginTime in interface User
        Returns:
        login time
      • setLastLoginTime

        public void setLastLoginTime​(long lastLoginTime)
        Specified by:
        setLastLoginTime in interface User
      • getName

        public java.lang.String getName()
        Description copied from interface: User
        Get the User name
        Specified by:
        getName in interface User
        Returns:
        the user name
      • setName

        public void setName​(java.lang.String name)
        Description copied from interface: User
        DO NOT use this method User names cannot be changed at runtime: they are unique and decided at login time exclusively. If you wish to alter the username of a specific client it can be done a login time as described in this article
        Specified by:
        setName in interface User
      • getPlayerId

        public int getPlayerId()
        Description copied from interface: User
        Get the playerId of the User (if applicable).
        The User should be currently joined in a Game Room for this method to return a meaningful value.
        playerId == 0, if the Room is not a Game Room
        playerID > 0, if the Room is a Game Room
        Specified by:
        getPlayerId in interface User
        Returns:
        the player id
      • getPlayerId

        public int getPlayerId​(Room room)
        Description copied from interface: User
        Get the playerId for the User in a specific Room
        Specified by:
        getPlayerId in interface User
        Returns:
        the playerId
        See Also:
        User.getPlayerId()
      • getPlayerIds

        public java.util.Map<Room,​java.lang.Integer> getPlayerIds()
        Description copied from interface: User
        Get a map of playerId(s) per Room
        This method can be used when a player is currently engaged in multiple games at the same time
        Specified by:
        getPlayerIds in interface User
        Returns:
        the map of playerIds per room
        See Also:
        User.getPlayerId()
      • setPlayerId

        public void setPlayerId​(int id,
                                Room room)
        Specified by:
        setPlayerId in interface User
      • isPlayer

        public boolean isPlayer()
        Description copied from interface: User
        Check if the User is a Player in the current Room (only for Game Rooms)
        Specified by:
        isPlayer in interface User
        Returns:
        true if the User is a player in the current Room
      • isSpectator

        public boolean isSpectator()
        Description copied from interface: User
        Check if the User is a Spectator in the current Room (only for Game Rooms)
        Specified by:
        isSpectator in interface User
        Returns:
        true if the User is a spectator in the current Room
      • isPlayer

        public boolean isPlayer​(Room room)
        Description copied from interface: User
        Check if the User is Player in a specific Room
        Specified by:
        isPlayer in interface User
        Parameters:
        room - the room
        Returns:
        true if the User is a player in the specified Room
      • isSpectator

        public boolean isSpectator​(Room room)
        Description copied from interface: User
        Check if the User is Spectator in a specific Room
        Specified by:
        isSpectator in interface User
        Parameters:
        room - the rooom
        Returns:
        true if the User is a spectator in the specified Room
      • getProperty

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

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

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

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

        public void removeProperty​(java.lang.Object key)
        Description copied from interface: User
        Removes a custom property
        Specified by:
        removeProperty in interface User
        Parameters:
        key - the name of the property
      • getSession

        public ISession getSession()
        Description copied from interface: User
        Get the session object linked to this User
        Specified by:
        getSession in interface User
        Returns:
        the user sessions object
      • getVariablesCount

        public int getVariablesCount()
        Description copied from interface: User
        Return the number of UserVariables for this User
        Specified by:
        getVariablesCount in interface User
        Returns:
        the number of UserVariables
      • getVariable

        public UserVariable getVariable​(java.lang.String varName)
        Description copied from interface: User
        Return a UserVariable. It can return null if the UserVariable doesn't exist
        Specified by:
        getVariable in interface User
        Parameters:
        varName - the name of the variable
        Returns:
        the UserVariable
      • containsVariable

        public boolean containsVariable​(java.lang.String varName)
        Description copied from interface: User
        Checks whether or not the User has a specific UserVariable
        Specified by:
        containsVariable in interface User
        Parameters:
        varName - the name of the variable
        Returns:
        true if the UserVariable exists, false otherwise
      • getVariables

        public java.util.List<UserVariable> getVariables()
        Description copied from interface: User
        Obtain the full list of UserVariables
        Specified by:
        getVariables in interface User
        Returns:
        the list of UserVariables
      • removeVariable

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

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

        public void setLastRequestTime​(long lastRequestTime)
        Specified by:
        setLastRequestTime in interface User
      • setBadWordsWarnings

        public void setBadWordsWarnings​(int badWordsWarnings)
        Specified by:
        setBadWordsWarnings in interface User
      • getFloodWarnings

        public int getFloodWarnings()
        Specified by:
        getFloodWarnings in interface User
      • setFloodWarnings

        public void setFloodWarnings​(int floodWarnings)
        Specified by:
        setFloodWarnings in interface User
      • setExtFloodWarnings

        public void setExtFloodWarnings​(int count)
        Specified by:
        setExtFloodWarnings in interface User
      • getLastLoginTime

        public long getLastLoginTime()
      • isBeingKicked

        public boolean isBeingKicked()
        Specified by:
        isBeingKicked in interface User
      • setBeingKicked

        public void setBeingKicked​(boolean flag)
        Specified by:
        setBeingKicked in interface User
      • setReconnectionSeconds

        public void setReconnectionSeconds​(int seconds)
        Specified by:
        setReconnectionSeconds in interface User
      • equals

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

        public java.lang.String getDump()
        Description copied from interface: User
        Return a full dump of the User properties, useful for debugging
        Specified by:
        getDump in interface User
        Returns:
        the User debug info
      • getAdminHelper

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

        public void setAdminHelper​(com.smartfoxserver.v2.util.IAdminHelper adminHelper)
      • setLastProxyList

        public void setLastProxyList​(java.util.List<User> proxyList)
        Specified by:
        setLastProxyList in interface User
      • getCountry

        public Country getCountry()
        Description copied from interface: User
        If the geolocation service is enabled in the Zone it will return the location of the user
        Specified by:
        getCountry in interface User
        Returns:
        the location of the user, null if the geolocation DB did not provide a match
      • getPersistentRoomVarReferences

        public java.util.Set<java.lang.Integer> getPersistentRoomVarReferences()
        Specified by:
        getPersistentRoomVarReferences in interface User