Package com.smartfoxserver.entities
Class SFSUser
java.lang.Object
com.smartfoxserver.entities.SFSUser
- All Implemented Interfaces:
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
- 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 generate the new User and add it to the system.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCreatedRoom(Room room) voidaddJoinedRoom(Room room) voidaddPersistentRoomVarReference(Room target) booleancontainsProperty(Object key) Checks whether a custom property exists or notbooleancontainsVariable(String varName) Checks whether or not the User has a specific UserVariable setvoiddisconnect(IDisconnectionReason reason) booleancom.smartfoxserver.util.IAdminHelpercom.smartfoxserver.entities.audio.AudioStreamInfointGet the BuddyProperty objectBy default each client API sends a different "signature" identifying the client technology (e.g.If the geolocation service is enabled in the Zone it will return the location of the userGet a list of Rooms created by this UsergetDump()Return a full dump of the User properties, useful for debuggingintintintgetId()Get the unique user IDReturn the User IP addressA list of Rooms currently joined by the UserA reference to the last Room that was joined by this UserlonglonglongGet the user login time (Unix timestamp in milliseconds)intGet the maximum allowed User Variables for this UsergetName()Get the User nameintGet the number of Rooms created by the UserintGet the playerId of the User (if applicable).intgetPlayerId(Room room) Get the playerId for the User in a specific RoomGet a map of playerId(s) per Room
This method can be used when a player is currently engaged in multiple games at the same timeshortReturn the Privilege ID of the User.Get the map with all User propertiesgetProperty(Object key) Get any custom property attached to this User.intGet the session object linked to this UserGet a list of Room Groups subscribed by the UsergetUserVariablesData(boolean isRecipient) getVariable(String varName) Returns the UserVariable with the provided name.Obtain the full list of UserVariablesintReturn the number of UserVariables for this UsergetZone()Get the Zone where the User is currently logged inbooleanisAdmin()booleanbooleanCheck if the User is connectedbooleanisJoinedInRoom(Room room) Check if a User is joined in a RoombooleanbooleanisNpc()Returns the NPC flagbooleanisPlayer()Check if the User is a Player in the current Room (only for Game Rooms)booleanCheck if the User is Player in a specific RoombooleanCheck 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 RoombooleanCheck if the User is subscribed to a certain Room GroupbooleanCheck if the User has SuperUser privileges (allows to send mod/admin messages and kick/ban Users)voidremoveCreatedRoom(Room room) voidremoveJoinedRoom(Room room) voidremoveProperty(Object key) Removes a custom propertyvoidremoveVariable(String varName) voidsetAdminHelper(com.smartfoxserver.util.IAdminHelper adminHelper) voidsetAudioStreamInfo(com.smartfoxserver.entities.audio.AudioStreamInfo info) voidsetBadWordsWarnings(int badWordsWarnings) voidsetBeingKicked(boolean flag) voidsetConnected(boolean flag) voidsetExtFloodWarnings(int count) voidsetFloodWarnings(int floodWarnings) voidsetJoining(boolean flag) voidsetLastLoginTime(long lastLoginTime) voidsetLastMMOItemsList(List<BaseMMOItem> mmoItemsList) voidsetLastProxyList(List<User> proxyList) voidsetLastRequestTime(long lastRequestTime) voidsetMaxAllowedVariables(int max) voidvoidsetPlayerId(int id, Room room) voidsetPrivilegeId(short id) voidsetProperty(Object key, Object val) Attach a custom (server-side only) property to the User objectvoidsetReconnectionSeconds(int seconds) voidsetVariable(UserVariable var) voidsetVariables(List<UserVariable> userVariables) voidvoidsubscribeGroup(String id) toSFSArray(Room room) toString()voidvoid
-
Constructor Details
-
SFSUser
-
SFSUser
-
-
Method Details
-
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 (default)
- 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 privileges (allows to send mod/admin messages and kick/ban Users)- Specified by:
isSuperUserin interfaceUser- Returns:
- true if the User has SuperUser capabilities
-
isAdmin
public boolean isAdmin() -
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
-
setConnected
public void setConnected(boolean flag) - Specified by:
setConnectedin interfaceUser
-
isJoining
public boolean isJoining() -
setJoining
public void setJoining(boolean flag) - Specified by:
setJoiningin interfaceUser
-
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
- Specified by:
addCreatedRoomin interfaceUser
-
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
- Specified by:
removeCreatedRoomin interfaceUser
-
addJoinedRoom
- Specified by:
addJoinedRoomin interfaceUser
-
removeJoinedRoom
- 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
- Specified by:
subscribeGroupin interfaceUser
-
unsubscribeGroup
- Specified by:
unsubscribeGroupin interfaceUser
-
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
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
- Specified by:
disconnectin interfaceUser
-
isNpc
public boolean isNpc()Description copied from interface:UserReturns the NPC flag -
getJoinedRooms
Description copied from interface:UserA list of Rooms currently joined by the User- Specified by:
getJoinedRoomsin interfaceUser- Returns:
- the list of Rooms
-
getZone
Description copied from interface:UserGet the Zone where the User is currently logged in -
setZone
-
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
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 in milliseconds)- Specified by:
getLoginTimein interfaceUser- Returns:
- login time
-
setLastLoginTime
public void setLastLoginTime(long lastLoginTime) - Specified by:
setLastLoginTimein interfaceUser
-
getName
Description copied from interface:UserGet the User name -
setName
-
getClientType
Description copied from interface:UserBy default each client API sends a different "signature" identifying the client technology (e.g. Unity, Godot, Javascript) and version of the API.- Specified by:
getClientTypein interfaceUser- Returns:
- the string identifying the type of connected client
-
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
Description copied from interface:UserGet the playerId for the User in a specific Room- Specified by:
getPlayerIdin interfaceUser- Parameters:
room-- Returns:
- the playerId
- See Also:
-
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:
-
setPlayerId
- 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
Description copied from interface:UserCheck if the User is Player in a specific Room -
isSpectator
Description copied from interface:UserCheck if the User is Spectator in a specific Room- Specified by:
isSpectatorin interfaceUser- Parameters:
room- the Room- Returns:
- true if the User is a spectator in the specified Room
-
getProperty
Description copied from interface:UserGet any custom property attached to this User.- Specified by:
getPropertyin interfaceUser- Parameters:
key-- Returns:
- the value
-
getProperties
Description copied from interface:UserGet the map with all User properties- Specified by:
getPropertiesin interfaceUser- Returns:
- the map with all User properties
-
setProperty
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
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
Description copied from interface:UserRemoves a custom property- Specified by:
removePropertyin interfaceUser- Parameters:
key- the name of the property
-
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
Description copied from interface:UserReturns the UserVariable with the provided name. Returns null if the UserVariable doesn't exist.- Specified by:
getVariablein interfaceUser- Parameters:
varName- the name of the variable- Returns:
- the UserVariable
-
setVariable
- Specified by:
setVariablein interfaceUser- Throws:
SFSVariableException
-
setVariables
- Specified by:
setVariablesin interfaceUser- Throws:
SFSVariableException
-
containsVariable
Description copied from interface:UserChecks whether or not the User has a specific UserVariable set- Specified by:
containsVariablein interfaceUser- Parameters:
varName- the name of the variable- Returns:
- true if the UserVariable exists
-
getVariables
Description copied from interface:UserObtain the full list of UserVariables- Specified by:
getVariablesin interfaceUser- Returns:
- the list of UserVariables
-
removeVariable
- Specified by:
removeVariablein interfaceUser
-
toString
-
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
- Specified by:
getUserVariablesDatain interfaceUser
-
getUserVariablesData
-
getReconnectionSeconds
public int getReconnectionSeconds()- Specified by:
getReconnectionSecondsin interfaceUser
-
setReconnectionSeconds
public void setReconnectionSeconds(int seconds) - Specified by:
setReconnectionSecondsin interfaceUser
-
toSFSArray
- Specified by:
toSFSArrayin interfaceUser
-
toSFSArray
- Specified by:
toSFSArrayin interfaceUser
-
equals
-
getDump
Description copied from interface:UserReturn a full dump of the User properties, useful for debugging -
getAdminHelper
public com.smartfoxserver.util.IAdminHelper getAdminHelper() -
setAdminHelper
public void setAdminHelper(com.smartfoxserver.util.IAdminHelper adminHelper) -
getLastProxyList
- Specified by:
getLastProxyListin interfaceUser
-
setLastProxyList
- Specified by:
setLastProxyListin interfaceUser
-
getLastMMOItemsList
- Specified by:
getLastMMOItemsListin interfaceUser
-
setLastMMOItemsList
- Specified by:
setLastMMOItemsListin interfaceUser
-
getCurrentMMORoom
- Specified by:
getCurrentMMORoomin interfaceUser
-
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
-
getAudioStreamInfo
public com.smartfoxserver.entities.audio.AudioStreamInfo getAudioStreamInfo()- Specified by:
getAudioStreamInfoin interfaceUser
-
setAudioStreamInfo
public void setAudioStreamInfo(com.smartfoxserver.entities.audio.AudioStreamInfo info) - Specified by:
setAudioStreamInfoin interfaceUser
-
addPersistentRoomVarReference
- Specified by:
addPersistentRoomVarReferencein interfaceUser
-
getPersistentRoomVarReferences
- Specified by:
getPersistentRoomVarReferencesin interfaceUser
-