BF2 Statistics
Gathering Data
The official player stats that are accessible in-game via BFHQ are also accessible via simple HTTP calls. There are several URLs for accessing the statistics for each player. Each function takes a variety of parameters encoded via standard &keyword=value CGI parameters. The base URLs are:
http://bf2web.gamespy.com/ASP/getplayerinfo.aspx
http://bf2web.gamespy.com/ASP/getunlocksinfo.aspx
http://bf2web.gamespy.com/ASP/getrankinfo.aspx
http://bf2web.gamespy.com/ASP/getbackendinfo.aspx
http://bf2web.gamespy.com/ASP/getawardsinfo.aspx
http://bf2web.gamespy.com/ASP/getleaderboard.aspx
http://bf2web.gamespy.com/ASP/searchforplayers.aspx
Note: These URLs are currently being blocked due to server performance problems, please see the discussion section for details. You may also rely upon essay orderfor getting all the necessary information just in time.
Each function returns data in a similar standard format, the data is simple text with tab seperated data values. The opening line will either be an O or an E, an E signifies an error has occurred, whereas an O is valid data. The last line of the returned data starts with a $ followed by the number of bytes in the message (without tabs, newlines, or the length itself), followed by a final $. When valid data is returned, the lines consist of header and data rows, indicated by H and D. Each header row is followed by one or more data rows.
Example of valid data
O H rank chng decr D 2 1 0 $ 18 $
Example of an error
E 107 $ 4 $
Function: getplayerinfo
Accessing this function gives some information on how it works. To get information for a specific player, you can pass either the players ID or Nickname.
Accepted parameters
- pid
- (integer) Unique player ID
-
nick :(string) Unique player nickname (interestingly enough, the nick parameter is not case sensitive --MadHatter )
seems "nick" is no longer accepted as of 08 november 2005 (perhaps this is temporary. also it seems only the full query produced in game gets a response from the stats servers) -- MadHatter - info
- Requested fields. Returns all fields if empty. Use per* for basic info. (Comma separated list of strings "&info=rank,scor".)
- weapon
- Filter function. Returns just demanded fields. (Comma separated list of numbers, range 0 to 12 "&weapon=0,1,2,3". Weapon codes: 0 = "Assault Rifle", 1 = "Grenade Launcher", 2 = "Carbine", 3 = "Light Machinegun", 4 = "Sniper", 5 = "Pistol", 6 = "Anti-Tank", 7 = "Sub-Machinegun", 8 = "Shotgun", 9 = "Knife", 10 = "Defibrilator", 11 = "Explosives", 12 = "Grenade", 13 = "Zipline")
- debug
- Unknown values.
- transpose
- Mode of data output. (Values 0 or 1 "&transpose=0")
- nocache
- Numerical value.
Returned Results
The amount of data returned per line is quite large (2,000 characters or so), the example below is truncated.
O H asof D 1119891952 H pid nick scor jond wins loss mode0 mode1 mode2 time ... D 43861616 -=EA=-Vex 138 1118768100 3 7 10 ... $ 1792 $
Line 2: asof informs us "as of" when this data was collected.
Line 3: This contains a unix timestamp value (in seconds) for the above item (i.e the date of collection). This time seems to be the time of the actual request, rather than the time of the last update to the data on Gamespy's servers.
Line 4: These are the headers for all the players statistic information
Line 5: This is all the actual data.
Details of each of the data column meanings can be seen here: getplayerinfo columns
NOTE: As of atleast November 8th 2005 nick=(string) is no longer accepted. If nick= is used, the test html form with
Nick: [ text input ] [X] Test All [ Submit Button ]
will be returned instead of the results like it used to.
Battlefield 2 Internal Calls
The actual call made by Battlefield 2 to get the basic player stats is as follows: Example. The parameters passed to the function are as follows:
pid set to the logged in players id. info set to per*,cmb*,twsc,cpcp,cacp,dfcp,kila,heal,rviv,rsup,rpar,tgte,dkas,dsab, cdsc,rank,cmsc,kick,kill,deth,suic,ospm,klpm,klpr,dtpr,bksk,wdsk,bbrs,tcdr,ban,dtpm, lbtl,osaa,vrk,tsql,tsqm,tlwf,mvks,vmks,mvn*,vmr*,fkit,fmap,fveh,fwea,wtm-,wkl-,wdt-, wac-,wkd-,vtm-,vkl-,vdt-,vkd-,vkr-,atm-,awn-,alo-,abr-,ktm-,kkl-,kdt-,kkd-
To get the time details (time playing a particular map, weapon, etc), Battlefield 2 makes the follow call: Example. The parameters passed to the function are as follows:
pid set to the logged in players id. info set to ktm-,vtm-,wtm-,mtm- kit set to kit id vehicle set to vehicle id weapon set to weapon id map set to map id
To get details for all the maps (time played, wins, losses), Battlefield 2 makes the follow call: Example. The parameters passed to the function are as follows:
pid set to the logged in players id. info set to mtm-,mwn-,mls-
Function: getunlocksinfo
This provides details of the players unlocked weapons.
Accepted parameters
- pid
- (integer) Unique player ID
- nick
- (string) Unique player nickname
Returned results
Sample below is for a character with no weapons unlocked. (s would indicate a weapon as unlocked)
O H pid nick asof D 44314195 KuranesGrey 1120492111 H enlisted officer D 0 0 H id state D 11 n D 22 n D 33 n D 44 n D 55 n D 66 n D 77 n $ 98 $
Battlefield 2 Internal Call
The actual call made by Battlefield 2 to get the unlocks information is as follows: Example. The parameters passed to the function are as follows:
pid set to the logged in players id.
Function: getrankinfo
This function provides details on a particular players rank.
Accepted parameters
- pid
- (integer) Unique player ID
Returned Results
The function returns data in the standard format, the rank column contains the players rank, the other two data columns are unknown at present.
O H rank chng decr D 2 1 0 $ 18 $
note: The chng Column seems to be the Promote Rank Announce flag.
with this flag set to 1, after logging in game, a rank Promotion announcement pops up
The decr Colums seems to be its opposite. settin this flag to 1, will pop up a demotion announcement.
--SatcomNL 07:46, 28 Jul 2005 (MDT)
Battlefield 2 Internal Call
The actual call made by Battlefield 2 to get the rank information is as follows: Example. The parameters passed to the function are as follows:
pid set to the logged in players id.
Function: getbackendinfo
This function appears to simply provide a list of the weapon unlocks.
Accepted parameters
None known at present
Returned Results
H ver now D 0.1 1139053989 H id kit name descr D 11 0 Chsht_protecta Protecta shotgun with slugs D 22 1 Usrif_g3a3 H&K G3 D 33 2 USSHT_Jackhammer Jackhammer shotgun D 44 3 Usrif_sa80 SA-80 D 55 4 Usrif_g36c G36C D 66 5 RULMG_PKM PKM D 77 6 USSNI_M95_Barret Barret M82A2 (.50 cal rifle) D 88 1 sasrif_fn2000 FN2000 D 99 2 sasrif_mp7 MP-7 D 111 3 sasrif_g36e G36E D 222 4 usrif_fnscarl FN SCAR - L D 333 5 sasrif_mg36 MG36 D 444 0 eurif_fnp90 P90 D 555 6 gbrif_l96a1 L96A2 $ 391 $
Line 2: ver appears to indicate server version? now is the current server time.
Line 3: These are the data for the above sections, the now data is a unix timestamp value.
Line 4: The headers are as follows
- id which links to the unlock ID found in the getunlocksinfo function.
- kit this is the kit number that the unlock is associated to, see BF2Stats_LookUp_Values.
- name this is the unlocked weapon name.
- descr this is the description of the weapon.
Line 5 - Line 16: The actual unlock weapon data.
Battlefield 2 Internal Call
The actual call made by Battlefield 2 to get the backend information is as follows: Example. No parameters are passed to the function.
Function: getawardsinfo
This provides a list of awards for a particular player.
Accepted parameters
- pid
- (integer) Unique player ID
Returned Results
The data is returned as simple text, using tabs to seperate each item of data.
O H pid asof D 43861616 1120006575 H award level when first D 1031119 1 1119898482 0 D 1031120 1 1119999271 0 D 1220118 1 1119583630 0 D 1220803 1 1119897005 0 D 2051902 1 1119999271 1119999271 D 3211305 0 1119999271 0 $ 177 $
Line 2: Contains headers for pid and asof, these are the player id and the time when the data was collected.
Line 3: This contains the players id and a unix timestamp value.
Line 4: These are the headers for all the players awards.
Line 5 - Line 10: This is all the actual data. See the BF2Stats_LookUp_Values page for award names.
Line 11: This appears to be some sort of length value?
Details of each of the data column meanings can be seen here: getawardsinfo columns
Battlefield 2 Internal Call
The actual call made by Battlefield 2 to get the awards information is as follows: Example. The parameters passed to the function are as follows:
pid set to the logged in players id.
Function: getleaderboard
This provides details of the leaderboard. This function is quite complex and can be called in various modes. It also is currently (2005-07-04) returning errors quite frequently.
Lookup player's rank
Accepted parameters
- pid
- (integer) Unique player ID
- nick
- (string) Unique player nickname
- type
- (string) "score", "kit", "vehicle", "weapon"
- id
- (string)
- score → "overall", "combat", "commander", "team"
- kit → 0 - 6
- vehicle → 0 - 6 (id 5 is not supported)
- weapon → 0 - 8
- army → 0-2 (other id's are not supported)
- map → 0-6, 100-105 (id's 104, 300-307 and 601 are not supported!?)
Returned results
http://bf2web.gamespy.com/ASP/getleaderboard.aspx?pid=44314195&type=score&id=overall
O H size asof D 945816 1119531977 H n pid nick score totaltime playerrank countrycode D 53275 44314195 KuranesGrey 209 14885 0 US $ 107 $
Get top N players by score
Accepted parameters
- type
- (string) "score", "timeplayed", "risingstar" --MHacker 02:48, 9 Oct 2005 (MDT)
- id
- (string) "overall", "combat", "commander", "team" --MHacker 02:48, 9 Oct 2005 (MDT)
- after
- (integer) # of positions to fetch
- pos
- (integer) optional
- before
- (integer) optional
Returned Results
http://bf2web.gamespy.com/ASP/getleaderboard.aspx?type=score&id=overall&after=3
O H size asof D 432214 1120444326 H n pid nick score totaltime playerrank countrycode D 1 43390321 -=ScharfuhrerKarr=- 29531 257854 4 US D 2 44449228 -=ScharfuhrerKonig=- 25715 258648 4 US D 3 43037608 Striff 22397 160288 3 US D 4 44479050 =BOD=Grim 21517 255351 3 US $ 221 $
size is the total quantity of ranked players stored in the gamespy database...
More Official Queries
These are the official queries captured from the BF2 client. They always assume the top of the list.
Scores, Overall
http://bf2web.gamespy.com/ASP/getleaderboard.aspx?type=score&id=overall&pos=1&before=0&after=19
Scores, Rising Star
http://bf2web.gamespy.com/ASP/getleaderboard.aspx?type=risingstar&pos=1&before=0&after=19
Scores, Commander
http://bf2web.gamespy.com/ASP/getleaderboard.aspx?type=score&id=commander&pos=1&before=0&after=19
Scores, Teamwork
http://bf2web.gamespy.com/ASP/getleaderboard.aspx?type=score&id=team&pos=1&before=0&after=19
Scores, Combat
http://bf2web.gamespy.com/ASP/getleaderboard.aspx?type=score&id=combat&pos=1&before=0&after=19
Kits, replace X with kit id
http://bf2web.gamespy.com/ASP/getleaderboard.aspx?type=kit&id=X&pos=1&before=0&after=19
Vehicles, replace X with vehicle id
http://bf2web.gamespy.com/ASP/getleaderboard.aspx?type=vehicle&id=X&pos=1&before=0&after=19
Kit equipment, replace X with weapon id
http://bf2web.gamespy.com/ASP/getleaderboard.aspx?type=weapon&id=X&pos=1&before=0&after=19
Notes: The client adds 20 to the "pos" value, for the next batch of players to display, on pressing next, the rest stays the same, so for second page, pos would be 21. The client always sends two questions to the server, one is the above, the other is sent before that one, is a query for the players position, that looks like this for the overall score: "/ASP/getleaderboard.aspx?pid=PID&type=score&id=overall".
Function: searchforplayers
Accepted parameters
- nick
- (string) "part or full nickname"
- where
- (string) "a" (any), "b" (begin), "e" (end), "x" (exact)
- sort
- (string) "a" (alpha/numeric), "r" (reverse), if not set, sorted by ASCII worth
- debug
- (string) "txs" (function unknown!)
- transpose
- (boolean) "0" or "1"
Returned Results
http://bf2web.gamespy.com/ASP/searchforplayers.aspx?nick=[xxxx]&where=b&sort=a&debug=txs&transpose=0
O H asof D 1135006849 H n pid nick score D 1 59647909 [xxxx]-=WS=-Green 0 D 2 48335844 [xxxx]12thRLJaded 0 D 3 47814291 [xxxx]Backstabber 1720 $ 118 $
Example code for gathering data
Some Python code is available here: http://65.254.53.148/bf2/Bf2View.cgi
Some PHP code available here: http://www.puonti.net/stuff/bf2-xml_parser.zip
(Note: line 7 of the formattime function should read "} else if($hours >= 10) {" --Shufty 11:24, 23 Sep 2005 (MDT)) *DEAD*
PHP-class for fetching BF2 statistics is available here: http://snailbox.ath.cx:4880/bf2stats/ (more info at [1])
Byte Size Appender: PHP Script that automatically appends the proper byte size line to the end of bf2web output scripts.
An open source VB6 GUI Stats program is available here: http://www.HToC.com/BF2Stats/
PHP sample : It works.. depends if the HTTP server allows it :
<?php $pid = 'REQUESTED_PID'; $filename = "http://bf2web.gamespy.com/ASP/getplayerinfo.aspx?pid=$pid"; ini_set("user_agent","GameSpyHTTP/1.0"); $fp = fopen ($filename, "r"); $data = ; while (!feof ($fp)) { print fgets( $fp, 4096 ); } ?>
PHP sample which uses cURL
<?php $pid = 'REQUESTED_PID'; $ch = curl_init(); $header[]="User-Agent: GameSpyHTTP/1.0\r\n"; $header[]="Connection: close\r\n"; curl_setopt($ch, CURLOPT_URL, "http://bf2web.gamespy.com/ASP/getplayerinfo.aspx?pid=$pid"); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HTTPHEADER,$header); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); $data=curl_exec($ch); print_r($data); ?>
--Pailakka 18:20, 09 Dec 2005 (GMT)
PHP parser
<?php /** * Creates an array by using one array for keys and another for its values * * @author Daniel Luft (erozion at t-online.de) * @param array $keys * @param array $values * @return array */ if (!function_exists('array_combine')) { function array_combine($keys, $values) { if (!is_array($keys)) { user_error( 'array_combine() expects parameter 1 to be array, ' . gettype($keys) . ' given', E_USER_WARNING ); return; } if (!is_array($values)) { user_error( 'array_combine() expects parameter 2 to be array, ' . gettype($values) . ' given', E_USER_WARNING ); return; } $keysCount = count($keys); $valuesCount = count($values); if ($keysCount !== $valuesCount) { user_error( 'array_combine() Both parameters should have equal number of elements', E_USER_WARNING ); return false; } if ($keysCount === 0 || $valuesCount === 0) { user_error( 'array_combine() Both parameters should have number of elements at least 0', E_USER_WARNING ); return false; } $combined = array(); foreach ($keys as $index => $key) { $combined[$key] = $values[$index]; } return $combined; } } /** * Gets the statistics from bf2web.gamespy.com as associative array * * @author Daniel Luft (erozion at t-online.de) * @param string $rawData * @return array */ function parseData($rawData) { if (! preg_match_all('!^O\n(.*?)\n?\$\t(\d+)\t\$\n$!s', $rawData, $matches) ) return false; $lines = preg_split('!\n!', $matches[1][0], -1, PREG_SPLIT_NO_EMPTY); $result = array(); foreach ($lines as $line) { $data = explode("\t", $line); $flag = array_shift($data); if (strtoupper($flag) == 'H') { $header = $data; continue; } $result[] = array_combine($header, $data); } return $result; } ?>
- note array_combine(...) is only available in PHP 5 or later.
- thanks for the hint (eRoZion)
Look up values
The identification numbers and corresponding text details can be found here, BF2Stats_LookUp_Values
Things to add
- Further details on the various functions
- Example URLs for each return data
- Add more example code (working on some php code at the moment)
- Other parameters for getleaderboard: id, type
Mysteries
- The time columns for 'Squad Leader', 'Squad Member' and 'Lone Wolf' don't appear to be returned by the getplayerinfo, despite being listed in the column list. Resolution - To get these fields (and possibly some others), you need to use the info parameter in the getplayerinfo function, Example Call
(Resolution does not work since 08 november 2005, we need the exact query executed by the client, the server does not give proper response to non-standard info parameters) --Flatline 01:29, 10 Nov 2005 (MST)
- What do the chng and decr columns represent in the getrankinfo function? More information - These fields appear to stand for changed and decreased, and are some form of flag...[Update!] These flags are for announcing a Promotion - Demotion in rank after logging into gamespy [/update]
- The columns tgm (gasmask) and tnv (nightvision) are nowhere documented. The server returns 0 values for every player. Maybe another pair of unused columns? Or SF specific ones (nightvision, teargas?) ShimonMoon 11 Dec 2005
- Perhaps the columns de-6, de-7, de-8 standing for the destruction of the commanders toys (radar, UAV and artillery)?
- de-? stands for deployed. de-6 = deployed tactical(flashbang, teargas), de-7 = deployed grappling hook, de-8 = deployed zip line.
External Links
Official test framework: helps you learn how to construct URLs *DEAD* *It seems this url is back online*
BF2 url tester: Enter an url and hit submit on the page to see which results are returned. Also generates some very basic php code to fetch results from an url.
BF2E.com, Battlefield 2 Web-based stats viewer, NO CACHING EVER
_l0ser's Signature Image Generator. One of the first. Provided by LANCAMP.com
Official URL for gathering data - please see the discussion section for details on why this link no longer works as expected.
Alternative Battlefield Ranking - A total Makeover of Bighamster's Bf2stats ( which is discontinued ) The total New approach, with a Web Backend and Serverside python Scripts makes ABR the Big Brother of EA's stats. With Mod Support,'Seee your stats in BFHQ' makes it ideal for creating Tournaments or private Stats with rank's and ingame awards included -all fully customizable. ABR has its own Backend exactly like EA.
Alternative Battlefield Ranking Stats Page - Official ABR Stats WebPage.
Battlefield.cl Chilean Community Stats Webpage (ABR), pool chemicals ] - Custom Stats webpage using ABR Stats servers for the Chilean Community of http://www.battlefield.cl
BF2Sigs - BF2 Stat and Server Signatures. (Now supporting Alternative BattleField Ranking)
WBFHQ - An application to get all your stats, save them, compare them, ... see screenshots for more details
Tomaplomo - BF2 Statistics and dynamic signatures in spanish
ClanXS: BF2Stats for Eggdrop - Get your stats on IRC (TCL script)
Battlefield (2) Stats Viewer - Comfortable Bf2 Stats application (Receive, view and compare your Stats)
BF2Statistics.com - Your Own Private Ranked Server wich is capable to produce: In-game awards, ranks, unlocks and Stats to appear in BFHQ. Your Own database hosted on your server, and fully in your control. Your Own WebStats System installed locally, to view and compare your stats with other clan members or players. You control ranks, score and other in-game ranking parameters. In other words we are giving you the opportunity to install a Ranking System where ever you want it : clan server, lan parties and public Servers.
Wargrounds.net BF2 Player Stats - A Battlefield 2 Official player statistics viewer.