Online/offline

For discussions about game development that does not fit in any of the other topics.
Post Reply
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Online/offline

Post by Chris »

What is this written in? Does it work in sync or async? Best practice would be to have an observable data instance in your RAM to save polling a database server. Let the instance update the database server on x amount of events triggered or something.

As for removing the sprite, let there be an event in the display tree that binds to the user logging out.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Online/offline

Post by Chris »

What happens when the user closes the window? Your website disappears. So function b most likely will never happen.

What you could do is save a time stamp of when the use last visited a page on the website. Then to calculate who's online, get a list of people who were active between now - 5 minutes.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Online/offline

Post by Chris »

There are different techniques. Ajax would be one of them. WebSockets are part of the HTML5 standard so they would be an option for you aswell.

What kind of data model are you using to store the user information? A MySQL database or a JavaScript instance of some sort?
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: Online/offline

Post by Callan S. »

If I understand right I'd have a world stats time value recorded. Then on every page I'd include a page that checks if five minutes (or whatever interval) has passed since the last recording of time in the world stats. If so, search for all players who's last action was over five minutes ago. Then write the current time in the world stats time value again.

Sure, the player closing their browser wont trigger this page, but any other player will, so same effect in the end.
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Online/offline

Post by Chris »

I'd recommend Reverse-Ajax/Commet if you aren't going to use WebSockets, because what you are wanting to build is basically a real-time connection.

Flow:

View -> Send Server Current Client Data -> Server compares clients data with database data -> Poll Database Until Update Found -> When update is found -> Send client new data model -> Update Clients data model -> Update view -> Loop
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Online/offline

Post by Jackolantern »

That is called "long-polling". There are quite a few tutorials out there, although I am not sure about which ones are good. If you Google that and try a couple of them hopefully one will work out :)

EDIT: But do keep in mind that long-polling is nowhere near as efficient as websockets, and it does not scale well. But with a smaller userbase and provided you can tolerate the increased latency, it is much more simple to implement than websockets (long-polling can be done in nearly any server-side language, but not so with websockets. At least not done to scale).
The indelible lord of tl;dr
Post Reply

Return to “General Development”