1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
define ('QUAKE3',"\xFF\xFF\xFF\xFFgetstatus\x00");
function getpString(&$chaine, $stop="\\")
{
$data = substr($chaine, 0, strpos($chaine, $stop));
$chaine = substr($chaine, strpos($chaine, $stop) + 1);
return ($data);
}
function getInfosQuake3($reponse, &$info)
{
$reponse = substr($reponse, strpos($reponse, chr(10)) + 2);
$joueurs = substr($reponse, strpos($reponse, chr(10)) + 2);
$reponse = substr($reponse, 0, strpos($reponse, chr(10)));
while ($reponse != "")
$info[getpString($reponse)] = getpString($reponse);
if (!empty($joueurs))
{
$info['listplayers'] = Array();
while ($joueurs != "")
{
$details = getpString($joueurs, chr(10));
array_push($info['listplayers'], array("frag" => getpString($details, ' '), "ping" => getpString($details, ' '), "name" => $details));
}
}
return (1);
}
function infoServ($ip, $port, &$info, $cmd)
{
$socket = stream_socket_client('udp://'.$ip.':'.$port, $errno);
if (empty($errno))
{
stream_set_timeout($socket, 1);
$length = strlen($cmd);
fwrite($socket, $cmd, $length);
$reponse = fread($socket, 1500);
}
if (empty($reponse))
return (0);
else
{
if (substr($reponse, 0, 5) == "\xFF\xFF\xFF\xFFs")
return (getInfosQuake3($reponse,$info));
else
return (0);
}
} |