User session property vs user variable

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

Moderators: Lapo, Bax

albymack
Posts: 17
Joined: 09 May 2022, 21:17

User session property vs user variable

Postby albymack » 02 Aug 2022, 23:45

In the example:
https://smartfoxserver.com/blog/custom- ... -database/

In the LoginEventHandler, you store the database id into the session property.

Then in the ZoneJoinEventHandler, you have code that moves the session property into a hidden user variable:

--- code from the example

// dbid is a hidden UserVariable, available only server side
UserVariable uv_dbId = new SFSUserVariable("dbid", theUser.getSession().getProperty(DBLogin.DATABASE_ID));

----

Why move the dbid into a hidden user variable instead of keeping it in the user's session property? What are the advantages/disadvantages? I noticed in my experiments that even in my room's extension, I'm still able the access the user's session to get dbid, so why bother moving it into user variable?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: User session property vs user variable

Postby Lapo » 03 Aug 2022, 08:05

Hi,
essentially it is just for convenience, since you're probably going to use multiple UserVariables for each client.
It's about keeping the User's data in one place. But you can do otherwise (i.e. use Properties) and it will be fine as well.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 46 guests