Page 1 of 1

Re: Online/offline

Posted: Tue Apr 09, 2013 10:50 am
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.

Re: Online/offline

Posted: Wed Apr 10, 2013 7:37 am
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.

Re: Online/offline

Posted: Wed Apr 10, 2013 11:53 am
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?

Re: Online/offline

Posted: Thu Apr 11, 2013 4:00 am
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.

Re: Online/offline

Posted: Fri Apr 12, 2013 1:51 pm
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

Re: Online/offline

Posted: Sat Apr 13, 2013 2:43 am
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).