Page 1 of 1

SFSEventParam Where Applicable

Posted: 11 Nov 2010, 08:15
by Gnoll
Hi Lapo,

I was wondering is there documentation on where which SFSEventParam's are applicable?

I was banging my head against the desk for a long time before realizing session was a null param at the UserJoinZone stage.

I was also wondering, should the USER_LOGOUT event also fire when DISCONNECT happens?

Regards,
Josh

Posted: 11 Nov 2010, 08:21
by jpardoe
Gnoll, session is not a null param at UserJoinZone stage.

What I do, is write userData to the session in the USER_LOGIN event handler:

Code: Select all

ISession session = (ISession) event.getParameter(SFSEventParam.SESSION);

// Store userData in the current session.
session.setProperty("userData", userData);

...then in the USER_JOIN_ZONE event handler, I do:

Code: Select all

SFSObject userData = (SFSObject) session.getProperty("userData");


Posted: 11 Nov 2010, 08:40
by Gnoll
That's what I was doing for my AccountId when interfacing with the database.

I had a huge post written up wondering if sessions persisted, then I tried tracing my session object (got the same way) and it was null. >_> Then I tried using user.getSession() and all worked fine.

Posted: 11 Nov 2010, 08:45
by jpardoe
Oh yes, sorry I missed out a crucial part in USER_JOIN_ZONE handler:

Code: Select all

ISession session = user.getSession();

SFSObject userData = (SFSObject) session.getProperty("userData"); 


Posted: 11 Nov 2010, 08:47
by Gnoll
That's my point... :)

That works while

Code: Select all

ISession session = (ISession) event.getParameter(SFSEventParam.SESSION);
doesn't work.

I was asking that this be documented, so we know which cases it is available in. For example it works in the LOGIN event.

Posted: 11 Nov 2010, 08:52
by jpardoe
Oh I see. Sorry. I'll just be leaving now... :oops:

Posted: 11 Nov 2010, 10:53
by Lapo
@Gnoll:
I was banging my head against the desk for a long time before realizing session was a null param at the UserJoinZone stage.
You should take a closer look at the Javadoc, SFSEventType class. It documents each event clearly with all its parameters. No need to bang your head anywhere :)

http://docs2x.smartfoxserver.com/api-do ... tType.html

The SFSEventParam enum can be used all over your code. Its fields cover all the possible event parameters available in the system provided that you consult the above mentioned documentation page to check which parameters are passed in each event.

Hope it helps