Parašė Soo-2· 2009 Vas. 21 20:02:15
#1
Sveiki. susiduriau su problema. man reike kad
css serverio paneleje kad kai buna isjungtas serveris pr zemelapio pavadinimo ir pr zaideju skaiciau rodytu N/A, o dabar kai servas off tai nk nerodo. Stai paneles kodas:
<?PHP
include_once "settings.php";
if (!defined("IN_FUSION")) { header("Location:../../index.php"); exit; }
//-----------------Ïîëó÷åíèå èíôîðìàöèè -------------------//
$maps_dir = IMAGES."css_maps/"; //ïóòü äëÿ êàðòèíîê
$data = monitor_server_css("78.58.66.234", 27015, "halflife", "info"); // èçìåíèòå IP íà ñâîé!!!!
$img = $maps_dir.$data['mapname'].".jpg";
if (file_exists($img)) {} else {$img = $maps_dir."no_image.jpg";}
function monitor_server_css($ip, $port, $game, $request)
{
$fp = @fsockopen("udp://$ip", $port, $errno, $errstr, 1);
if (!$fp) { return FALSE; }
stream_set_timeout($fp, 1, 0);
stream_set_blocking($fp, true);
if (($request == "settings" || $request == "players"))
{
$challenge_code = "\xFF\xFF\xFF\xFF\x57";
fwrite($fp, $challenge_code);
$buffer = fread($fp, 4096);
if (!trim($buffer)) { fclose($fp); return FALSE; }
$challenge_code = substr($buffer, 5, 4);
}
if ($request == "info") { $challenge = "\xFF\xFF\xFF\xFFTSource Engine Query\x00"; }
if ($request == "players") { $challenge = "\xFF\xFF\xFF\xFFU".$challenge_code; }
if ($request == "settings") { $challenge = "\xFF\xFF\xFF\xFFV".$challenge_code; }
fwrite($fp, $challenge);
$buffer = fread($fp, 4096);
if (!$buffer) { fclose($fp); return FALSE; }
if ($request == "settings")
{
$second_packet = fread($fp, 4096);
if (strlen($second_packet) > 0)
{
$reverse_check = dechex(ord($buffer[8]));
if ($reverse_check[0] == "1")
{
$tmp = $buffer;
$buffer = $second_packet;
$second_packet = $tmp;
}
$buffer = substr($buffer, 13);
$second_packet = substr($second_packet, 9);
$buffer = trim($buffer.$second_packet);
}
else
{
$buffer = trim(substr($buffer, 4));
}
}
else
{
$buffer = trim(substr($buffer, 4));
}
fclose($fp);
if (!trim($buffer)) { return FALSE; }
/*--------------------Ñòàíäàðòíàÿ èíôîðìàöèÿ î ñåðâåðå----------------------------*/
if ($request == "info")
{
unset($data);
$tmp = explode("\x00", $buffer);
$place = strlen($tmp[0].$tmp[1].$tmp[2].$tmp[3].$tmp[4]) + 5;
$data['hostname'] = $tmp[0]; //hostname
$data['mapname'] = $tmp[1]; //name map in server now
$data['gamemod'] = $tmp[2]; //name modification Half Life
$data['Ngamemod'] = $tmp[3]; //name server
$data['players'] = ord($buffer[$place + 0]);
$data['maxplayers'] = ord($buffer[$place + 1]);
$data['numbots'] = ord($buffer[$place + 3]); // BOTS
$data['ip'] = $ip;
$data['server_os'] = $buffer[$place + 5]; // W indows or L inux
return $data; // RETURN INFO
}
/*----------------------------------------------------------------------------------*/
if ($request == "players")
{
// $buffer[0] = datatype = D for steam players
// ord($buffer[1]) = number of rules returned
$player_number = 0;
$position = 2; // START POINT
do
{
$player_number++; // INCREMENT PLAYER NUMBER
$player[$player_number]['id'] = ord($buffer[$position]);
$position ++; // GET PLAYER GAME ID
while($buffer[$position] != "\x00" && $position < 4000) // NAME LOOP WITH 4000 CHARACTER TIMEOUT
{
$player[$player_number]['name'] .= $buffer[$position]; // COLLECT PLAYER NAME
$position ++;
}
$player[$player_number]['score'] = (ord($buffer[$position + 1]))
+ (ord($buffer[$position + 2]) * 256)
+ (ord($buffer[$position + 3]) * 65536)
+ (ord($buffer[$position + 4]) * 16777216);
if ($player[$player_number]['score'] > 2147483648) { $player[$player_number]['score'] -= 4294967296; } // NEGATIVE SCORES ( -1 )
$time = substr($buffer, $position + 5, 4); // PLAYER TIME IN BYTES
if (strlen($time) < 4) { return FALSE; } // CHECK FOR MISSING BYTES
list(,$time) = unpack("f", $time); // CONVERT BYTES TO DECIMAL
$time = mktime(0, 0, $time); // CONVERT DECIMAL TO UNIX TIMESTAMP
$player[$player_number]['time'] = date("H:i:s", $time); // CONVERT TIMESTAMP TO HUMAN READABLE TIME
$position += 9;
}
while ($position < strlen($buffer)); // REPEAT UNTIL THE END OF THE BUFFER
return $player;
}
/*----------------------------------------------------------------------------------*/
if ($request == "settings")
{
// $buffer[0] = datatype = E for steam rules
// ord($buffer[1]) = number of rules returned
$tmp = substr($buffer, 2); // REMOVE BEGINNING DATA BYTES
$rawdata = explode("\x00", $tmp);
for($i=1; $i<count($rawdata); $i=$i+2)
{
$rawdata[$i] = strtolower($rawdata[$i]); // MAKE ARRAY KEYS LOWERCASE
$setting[$rawdata[$i]] = $rawdata[$i+1]; // LOAD DATA IN AN ARRAY
}
return $setting; // RETURN INFO
}
}
/*--------------Âûâîä èíôîðìàöèè î ñåðâåðå------------------*/ // èçìåíèòå àäðåñ_âàøåãî_ñàéòà è 127.0.0.1 íà IP àäðåñ ñåðâåðà!
$server_css = "
<table> <td class='map'>
<img src='". $img ."' width='91'height='72' style='opacity:0.4;filter:alpha(opacity=40)'
onmouseover='this.style.opacity=1;this.filters.alpha.opacity=100'
onmouseout='this.style.opacity=0.4;this.filters.alpha.opacity=40'></td>
<td>
<font color=#747c4c style='padding-left:23px;'><b>Ip adresas: 127.0.0.1:27015</b></font><br>
<font color=#747c4c style='padding-left:10px;'><b>Pavadinimas: <b>CSS-LT</b><br>
<font color=#747c4c style='padding-left:26px;'><b>Þemëlapis: <b>".$data[mapname]."</b><br>
<font color=#747c4c style='padding-left:45px;'><b>ÞaidÞia: <b>".$data[players]."/".$data[maxplayers]."</b></td></table>
";
/*--------------Âûâîä èíôîðìàöèè è çàêðûòèå áëîêà----------*/
echo "$server_css";
?>
Redagavo Soo-2· 2009 Vas. 22 10:02:30
Parašė Soo-2· 2009 Vas. 22 09:02:39
#3
Dekui. O kaip ta paty padaryti su situo.?
".$data[players]."/".$data[maxplayers]."
kai buna servas off tai rodo tik ta
/ o man reike kad vietoi to rodytu N/A