AAO25.com

America's Army => General Chat => Topic started by: Spanky on Monday, September 16, 2013, 18:44:54 PM

Title: JSON Statistics for Assist
Post by: Spanky on Monday, September 16, 2013, 18:44:54 PM
Rapture came to me earlier asking for a way to have the number of players and number of servers passed on to other websites. So, I decided to export the stats from AAO25 into JSON format with some PHP code. Here it is for anyone to use:

http://aao25.com/stats/json.php

Example output:
Code: [Select]
{"players":"73","servers":"83","top server":"{ATAS} - TR - EU - SERVER","auth":"online","auth_time":"1379373722","downloads":"62,488","assist_ver":"7.48","assist_news":"Visit http:\/\/aao25.com for updates.","most_players":"132","most_players_time":"1379270942"}
Per the example above, stats are ordered as follows:
Players In-Game: 73 - [Will not be updated if auth is offline]
Servers Online: 83 - [Will not be updated if auth is offline]
Top Server: {ATAS} - TR - EU - SERVER - [Shows server with the most players, ill not be updated if auth is offline]
Authorization Status: online - [will show 'offline' when auth is down]
Authorization Last Online: 1379373722 - [unix timestamp, CST, -6 UTC, can be converted with PHP date();]
Assist Downloads: 62,488 - [Taken directly from SourceForge]
Assist Version: 7.48
Assist News: Visit http:\/\/aao25.com for updates - [News shown in the Assist client]
Most Players Online Ever: 132
Most Players Online Time: 1379270942 - [The unix timestamp that the 132 players were on, , CST, -6 UTC, can be converted with PHP date();]
Title: Re: JSON Statistics for Assist
Post by: M_TopSecret on Monday, September 16, 2013, 18:49:09 PM
Thanks Spank!  :style:
Title: Re: JSON Statistics for Assist
Post by: Spanky on Monday, September 16, 2013, 18:50:50 PM
Thanks Spank!  :style:

Would you like the Auth online/offline status as well? No sense displaying # of players if auth is down. The way I have the code here, if auth is down, # of players doesn't get updated so you could return the # of players that was online just before auth was down and that might confuse people. Anything else you could think of?
Title: Re: JSON Statistics for Assist
Post by: alechko1 on Monday, September 16, 2013, 18:58:01 PM
I can do interactive charts like that when you can hover with your mouth or press on them to change visualizatopn if you think you can find it a use for it (or if I wont be too lazy working on that)

http://ramnathv.github.io/rCharts/
Title: Re: JSON Statistics for Assist
Post by: Spanky on Monday, September 16, 2013, 19:10:46 PM
I can do interactive charts like that when you can hover with your mouth or press on them to change visualizatopn if you think you can find it a use for it (or if I wont be too lazy working on that)

http://ramnathv.github.io/rCharts/

I started work on some, got most of my ideas implemented:
http://aao25.com/info#Player_Stats

Since Assist was shut down, I wiped all the stats so there wasn't a gap in the timeline so it may take another week for the other charts to populate.
Title: Re: JSON Statistics for Assist
Post by: Jared on Monday, September 16, 2013, 19:14:21 PM
nice work spank  :?
Title: Re: JSON Statistics for Assist
Post by: Spanky on Monday, September 16, 2013, 19:15:47 PM
nice work spank  :?

Thanks. Auth is added. Values are either online or offline. I know it should probably be true/false but I don't feel like going through all the code and editing it for pretty much no gain.
Title: Re: JSON Statistics for Assist
Post by: Spanky on Monday, September 16, 2013, 19:31:50 PM
Updated original post with some ghetto documentation and more stats for the JSON output.
Title: Re: JSON Statistics for Assist
Post by: ibad on Monday, September 16, 2013, 20:13:17 PM
you should also note that if youre going to be displaying this information, use htmlentities() to prevent xss /csrf attacks. Unless of course its already filtered from when spanky extracts it. Either way it can't hurt =D
Title: Re: JSON Statistics for Assist
Post by: HANG_JEBAT on Monday, September 16, 2013, 21:09:14 PM
Good job, I hope it's will reach the old players.  :up:
Title: Re: JSON Statistics for Assist
Post by: Spanky on Monday, September 16, 2013, 21:28:46 PM
you should also note that if youre going to be displaying this information, use htmlentities() to prevent xss /csrf attacks. Unless of course its already filtered from when spanky extracts it. Either way it can't hurt =D

Most of these stats couldn't be altered by outside people unless they hacked into the master server. Players & Servers are calculated by parsing the server list so if that got hijacked, the code would screw up in trying to add the non-numeric text to the tally. Pretty much the only one that could be 'hacked' is the 'top server' and could easily be done by reporting a server to Assist with 40 players, making it the 'top server'. So, the top server text is passed through this:
Code: [Select]
<?php $name htmlspecialchars(preg_replace('/[^(\x20-\x7F)]*/',''urldecode($pieces[4]))); ?>That strips weird characters that gamers come up with, replaces the %20 that Assist uses for spaces and replaces <, >, /, and &. So the output shouldn't harm a website. After running it through that, I also do a mysqli real_escape_string before entering it into the database for this site.

Still, it wouldn't hurt to re-process it on your end just to make 100% sure. I'll be the first to admit, I didn't go to school for this so I'm sure everything I make could be done better and probably isn't 100% secure/safe/efficient :)
Title: Re: JSON Statistics for Assist
Post by: ibad on Monday, September 16, 2013, 21:39:07 PM
All good just wanted to make sure , I use twig with autoescape on, very helpful.
Title: Re: JSON Statistics for Assist
Post by: 82nd_DXO_COL=Shad on Tuesday, January 14, 2014, 15:04:25 PM
return values in php:

Code: [Select]
<?php
function assist_stats(){
 
$fd fsockopen"aao25.com"80$errno$errstr30);
 if(
$fd){
  
fwrite($fd"GET /stats/json.php HTTP/1.1\r\nHost: aao25.com\r\nConnection: Close\r\n\r\n");
  
$res=@fread($fd1024);
  
fclose($fd);
 }
 else return 
false;
 if(!empty(
$res)){
  
$startpos=strpos($res,'{');
  
$endpos=strpos($res,'}')+1;
  if(
$startpos && $endpos) {
   
$str=substr($res,$startpos,($endpos-$startpos));
   
$varArr=json_decode($str,true);
   return 
$varArr;
  }
 else return 
false;
 }
 else return 
false;
}

$varArr=assist_stats();
if(
count($varArr)){
 echo 
"players: {$varArr['players']}\n";
 echo 
"servers: {$varArr['servers']}\n";
 echo 
"top server: {$varArr['top server']}\n";
 echo 
"auth: {$varArr['auth']}\n";
 echo 
"auth_time: ".date('r',$varArr['auth_time'])."\n";
 echo 
"downloads: {$varArr['downloads']}\n";
 echo 
"assist_ver: {$varArr['assist_ver']}\n";
 echo 
"assist_news: {$varArr['assist_news']}\n";
 echo 
"most_players: {$varArr['most_players']}\n";
 echo 
"most_players_time: ".date('r',$varArr['most_players_time'])."\n";
}
?>
Title: Re: JSON Statistics for Assist
Post by: 82nd_DXO_COL=Shad on Wednesday, January 22, 2014, 08:38:49 AM
Auth: online Sun, 05 Jan 2014 13:08:01 -0600
Ver: 8.02
Most Players: 199 Sat, 04 Jan 2014 14:57:01 -0600
Assist News:
Happy Hollidays Enjoy your surprise. Visit us at aao25.com

These stats correct?  I thought we were at 8.0.3
Title: Re: JSON Statistics for Assist
Post by: ELiZ on Wednesday, January 22, 2014, 08:44:20 AM
Auth: online Sun, 05 Jan 2014 13:08:01 -0600
Ver: 8.02
Most Players: 199 Sat, 04 Jan 2014 14:57:01 -0600
Assist News:
Happy Hollidays Enjoy your surprise. Visit us at aao25.com

These stats correct?  I thought we were at 8.0.3

I've changed the location of the file so the crons don't updated that information anymore.
Title: Re: JSON Statistics for Assist
Post by: Spanky on Saturday, January 25, 2014, 16:53:02 PM
Also, no crons are running and they haven't been running for some time. All the information is many weeks old.
Title: Re: JSON Statistics for Assist
Post by: RealHarm on Monday, January 27, 2014, 13:17:02 PM
Also, no crons are running and they haven't been running for some time. All the information is many weeks old.
And why dont you enable them again?