Internal Event :: loginRequest
Availability:
SmartFoxServer PRO 1.2.1
Event name:
loginRequest
Description:
This event is fired when a user is trying to connect to a Zone.
The event is available only for Zone
Level extensions.
In order to receive this event the customLogin attribute of
your Zone should be set to true. If it is set to false the user will login
using the default SmartFoxServer login procedure.
Turning on the
customLogin attribute allows developers to handle the login
with his own custom logic, mayb using a database etc...
Properties:
name | description | type | |
nick | The nickname sent by the user | java.lang.String (*) | |
pass | The password sent by the user | java.lang.String (*) | |
chan | The socket channel representing the client connection. | object |
(*) A note on data types: the parameters passed by the server events to the running extensions are all Java types.
You can use them transparently in Actionscript or cast them to AS native data types.
» javadoc for -> java.lang.String
Example:
Here's an example of a very simple custom login function.function handleInternalEvent(evtObj) { if (evt.name == "loginRequest") { var nick = evt.nick var pass = evt.pass var chan = evt.chan // Check login if (nick == "Smart" && pass == "Fox") { // Successfull ... but ... // we're not done YET! The server may refuse to login the user because the Zone is full // or another user has the same name, or the user was banned etc ... // We ask the server to login this new user var obj = _server.loginUser(nick, pass, chan) // Let's see the server response! if (obj.success == true) { // Success!! trace("Welcome " + nick) } else { // Login failed trace("Sorry mate, there was a server error: " + obj.error) } } } }
See also: