Help me to use session ???

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

Moderators: Lapo, Bax

User avatar
khanhdev
Posts: 30
Joined: 24 Mar 2017, 11:32

Help me to use session ???

Postby khanhdev » 05 May 2017, 04:08

I want to save the sessionID or SessionHash to get the corresponding user. But I have tried these two ways but they are not working.

This way the error is in line 16
Image

This way session is null
Image

:?: :?: :?:
User avatar
Lapo
Site Admin
Posts: 23007
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Help me to use session ???

Postby Lapo » 05 May 2017, 08:18

Hi,
I am not sure why you would want to "save" those values. They only exist for the duration of the user's session, so they are already "saved" in the sense that you can access them at any time, given the User object.

Can you better explain?

thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
khanhdev
Posts: 30
Joined: 24 Mar 2017, 11:32

Re: Help me to use session ???

Postby khanhdev » 05 May 2017, 08:33

Lapo wrote:Hi,
I am not sure why you would want to "save" those values. They only exist for the duration of the user's session, so they are already "saved" in the sense that you can access them at any time, given the User object.

Can you better explain?

thanks


I'm wondering why I can not use the function getSessionByHash () and the getSessionById ()?
User avatar
khanhdev
Posts: 30
Joined: 24 Mar 2017, 11:32

Re: Help me to use session ???

Postby khanhdev » 05 May 2017, 08:37

Please take a look at my code. Where "user" is the current user request to server
User avatar
Lapo
Site Admin
Posts: 23007
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Help me to use session ???

Postby Lapo » 05 May 2017, 09:44

I am sorry but the code you have posted makes very little sense.

You already have the User object and you're writing 4 lines of code to obtain the same user object? Why?
If you have a User object and you need its session, the just use

Code: Select all

user.getSession()

Other than that you should never need to mess with Sessions in your code. That's low level stuff that is not useful for implementing the game logic. On the other hand if you mess with its state you may cause problems.

If you have a specific use case then please explain.

In the second example you're trying to obtain a Session via it's ID but you're passing the Session's hash which is not the same thing.
The ID is a numeric value, the hash is a String.

As I said, Sessions are managed for you so you can concentrate on your game logic, instead of dealing with lower level stuff. If I have misunderstood then clarify what's the purpose of this.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Google [Bot] and 62 guests