Code: Select all
<html><head><meta charset="utf-8"> <title>Serveriai</title><link href="css/bootstrap.min.css" rel="stylesheet"> <style> tr td, tr th { text-align: center !important; } tr td.motd, tr th.motd { text-align: left !important; } </style> <!-- HTML5 shim --> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--></head><body style="width: 800px; margin: 0 auto;"> <table class='table table-bordered table-striped'> <thead> <tr style='height: 30px; background: rgba(0, 0, 0, 0.8);'> <th width='55px'><center><font color='white'>Statusas</font></center></th> <th class='motd'><center><font color='white'>Serverio pavadinimas</font></center></th> <th><font color='white'>Serverio IP</font></th> <th width='70px'><font color='white'>Žaidėjai</font></th> <th><font color='white'>Žemėlapis</font></th> </tr> </thead> <?php $ip = "xxx.xxx.xx.xx"; $port = "27016"; function openserveriai() { } function closeserveriai() { } function getnextstring(&$data) { $temp=""; $counter=0; while (ord($data[$counter++])!=0) $temp.=$data[$counter-1]; $data=substr($data,strlen($temp)+1); return $temp; } function getnextbytevalue(&$data) { $temp=ord($data[0]); $data=substr($data,1); return $temp; } $map = ''; $players = ''; $maxplayers = ''; $servername = ''; $output = ''; $live_server = '0'; $packet = '0'; $packet = "\xFF\xFF\xFF\xFFTSource Engine Query\x00"; $live_server = fsockopen("udp://".$ip, $port); if(!$live_server) { $output = "Off"; } else { fwrite($live_server, $packet); socket_set_timeout($live_server,1,0); $junk = fread($live_server,5); $status = socket_get_status($live_server); $do = 1; $server_info= ""; while($do) { $str_1 = fread($live_server,1); $server_info .= $str_1; $status = socket_get_status($live_server); if($status["unread_bytes"] == 0) {$do = 0;} } fclose($live_server); if (strlen($server_info) > 0) { $success = 1; $junk = getnextstring($server_info); $servername = getnextstring($server_info); $map = getnextstring($server_info); $junk = getnextstring($server_info); $junk = getnextstring($server_info); $players = getnextbytevalue($server_info); $maxplayers = getnextbytevalue($server_info); } if ($players != '') { $players = $players; } else { $players = "0"; } if ($maxplayers != '') { $maxplayers = $maxplayers; } else { $maxplayers = "0"; } if ($output != "Full" and $players != "0" or $maxplayers != "0") { $output = $output; } else { $output = "<font color='#FF0000'>Išjungtas</font>"; } if ($map != '') { $map = $map; } else { $map = "--"; $maxplayers = "--"; $players = "--"; } if ($servername != '') { $servername = $servername; } else { $servername = "--"; } } if($players == $maxplayers && $players != '--') { $players = "" . $players . ""; } else if($players > $maxplayers-3 && $players != '--') { $players = "" . $players . ""; } else { $players = "" . $players . ""; } if ( strlen($map) > 19 ) { $map = substr($map, 0, 19) . '...'; } echo " <tbody> <tr style='background: rgba(0, 0, 0, 0.5);'> "; if ($map == '--') { echo "<td><span style='font-weight: bold; color: #a24c4c; font-size: 10pt;'>Išjungtas</i></span></td>"; } else { echo "<td><span style='font-weight: bold; color: #4ca24e; font-size: 10pt;'>Įjungtas</i></span></td>"; } echo " <td><span style='font-weight: bold; color: #fff; font-size: 10pt;'>". $servername ."</td> <td><span style='font-weight: bold; color: #97c6e5; font-size: 10pt;'>". $ip .":". $port ."</span></td> <td><span style='font-weight: bold; color: #fff; font-size: 10pt;'>". $players ." / ". $maxplayers ."</span></td> <td><span style='font-weight: bold; color: #fff; font-size: 10pt;'>". $map ."</td> </tr> </tbody> "; ?> </table></body></html>