PDA

View Full Version : PHP + mysql => multi user problem



murkywaters
11 Jun 2009, 11:05 AM
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.

Alan
11 Jun 2009, 12:32 PM
Every 5 seconds? That seems excessive. But you could do it if you wanted. You could also update a timestamp everytime they refresh the page, assuming that someone who has been away for 5 or 10 minutes is gone offline, and remove their fighter then.

Here's a thought, you mentioned fighters are available when the user is logged in? For other users to fly or shoot down, or just a list of active players?

You could add to the drama of the game, by not removing the fighter from the available list unless the user logs out (you could call it docking/landing etc...). Their fighter would then be up for grabs to other players (to pilot or shoot), and it would make the game a little bit more realistic.

If you are trying to keep track of active players, then I would say just count the active sessions. It's only for viewable statistics and not too important.