How do I do something ON EXIT

Get help using Construct 2

Post » Fri Mar 20, 2015 9:43 am

How do you run code immediately before the user presses the [X] on the browser ?

Im trying to update a variable on the server using a AJAX request when the user exits out in order to log them out.

I tried "on end of layout" but that only works when the user changes layouts, not exits the entire browser... or shuts off their computer etc
B
3
Posts: 9
Reputation: 195

Post » Fri Mar 20, 2015 1:55 pm

Web browsers don't have a way to process calls on exit. However, to use a proper log in system, all you need to do, is create a session variable on start of the program and set it on the server side. Each time the client tries to communicate to the server, it compares the local variable with that on the server and, if they are different, then the user is logged out. A simple way to implement this is just to use the time stamp of when the game first connected.

The events would go something like this:
On start of game: set local session variable to empty
If local session variable is empty: User signs in and the session variable is set to current time stamp
If local session variable != server session variable: User signs in and the session variable is set to current time stamp
If client fails to get a response from the server: set session variable to empty
If client can contact server and local session variable = server session variable: client is logged in

This is only one way to handle disconnecting a client. Of course, I would supplement this with a time out so if the client had not transmitted to the server after say 5 minutes, the client would have to sign back in.

If you haven't yet, you should read up on web page security for sign in pages using session variables.
B
38
S
12
G
11
Posts: 331
Reputation: 7,712


Return to How do I....?

Who is online

Users browsing this forum: Exabot [Bot], oddreal and 4 guests