You are not logged in.

#1 11 Jan 2008 4:28 am

azzlack
Senior Member
From: Bergen, Norway
Registered: Jan 2008
Posts: 26
Website

BF2 rank script - how to show online status

Is there a way to get information about the online status of a player?

I was thinking of something showing if the pid queried is offline (not playing bf2) or online and then show which server he is playing on?

Would it be possible to use the "sv*-" parameter to find the server a player is on?

You can see the script in action here: http://bobforum.eyecatch.no/stats/?nick=Eyecatch


Regards,
Ove Andersen

Last edited by azzlack (11 Jan 2008 5:04 am)


Web Developer and Designer.
Currently studying for Bachelor of Computer Science degree ...

Offline

 

#2 11 Jan 2008 8:50 am

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: BF2 rank script - how to show online status

you may be able to base whether they are currently playing off of the lbtl (last battle time) field given some threshold (15 minutes or something), and where they are playing off of the svr-0 field.

I haven't ever tried it myself, but in theory it should work.  otherwise you'd have to track all the servers online and query that data to see whether the player is playing and where.

Offline

 

#3 11 Jan 2008 12:24 pm

azzlack
Senior Member
From: Bergen, Norway
Registered: Jan 2008
Posts: 26
Website

Re: BF2 rank script - how to show online status

i already implemented the lbtl, but when i tried to add the svr-0 field to the query, i get an index out of bounds error.

on second thought, doesn't the per* parameter already include the svr-0?

if so, how should i edit the index.php?


Web Developer and Designer.
Currently studying for Bachelor of Computer Science degree ...

Offline

 

#4 11 Jan 2008 3:56 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: BF2 rank script - how to show online status

per* doesn't include the server that they're currently on.  you can tell whether they're online using lbtl (there's like a 20 minute difference between my web server and the time I see being reported for someone I know is online).

you should be able to tell what server they're on using svr-0, but you have to do additional queries to get that.  since gamespy only allows certain combinations of parameters in getplayerinfo, I'll have to log in and try to pull my stats, and see what query the svr- parameters show up in (and then add that to my bf2_player.php file).

I updated my bf2_player.php file to include all of the queries that I put in the comments of that file.  if you want to update the one you have and use this one, then you're more then welcome to.  this version allows either nick or pid to be passed in to the constructor of bf2_player.  if it finds the player, then is_valid will be true.

here's the code for that:

Code:

<?php
/* A class that loads a players stats, awards and other info
 *
 * 
 * /ASP/getplayerinfo.aspx?pid=${PID}&info=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-
 * /ASP/getplayerinfo.aspx?pid=${PID}&info=ktm-,vtm-,wtm-,mtm-&kit=4&vehicle=0&weapon=2&map=4
 * /ASP/getplayerinfo.aspx?pid=${PID}&info=mtm-,mwn-,mls-
 * /ASP/getunlocksinfo.aspx?pid=${PID}
 * /ASP/getrankinfo.aspx?pid=${PID}
 * /ASP/getbackendinfo.aspx
 * /ASP/getawardsinfo.aspx?pid=${PID}
 */
class bf2_player {
    var $_pid = 0;
    var $_nick = false;
    /*
     * @var array an associative array containing the players stats
     * @access public
     */
    var $stats = array();
    /* 
     * @var bf2_weapons_map an associative array containing a list of weapons and their lock / unlock status
     * @access public
     */
    var $unlocks;
    /*
     * @var bf2_award_map lists the players awards
     */
    var $awards;
    /*
     * @var boolean tells whether we were able to load the players info.
     */
    var $is_valid_player = false;
    function bf2_player($resource=false) {                
        require_once("lib/http.php");
        require_once("bf2_weapon.php");
        require_once("bf2_weapon_map.php");
        require_once("bf2_award_info.php");
        require_once("bf2_award_map.php");
        
        if(!$resource) return;
        
        if(!intval($resource)) {
            $this->_nick = $resource;
            $this->_get_pid();
        } else {
            $this->_pid = intval($resource);
        }
        $this->is_valid_player = $this->_pid > 0;
        if($this->is_valid_player) {
            $this->unlocks = new bf2_weapons_map();
            $this->_get_stats();
            //$this->_get_unlocks();
            //$this->_get_awards();
        }
    }
    function _get_stats() {        
        $url = "http://BF2Web.gamespy.com/ASP/getplayerinfo.aspx?pid=".$this->_pid."&info=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-";
        $results = $this->_query_ea($url);
        $this->stats = array();
        $this->_get_result_set($results, $this->stats);
        
        $url = "http://BF2Web.gamespy.com/ASP/getplayerinfo.aspx?pid=".$this->_pid."&info=ktm-,vtm-,wtm-,mtm-&kit=4&vehicle=0&weapon=2&map=4";
        $results = $this->_query_ea($url);
        $this->_get_result_set($results, $this->stats);
        
        $url = "http://BF2Web.gamespy.com/ASP/getplayerinfo.aspx?pid=".$this->_pid."&info=mtm-,mwn-,mls-";
        $results = $this->_query_ea($url);
        $this->_get_result_set($results, $this->stats);
        
//        $url = "http://BF2Web.gamespy.com/ASP/getplayerinfo.aspx?pid=".$this->_pid."&info=sv*-";
//        $results = $this->_query_ea($url);
//        $this->_get_result_set($results, $this->stats);
        
        $url = "";
        
    }    
    function _get_unlocks() {
//        $bed = "";
//        $this->_map_backend_data($bed);
//        $url = "http://BF2Web.gamespy.com/ASP/getunlocksinfo.aspx?pid=".$this->_pid;
    }
    function _get_awards() {
        $url = "http://bf2web.gamespy.com/ASP/getawardsinfo.aspx?pid=".$this->_pid;
        $response = $this->_query_ea($url);
        $this->_build_awards($response);
    }
    function _get_pid() {
        $url = "http://BF2Web.gamespy.com/ASP/searchforplayers.aspx?where=x&nick=".$this->_nick;
        $response = $this->_query_ea($url);            
        $this->_get_result_set($response, $result);
        if(isset($result)) {
            $this->_pid = $result['pid'];
            $this->_nick = $result['nick'];
        }else {
            $this->_pid = -1;
        }
    }
    function _map_backend_data($str) {
            /*  CURRENT WEAPON LIST REPORT
                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                
            */
        $lines = explode("\n", $str);
        $results = array();
        $line_count = count($lines);
        $line_num = 0;
        $stats = array();
        while ($line_num < $line_count) {
            $next_line = $line_num + 1;
            $line_one = explode("\t", $lines[$line_num]);
            $len = count($line_one);
            if($line_one[0] == '$') {
                break;
            }
            if($line_one[0] == 'O') {
                    $line_num++;
                    continue;
            }
            if($line_one[0] == 'H') {
                $line_two = explode('    ', $lines[$next_line]);
                $line_two_len = count($line_two);
                if($line_two_len > 0 && $line_two[0] == 'D') {                
                    for($index = 1; $index <= $len; $index++) {
                        if(isset($line_one[$index])) {
                            $results[$line_one[$index]] = trim($line_two[$index]);
                        }
                    }
                }else {
                    $line_num++;
                    continue;
                }
            }
            $line_num+=2;
        }
        return $results;
    }
    function _query_ea($url) {       
        $search_request = new http_class();
        $search_request->timeout = 0;
        $search_request->data_timeout = 0;
        $search_request->user_agent="GameSpyHTTP/1.0";
        $args = null;
        $error = $search_request->GetRequestArguments($url, $args);
        if($error != "") {
            $search_request->Close();
            return -1;
        }    
        $error = $search_request->Open($args);
        flush();
        if($error != "") {
            $search_request->Close();
            return -1;
        }
        $search_request->SendRequest($args);
        flush();
        $headers = array();
        $search_request->ReadReplyHeaders($headers);
        if($search_request->response_status != "200") {
            $search_request->Close();
            return -1;
        }
        if($search_request->content_length_set && $search_request->content_length <= 0) {
            $search_request->Close();
            return -1;
        }
        $body = false;
        do {
            $buffer = 0;
            $error=$search_request->ReadReplyBody($buffer, 4096);
            $body .= $buffer;
        }while($error == ""    && strlen($buffer) != 0);
        $search_request->Close();
        return $body;        
    }
    function _get_result_set($str, &$results) {
        $lines = explode("\n", $str);
        $line_count = count($lines);
        $line_num = 0;
        $stats = array();
        while ($line_num < $line_count) {
            $next_line = $line_num + 1;
            $line_one = explode("\t", $lines[$line_num]);
            $len = count($line_one);
            if($line_one[0] != '$') {
                if($line_one[0] == 'O') {
                    $line_num++;
                    continue;
                }
                else if($line_one[0] == 'H') {
                    $line_two = explode('    ', $lines[$next_line]);
                    $line_two_len = count($line_two);
                    if($line_two_len > 0 && $line_two[0] == 'D') {                
                        for($index = 1; $index <= $len; $index++) {
                            if(isset($line_one[$index])) {
                                $results[$line_one[$index]] = trim($line_two[$index]);
                            }
                        }
                    }else {
                        $line_num++;
                        continue;
                    }
                }
                $line_num+=2;
            }else {
                break;
            }
        }
    }
    function _build_awards($str) {
        $awards_map = new bf2_award_map();
        $lines = explode("\n", $str);
        $results = array();
        $line_count = count($lines);
        $line_num = 0;
        $stats = array();
        while ($line_num < $line_count) {
            $next_line = $line_num + 1;
            $line_one = explode("\t", $lines[$line_num]);
            $len = count($line_one);            
            if($line_one[0] == 'O') {
                $line_num++;
                continue;
            } else if($line_one[0] == 'H') {
            } else if($line_one[0] == '$') {
                break;
            }
            $line_num++;
                
        }
        return $results;
    }
}

?>

and I'll add the queries (if the game does them) later on tonight when I get home from work.

Offline

 

#5 11 Jan 2008 8:43 pm

MadHatter
Administrator
From: Dallas TX
Registered: Jun 2006
Posts: 529
Website

Re: BF2 rank script - how to show online status

well, I decompiled both the game client and server, and while svr-* is listed on the GetPlayerInfo columns page on bf2tech, it is not physically located in either binary.

I also pulled every available stat from in game client, and captured every network packet, and it never showed up, so my guess is that once upon a time, that parameter was allowed in a custom query to getplayerinfo, but is not allowed anymore.

as far as I can see it, your other options are, 1. poll every game server out there and store player info that you can query against, or 2. scrape game-monitor.com, or pay them for online services (like an xml feed that you can query against).

Offline

 

#6 13 Jan 2008 11:11 pm

azzlack
Senior Member
From: Bergen, Norway
Registered: Jan 2008
Posts: 26
Website

Re: BF2 rank script - how to show online status

Thank you for the help. I will just use the lbtl as you said first to tell if the player is online or not.
For a simple stats script, querying everything out there is too much.

Anyways, thanks for taking the time to help me!

Regards,
Ove Andersen


Web Developer and Designer.
Currently studying for Bachelor of Computer Science degree ...

Offline

 



© 2003 - 2024 NullFX
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License