User class

Availability:

SmartFoxServer PRO 1.2.1

Description:

A User object represents a client connected to the server and logged in one Zone. (It can be present in one room or more)
Here follows a list of public methods for this object.

Public Methods:

getIpAddress()   Return the ip address of the client
getLastMessageTime()   Return the time (expressed in milliseconds) of the last time a message was sent
getLoginTime()   Return the login time (expressed in milliseconds)
getName()   Return the user name
getPlayerIndex()   Return the player index for the current room
getPlayerIndex(roomObj)   Return the player index for the specified room
getRoomsConnected()   Return an array containing the roomId(s) of all rooms where the user is connected
getUserId()   Return the unique User id
getVariable(name)   Return the room variable with the requested name
getVariables()   Return a java.util.HashMap with all the User Variables
isAdmin()   Return true if the user is an administrator
isModerator()   Return true if the user is a moderator
isSpectator()   Return true if the user is set as spectator
setAsModerator(flag)   Set the status of the moderator flag
updateMessageTime()   Updates the last messge time counter

Public Properties:

It is also possible to "attach" your own custom properties to the User() object by using the public "properties" object. The object works like an associative array. Below follows a list of methods available:

put(key, value)   Put a new value/object
get(key)   Retrive the value/object for the passed key. If the object doesn't exist it returns null
remove(key)   Remove the value/object
size()   Return the size of the properties array


Example:

var score = 1500
var bestScore = 12000
var weapons = ["axe", "sword", "knife", "bow"]

// Save data in the user.properties associative array
user.properties.put("score", score)
user.properties.put("bestScore", bestScore)
user.properties.put("weapons", weapons)

// Retrieve data and display it
var list = user.properties.get("weapons")

for (var i in list)
	trace("Weapon: " + list[i])