Advertisement
Guest User

Untitled

a guest
May 7th, 2016
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.56 KB | None | 0 0
  1. <?php
  2.     use xPaw\MinecraftPing;
  3.     use xPaw\MinecraftPingException;
  4.  
  5.     // Edit this ->
  6.     define( 'MQ_SERVER_ADDR', '185.116.156.78' );
  7.     define( 'MQ_SERVER_PORT', 1 );
  8.     define( 'MQ_TIMEOUT', 1 );
  9.     // Edit this <-
  10.  
  11.     // Display everything in browser, because some people can't look in logs for errors
  12.     Error_Reporting( E_ALL | E_STRICT );
  13.     Ini_Set( 'display_errors', true );
  14.  
  15.     require __DIR__ . '/src/MinecraftPing.php';
  16.     require __DIR__ . '/src/MinecraftPingException.php';
  17.  
  18.     $Timer = MicroTime( true );
  19.  
  20.     $Info = false;
  21.     $Query = null;
  22.  
  23.     try
  24.     {
  25.         $Query = new MinecraftPing( MQ_SERVER_ADDR, MQ_SERVER_PORT, MQ_TIMEOUT );
  26.  
  27.         $Info = $Query->Query( );
  28.  
  29.         if( $Info === false )
  30.         {
  31.             /*
  32.              * If this server is older than 1.7, we can try querying it again using older protocol
  33.              * This function returns data in a different format, you will have to manually map
  34.              * things yourself if you want to match 1.7's output
  35.              *
  36.              * If you know for sure that this server is using an older version,
  37.              * you then can directly call QueryOldPre17 and avoid Query() and then reconnection part
  38.              */
  39.  
  40.             $Query->Close( );
  41.             $Query->Connect( );
  42.  
  43.             $Info = $Query->QueryOldPre17( );
  44.         }
  45.     }
  46.     catch( MinecraftPingException $e )
  47.     {
  48.         $Exception = $e;
  49.     }
  50.  
  51.     if( $Query !== null )
  52.     {
  53.         $Query->Close( );
  54.     }
  55.  
  56.     $Timer = Number_Format( MicroTime( true ) - $Timer, 4, '.', '' );
  57. ?>
  58. <!DOCTYPE html>
  59. <html lang="en">
  60. <head>
  61.     <meta charset="utf-8">
  62.     <title>Minecraft Ping PHP Class</title>
  63.  
  64.     <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
  65.     <style type="text/css">
  66.         .jumbotron {
  67.             margin-top: 30px;
  68.             border-radius: 0;
  69.         }
  70.  
  71.         .table thead th {
  72.             background-color: #428BCA;
  73.             border-color: #428BCA !important;
  74.             color: #FFF;
  75.         }
  76.     </style>
  77. </head>
  78.  
  79. <body>
  80.     <div class="container">
  81.         <div class="jumbotron">
  82.             <h1>Minecraft Ping PHP Class</h1>
  83.  
  84.             <p>This class was created to query Minecraft servers. It works starting from Minecraft 1.0.</p>
  85.  
  86.             <p>
  87.                 <a class="btn btn-large btn-primary" href="http://xpaw.me">Made by xPaw</a>
  88.                 <a class="btn btn-large btn-primary" href="https://github.com/xPaw/PHP-Minecraft-Query">View on GitHub</a>
  89.                 <a class="btn btn-large btn-danger" href="https://github.com/xPaw/PHP-Minecraft-Query/blob/master/LICENSE">MIT license</a>
  90.             </p>
  91.         </div>
  92.  
  93. <?php if( isset( $Exception ) ): ?>
  94.         <div class="panel panel-primary">
  95.             <div class="panel-heading"><?php echo htmlspecialchars( $Exception->getMessage( ) ); ?></div>
  96.             <p><?php echo nl2br( $e->getTraceAsString(), false ); ?></p>
  97. <?php else: ?>
  98.         <div class="row">
  99.                 <table class="table table-bordered table-striped">
  100.         </div>
  101.                     <thead>
  102.                         <tr>
  103.                             <th colspan="2">Server Info <em>(queried in <?php echo $Timer; ?>s)</em></th>
  104.                         </tr>
  105.                     </thead>
  106.                     <tbody>
  107. <?php if( $Info !== false ): ?>
  108. <?php foreach( $Info as $InfoKey => $InfoValue ): ?>
  109.                         <tr>
  110.                             <td><?php echo htmlspecialchars( $InfoKey ); ?></td>
  111.                             <td><?php
  112.     if( $InfoKey === 'favicon' )
  113.     {
  114.         echo '<img width="64" height="64" src="' . Str_Replace( "\n", "", $InfoValue ) . '">';
  115.     }else if( Is_Array( $InfoValue ) )
  116.     {
  117.         echo "<pre>";
  118.         print_r( $InfoValue );
  119.         echo "</pre>";
  120.     }
  121.     else
  122.     {
  123.         echo htmlspecialchars( $InfoValue );
  124.     }
  125. ?></td>
  126.                         </tr>
  127. <?php endforeach; ?>
  128. <?php else: ?>
  129.                         <tr>
  130.                             <td colspan="2">No information received</td>
  131.                         </tr>
  132. <?php endif; ?>
  133.                     </tbody>
  134.                 </table>
  135.         </div>
  136. <?php endif; ?>
  137.     </div>
  138. <?php   echo $InfoValue["max"]; ?>
  139. </body>
  140. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement