Package com.smartfoxserver.v2.entities
Class SFSUser
- java.lang.Object
-
- com.smartfoxserver.v2.entities.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
- Establish a connection to the server and perform a successful handshake via the client API. This will create a new Session in the system.
- Perform a successful Login request which will in turn generate the new User in the chosen Zone.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCreatedRoom(Room room)
void
addJoinedRoom(Room room)
void
addPersistentRoomVarReference(Room target)
boolean
containsProperty(java.lang.Object key)
Checks whether a custom property exists or notboolean
containsVariable(java.lang.String varName)
Checks whether or not the User has a specific UserVariablevoid
disconnect(IDisconnectionReason reason)
boolean
equals(java.lang.Object obj)
com.smartfoxserver.v2.util.IAdminHelper
getAdminHelper()
int
getBadWordsWarnings()
BuddyProperties
getBuddyProperties()
Get the BuddyProperty objectCountry
getCountry()
If the geolocation service is enabled in the Zone it will return the location of the userjava.util.List<Room>
getCreatedRooms()
Get a list of Rooms created by this UserMMORoom
getCurrentMMORoom()
java.lang.String
getDump()
Return a full dump of the User properties, useful for debuggingint
getExtFloodWarnings()
int
getFloodWarnings()
int
getId()
Get the unique user IDjava.lang.String
getIpAddress()
Return the User IP addressjava.util.List<Room>
getJoinedRooms()
A list of Rooms currently joined by the UserRoom
getLastJoinedRoom()
A reference to the last Room that was joined by this Userlong
getLastLoginTime()
java.util.List<BaseMMOItem>
getLastMMOItemsList()
java.util.List<User>
getLastProxyList()
long
getLastRequestTime()
long
getLoginTime()
Get the user login time (Unix timestamp)int
getMaxAllowedVariables()
Get the maximum allowed User Variables for this Userjava.lang.String
getName()
Get the User nameint
getOwnedRoomsCount()
Get the number of Rooms created by the Userjava.util.Set<java.lang.Integer>
getPersistentRoomVarReferences()
int
getPlayerId()
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 Roomint
getPlayerId(Room room)
Get the playerId for the User in a specific Roomjava.util.Map<Room,java.lang.Integer>
getPlayerIds()
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 timeshort
getPrivilegeId()
Return the Privilege ID of the User.java.util.concurrent.ConcurrentMap<java.lang.Object,java.lang.Object>
getProperties()
Get the map with all User propertiesjava.lang.Object
getProperty(java.lang.Object key)
Get any custom property attached to this User.int
getReconnectionSeconds()
ISession
getSession()
Get the session object linked to this Userjava.util.List<java.lang.String>
getSubscribedGroups()
Get a list of Room Groups subscribed by the UserISFSArray
getUserVariablesData()
UserVariable
getVariable(java.lang.String varName)
Return a UserVariable.java.util.List<UserVariable>
getVariables()
Obtain the full list of UserVariablesint
getVariablesCount()
Return the number of UserVariables for this UserZone
getZone()
Get the Zone where the User is currently logged inboolean
isBeingKicked()
boolean
isConnected()
Check if the User is connectedboolean
isJoinedInRoom(Room room)
Check if a User is joined in a Roomboolean
isJoining()
boolean
isLocal()
Returns true if the User is connected to the local cluster nodeboolean
isNpc()
Returns the NPC flagboolean
isPlayer()
Check if the User is a Player in the current Room (only for Game Rooms)boolean
isPlayer(Room room)
Check if the User is Player in a specific Roomboolean
isSpectator()
Check if the User is a Spectator in the current Room (only for Game Rooms)boolean
isSpectator(Room room)
Check if the User is Spectator in a specific Roomboolean
isSubscribedToGroup(java.lang.String id)
Check if the User is subscribed to a certain Room Groupboolean
isSuperUser()
Check if the User has SuperUser capabilities (kicking/banning etc...)void
removeCreatedRoom(Room room)
void
removeJoinedRoom(Room room)
void
removeProperty(java.lang.Object key)
Removes a custom propertyvoid
removeVariable(java.lang.String varName)
void
setAdminHelper(com.smartfoxserver.v2.util.IAdminHelper adminHelper)
void
setBadWordsWarnings(int badWordsWarnings)
void
setBeingKicked(boolean flag)
void
setConnected(boolean flag)
void
setExtFloodWarnings(int count)
void
setFloodWarnings(int floodWarnings)
void
setJoining(boolean flag)
void
setLastLoginTime(long lastLoginTime)
void
setLastMMOItemsList(java.util.List<BaseMMOItem> mmoItemsList)
void
setLastProxyList(java.util.List<User> proxyList)
void
setLastRequestTime(long lastRequestTime)
void
setMaxAllowedVariables(int max)
void
setName(java.lang.String name)
DO NOT use this method User names cannot be changed at runtime: they are unique and decided at login time exclusively.void
setPlayerId(int id, Room room)
void
setPrivilegeId(short id)
void
setProperty(java.lang.Object key, java.lang.Object val)
Attach a custom (server-side only) property to the User objectvoid
setReconnectionSeconds(int seconds)
void
setVariable(UserVariable var)
void
setVariables(java.util.List<UserVariable> userVariables)
void
setZone(Zone currentZone)
void
subscribeGroup(java.lang.String id)
ISFSArray
toSFSArray()
ISFSArray
toSFSArray(Room room)
java.lang.String
toString()
void
unsubscribeGroup(java.lang.String id)
void
updateLastRequestTime()
-
-
-
Method Detail
-
getBuddyProperties
public BuddyProperties getBuddyProperties()
Description copied from interface:User
Get the BuddyProperty object- Specified by:
getBuddyProperties
in interfaceUser
- Returns:
- the buddy properties
-
getId
public int getId()
Description copied from interface:User
Get the unique 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 interfaceUser
- Returns:
- the privilege id
-
setPrivilegeId
public void setPrivilegeId(short id)
- Specified by:
setPrivilegeId
in interfaceUser
-
isSuperUser
public boolean isSuperUser()
Description copied from interface:User
Check if the User has SuperUser capabilities (kicking/banning etc...)- Specified by:
isSuperUser
in interfaceUser
- 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 interfaceUser
- 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
-
setConnected
public void setConnected(boolean flag)
- Specified by:
setConnected
in interfaceUser
-
setJoining
public void setJoining(boolean flag)
- Specified by:
setJoining
in interfaceUser
-
getIpAddress
public java.lang.String getIpAddress()
Description copied from interface:User
Return the User IP address- Specified by:
getIpAddress
in interfaceUser
- 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 interfaceUser
- Returns:
- the number of variables
-
setMaxAllowedVariables
public void setMaxAllowedVariables(int max)
- Specified by:
setMaxAllowedVariables
in interfaceUser
-
addCreatedRoom
public void addCreatedRoom(Room room)
- Specified by:
addCreatedRoom
in interfaceUser
-
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 interfaceUser
- Returns:
- the list of Rooms (if any)
-
removeCreatedRoom
public void removeCreatedRoom(Room room)
- Specified by:
removeCreatedRoom
in interfaceUser
-
addJoinedRoom
public void addJoinedRoom(Room room)
- Specified by:
addJoinedRoom
in interfaceUser
-
removeJoinedRoom
public void removeJoinedRoom(Room room)
- Specified by:
removeJoinedRoom
in interfaceUser
-
getOwnedRoomsCount
public int getOwnedRoomsCount()
Description copied from interface:User
Get the number of Rooms created by the User- Specified by:
getOwnedRoomsCount
in interfaceUser
- Returns:
- the number of Rooms created by the User
-
subscribeGroup
public void subscribeGroup(java.lang.String id)
- Specified by:
subscribeGroup
in interfaceUser
-
unsubscribeGroup
public void unsubscribeGroup(java.lang.String id)
- Specified by:
unsubscribeGroup
in interfaceUser
-
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 interfaceUser
- 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 interfaceUser
- 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 interfaceUser
-
isNpc
public boolean isNpc()
Description copied from interface:User
Returns the NPC flag
-
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 interfaceUser
- Returns:
- the list of Rooms
-
getZone
public Zone getZone()
Description copied from interface:User
Get the Zone where the User is currently logged in
-
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 interfaceUser
- 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 interfaceUser
- 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 interfaceUser
- Returns:
- login time
-
setLastLoginTime
public void setLastLoginTime(long lastLoginTime)
- Specified by:
setLastLoginTime
in interfaceUser
-
getName
public java.lang.String getName()
Description copied from interface:User
Get 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
-
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 interfaceUser
- 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 interfaceUser
- 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 interfaceUser
- Returns:
- the map of playerIds per room
- See Also:
User.getPlayerId()
-
setPlayerId
public void setPlayerId(int id, Room room)
- Specified by:
setPlayerId
in interfaceUser
-
isPlayer
public boolean isPlayer()
Description copied from interface:User
Check if the User is a Player in the current Room (only for Game Rooms)
-
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 interfaceUser
- 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
-
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 interfaceUser
- 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 interfaceUser
- 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 interfaceUser
- 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 interfaceUser
- Parameters:
key
- the property nameval
- 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 interfaceUser
- 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 interfaceUser
- 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 interfaceUser
- 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 interfaceUser
- 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 interfaceUser
- Parameters:
varName
- the name of the variable- Returns:
- the UserVariable
-
setVariable
public void setVariable(UserVariable var) throws SFSVariableException
- Specified by:
setVariable
in interfaceUser
- Throws:
SFSVariableException
-
setVariables
public void setVariables(java.util.List<UserVariable> userVariables) throws SFSVariableException
- Specified by:
setVariables
in interfaceUser
- Throws:
SFSVariableException
-
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 interfaceUser
- 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 interfaceUser
- Returns:
- the list of UserVariables
-
removeVariable
public void removeVariable(java.lang.String varName)
- Specified by:
removeVariable
in interfaceUser
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getLastRequestTime
public long getLastRequestTime()
- Specified by:
getLastRequestTime
in interfaceUser
-
updateLastRequestTime
public void updateLastRequestTime()
- Specified by:
updateLastRequestTime
in interfaceUser
-
setLastRequestTime
public void setLastRequestTime(long lastRequestTime)
- Specified by:
setLastRequestTime
in interfaceUser
-
getBadWordsWarnings
public int getBadWordsWarnings()
- Specified by:
getBadWordsWarnings
in interfaceUser
-
setBadWordsWarnings
public void setBadWordsWarnings(int badWordsWarnings)
- Specified by:
setBadWordsWarnings
in interfaceUser
-
getFloodWarnings
public int getFloodWarnings()
- Specified by:
getFloodWarnings
in interfaceUser
-
setFloodWarnings
public void setFloodWarnings(int floodWarnings)
- Specified by:
setFloodWarnings
in interfaceUser
-
getExtFloodWarnings
public int getExtFloodWarnings()
- Specified by:
getExtFloodWarnings
in interfaceUser
-
setExtFloodWarnings
public void setExtFloodWarnings(int count)
- Specified by:
setExtFloodWarnings
in interfaceUser
-
getLastLoginTime
public long getLastLoginTime()
-
isBeingKicked
public boolean isBeingKicked()
- Specified by:
isBeingKicked
in interfaceUser
-
setBeingKicked
public void setBeingKicked(boolean flag)
- Specified by:
setBeingKicked
in interfaceUser
-
getUserVariablesData
public ISFSArray getUserVariablesData()
- Specified by:
getUserVariablesData
in interfaceUser
-
getReconnectionSeconds
public int getReconnectionSeconds()
- Specified by:
getReconnectionSeconds
in interfaceUser
-
setReconnectionSeconds
public void setReconnectionSeconds(int seconds)
- Specified by:
setReconnectionSeconds
in interfaceUser
-
toSFSArray
public ISFSArray toSFSArray(Room room)
- Specified by:
toSFSArray
in interfaceUser
-
toSFSArray
public ISFSArray toSFSArray()
- Specified by:
toSFSArray
in interfaceUser
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
getDump
public java.lang.String getDump()
Description copied from interface:User
Return a full dump of the User properties, useful for debugging
-
getAdminHelper
public com.smartfoxserver.v2.util.IAdminHelper getAdminHelper()
-
setAdminHelper
public void setAdminHelper(com.smartfoxserver.v2.util.IAdminHelper adminHelper)
-
getLastProxyList
public java.util.List<User> getLastProxyList()
- Specified by:
getLastProxyList
in interfaceUser
-
setLastProxyList
public void setLastProxyList(java.util.List<User> proxyList)
- Specified by:
setLastProxyList
in interfaceUser
-
getLastMMOItemsList
public java.util.List<BaseMMOItem> getLastMMOItemsList()
- Specified by:
getLastMMOItemsList
in interfaceUser
-
setLastMMOItemsList
public void setLastMMOItemsList(java.util.List<BaseMMOItem> mmoItemsList)
- Specified by:
setLastMMOItemsList
in interfaceUser
-
getCurrentMMORoom
public MMORoom getCurrentMMORoom()
- Specified by:
getCurrentMMORoom
in interfaceUser
-
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 interfaceUser
- Returns:
- the location of the user, null if the geolocation DB did not provide a match
-
addPersistentRoomVarReference
public void addPersistentRoomVarReference(Room target)
- Specified by:
addPersistentRoomVarReference
in interfaceUser
-
getPersistentRoomVarReferences
public java.util.Set<java.lang.Integer> getPersistentRoomVarReferences()
- Specified by:
getPersistentRoomVarReferences
in interfaceUser
-
-