SFSEventParam Where Applicable

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

Moderators: Lapo, Bax

Post Reply
Gnoll
Posts: 128
Joined: 10 Mar 2009, 10:14

SFSEventParam Where Applicable

Post 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
jpardoe
Posts: 132
Joined: 31 Aug 2009, 20:54

Post 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");

Gnoll
Posts: 128
Joined: 10 Mar 2009, 10:14

Post 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.
jpardoe
Posts: 132
Joined: 31 Aug 2009, 20:54

Post 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"); 

Gnoll
Posts: 128
Joined: 10 Mar 2009, 10:14

Post 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.
jpardoe
Posts: 132
Joined: 31 Aug 2009, 20:54

Post by jpardoe »

Oh I see. Sorry. I'll just be leaving now... :oops:
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

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