Class SFSUser

java.lang.Object
sfs3.client.entities.SFSUser
All Implemented Interfaces:
User

public class SFSUser extends Object implements User
The SFSUser object represents a client logged in SmartFoxServer.

The SmartFoxServer 3 client API are not aware of all the clients (users) connected to the server, but only of those that are in the same Rooms joined by the current client; this reduces the traffic between the client and the server considerably. In order to interact with other users the client should join other Rooms or use the Buddy List system to keep track of and interact with friends.

See Also:
  • Field Details

    • id

      protected int id
    • privilegeId

      protected int privilegeId
    • name

      protected String name
    • isItMe

      protected boolean isItMe
    • variables

      protected Map<String,UserVariable> variables
    • playerIdByRoomId

      protected Map<Integer,Integer> playerIdByRoomId
    • userManager

      protected IUserManager userManager
    • aoiEntryPoint

      protected Vec3D aoiEntryPoint
  • Constructor Details

    • SFSUser

      public SFSUser(int id, String name)
    • SFSUser

      public SFSUser(int id, String name, boolean isItMe)
      Creates a new SFSUser instance.

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

      Parameters:
      id - The user id.
      name - The user name.
      isItMe - If true, the user being created corresponds to the current client.
  • Method Details

    • fromSFSArray

      public static User fromSFSArray(ISFSArray sfsa, Room room)
      Internal
    • fromSFSArray

      public static User fromSFSArray(ISFSArray sfsa)
      Internal
    • getId

      public int getId()
      Description copied from interface: User
      The id of this user. It is unique and it is generated by the server when the user is created.
      Specified by:
      getId in interface User
    • getName

      public String getName()
      Description copied from interface: User
      The name of this user. Two users in the same Zone can't have the same name (case sensitive)
      Specified by:
      getName in interface User
    • getPlayerId

      public int getPlayerId()
      Description copied from interface: User
      Returns the id of this user as a player in a Game Room.

      This property differs from the id property and it's used to indicate which player number is assigned to a user inside a Game Room. For example, in a Game Room for 5 players the first client joining it will have playerId equal to 1, the second will have it equal to 2 and so forth. When a user leaves the Room the player slot is freed up and the next user joining the Room will take it.

      The playerId property applies to Game Rooms only; in standard Rooms it is always 0. Also, in Game Rooms a playerId value lower than 0 indicates that the user is a spectator.

      If the user is inside multiple Game Rooms at the same time, a different playerId value will be assigned to him in each Room. In this case this property returns the value corresponding to the last joined Room; in order to obtain the playerId value in a specific Room, use the getPlayerId() method.

      Specified by:
      getPlayerId in interface User
      See Also:
    • isPlayer

      public boolean isPlayer()
      Description copied from interface: User
      Indicates whether this user is a player (playerId greater than 0) in the last joined Room or not. Non-Game Rooms always return false.

      If the user is inside multiple Game Rooms at the same time, use the isPlayerInRoom() method.

      Specified by:
      isPlayer in interface User
      See Also:
    • isSpectator

      public boolean isSpectator()
      Description copied from interface: User
      Indicates whether this user is a spectator (playerId lower than 0) in the last joined Room or not. Non-Game Rooms always return false.

      If the user is inside multiple Game Rooms at the same time, use the isSpectatorInRoom() method.

      Specified by:
      isSpectator in interface User
      See Also:
    • getPlayerId

      public int getPlayerId(Room room)
      Description copied from interface: User
      Returns the playerId value of this user in the passed Room. See the playerId property description for more informations.
      Specified by:
      getPlayerId in interface User
      Parameters:
      room - The Room object representing the Room to retrieve the player id from.
      Returns:
      The playerId of this user in the passed Room.
      See Also:
    • setPlayerId

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

      public void removePlayerId(Room room)
      Specified by:
      removePlayerId in interface User
      Internal
    • getPrivilegeId

      public int getPrivilegeId()
      Description copied from interface: User
      Returns the id which identifies the privilege level of this user.

      NOTE: setting the privilegeId property manually has no effect on the server and can disrupt the API functioning. Privileges are assigned to the user by the server when the user logs in.

      Specified by:
      getPrivilegeId in interface User
      See Also:
    • setPrivilegeId

      public void setPrivilegeId(int privilegeId)
      Specified by:
      setPrivilegeId in interface User
      Internal
    • getUserManager

      public IUserManager getUserManager()
      Description copied from interface: User
      Returns a reference to the User Manager which manages this user.

      NOTE: setting the userManager property manually has no effect on the server and can disrupt the API functioning.

      Specified by:
      getUserManager in interface User
    • setUserManager

      public void setUserManager(IUserManager userManager)
      Specified by:
      setUserManager in interface User
      Internal
    • isGuest

      public boolean isGuest()
      Description copied from interface: User
      Indicates whether this user logged in as a guest or not. Guest users have the privilegeId property se to UserPrivileges.GUEST.
      Specified by:
      isGuest in interface User
      Returns:
      true if this user is a guest.
      See Also:
    • isStandardUser

      public boolean isStandardUser()
      Description copied from interface: User
      Indicates whether this user logged in as a standard user or not. Standard users have the privilegeId property se to UserPrivileges.STANDARD.
      Specified by:
      isStandardUser in interface User
      Returns:
      true if this user is a standard user.
      See Also:
    • isModerator

      public boolean isModerator()
      Description copied from interface: User
      Indicates whether this user logged in as a moderator or not. Moderator users have the privilegeId property set to UserPrivileges.MODERATOR.
      Specified by:
      isModerator in interface User
      Returns:
      true if this user is a moderator.
      See Also:
    • isAdmin

      public boolean isAdmin()
      Description copied from interface: User
      Indicates whether this user logged in as an administrator or not. Administrator users have the privilegeId property set to UserPrivileges.ADMINISTRATOR.
      Specified by:
      isAdmin in interface User
      Returns:
      true if this user is an administrator.
      See Also:
    • isPlayerInRoom

      public boolean isPlayerInRoom(Room room)
      Description copied from interface: User
      Indicates whether this user is a player (playerId greater than 0) in the passed Room or not. Non-Game Rooms always return false.

      If a user can join one Game Rooms at a time only, use the isPlayer property.

      Specified by:
      isPlayerInRoom in interface User
      Parameters:
      room - The Room object representing the Room where to check if this user is a player.
      Returns:
      true if this user is a player in the passed Room.
      See Also:
    • isSpectatorInRoom

      public boolean isSpectatorInRoom(Room room)
      Description copied from interface: User
      Indicates whether this user is a spectator (playerId lower than 0) in the passed Room or not. Non-Game Rooms always return false.

      If a user can join one Game Rooms at a time only, use the isSpectator property.

      Specified by:
      isSpectatorInRoom in interface User
      Parameters:
      room - The Room object representing the Room where to check if this user is a spectator.
      Returns:
      true if this user is a spectator in the passed Room.
      See Also:
    • isJoinedInRoom

      public boolean isJoinedInRoom(Room room)
      Description copied from interface: User
      Indicates whether this user joined the passed Room or not.
      Specified by:
      isJoinedInRoom in interface User
      Parameters:
      room - The Room object representing the Room where to check the user presence.
      Returns:
      true if this user is inside the passed Room.
    • isItMe

      public boolean isItMe()
      Description copied from interface: User
      Indicates if this User object represents the current client.
      Specified by:
      isItMe in interface User
      See Also:
    • getVariables

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

      public UserVariable getVariable(String varName)
      Description copied from interface: User
      Retrieves a User Variable from its name.
      Specified by:
      getVariable in interface User
      Parameters:
      varName - The name of the User Variable to be retrieved.
      Returns:
      The UserVariable object representing the User Variable, or null if no User Variable with the passed name is associated with this user.
      See Also:
    • setVariable

      public void setVariable(UserVariable userVariable)
      Specified by:
      setVariable in interface User
    • setVariables

      public void setVariables(List<? extends UserVariable> userVariables)
      Specified by:
      setVariables in interface User
      Internal
    • containsVariable

      public boolean containsVariable(String name)
      Description copied from interface: User
      Indicates whether this user has the specified User Variable set or not.
      Specified by:
      containsVariable in interface User
      Parameters:
      name - The name of the User Variable whose existence must be checked.
      Returns:
      true if a User Variable with the passed name is set for this user.
    • getAOIEntryPoint

      public Vec3D getAOIEntryPoint()
      Description copied from interface: User
      Returns the entry point within the User's AOI where this client "appeared" with the last PROXIMITY_LIST_UPDATE event. This field is populated only if the MMORoom is configured to receive this data.
      Specified by:
      getAOIEntryPoint in interface User
      See Also:
    • setAOIEntryPoint

      public void setAOIEntryPoint(Vec3D aoiEntryPoint)
      Specified by:
      setAOIEntryPoint in interface User
    • 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 user id, name and a boolean indicating if the SFSUser object represents the current client.
      Overrides:
      toString in class Object
      Returns:
      The string representation of the SFSUser object.
    • replaceVariables

      public void replaceVariables(List<UserVariable> vars)
      Internal