_server.loginUser()
Availability:
SmartFoxServer PRO 1.2.1
Usage:
_server.loginUser(nick, pass, channel, forceLogin)
Description:
Logs a user in, creating a User object (it.gotoandplay.smartfoxserver.data.User)
for the client.
Each client connected with SmartFoxServer has its own Chanel object
representing the socket connection. After successfully logging in, the client
becomes a "real" user and its User object is created.
This method is normally used when you receive an event of type "loginRequest"
Properties:
| nick | the user nickname | |
| pass | the user password | |
| channel | the Channel object | |
| forceLogin | (optional) if true allows to force the login even if the user is still connected/logged in. (New since 1.6.3) |
Returns:
An object with two properties:
| success | True, if login was successfull | |
| error | The error message of the server if login failed |
Example:
/*
* This method handles internal events
* Internal events are dispactched by the Zone or Room where the extension is attached to
*
* the (evt) object
*/
function handleInternalEvent(evt)
{
if (evt.name == "loginRequest")
{
var error = ""
var nick = evt["nick"]
var pass = evt["pass"]
var chan = evt["chan"]
if (pass != "The Password")
{
error = "Authentication failed"
}
else
{
var obj = _server.loginUser(nick, pass, chan)
if (obj.success == false)
error = obj.error
else
{
var u = _server.instance.getUserByChannel(chan)
trace("User " + u.getName() + " logged in")
}
}
// Send response to client
var response = new Object()
if (error == "")
{
response._cmd = "logOK"
}
else
{
response._cmd = "logKO"
response.err = error
}
/*
* NOTE:
* usually the 4th parameter of the sendResponse is a list of users object that will
* receive this message.
*
* Only when handling a login request you can pass a channel instead of a list of Users
*/
_server.sendResponse(response, -1, null, chan)
}
}
See also: