ProfesseurCraft

Traitement php query et rcon

Oct 3rd, 2013
2,479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.92 KB | None | 0 0
  1. <?php
  2.  
  3.     //--------------------------------------------------------------------------
  4.     //          CONNEXION AU RCON POUR ENVOYER DES COMMANDES AU SERVEUR
  5.     //--------------------------------------------------------------------------
  6.     require_once('Rcon.class.php');
  7.  
  8.     $r = new rcon("127.0.0.1",25567,"test"); // Remplacer l'ip, le port et le mot de passe par les votres
  9.  
  10.     if(isset($_POST['submit'])){
  11.  
  12.         $command = $_POST['command'];
  13.  
  14.             if($r->Auth())
  15.             {
  16.             $r->rconCommand($command);
  17.             }
  18.     }
  19.  
  20.     //--------------------------------------------------------------------------
  21.     //      CONNEXION AU QUERY POUR RECEVOIR DES INFORMATIONS DE VOTRE SERVEUR
  22.     //--------------------------------------------------------------------------
  23.  
  24.     define( 'MQ_SERVER_ADDR', '127.0.0.1' ); // Remplacer l'ip par la votre
  25.     define( 'MQ_SERVER_PORT', 25566 ); // Remplacer le port par le votre
  26.     define( 'MQ_TIMEOUT', 1 );
  27.  
  28.     Error_Reporting( E_ALL | E_STRICT );
  29.     Ini_Set( 'display_errors', true );
  30.  
  31.     require __DIR__ . '/MinecraftQuery.class.php';
  32.  
  33.     $Timer = MicroTime( true );
  34.     $Query = new MinecraftQuery( );
  35.  
  36.     try
  37.     {
  38.         $Query->Connect( MQ_SERVER_ADDR, MQ_SERVER_PORT, MQ_TIMEOUT );
  39.     }
  40.     catch( MinecraftQueryException $e )
  41.     {
  42.         $Error = $e->getMessage( );
  43.     }
  44. ?>
  45. <!DOCTYPE html>
  46. <html lang="en">
  47. <head>
  48.     <meta charset="utf-8">
  49.     <title>Minecraft Query PHP Class</title>
  50.    
  51.     <!-- BOOSTRAP EST UN FRAMEWORK CSS QUI PERMET DE STYLISER LE CODE CI-DESSOUS, CA CODE LE CSS A VOTRE PLACE -->
  52.     <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
  53.     <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css">
  54.     <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
  55.  
  56.     <!-- UN PEU DE CSS POUR ADAPTER BOOTSTRAP A NOS BESOINS -->
  57.     <style type="text/css">
  58.         .jumbotron {
  59.             margin-top: 30px;
  60.             border-radius: 0;
  61.         }
  62.        
  63.         .table thead th {
  64.             background-color: #428BCA;
  65.             border-color: #428BCA !important;
  66.             color: #FFF;
  67.         }
  68.         textarea:focus, input[type="text"]:focus,textarea[type="text"]:focus,   input[type="password"]:focus, input[type="datetime"]:focus, input[type="datetime-local"]:focus, input[type="date"]:focus, input[type="month"]:focus, input[type="time"]:focus, input[type="week"]:focus, input[type="number"]:focus, input[type="email"]:focus, input[type="url"]:focus, input[type="search"]:focus, input[type="tel"]:focus,  input[type="color"]:focus, .uneditable-input:focus, .form-control:focus {  
  69.         border-color: none;
  70.         box-shadow:none;
  71.         outline: none;
  72.         }
  73.     </style>
  74.  
  75. </head>
  76.  
  77. <body>
  78.  
  79.     <!-- ________________________________________________________________________________ -->
  80.     <!-- L'UTILISATION DE TABLEAUX N'EST PAS OBLIGATOIRE, CA N'EST QU'UNE DEMONSTRATION   -->
  81.     <!--    VOUS POUVEZ ADAPATER LE HTML A VOS BESOINS MAIS NE MODIFIEZ PAS LE PHP SAUF   -->
  82.     <!--                        SI VOUS SAVEZ CE QUE VOUS FAITES                          -->
  83.     <!-- ________________________________________________________________________________ -->
  84.  
  85.     <div class="container">
  86.         <div class="jumbotron">
  87.             <h2>Minecraft Query PHP Class et RCON remote console class</h2>
  88.            
  89.             <p>Grâce à l'utilisation de ces deux class, nous pouvons recevoir des informations de notre serveur et
  90.                 envoyer des commandes sans plugins.<br />
  91.             La seule chose que vous aurez à faire, c'est activer query et rcon dans le fichier server.properties.
  92.             </p>
  93.            
  94.         </div>
  95.  
  96. <?php if( isset( $Exception ) ): ?>
  97.         <div class="panel panel-primary">
  98.             <div class="panel-heading"><?php echo htmlspecialchars( $Exception->getMessage( ) ); ?></div>
  99.             <p><?php echo nl2br( $e->getTraceAsString(), false ); ?></p>
  100.         </div>
  101. <?php else: ?>
  102.         <div class="row">
  103.             <div class="col-sm-6">
  104.                 <table class="table table-bordered table-striped">
  105.                     <thead>
  106.                         <tr>
  107.                             <th colspan="2">Information serveur <em>(queried in <?php echo $Timer; ?>s)</em></th>
  108.                         </tr>
  109.                     </thead>
  110.                     <tbody>
  111.                         <?php if( ( $Info = $Query->GetInfo( ) ) !== false ): ?>
  112.                         <?php foreach( $Info as $InfoKey => $InfoValue ): ?>
  113.                         <tr>
  114.                             <td><?php echo htmlspecialchars( $InfoKey ); ?></td>
  115.                             <td><?php
  116.                                 if( Is_Array( $InfoValue ) )
  117.                                 {
  118.                                     echo "<pre>";
  119.                                     print_r( $InfoValue );
  120.                                     echo "</pre>";
  121.                                 }
  122.                                 else
  123.                                 {
  124.                                     echo htmlspecialchars( $InfoValue );
  125.                                 }
  126.                             ?>
  127.                             </td>
  128.                         </tr>
  129.                         <?php endforeach; ?>
  130.                         <?php else: ?>
  131.                         <tr>
  132.                             <td colspan="2">Pas d'informations reçues</td>
  133.                         </tr>
  134.                         <?php endif; ?>
  135.                     </tbody>
  136.                 </table>
  137.             </div>
  138.             <div class="col-sm-6">
  139.                 <table class="table table-bordered table-striped">
  140.                     <thead>
  141.                         <tr>
  142.                             <th>Joueurs</th>
  143.                         </tr>
  144.                     </thead>
  145.                     <tbody>
  146.                         <?php if( ( $Players = $Query->GetPlayers( ) ) !== false ): ?>
  147.                         <?php foreach( $Players as $Player ): ?>
  148.                         <tr>
  149.                             <td><?php echo htmlspecialchars( $Player ); ?></td>
  150.                         </tr>
  151.                         <?php endforeach; ?>
  152.                         <?php else: ?>
  153.                         <tr>
  154.                             <td>Aucun joueur en ligne</td>
  155.                         </tr>
  156.                         <?php endif; ?>
  157.                     </tbody>
  158.                 </table>
  159.  
  160.                 <!-- Envoie de commande -->
  161.                 <table class="table table-bordered table-striped">
  162.                     <thead>
  163.                     <tr>
  164.                     <th>Envoyer une commande</th>
  165.                     </tr>
  166.                     </thead>
  167.  
  168.                     <tbody>
  169.                         <tr>
  170.                             <td>
  171.                                 <form method="post" role="form">
  172.                                     <div class="input-group">
  173.                                         <span class="input-group-addon"><span class="glyphicon glyphicon-chevron-right"></span></span>
  174.                                         <input type="text" name="command" class="form-control" placeholder="Entrez votre commande">
  175.                                         <span class="input-group-btn">
  176.                                         <input type="submit" name="submit" class="btn btn-default" value="Envoyer" />
  177.                                         </span>
  178.                                     </div>
  179.                                 </form>
  180.  
  181.                             </td>
  182.                         </tr>
  183.                     </tbody>
  184.  
  185.                 </table>
  186.  
  187.             </div>
  188.         </div>
  189. <?php endif; ?>
  190.     </div>
  191. </body>
  192. </html>
Advertisement
Add Comment
Please, Sign In to add comment