Class SFSUser
- java.lang.Object
-
- sfs2x.client.entities.SFSUser
-
- All Implemented Interfaces:
User
public class SFSUser extends java.lang.Object implements User
The SFSUser object represents a client logged in SmartFoxServer.The SmartFoxServer 2X 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:
SmartFox.userManager
,SmartFox.buddyManager
,JoinRoomRequest
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsVariable(java.lang.String name)
Indicates whether this user has the specified User Variable set or not.static User
fromSFSArray(com.smartfoxserver.v2.entities.data.ISFSArray sfsa)
* API internal usage only *static User
fromSFSArray(com.smartfoxserver.v2.entities.data.ISFSArray sfsa, Room room)
* API internal usage only *Vec3D
getAOIEntryPoint()
Returns the entry point within the User's AOI where this client "appeared" with the last PROXIMITY_LIST_UPDATE event.int
getId()
Indicates the id of this user.java.lang.String
getName()
Indicates the name of this user.int
getPlayerId()
Returns the id of this user as a player in a Game Room.int
getPlayerId(Room room)
Returns the playerId value of this user in the passed Room.int
getPrivilegeId()
Returns the id which identifies the privilege level of this user.java.util.Map<java.lang.String,java.lang.Object>
getProperties()
Defines a generic utility object that can be used to store custom User data.IUserManager
getUserManager()
Returns a reference to the User Manager which manages this user.UserVariable
getVariable(java.lang.String varName)
Retrieves a User Variable from its name.java.util.List<UserVariable>
getVariables()
Retrieves all the User Variables of this user.boolean
isAdmin()
Indicates whether this user logged in as an administrator or not.boolean
isGuest()
Indicates whether this user logged in as a guest or not.boolean
isItMe()
Indicates if this User object represents the current client.boolean
isJoinedInRoom(Room room)
Indicates whether this user joined the passed Room or not.boolean
isModerator()
Indicates whether this user logged in as a moderator or not.boolean
isPlayer()
Indicates whether this user is a player (playerId greater than0
) in the last joined Room or not.boolean
isPlayerInRoom(Room room)
Indicates whether this user is a player (playerId greater than0
) in the passed Room or not.boolean
isSpectator()
Indicates whether this user is a spectator (playerId lower than0
) in the last joined Room or not.boolean
isSpectatorInRoom(Room room)
Indicates whether this user is a spectator (playerId lower than0
) in the passed Room or not.boolean
isStandardUser()
Indicates whether this user logged in as a standard user or not.void
removePlayerId(Room room)
* API internal usage only *void
setAOIEntryPoint(Vec3D aoiEntryPoint)
* API internal usage only *void
setPlayerId(int id, Room room)
* API internal usage only *void
setPrivilegeId(int privilegeId)
* API internal usage only *void
setProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
Defines a generic utility object that can be used to store custom User data.void
setUserManager(IUserManager userManager)
* API internal usage only *void
setVariable(UserVariable userVariable)
* API internal usage only *void
setVariables(java.util.List<? extends UserVariable> userVariables)
* API internal usage only *java.lang.String
toString()
Returns a string that contains the user id, name and a boolean indicating if the SFSUser object represents the current client.
-
-
-
Constructor Detail
-
SFSUser
public SFSUser(int id, java.lang.String name)
-
SFSUser
public SFSUser(int id, java.lang.String name, boolean isItMe)
Creates a new SFSUser instance.NOTE: developers never instantiate a SFSUser manually: this is done by the SmartFoxServer 2X API internally.
- Parameters:
id
- The user id.name
- The user name.isItMe
- Iftrue
, the user being created corresponds to the current client.
-
-
Method Detail
-
fromSFSArray
public static User fromSFSArray(com.smartfoxserver.v2.entities.data.ISFSArray sfsa, Room room)
* API internal usage only *
-
fromSFSArray
public static User fromSFSArray(com.smartfoxserver.v2.entities.data.ISFSArray sfsa)
* API internal usage only *
-
getId
public int getId()
Description copied from interface:User
Indicates the id of this user. It is unique and it is generated by the server when the user is created.
-
getName
public java.lang.String getName()
Description copied from interface:User
Indicates the name of this user. Two users in the same Zone can't have the same name.
-
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 to2
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 than0
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 interfaceUser
- See Also:
User.getPlayerId(Room)
-
isPlayer
public boolean isPlayer()
Description copied from interface:User
Indicates whether this user is a player (playerId greater than0
) in the last joined Room or not. Non-Game Rooms always returnfalse
.If the user is inside multiple Game Rooms at the same time, use the isPlayerInRoom() method.
- Specified by:
isPlayer
in interfaceUser
- See Also:
User.getPlayerId()
,User.isPlayerInRoom(Room)
,User.isSpectator()
-
isSpectator
public boolean isSpectator()
Description copied from interface:User
Indicates whether this user is a spectator (playerId lower than0
) in the last joined Room or not. Non-Game Rooms always returnfalse
.If the user is inside multiple Game Rooms at the same time, use the isSpectatorInRoom() method.
- Specified by:
isSpectator
in interfaceUser
- See Also:
User.getPlayerId()
,User.isSpectatorInRoom(Room)
,User.isPlayer()
-
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 interfaceUser
- 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:
User.getPlayerId()
-
setPlayerId
public void setPlayerId(int id, Room room)
* API internal usage only *- Specified by:
setPlayerId
in interfaceUser
-
removePlayerId
public void removePlayerId(Room room)
* API internal usage only *- Specified by:
removePlayerId
in interfaceUser
-
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 interfaceUser
- See Also:
UserPrivileges
-
setPrivilegeId
public void setPrivilegeId(int privilegeId)
* API internal usage only *- Specified by:
setPrivilegeId
in interfaceUser
-
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 interfaceUser
-
setUserManager
public void setUserManager(IUserManager userManager)
* API internal usage only *- Specified by:
setUserManager
in interfaceUser
-
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 interfaceUser
- Returns:
true
if this user is a guest.- See Also:
User.isStandardUser()
,User.isModerator()
,User.isAdmin()
,User.getPrivilegeId()
,UserPrivileges.GUEST
-
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 interfaceUser
- Returns:
true
if this user is a standard user.- See Also:
User.isGuest()
,User.isModerator()
,User.isAdmin()
,User.getPrivilegeId()
,UserPrivileges.STANDARD
-
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 interfaceUser
- Returns:
true
if this user is a moderator.- See Also:
User.isGuest()
,User.isStandardUser()
,User.isAdmin()
,User.getPrivilegeId()
,UserPrivileges.MODERATOR
-
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 interfaceUser
- Returns:
true
if this user is an administrator.- See Also:
User.isGuest()
,User.isStandardUser()
,User.isModerator()
,User.getPrivilegeId()
,UserPrivileges.ADMINISTRATOR
-
isPlayerInRoom
public boolean isPlayerInRoom(Room room)
Description copied from interface:User
Indicates whether this user is a player (playerId greater than0
) in the passed Room or not. Non-Game Rooms always returnfalse
.If a user can join one Game Rooms at a time only, use the isPlayer property.
- Specified by:
isPlayerInRoom
in interfaceUser
- 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:
User.getPlayerId()
,User.isPlayer()
,User.isSpectatorInRoom(Room)
-
isSpectatorInRoom
public boolean isSpectatorInRoom(Room room)
Description copied from interface:User
Indicates whether this user is a spectator (playerId lower than0
) in the passed Room or not. Non-Game Rooms always returnfalse
.If a user can join one Game Rooms at a time only, use the isSpectator property.
- Specified by:
isSpectatorInRoom
in interfaceUser
- 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:
User.getPlayerId()
,User.isSpectator()
,User.isPlayerInRoom(Room)
-
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 interfaceUser
- 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 interfaceUser
- See Also:
SmartFox.getMySelf()
-
getVariables
public java.util.List<UserVariable> getVariables()
Description copied from interface:User
Retrieves all the User Variables of this user.- Specified by:
getVariables
in interfaceUser
- Returns:
- The list of UserVariable objects associated with the user.
- See Also:
UserVariable
,User.getVariable(String)
-
getVariable
public UserVariable getVariable(java.lang.String varName)
Description copied from interface:User
Retrieves a User Variable from its name.- Specified by:
getVariable
in interfaceUser
- 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:
User.getVariables()
,SetUserVariablesRequest
-
setVariable
public void setVariable(UserVariable userVariable)
* API internal usage only *- Specified by:
setVariable
in interfaceUser
-
setVariables
public void setVariables(java.util.List<? extends UserVariable> userVariables)
* API internal usage only *- Specified by:
setVariables
in interfaceUser
-
containsVariable
public boolean containsVariable(java.lang.String name)
Description copied from interface:User
Indicates whether this user has the specified User Variable set or not.- Specified by:
containsVariable
in interfaceUser
- 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.
-
getProperties
public java.util.Map<java.lang.String,java.lang.Object> getProperties()
Description copied from interface:User
Defines a generic utility object that can be used to store custom User data. The values added to this object are for client-side use only and are never transmitted to the server or to the other clients.- Specified by:
getProperties
in interfaceUser
- See Also:
User.setProperties(Map)
-
setProperties
public void setProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
Description copied from interface:User
Defines a generic utility object that can be used to store custom User data. The values added to this object are for client-side use only and are never transmitted to the server or to the other clients.- Specified by:
setProperties
in interfaceUser
- See Also:
User.getProperties()
-
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 interfaceUser
- See Also:
MMORoomSettings
,SFSEvent.PROXIMITY_LIST_UPDATE
-
setAOIEntryPoint
public void setAOIEntryPoint(Vec3D aoiEntryPoint)
Description copied from interface:User
* API internal usage only *- Specified by:
setAOIEntryPoint
in interfaceUser
-
toString
public java.lang.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 classjava.lang.Object
- Returns:
- The string representation of the SFSUser object.
-
-