Guest User

Untitled

a guest
Oct 15th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php
  2. $server = new MCServerStatus("play.jrcraft.net", 25565);
  3. class MCServerStatus {
  4.     public $server;
  5.     public $online, $motd, $online_players, $max_players;
  6.     public $error = "OK";
  7.     function __construct($url, $port = '25565') {
  8.  
  9.         $this->server = array(
  10.             "url" => $url,
  11.             "port" => $port
  12.         );
  13.  
  14.         if ( $sock = @stream_socket_client('tcp://'.$url.':'.$port, $errno, $errstr, 1) ) {
  15.  
  16.             $this->online = true;
  17.  
  18.             fwrite($sock, "\xfe");
  19.             $h = fread($sock, 2048);
  20.             $h = str_replace("\x00", '', $h);
  21.             $h = substr($h, 2);
  22.             $data = explode("\xa7", $h);
  23.             unset($h);
  24.             fclose($sock);
  25.  
  26.             if (sizeof($data) == 3) {
  27.                 $this->motd = $data[0];
  28.                 $this->online_players = (int) $data[1];
  29.                 $this->max_players = (int) $data[2];
  30.             }
  31.             else {
  32.                 $this->error = "Cannot retrieve server info.";
  33.             }
  34.  
  35.         }
  36.         else {
  37.             $this->online = false;
  38.             $this->error = "Cannot connect to server.";
  39.         }
  40.  
  41.     }
  42. }
  43. $var = $server->online;
  44. print '<div id="serverstatus">';
  45. print '<b>JRCraft is';
  46. if ($server->online) echo'<span class="online">Online</span></b>';
  47. else echo  '<span class="offline">Offline</span></b>';
  48. print '<br />';
  49. echo $server->online_players;
  50. print ' Players Playing <br />';
  51. echo $server->max_players;
  52. print ' Slots<br />';
  53. echo "<p style='font-size:10px;margin-top:2px;text-align:center;'>Last Updated: ".date('jS F Y H:i', filemtime($cachefile))."</span>";
  54. print ' </div>';
  55. ?>
Add Comment
Please, Sign In to add comment