05.11.2011, 03:40
Hi guys, I made this little thing that gets some basic server stats. I was just wondering, Is it possible to make this code:
Into a JavaScript version of it? Like.. the same exact function, but coded in JavaScript. If it is possible, can you please tell me how? It would mean a lot. Anyway, thanks! Later.
Код:
<html>
<?php
getstats();
function getstats()
{
$ip = "24.111.46.103";
$port = "7777";
$fp = fsockopen('udp://' . $ip, $port, $errno, $errstr,0.0);
if (!$fp)
{
echo "offline";
}
else
{
$packet = 'SAMP';
$packet .= chr(strtok($ip, '.'));
$packet .= chr(strtok('.'));
$packet .= chr(strtok('.'));
$packet .= chr(strtok('.'));
$packet .= chr($port & 0xFF);
$packet .= chr($port >> 8 & 0xFF);
fwrite($fp, $packet.'i');
fread($fp, 11);
$is_passworded = ord(fread($fp, 1));
$plr_count = ord(fread($fp, 2));
$max_plrs = ord(fread($fp, 2));
$strlen = ord(fread($fp, 4));
$hostname = htmlentities(fread($fp, $strlen));
$strlen = ord(fread($fp, 4));
$gamemode = htmlentities(fread($fp, $strlen));
$strlen = ord(fread($fp, 4));
$mapname = htmlentities(fread($fp, $strlen));
if($is_passworded == 1)
{
$is_passworded = "yes";
}
else if($is_passworded == 0)
{
$is_passworded = "no";
}
echo "Hostname : $hostname " . "<br>";
echo "Gamemode : $gamemode ". "<br>";
echo "Map : $mapname ". "<br>";
echo "Players: $plr_count/$max_plrs". "<br>";
echo "Passoword: $is_passworded". "<br>";
fwrite($fp, $packet.'c');
fread($fp, 11);
fclose($fp);
}
}
?>
</html>


