Class SFSUser

java.lang.Object
com.smartfoxserver.entities.SFSUser
All Implemented Interfaces:
User

public class SFSUser extends 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 its connection to the server.

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
  • Store custom, server-side only properties
  • Keep track of every User's player id for each joined game Room
In order to generate a User 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 generate the new User and add it to the system.
Once the User is successfully added to the system the client is able to send any request to the Server API or to custom user Extensions.
See Also:
  • Constructor Details

  • Method Details

    • 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 (default)
      • 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 privileges (allows to send mod/admin messages and kick/ban Users)
      Specified by:
      isSuperUser in interface User
      Returns:
      true if the User has SuperUser capabilities
    • isAdmin

      public boolean isAdmin()
      Specified by:
      isAdmin in interface User
      Returns:
      true if the User is an Administrator
    • 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
    • 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 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
    • addCreatedRoom

      public void addCreatedRoom(Room room)
      Specified by:
      addCreatedRoom in interface User
    • getCreatedRooms

      public 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)
    • removeCreatedRoom

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

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

      public void removeJoinedRoom(Room room)
      Specified by:
      removeJoinedRoom 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(String id)
      Specified by:
      subscribeGroup in interface User
    • unsubscribeGroup

      public void unsubscribeGroup(String id)
      Specified by:
      unsubscribeGroup in interface User
    • getSubscribedGroups

      public List<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(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
    • disconnect

      public void disconnect(IDisconnectionReason reason)
      Specified by:
      disconnect in interface User
    • 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 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 in milliseconds)
      Specified by:
      getLoginTime in interface User
      Returns:
      login time
    • setLastLoginTime

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

      public 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(String name)
      Specified by:
      setName in interface User
    • getClientType

      public String getClientType()
      Description copied from interface: User
      By default each client API sends a different "signature" identifying the client technology (e.g. Unity, Godot, Javascript) and version of the API.
      Specified by:
      getClientType in interface User
      Returns:
      the string identifying the type of connected client
    • 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
      Parameters:
      room -
      Returns:
      the playerId
      See Also:
    • getPlayerIds

      public Map<Room,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:
    • 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 Room
      Returns:
      true if the User is a spectator in the specified Room
    • getProperty

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

      public ConcurrentMap<Object,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(Object key, 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(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(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(String varName)
      Description copied from interface: User
      Returns the UserVariable with the provided name. Returns null if the UserVariable doesn't exist.
      Specified by:
      getVariable in interface User
      Parameters:
      varName - the name of the variable
      Returns:
      the UserVariable
    • setVariable

      public void setVariable(UserVariable var) throws SFSVariableException
      Specified by:
      setVariable in interface User
      Throws:
      SFSVariableException
    • setVariables

      public void setVariables(List<UserVariable> userVariables) throws SFSVariableException
      Specified by:
      setVariables in interface User
      Throws:
      SFSVariableException
    • containsVariable

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

      public 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(String varName)
      Specified by:
      removeVariable in interface User
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getLastRequestTime

      public long getLastRequestTime()
      Specified by:
      getLastRequestTime in interface User
    • updateLastRequestTime

      public void updateLastRequestTime()
      Specified by:
      updateLastRequestTime in interface User
    • setLastRequestTime

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

      public int getBadWordsWarnings()
      Specified by:
      getBadWordsWarnings 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
    • getExtFloodWarnings

      public int getExtFloodWarnings()
      Specified by:
      getExtFloodWarnings 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
    • getUserVariablesData

      public ISFSArray getUserVariablesData()
      Specified by:
      getUserVariablesData in interface User
    • getUserVariablesData

      public ISFSArray getUserVariablesData(boolean isRecipient)
    • getReconnectionSeconds

      public int getReconnectionSeconds()
      Specified by:
      getReconnectionSeconds in interface User
    • setReconnectionSeconds

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

      public ISFSArray toSFSArray(Room room)
      Specified by:
      toSFSArray in interface User
    • toSFSArray

      public ISFSArray toSFSArray()
      Specified by:
      toSFSArray in interface User
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getDump

      public 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.util.IAdminHelper getAdminHelper()
    • setAdminHelper

      public void setAdminHelper(com.smartfoxserver.util.IAdminHelper adminHelper)
    • getLastProxyList

      public List<User> getLastProxyList()
      Specified by:
      getLastProxyList in interface User
    • setLastProxyList

      public void setLastProxyList(List<User> proxyList)
      Specified by:
      setLastProxyList in interface User
    • getLastMMOItemsList

      public List<BaseMMOItem> getLastMMOItemsList()
      Specified by:
      getLastMMOItemsList in interface User
    • setLastMMOItemsList

      public void setLastMMOItemsList(List<BaseMMOItem> mmoItemsList)
      Specified by:
      setLastMMOItemsList in interface User
    • getCurrentMMORoom

      public MMORoom getCurrentMMORoom()
      Specified by:
      getCurrentMMORoom 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
    • getAudioStreamInfo

      public com.smartfoxserver.entities.audio.AudioStreamInfo getAudioStreamInfo()
      Specified by:
      getAudioStreamInfo in interface User
    • setAudioStreamInfo

      public void setAudioStreamInfo(com.smartfoxserver.entities.audio.AudioStreamInfo info)
      Specified by:
      setAudioStreamInfo in interface User
    • addPersistentRoomVarReference

      public void addPersistentRoomVarReference(Room target)
      Specified by:
      addPersistentRoomVarReference in interface User
    • getPersistentRoomVarReferences

      public Set<Integer> getPersistentRoomVarReferences()
      Specified by:
      getPersistentRoomVarReferences in interface User