murkywaters
11 Jun 2009, 12:05 PM
Ok.. I usually do not write in forums.. simply because someone else always has had the same issue before me. BUT in this case, I'm not even sure how to ask the question.. So hang in there:
The problem:
I am creating a web site game where users create an online fighter and then will fight others that are online at that time in a turn based fighting system of probabilities and luck of the roll.
I'm using PHP, MySQL, AJAX, Javascript and CSS to create the site and What I'm thinking is that when a user logs in, it'll put their fighter in a database table of available fighters... That's easy.. THE PROBLEM is when they close the window to log off (instead of pressing a log off button) How will the database table know that the user is no longer on and delete the fighter from the available fighters list?
AS I'M TYPING.. I had an idea... I'm not sure if it's the best.. but probably would work... How about running a script from every logged in user that checks the available fighters every... say 5 seconds and deletes older timestamped fighters more than say 8 seconds old. Every fighter.. if logged in will send an update to the timestamp so that it knows it's the fighter is still available?
Would that be too network intensive? Is there an easier way? I know it can be done.. I've used an Ajax Chat room that does exactly what I want.
The problem:
I am creating a web site game where users create an online fighter and then will fight others that are online at that time in a turn based fighting system of probabilities and luck of the roll.
I'm using PHP, MySQL, AJAX, Javascript and CSS to create the site and What I'm thinking is that when a user logs in, it'll put their fighter in a database table of available fighters... That's easy.. THE PROBLEM is when they close the window to log off (instead of pressing a log off button) How will the database table know that the user is no longer on and delete the fighter from the available fighters list?
AS I'M TYPING.. I had an idea... I'm not sure if it's the best.. but probably would work... How about running a script from every logged in user that checks the available fighters every... say 5 seconds and deletes older timestamped fighters more than say 8 seconds old. Every fighter.. if logged in will send an update to the timestamp so that it knows it's the fighter is still available?
Would that be too network intensive? Is there an easier way? I know it can be done.. I've used an Ajax Chat room that does exactly what I want.