How to get SessionLen?

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
moccha
Posts: 112
Joined: 13 Feb 2014, 16:09

How to get SessionLen?

Postby moccha » 12 Jun 2021, 00:04

Hi Lapo,

When a user logs out, I can see that the session length "SessionLen" is logged in the disconnect message. I would like to get that value for the user and store it in my database when they're disconnecting. I don't see how to access that value in the docs.

Is there a way for me to grab it or should I just create the variable myself when a user disconnects, eg.

Code: Select all

timestamp - user.getLoginTime()
?
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: How to get SessionLen?

Postby Lapo » 12 Jun 2021, 05:55

Hi,
the Session object has a getCreationTime() method, that returns a timestamp (long)
You can subtract that value from the current timestamp ( System.currentTimeMillis() ) to get the length. In other words:

Code: Select all

long now = System.currentTimeMillis();
long sessionLen = now - user.getSession().getCreationTime();


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

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 45 guests