Set User Variables Upon Server Side Login

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
yqtang
Posts: 13
Joined: 03 May 2022, 19:14

Set User Variables Upon Server Side Login

Post by yqtang »

Hi Lapo,

I am trying to achieve passing extra parameters when user logged in on server side, and do something with these parameters when this user disconnects. I've set up login handler, zone join handler and disconnection handler. I successfully grab the parameter inside login handler. The problem is I tried to set User Variables but the user, by that time, is not ready. That means I got null if I try to get the "User" parameter. Then I tried to do so in zone join handler. Unfortunately, even though the user will be ready then, I lost access to login parameters.

What's your suggestions on this? How can I store user specific data inside join handler and grab it inside disconnection handler? Thank you in advance!
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Set User Variables Upon Server Side Login

Post by Lapo »

Hi,
you're correct, the User object does not exist yet when you log in and it is created and passed in the USER_JOIN_ZONE event.
However you can store any parameter in the Session with:

Code: Select all

session.setProperty("name", value);

And read them back in the JOIN event with:

Code: Select all

var value = (Integer) user.getSession().getProperty("name");


If these parameters are supposed to be used to create UserVariables you can already prepare the SFSUserVariable object in the LOGIN event and store that in the Session properties.
Example:

Code: Select all

session.setProperty("myVar", new SFSUserVariable("name", value);


You get the idea.
Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply