2016-03-27 7 views
1

現在ネットワークのウェブサイトにあるMinecraftサーバーのネットワークに接続しているプレーヤーの数を表示するライブプレーヤーカウンターを作成しようとしています。たとえば、Hyperbianには、ページの右上にプレーヤーカウンターがあります。ウェブページ上の別のPHPファイルから配列を表示

ping、motd、接続されたプレーヤー、サーバー名などの情報をメインサーバーに照会して、きちんとした小さなテーブルに表示する.phpスクリプトをセットアップできました。

Players.php

<?php 
//ini_set("display_errors", 1); 
//ini_set("track_errors", 1); 
//ini_set("html_errors", 1); 
//error_reporting(E_ALL); 
//The following script is tested only with servers running on Minecraft 1.7. 
$SERVER_IP = "142.4.210.112"; //Insert the IP of the server you want to query. 
$SERVER_PORT = "25565"; //Insert the PORT of the server you want to ping. Needed to get the favicon, motd, players online and players max. etc 
$QUERY_PORT = "25565"; //Port of query.port="" in your server.properties. Needed for the playerlist! Can be the same like the port or different. Query must be enabled in your server.properties file! 
$HEADS = "3D"; //"normal"/"3D" 
$show_max = "unlimited"; // how much playerheads should we display? "unlimited"/"10"/"53"/ ... 
$SHOW_FAVICON = "on"; //"off"/"on" 
$TITLE = "My fancy Serverpage"; 
$TITLE_BLOCK_ONE = "General Information"; 
$TITLE_BLOCK_TWO = "Players"; 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
$ping = json_decode(file_get_contents('http://api.minetools.eu/ping/' . $SERVER_IP . '/' . $SERVER_PORT . ''), true); 
$query = json_decode(file_get_contents('http://api.minetools.eu/query/' . $SERVER_IP . '/' . $QUERY_PORT . ''), true); 
//Put the collected player information into an array for later use. 
if(empty($ping['error'])) { 
    $version = $ping['version']['name']; 
    $online = $ping['players']['online']; 
    $max = $ping['players']['max']; 
    $motd = $ping['description']; 
    $favicon = $ping['favicon']; 
} 
if(empty($query['error'])) { 
    $playerlist = $query['Playerlist']; 
} 
?> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="utf-8"> 
     <title><?php echo htmlspecialchars($TITLE); ?></title> 
     <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css"> 
     <link href='http://fonts.googleapis.com/css?family=Lato:300,400' rel='stylesheet' type='text/css'> 
     <link href="https://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet"> 
     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> 
     <script type="text/javascript" src="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script> 
     <script language="javascript"> 
     jQuery(document).ready(function(){ 
      $("[rel='tooltip']").tooltip(); 
     }); 
     </script> 
     <style> 
     /*Custom CSS Overrides*/ 
     body { 
      font-family: 'Lato', sans-serif !important; 
     } 
     </style> 
    </head> 
    <body> 
    <div class="container"> 
     <h1><?php echo htmlspecialchars($TITLE); ?></h1><hr>  
     <div class="row"> 
      <div class="span4"> 
       <h3><?php echo htmlspecialchars($TITLE_BLOCK_ONE); ?></h3> 
       <table class="table table-striped"> 
        <tbody> 
         <tr> 
          <td><b>IP</b></td> 
          <td><?php echo $SERVER_IP; ?></td> 
         </tr> 
        <?php if(empty($ping['error'])) { ?> 
         <tr> 
          <td><b>Version</b></td> 
          <td><?php echo $version; ?></td> 
         </tr> 
        <?php } ?> 
        <?php if(empty($ping['error'])) { ?> 
         <tr> 
          <td><b>Players</b></td> 
          <td><?php echo "".$online."/".$max."";?></td> 
         </tr> 
        <?php } ?> 
         <tr> 
          <td><b>Status</b></td> 
          <td><?php if(empty($ping['error'])) { echo "<i class=\"icon-ok-sign\"></i> Server is online"; } else { echo "<i class=\"icon-remove-sign\"></i> Server is offline";}?></td> 
         </tr> 
        <?php if(empty($ping['error'])) { ?> 
        <?php if(!empty($favicon)) { ?> 
        <?php if ($SHOW_FAVICON == "on") { ?> 
         <tr> 
          <td><b>Favicon</b></td> 
          <td><img src='<?php echo $favicon; ?>' width="64px" height="64px" style="float:left;"/></td> 
         </tr> 
        <?php } ?> 
        <?php } ?> 
        <?php } ?> 
        </tbody> 
       </table> 
      </div> 
      <div class="span8" style="font-size:0px;"> 
       <h3><?php echo htmlspecialchars($TITLE_BLOCK_TWO); ?></h3> 
       <?php 
       if($HEADS == "3D") { 
        $url = "https://cravatar.eu/helmhead/"; 
       } else { 
        $url = "https://cravatar.eu/helmavatar/"; 
       } 
       if(empty($query['error'])) { 
        if($playerlist != "null") { //is at least one player online? Then display it! 
         $shown = "0"; 
         foreach ($playerlist as $player) { 
          $shown++; 
          if($shown < $show_max + 1 || $show_max == "unlimited") { 
         ?> 
           <a data-placement="top" rel="tooltip" style="display: inline-block;" title="<?php echo $player;?>"> 
           <img src="<?php echo $url.$player;?>/50" size="40" width="40" height="40" style="width: 40px; height: 40px; margin-bottom: 5px; margin-right: 5px; border-radius: 3px; "/></a> 
        <?php } 
         } 
         if($shown > $show_max && $show_max != "unlimited") { 
          echo '<div class="span8" style="font-size:16px; margin-left: 0px;">'; 
          echo "and " . (count($playerlist) - $show_max) . " more ..."; 
          echo '</div>'; 
         } 
        } else { 
         echo "<div class=\"alert\" style=\"font-size:16px;\"> There are no players online at the moment!</div>"; 
        } 
       } else { 
        echo "<div class=\"alert\" style=\"font-size:16px;\"> Query must be enabled in your server.properties file!</div>"; 
       } ?> 
      </div> 
     </div> 
    </div> 
    </body> 
</html> 

私は

<!DOCTYPE HTML> 

<html> 
    <head> 
    <title>Arylion Network</title> 

     <!-- load and instantiate ScrollReveal first --> 
    <script src="https://cdn.jsdelivr.net/scrollreveal.js/3.1.2/scrollreveal.min.js"></script> 

</script> 
    <script> 
     window.sr = ScrollReveal(); 

     // Add class to <html> if ScrollReveal is supported 
     if (sr.isSupported()) { 
     document.documentElement.classList.add('sr'); 
     } 

    </script> 

     <meta charset="utf-8" /> 
     <meta name="viewport" content="width=device-width, initial-scale=1" /> 
     <!--[if lte IE 8]><script src="assets/js/ie/html5shiv.js"></script><![endif]--> 
     <link rel="stylesheet" href="assets/css/main.css" /> 
     <!--[if lte IE 8]><link rel="stylesheet" href="assets/css/ie8.css" /><![endif]--> 




     <script> 
      window.sr = ScrollReveal(); 
     </script> 

    </head> 
    <body class="landing"> 
     <div id="page-wrapper"> 

      <!-- Header --> 
       <header id="header" class="alt"> 
        <h1><a href="index.html">Arylion Network</a></h1> 
        <nav id="nav"> 
         <ul> 
          <li><a href="index.html">Home</a></li> 

          <li><a href="#" class="button">Login</a></li> 
          <li><a href="#" class="button special">Sign Up</a></li> 

         </ul> 
        </nav> 
       </header> 


      <!-- Banner --> 


       <section id="banner"> 



        <h2>Arylion Network</h2> 
        <p>play.arylion.net</p> 
        <?php include 'players.php'; 
        echo "Join $players other players right now!"; 
        ?> 
          <p>Join *insert amount of players right now* other players right now!</p> 
         <ul class="list"> 
         <li><a href="#">Factions</a></li> 
         <li><a href="#">Skyblock</a></li> 
         <li><a href="#">Vote</a></li> 
         <li><a href="#">Store</a></li> 

       </section> 

       <script> 
        sr.reveal('.list', { duration: 2000}, { delay: 200}); 
       </script> 

      <!-- Main --> 
       <section id="about-us"> 

        <h2>About Us</h2> 
        <p>Arylion, established in ... with one mission: Provide brilliant, safe and competitive fun with a rich community. </p> 


       </section> 

      <!-- Footer --> 
       <footer id="footer"> 
        <ul class="icons"> 
         <li><a href="#" class="icon fa-twitter"><span class="label">Twitter</span></a></li> 
         <li><a href="#" class="icon fa-facebook"><span class="label">Facebook</span></a></li> 
         <li><a href="#" class="icon fa-instagram"><span class="label">Instagram</span></a></li> 
         <li><a href="#" class="icon fa-github"><span class="label">Github</span></a></li> 
         <li><a href="#" class="icon fa-dribbble"><span class="label">Dribbble</span></a></li> 
         <li><a href="#" class="icon fa-google-plus"><span class="label">Google+</span></a></li> 
        </ul> 
        <ul class="copyright"> 
         <li>&copy; Arylion Network All rights reserved.</li><li>Design: <a href="http://cmnatic.co.uk">CMNatic</a></li> 
        </ul> 
       </footer> 


     </div> 

     <!-- Scripts --> 
      <script src="assets/js/jquery.min.js"></script> 
      <script src="assets/js/jquery.dropotron.min.js"></script> 
      <script src="assets/js/jquery.scrollgress.min.js"></script> 
      <script src="assets/js/skel.min.js"></script> 
      <script src="assets/js/util.js"></script> 
      <!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]--> 
      <script src="assets/js/main.js"></script> 

    </body> 
</html> 
このHTMLファイルに(私はそれが$プレーヤーまたは$のplayerlistのどちらかだと信じて)接続のプレイヤーの量を表示するためのカウンタを取得しようとしています

もっと具体的には、配列を<p>Join *insert amount of players right now* other players right now!</p>のhtmlファイルに出力したい

私はこれをやろうとしていることがわかります。加工したもの)

雌鳥。あなたが大いに助けてくれればそれは長くなりました。

+0

質問を更新しました。ありがとうございました。 – user2908236

+0

質問。 1. players.phpにはたくさんのhtmlがありますが、それをすべて表示したいですか? 2. '$ players'を宣言している箇所を見つけることはできません。それは' $ playerlist'の行数だけですか? – Terminus

+0

1.この質問は具体的ではありませんが、各サーバーのplayers.phpへのリンクを作成する予定です。プレイヤーはサーバーの状態を見ることができ、phpファイルのHTMLはすべてのクエリ情報をわかりやすい表です。 2.これを振り返ってみると、$ playerlistに行数があると思います。これにはコードがあります: 'foreach($ playerlist $ player)' – user2908236

答えて

0

players.phpに直接プレイヤーの番号をエコーし​​ないのはなぜですか?

+0

私を許して、私はPHPで任意の手段で慣れていないよ。私はこれをしなくてはなりませんか? 'code' $ playersother playersに今すぐ参加しましょう!

?>をHTMLファイル – user2908236

+0

で試してみてください。echo 'Join' .count($ playerlist)。 '今すぐ他の選手たち! ';代わりにecho "他のプレイヤーに$プレイヤーを参加させてください!"; – YukiAsuna

+0

私はあなたがこのように示唆したコードを入れました: '<?php include 'players.php'; echo 'Join' .count($ playerlist)。 '今すぐ他の選手たち! '; ?> しかし、出力が得られません。これはコーディングの問題かクエリの問題ですか? ありがとう – user2908236

関連する問題