ISFSEvent USER null ?

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

TiagoR
Posts: 83
Joined: 15 Mar 2010, 11:42
Location: Portugal
Contact:

ISFSEvent USER null ?

Postby TiagoR » 02 Aug 2011, 10:48

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);
TR
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 02 Aug 2011, 11:26

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.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
TiagoR
Posts: 83
Joined: 15 Mar 2010, 11:42
Location: Portugal
Contact:

Postby TiagoR » 02 Aug 2011, 12:35

Then how you login a user?
TR
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 02 Aug 2011, 12:46

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.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
TiagoR
Posts: 83
Joined: 15 Mar 2010, 11:42
Location: Portugal
Contact:

Postby TiagoR » 02 Aug 2011, 12:49

thanks for the quick reply!
it seems the logic changed a bit from sfs pro to sfs2x but it makes sense.
thanks again.
TR
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 03 Aug 2011, 18:53

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
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 41 guests