Page 1 of 1

ISFSEvent USER null ?

Posted: 02 Aug 2011, 10:48
by TiagoR
Hi,
im having a problem with my custom login handler.

at the client I call the login method

Code: Select all

this.send( new LoginRequest(login, password, "twilightZone") );


but at the server when i try to get the User that sent the request

Code: Select all

public class LoginHandler extends BaseServerEventHandler
{

    @Override
    public void handleServerEvent(ISFSEvent event) throws SFSException
    {
        User user = (User) event.getParameter(SFSEventParam.USER);
        ...
    }
}


I get a NULL user!

I even tried to get the user by session id, or by name, and i always get a NULL user..
what am i doing wrong?
(I need the user to join a room)

Code: Select all

ISFSApi sfs = SmartFoxServer.getInstance().getAPIManager().getSFSApi();
sfs.joinRoom(user, room);

Posted: 02 Aug 2011, 11:26
by rjgtav
Hi. Yes that's right. As the user object is only created after a successful login, at the login time, there isn't yet an user object, that's why you get null when trying to retrieve it.

At the login time, you only have access to the session, not the user.

Posted: 02 Aug 2011, 12:35
by TiagoR
Then how you login a user?

Posted: 02 Aug 2011, 12:46
by rjgtav
Hi. The login happens automatically and only if you dont throw a login exception. And to join the room, you can do it when you receive the USER_JOIN_ZONE event, that is fired after a successful login and when the user joins the zone.

Posted: 02 Aug 2011, 12:49
by TiagoR
thanks for the quick reply!
it seems the logic changed a bit from sfs pro to sfs2x but it makes sense.
thanks again.

Posted: 03 Aug 2011, 18:53
by Lapo
Don't understimate the power of the docs ;)
Start from here:
http://docs2x.smartfoxserver.com/Develo ... ogin-phase
and follow the tutorial linked at the end of the article