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 voidaddCreatedRoom(Room room)voidaddJoinedRoom(Room room)voidaddPersistentRoomVarReference(Room target)booleancontainsProperty(java.lang.Object key)Checks whether a custom property exists or notbooleancontainsVariable(java.lang.String varName)Checks whether or not the User has a specific UserVariablevoiddisconnect(IDisconnectionReason reason)booleanequals(java.lang.Object obj)com.smartfoxserver.v2.util.IAdminHelpergetAdminHelper()intgetBadWordsWarnings()BuddyPropertiesgetBuddyProperties()Get the BuddyProperty objectCountrygetCountry()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 UserMMORoomgetCurrentMMORoom()java.lang.StringgetDump()Return a full dump of the User properties, useful for debuggingintgetExtFloodWarnings()intgetFloodWarnings()intgetId()Get the unique user IDjava.lang.StringgetIpAddress()Return the User IP addressjava.util.List<Room>getJoinedRooms()A list of Rooms currently joined by the UserRoomgetLastJoinedRoom()A reference to the last Room that was joined by this UserlonggetLastLoginTime()java.util.List<BaseMMOItem>getLastMMOItemsList()java.util.List<User>getLastProxyList()longgetLastRequestTime()longgetLoginTime()Get the user login time (Unix timestamp)intgetMaxAllowedVariables()Get the maximum allowed User Variables for this Userjava.lang.StringgetName()Get the User nameintgetOwnedRoomsCount()Get the number of Rooms created by the Userjava.util.Set<java.lang.Integer>getPersistentRoomVarReferences()intgetPlayerId()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 RoomintgetPlayerId(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 timeshortgetPrivilegeId()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.ObjectgetProperty(java.lang.Object key)Get any custom property attached to this User.intgetReconnectionSeconds()ISessiongetSession()Get the session object linked to this Userjava.util.List<java.lang.String>getSubscribedGroups()Get a list of Room Groups subscribed by the UserISFSArraygetUserVariablesData()UserVariablegetVariable(java.lang.String varName)Return a UserVariable.java.util.List<UserVariable>getVariables()Obtain the full list of UserVariablesintgetVariablesCount()Return the number of UserVariables for this UserZonegetZone()Get the Zone where the User is currently logged inbooleanisBeingKicked()booleanisConnected()Check if the User is connectedbooleanisJoinedInRoom(Room room)Check if a User is joined in a RoombooleanisJoining()booleanisLocal()Returns true if the User is connected to the local cluster nodebooleanisNpc()Returns the NPC flagbooleanisPlayer()Check if the User is a Player in the current Room (only for Game Rooms)booleanisPlayer(Room room)Check if the User is Player in a specific RoombooleanisSpectator()Check if the User is a Spectator in the current Room (only for Game Rooms)booleanisSpectator(Room room)Check if the User is Spectator in a specific RoombooleanisSubscribedToGroup(java.lang.String id)Check if the User is subscribed to a certain Room GroupbooleanisSuperUser()Check if the User has SuperUser capabilities (kicking/banning etc...)voidremoveCreatedRoom(Room room)voidremoveJoinedRoom(Room room)voidremoveProperty(java.lang.Object key)Removes a custom propertyvoidremoveVariable(java.lang.String varName)voidsetAdminHelper(com.smartfoxserver.v2.util.IAdminHelper adminHelper)voidsetBadWordsWarnings(int badWordsWarnings)voidsetBeingKicked(boolean flag)voidsetConnected(boolean flag)voidsetExtFloodWarnings(int count)voidsetFloodWarnings(int floodWarnings)voidsetJoining(boolean flag)voidsetLastLoginTime(long lastLoginTime)voidsetLastMMOItemsList(java.util.List<BaseMMOItem> mmoItemsList)voidsetLastProxyList(java.util.List<User> proxyList)voidsetLastRequestTime(long lastRequestTime)voidsetMaxAllowedVariables(int max)voidsetName(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.voidsetPlayerId(int id, Room room)voidsetPrivilegeId(short id)voidsetProperty(java.lang.Object key, java.lang.Object val)Attach a custom (server-side only) property to the User objectvoidsetReconnectionSeconds(int seconds)voidsetVariable(UserVariable var)voidsetVariables(java.util.List<UserVariable> userVariables)voidsetZone(Zone currentZone)voidsubscribeGroup(java.lang.String id)ISFSArraytoSFSArray()ISFSArraytoSFSArray(Room room)java.lang.StringtoString()voidunsubscribeGroup(java.lang.String id)voidupdateLastRequestTime()
-
-
-
Method Detail
-
getBuddyProperties
public BuddyProperties getBuddyProperties()
Description copied from interface:UserGet the BuddyProperty object- Specified by:
getBuddyPropertiesin interfaceUser- Returns:
- the buddy properties
-
getId
public int getId()
Description copied from interface:UserGet the unique user ID
-
getPrivilegeId
public short getPrivilegeId()
Description copied from interface:UserReturn the Privilege ID of the User. Default privilege IDs are:- 0: guest
- 1: regular user
- 2: moderator
- 3: administrator
- Specified by:
getPrivilegeIdin interfaceUser- Returns:
- the privilege id
-
setPrivilegeId
public void setPrivilegeId(short id)
- Specified by:
setPrivilegeIdin interfaceUser
-
isSuperUser
public boolean isSuperUser()
Description copied from interface:UserCheck if the User has SuperUser capabilities (kicking/banning etc...)- Specified by:
isSuperUserin interfaceUser- Returns:
- true if the User has SuperUser capabilities
-
isConnected
public boolean isConnected()
Description copied from interface:UserCheck if the User is connected- Specified by:
isConnectedin interfaceUser- Returns:
- true if the user has an active connection
-
isLocal
public boolean isLocal()
Description copied from interface:UserReturns true if the User is connected to the local cluster node
-
setConnected
public void setConnected(boolean flag)
- Specified by:
setConnectedin interfaceUser
-
setJoining
public void setJoining(boolean flag)
- Specified by:
setJoiningin interfaceUser
-
getIpAddress
public java.lang.String getIpAddress()
Description copied from interface:UserReturn the User IP address- Specified by:
getIpAddressin interfaceUser- Returns:
- the IP address
-
getMaxAllowedVariables
public int getMaxAllowedVariables()
Description copied from interface:UserGet the maximum allowed User Variables for this User- Specified by:
getMaxAllowedVariablesin interfaceUser- Returns:
- the number of variables
-
setMaxAllowedVariables
public void setMaxAllowedVariables(int max)
- Specified by:
setMaxAllowedVariablesin interfaceUser
-
addCreatedRoom
public void addCreatedRoom(Room room)
- Specified by:
addCreatedRoomin interfaceUser
-
getCreatedRooms
public java.util.List<Room> getCreatedRooms()
Description copied from interface:UserGet a list of Rooms created by this User- Specified by:
getCreatedRoomsin interfaceUser- Returns:
- the list of Rooms (if any)
-
removeCreatedRoom
public void removeCreatedRoom(Room room)
- Specified by:
removeCreatedRoomin interfaceUser
-
addJoinedRoom
public void addJoinedRoom(Room room)
- Specified by:
addJoinedRoomin interfaceUser
-
removeJoinedRoom
public void removeJoinedRoom(Room room)
- Specified by:
removeJoinedRoomin interfaceUser
-
getOwnedRoomsCount
public int getOwnedRoomsCount()
Description copied from interface:UserGet the number of Rooms created by the User- Specified by:
getOwnedRoomsCountin interfaceUser- Returns:
- the number of Rooms created by the User
-
subscribeGroup
public void subscribeGroup(java.lang.String id)
- Specified by:
subscribeGroupin interfaceUser
-
unsubscribeGroup
public void unsubscribeGroup(java.lang.String id)
- Specified by:
unsubscribeGroupin interfaceUser
-
getSubscribedGroups
public java.util.List<java.lang.String> getSubscribedGroups()
Description copied from interface:UserGet a list of Room Groups subscribed by the User- Specified by:
getSubscribedGroupsin interfaceUser- Returns:
- the list of groups
-
isSubscribedToGroup
public boolean isSubscribedToGroup(java.lang.String id)
Description copied from interface:UserCheck if the User is subscribed to a certain Room Group- Specified by:
isSubscribedToGroupin 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:
disconnectin interfaceUser
-
isNpc
public boolean isNpc()
Description copied from interface:UserReturns the NPC flag
-
getJoinedRooms
public java.util.List<Room> getJoinedRooms()
Description copied from interface:UserA list of Rooms currently joined by the User- Specified by:
getJoinedRoomsin interfaceUser- Returns:
- the list of Rooms
-
getZone
public Zone getZone()
Description copied from interface:UserGet the Zone where the User is currently logged in
-
getLastJoinedRoom
public Room getLastJoinedRoom()
Description copied from interface:UserA reference to the last Room that was joined by this User- Specified by:
getLastJoinedRoomin interfaceUser- Returns:
- the last joined Room
-
isJoinedInRoom
public boolean isJoinedInRoom(Room room)
Description copied from interface:UserCheck if a User is joined in a Room- Specified by:
isJoinedInRoomin interfaceUser- Parameters:
room- the Room- Returns:
- true if the User is joined in the passed Room
-
getLoginTime
public long getLoginTime()
Description copied from interface:UserGet the user login time (Unix timestamp)- Specified by:
getLoginTimein interfaceUser- Returns:
- login time
-
setLastLoginTime
public void setLastLoginTime(long lastLoginTime)
- Specified by:
setLastLoginTimein interfaceUser
-
getName
public java.lang.String getName()
Description copied from interface:UserGet the User name
-
setName
public void setName(java.lang.String name)
Description copied from interface:UserDO 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:UserGet 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:
getPlayerIdin interfaceUser- Returns:
- the player id
-
getPlayerId
public int getPlayerId(Room room)
Description copied from interface:UserGet the playerId for the User in a specific Room- Specified by:
getPlayerIdin interfaceUser- Returns:
- the playerId
- See Also:
User.getPlayerId()
-
getPlayerIds
public java.util.Map<Room,java.lang.Integer> getPlayerIds()
Description copied from interface:UserGet 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:
getPlayerIdsin interfaceUser- Returns:
- the map of playerIds per room
- See Also:
User.getPlayerId()
-
setPlayerId
public void setPlayerId(int id, Room room)- Specified by:
setPlayerIdin interfaceUser
-
isPlayer
public boolean isPlayer()
Description copied from interface:UserCheck if the User is a Player in the current Room (only for Game Rooms)
-
isSpectator
public boolean isSpectator()
Description copied from interface:UserCheck if the User is a Spectator in the current Room (only for Game Rooms)- Specified by:
isSpectatorin interfaceUser- Returns:
- true if the User is a spectator in the current Room
-
isPlayer
public boolean isPlayer(Room room)
Description copied from interface:UserCheck if the User is Player in a specific Room
-
isSpectator
public boolean isSpectator(Room room)
Description copied from interface:UserCheck if the User is Spectator in a specific Room- Specified by:
isSpectatorin 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:UserGet any custom property attached to this User.- Specified by:
getPropertyin interfaceUser- Returns:
- the value
-
getProperties
public java.util.concurrent.ConcurrentMap<java.lang.Object,java.lang.Object> getProperties()
Description copied from interface:UserGet the map with all User properties- Specified by:
getPropertiesin interfaceUser- Returns:
- the map with all User properties
-
setProperty
public void setProperty(java.lang.Object key, java.lang.Object val)Description copied from interface:UserAttach a custom (server-side only) property to the User object- Specified by:
setPropertyin interfaceUser- Parameters:
key- the property nameval- the property value
-
containsProperty
public boolean containsProperty(java.lang.Object key)
Description copied from interface:UserChecks whether a custom property exists or not- Specified by:
containsPropertyin 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:UserRemoves a custom property- Specified by:
removePropertyin interfaceUser- Parameters:
key- the name of the property
-
getSession
public ISession getSession()
Description copied from interface:UserGet the session object linked to this User- Specified by:
getSessionin interfaceUser- Returns:
- the user sessions object
-
getVariablesCount
public int getVariablesCount()
Description copied from interface:UserReturn the number of UserVariables for this User- Specified by:
getVariablesCountin interfaceUser- Returns:
- the number of UserVariables
-
getVariable
public UserVariable getVariable(java.lang.String varName)
Description copied from interface:UserReturn a UserVariable. It can return null if the UserVariable doesn't exist- Specified by:
getVariablein interfaceUser- Parameters:
varName- the name of the variable- Returns:
- the UserVariable
-
setVariable
public void setVariable(UserVariable var) throws SFSVariableException
- Specified by:
setVariablein interfaceUser- Throws:
SFSVariableException
-
setVariables
public void setVariables(java.util.List<UserVariable> userVariables) throws SFSVariableException
- Specified by:
setVariablesin interfaceUser- Throws:
SFSVariableException
-
containsVariable
public boolean containsVariable(java.lang.String varName)
Description copied from interface:UserChecks whether or not the User has a specific UserVariable- Specified by:
containsVariablein 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:UserObtain the full list of UserVariables- Specified by:
getVariablesin interfaceUser- Returns:
- the list of UserVariables
-
removeVariable
public void removeVariable(java.lang.String varName)
- Specified by:
removeVariablein interfaceUser
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getLastRequestTime
public long getLastRequestTime()
- Specified by:
getLastRequestTimein interfaceUser
-
updateLastRequestTime
public void updateLastRequestTime()
- Specified by:
updateLastRequestTimein interfaceUser
-
setLastRequestTime
public void setLastRequestTime(long lastRequestTime)
- Specified by:
setLastRequestTimein interfaceUser
-
getBadWordsWarnings
public int getBadWordsWarnings()
- Specified by:
getBadWordsWarningsin interfaceUser
-
setBadWordsWarnings
public void setBadWordsWarnings(int badWordsWarnings)
- Specified by:
setBadWordsWarningsin interfaceUser
-
getFloodWarnings
public int getFloodWarnings()
- Specified by:
getFloodWarningsin interfaceUser
-
setFloodWarnings
public void setFloodWarnings(int floodWarnings)
- Specified by:
setFloodWarningsin interfaceUser
-
getExtFloodWarnings
public int getExtFloodWarnings()
- Specified by:
getExtFloodWarningsin interfaceUser
-
setExtFloodWarnings
public void setExtFloodWarnings(int count)
- Specified by:
setExtFloodWarningsin interfaceUser
-
getLastLoginTime
public long getLastLoginTime()
-
isBeingKicked
public boolean isBeingKicked()
- Specified by:
isBeingKickedin interfaceUser
-
setBeingKicked
public void setBeingKicked(boolean flag)
- Specified by:
setBeingKickedin interfaceUser
-
getUserVariablesData
public ISFSArray getUserVariablesData()
- Specified by:
getUserVariablesDatain interfaceUser
-
getReconnectionSeconds
public int getReconnectionSeconds()
- Specified by:
getReconnectionSecondsin interfaceUser
-
setReconnectionSeconds
public void setReconnectionSeconds(int seconds)
- Specified by:
setReconnectionSecondsin interfaceUser
-
toSFSArray
public ISFSArray toSFSArray(Room room)
- Specified by:
toSFSArrayin interfaceUser
-
toSFSArray
public ISFSArray toSFSArray()
- Specified by:
toSFSArrayin interfaceUser
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
getDump
public java.lang.String getDump()
Description copied from interface:UserReturn 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:
getLastProxyListin interfaceUser
-
setLastProxyList
public void setLastProxyList(java.util.List<User> proxyList)
- Specified by:
setLastProxyListin interfaceUser
-
getLastMMOItemsList
public java.util.List<BaseMMOItem> getLastMMOItemsList()
- Specified by:
getLastMMOItemsListin interfaceUser
-
setLastMMOItemsList
public void setLastMMOItemsList(java.util.List<BaseMMOItem> mmoItemsList)
- Specified by:
setLastMMOItemsListin interfaceUser
-
getCurrentMMORoom
public MMORoom getCurrentMMORoom()
- Specified by:
getCurrentMMORoomin interfaceUser
-
getCountry
public Country getCountry()
Description copied from interface:UserIf the geolocation service is enabled in the Zone it will return the location of the user- Specified by:
getCountryin 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:
addPersistentRoomVarReferencein interfaceUser
-
getPersistentRoomVarReferences
public java.util.Set<java.lang.Integer> getPersistentRoomVarReferences()
- Specified by:
getPersistentRoomVarReferencesin interfaceUser
-
-