[bf1942] BF2 Stats

Steven Hartland killing at multiplay.co.uk
Tue Jul 5 12:37:43 EDT 2005


Unfortunately that code wont work as there's no guarantee the response
will be in one packet and the packet format they use in gs3 is not
directly combinable :(

    Steve / K
----- Original Message ----- 
From: "Jorrit Schippers" <jorrit at gameparty.net>
To: <bf1942 at icculus.org>
Sent: 05 July 2005 17:25
Subject: RE: [bf1942] BF2 Stats


Perhaps this piece of code gets you anywhere. Be careful that the port parameter is the gamespy port, not the game port. It uses the 
newest Gamespy protocol as far as I know, at least the one with the 0x0 byte separator, not the slash separator.

People with knowledge of PHP: feel free to comment.

function getplayerlist($ip, $port = 29900, &$errormsg, $timeout = 10) {
$initgarbagelength = 7;
$partsep = chr(0).chr(0);
$fieldsep = chr(0);

$fp = fsockopen('udp://'.$ip, $port, $errno, $errstr, $timeout);
if (!$fp) {
$errormsg = 'Error connecting to '.$ip.':'.$port.': #'.$errno.': '.$errstr;
return false;
}
socket_set_timeout($fp, $timeout);

fwrite($fp, hexchar('fefd002121212100ff00'));
$data = fread($fp, 10000);

$data = substr($data, $initgarbagelength, strlen($data));
$parts = explode($partsep, $data);

$players = array();
$fields = explode($fieldsep, $parts[0]);
foreach($fields AS $k=>$v) {
$fields[$k] = substr($v, 0, strlen($v) - 1);
}
$playerdata = explode($fieldsep, $parts[1]);
unset($playerdata[count($playerdata)-1]);

$numfields = count($fields);
$numplayers = count($playerdata) / $numfields;

for($i=0;$i<$numplayers;$i++) {
for($j=0;$j<$numfields;$j++) {
$players[$i][$fields[$j]] = $playerdata[$i*$numfields+$j];
}
}

usort($players, 'playerlistcompare');

return $players;
}

function playerlistcompare($a, $b) {
return strcmp($a['player'], $b['player']);
}

function hexchar($input) {
$chars = array();

for($i = 0; $i < strlen($input); $i+=2) {
$chars[] = chr(hexdec($input{$i}.$input{$i+1}));
}

return implode('', $chars);
}

Jorrit Schippers

-----Oorspronkelijk bericht-----
Van: Rüdiger [mailto:Webmaster at robin1977.de]
Verzonden: dinsdag 5 juli 2005 10:14
Aan: bf1942 at icculus.org
Onderwerp: [bf1942] BF2 Stats

I think you misunderstood my question last time. I would like to know if there is a complete script to display the stats of an 
unranked server on a Homepage. Not the playerstats of ranked servers. I am not a good PHP-coder, so its a unsolvable problem for me 
to code such a script. Can anyone help me with a complete stats script for listing players who played on the local unranked 
BF2-server?





================================================
This e.mail is private and confidential between Multiplay (UK) Ltd. and the person or entity to whom it is addressed. In the event of misdirection, the recipient is prohibited from using, copying, printing or otherwise disseminating it or any information contained in it. 

In the event of misdirection, illegible or incomplete transmission please telephone (023) 8024 3137
or return the E.mail to postmaster at multiplay.co.uk.




More information about the Bf1942 mailing list