number of users in a zone

Post here your questions about the Flash / Flex / Air API for SFS2X

Moderators: Lapo, Bax

gofa
Posts: 9
Joined: 20 Feb 2012, 13:50

number of users in a zone

Postby gofa » 18 Apr 2012, 13:54

How to find out the total number of useres in a zone, from the AS3 client sied API

eg. when my user logis in, i want to use the AS3 Api to get the number of players in the users zone
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: number of users in a zone

Postby rjgtav » 19 Apr 2012, 23:13

Hi.
Well, you can't get it from the client-side, but you can use a simple Zone-Level Extension to handle the job. Now it depends on how you want to organize things.
You could, for example, have an Arrival Zone where everyone would initially connect and retrieve from the extension the zones list and their user count.
Another way to accomplish is to set a task to run about every 5 minutes and each time it runs, it gets all zone's user count and updates a database or a xml file of your website.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
vmnikulin
Posts: 26
Joined: 17 Feb 2012, 12:48

Re: number of users in a zone

Postby vmnikulin » 05 Jun 2012, 19:42

Hello!

Please advise me what is a better way: create client request handler or generate xml file for embedded Jetty container with http access?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: number of users in a zone

Postby rjgtav » 06 Jun 2012, 15:49

Hi.
Well, the downside of the xml file approach is that the browser tends to cache those kind of files when you access them multiple times. The positive aspect of this approach is that this way you would release some of the pressure from the server, by handling this request outside of it.

The easiest way is to have a Client Request Handler in your Zone-Level extension that returns the value of the current Zone's user count. If you don't need to show such an accurate user count, then you can use a task that runs at a specific rate which, every time it runs, it checks all the Zone's user count and updates a local variable on the extension. Then, when a client asks for the user count, the extension can easily return these stored values, instead of calculating it at every request. The only downside of this approach is when you have multiple zones, as then you would need to connect 2 times to the server before being able to play the game: one for retrieving the Zone's data and the other one for finally logging in.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.

Return to “SFS2X ActionScript 3 API”

Who is online

Users browsing this forum: No registered users and 1 guest