0 Members and 1 Guest are viewing this topic.
<?php// PHP ASE parser for Soldat by FliesLikeABrick// May be used for other games with a few slight modifications// (mainly removing the part that pretties up the output)// You are free to use this code for anything you want and redistribute/modify at willfunction readASEString($sock,$length = false) { $length = $length ? $length : ord(fread($sock,1)); return fread($sock,$length-1);}function ASE($host,$port) { $info = Array(); $s = fsockopen("udp://$host",$port+123); fwrite($s,"s"); fread($s,4); readASEString($s); $info['port'] = readASEString($s); $info['servername'] = readASEString($s); $info['ip'] = gethostbyname($host); $info['mode'] = readASEString($s); $info['map'] = readASEString($s); $info['version'] = readASEString($s); $info['passworded'] = readASEString($s); $info['numplayers'] = readASEString($s); $info['maxplayers'] = readASEString($s); // prime the loop conditional $lengthstring = fread($s,1); $length = ord($lengthstring); // loop through the key/value pairs and set them while($length != 1) { $info[readASEString($s,$length)] = readASEString($s); $lengthstring = fread($s,1); $length = ord($lengthstring); } // this entire section can be removed if you don't use them $info['survival'] = $info['Survival'] == 'No' ? false:true; $info['realistic'] = $info['Realistic'] == 'No' ? false:true; $info['remaining'] = explode(' ',$info['Time Left']); $info['remaining'] = $info['remaining'][0]; $info['minutes'] = explode(':',$info['remaining']); $info['seconds'] = $info['minutes'][1]; $info['minutes'] = $info['minutes'][0]; $info['timelimit'] = explode(' ',$info['Time Limit']); $info['timelimit'] = $info['timelimit'][0]; $info['protected'] = $info['Protected'] == 'No' ? false:true; // end removable section $info['players'] = Array(); for($i=0;$i<$info['numplayers'];$i++) { $info['players'][$i] = Array(); fread($s,1); $info['players'][$i]['name'] = readASEString($s); $info['players'][$i]['team'] = readASEString($s); $info['players'][$i]['skin'] = readASEString($s); $info['players'][$i]['score'] = readASEString($s); $info['players'][$i]['ping'] = readASEString($s); $info['players'][$i]['time'] = readASEString($s); } return $info;}?>
Array( [port] => 23073 [servername] => U13 CTF Public [Chicago] [ip] => 67.106.77.193 [mode] => Capture the Flag [map] => ctf_Equinox [version] => 1.3.1 [passworded] => 0 [numplayers] => 12 [maxplayers] => 12 [Respawn Time] => 5 Secs [Bonus Frequency] => None [Survival] => No [Realistic] => No [System] => Linux [Time Left] => 16:32 Minutes [Time Limit] => 20 Minutes [Next Map] => ctf_Kampf [Protected] => No [respawntime] => 5 Secs [bonusfreq] => None [survival] => [realistic] => [os] => Linux [remaining] => 16:32 [minutes] => 16 [seconds] => 32 [timelimit] => 20 [nextmap] => ctf_Kampf [protected] => [players] => Array ( [0] => Array ( [name] => mr.ming [team] => Bravo [skin] => Bravo [score] => 9 [ping] => 116 [time] => 3m ) [1] => Array ( [name] => Kastor [team] => Alpha [skin] => Alpha [score] => 7 [ping] => 16 [time] => 36m ) [2] => Array ( [name] => El Padre [team] => Bravo [skin] => Bravo [score] => 5 [ping] => 33 [time] => 55m ) [3] => Array ( [name] => DI [team] => Bravo [skin] => Bravo [score] => 7 [ping] => 83 [time] => 12m ) [4] => Array ( [name] => Playing Soldat on my PSP [team] => Alpha [skin] => Alpha [score] => 1 [ping] => 50 [time] => 3m ) [5] => Array ( [name] => Sniper(1) [team] => Bravo [skin] => Bravo [score] => 6 [ping] => 83 [time] => 17m ) [6] => Array ( [name] => Diss [team] => Alpha [skin] => Alpha [score] => 6 [ping] => 16 [time] => 79m ) [7] => Array ( [name] => Milf.Hunter [team] => Alpha [skin] => Alpha [score] => 2 [ping] => 50 [time] => 6m ) [8] => Array ( [name] => Corsair [team] => Bravo [skin] => Bravo [score] => 22 [ping] => 33 [time] => 10m ) [9] => Array ( [name] => K-Vader [team] => Alpha [skin] => Alpha [score] => 4 [ping] => 16 [time] => 9m ) [10] => Array ( [name] => ==Gordon Freeman== [team] => Alpha [skin] => Alpha [score] => 26 [ping] => 183 [time] => 16m ) [11] => Array ( [name] => [Legends]--->Eclipse [team] => Bravo [skin] => Bravo [score] => 26 [ping] => 16 [time] => 9m ) ))
Code: [Select]Array( [Survival] => No [Realistic] => No [Protected] => No [survival] => [realistic] => [protected] =>
Array( [Survival] => No [Realistic] => No [Protected] => No [survival] => [realistic] => [protected] =>
Wow cool just when I login I see this thread.Good work looks good ExceptQuote from: FliesLikeABrick on March 25, 2007, 09:57:35 pmCode: [Select]Array( [Survival] => No [Realistic] => No [Protected] => No [survival] => [realistic] => [protected] =>The lowercase versions are empty..When I get the time I'll try it out.
$sort = array();foreach($info['players'] as $res)$sort[] = $res['score'];array_multisort($sort, SORT_DESC, $info['players']);
and how do u use that?? (sry, but i never really was interested in that)
With socket-functions.The server sends the whole packet in one and you cannot read parts from it with socket functions.So i connect with socket functions, get the whole thing, and continue with "virtual socket functions".Works fine Code: [Select]<?php// PHP ASE parser for Soldat by FliesLikeABrick// changed from fsockopen to socket_* functions by minus// May be used for other games with a few slight modifications// (mainly removing the part that pretties up the output)// You are free to use this code for anything you want and redistribute/modify at willfunction readASEString($sock,$length = false) { $length = $length ? $length : ord(vsocket_read($sock,1)); return vsocket_read($sock,$length-1);}function ASE($host,$port) { $info = Array(); // Using Socketfunctions $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_connect($s, $host, $port+123); socket_write($s,"s"); $vsock = socket_read($s,512); // read to "virtual socket" $vpos = 0; // virtual socket "pointer" socket_close($s); $s = &$vsock; vsocket_read($s,4); readASEString($s); $info['port'] = readASEString($s); $info['servername'] = readASEString($s); $info['ip'] = gethostbyname($host); $info['mode'] = readASEString($s); $info['map'] = readASEString($s); $info['version'] = readASEString($s); $info['passworded'] = readASEString($s); $info['numplayers'] = readASEString($s); $info['maxplayers'] = readASEString($s); // prime the loop conditional $lengthstring = vsocket_read($s,1); $length = ord($lengthstring); // loop through the key/value pairs and set them while($length != 1) { $info[readASEString($s,$length)] = readASEString($s); $lengthstring = vsocket_read($s,1); $length = ord($lengthstring); } // this entire section can be removed if you don't use them $info['survival'] = $info['Survival'] == 'No' ? false:true; $info['realistic'] = $info['Realistic'] == 'No' ? false:true; $info['remaining'] = explode(' ',$info['Time Left']); $info['remaining'] = $info['remaining'][0]; $info['minutes'] = explode(':',$info['remaining']); $info['seconds'] = $info['minutes'][1]; $info['minutes'] = $info['minutes'][0]; $info['timelimit'] = explode(' ',$info['Time Limit']); $info['timelimit'] = $info['timelimit'][0]; $info['protected'] = $info['Protected'] == 'No' ? false:true; // end removable section $info['players'] = Array(); for($i=0;$i<$info['numplayers'];$i++) { $info['players'][$i] = Array(); vsocket_read($s,1); $info['players'][$i]['name'] = readASEString($s); $info['players'][$i]['team'] = readASEString($s); $info['players'][$i]['skin'] = readASEString($s); $info['players'][$i]['score'] = readASEString($s); $info['players'][$i]['ping'] = readASEString($s); $info['players'][$i]['time'] = readASEString($s); } return $info;}function vsocket_read($vsock, $length){ global $vpos; $str = substr($vsock, $vpos, $length); $vpos += $length; return $str;}?>
<?php// PHP ASE parser for Soldat by FliesLikeABrick// changed from fsockopen to socket_* functions by minus// May be used for other games with a few slight modifications// (mainly removing the part that pretties up the output)// You are free to use this code for anything you want and redistribute/modify at willfunction readASEString($sock,$length = false) { $length = $length ? $length : ord(vsocket_read($sock,1)); return vsocket_read($sock,$length-1);}function ASE($host,$port) { $info = Array(); // Using Socketfunctions $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_connect($s, $host, $port+123); socket_write($s,"s"); $vsock = socket_read($s,512); // read to "virtual socket" $vpos = 0; // virtual socket "pointer" socket_close($s); $s = &$vsock; vsocket_read($s,4); readASEString($s); $info['port'] = readASEString($s); $info['servername'] = readASEString($s); $info['ip'] = gethostbyname($host); $info['mode'] = readASEString($s); $info['map'] = readASEString($s); $info['version'] = readASEString($s); $info['passworded'] = readASEString($s); $info['numplayers'] = readASEString($s); $info['maxplayers'] = readASEString($s); // prime the loop conditional $lengthstring = vsocket_read($s,1); $length = ord($lengthstring); // loop through the key/value pairs and set them while($length != 1) { $info[readASEString($s,$length)] = readASEString($s); $lengthstring = vsocket_read($s,1); $length = ord($lengthstring); } // this entire section can be removed if you don't use them $info['survival'] = $info['Survival'] == 'No' ? false:true; $info['realistic'] = $info['Realistic'] == 'No' ? false:true; $info['remaining'] = explode(' ',$info['Time Left']); $info['remaining'] = $info['remaining'][0]; $info['minutes'] = explode(':',$info['remaining']); $info['seconds'] = $info['minutes'][1]; $info['minutes'] = $info['minutes'][0]; $info['timelimit'] = explode(' ',$info['Time Limit']); $info['timelimit'] = $info['timelimit'][0]; $info['protected'] = $info['Protected'] == 'No' ? false:true; // end removable section $info['players'] = Array(); for($i=0;$i<$info['numplayers'];$i++) { $info['players'][$i] = Array(); vsocket_read($s,1); $info['players'][$i]['name'] = readASEString($s); $info['players'][$i]['team'] = readASEString($s); $info['players'][$i]['skin'] = readASEString($s); $info['players'][$i]['score'] = readASEString($s); $info['players'][$i]['ping'] = readASEString($s); $info['players'][$i]['time'] = readASEString($s); } return $info;}function vsocket_read($vsock, $length){ global $vpos; $str = substr($vsock, $vpos, $length); $vpos += $length; return $str;}?>
1188 is the size of the REFRESH packet, not of the ASE packet.Anyways, i changed it to 2048 to avoid errors.
Anyhow, what you should do is loop until the socket doesn't return any more data (either it will return "" or FALSE) to ensure you read it all.
<?php// PHP ASE parser for Soldat by FliesLikeABrick// changed from fsockopen to socket_* functions by minus// May be used for other games with a few slight modifications// (mainly removing the part that pretties up the output)// You are free to use this code for anything you want and redistribute/modify at willfunction readASEString($sock,$length = false) { $length = $length ? $length : ord(vsocket_read($sock,1)); return vsocket_read($sock,$length-1);}function ASE($host,$port) { $info = Array(); // Using Socketfunctions $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); socket_connect($s, $host, $port+123); if(socket_last_error() == 10054) { echo 'Server not running'; return false; } socket_write($s,"s"); $vsock = socket_read($s, 4096); // read to "virtual socket" $vpos = 0; // virtual socket "pointer" socket_close($s); $s = $vsock; vsocket_read($s,4); readASEString($s); $info['port'] = readASEString($s); $info['servername'] = readASEString($s); $info['ip'] = gethostbyname($host); $info['mode'] = readASEString($s); $info['map'] = readASEString($s); $info['version'] = readASEString($s); $info['passworded'] = readASEString($s); $info['numplayers'] = readASEString($s); $info['maxplayers'] = readASEString($s); // prime the loop conditional $lengthstring = vsocket_read($s,1); $length = ord($lengthstring); // loop through the key/value pairs and set them while($length != 1) { $info[readASEString($s,$length)] = readASEString($s); $lengthstring = vsocket_read($s,1); $length = ord($lengthstring); } // this entire section can be removed if you don't use them $info['survival'] = $info['Survival'] == 'No' ? false:true; $info['realistic'] = $info['Realistic'] == 'No' ? false:true; $info['remaining'] = explode(' ',$info['Time Left']); $info['remaining'] = $info['remaining'][0]; $info['minutes'] = explode(':',$info['remaining']); $info['seconds'] = $info['minutes'][1]; $info['minutes'] = $info['minutes'][0]; $info['timelimit'] = explode(' ',$info['Time Limit']); $info['timelimit'] = $info['timelimit'][0]; $info['protected'] = $info['Protected'] == 'No' ? false:true; // end removable section $info['players'] = Array(); for($i=0;$i<$info['numplayers'];$i++) { $info['players'][$i] = Array(); vsocket_read($s,1); $info['players'][$i]['name'] = readASEString($s); $info['players'][$i]['team'] = readASEString($s); $info['players'][$i]['skin'] = readASEString($s); $info['players'][$i]['score'] = readASEString($s); $info['players'][$i]['ping'] = readASEString($s); $info['players'][$i]['time'] = readASEString($s); } return $info;}function vsocket_read($vsock, $length){ global $vpos; $str = substr($vsock, $vpos, $length); $vpos += $length; return $str;}?>