最MC论坛

标题: [开源]Minecraft服务器信息/状态/玩家显示页面[PHP大法好] [打印本页]

作者: Tain    时间: 2014-12-28 14:58
标题: [开源]Minecraft服务器信息/状态/玩家显示页面[PHP大法好]
本帖最后由 Tain 于 2014-12-28 14:59 编辑

[简洁]
这是一个非常高(di)端大(xiao)气的PHP网页,用于在网页上即使显示服务器信息 状态 和玩家。
源码由PHP开发,只要放到支持PHP语言的空间上就能直接使用了
实例:(免费空间不好意思发出来,各位有域名有主机的小伙伴们使用后请把连接发上来提供大家看看)
食用方法:在PHP中已有标注,只需要输入你服务器的IP和端口即可。
推荐免费空间地址:http://api.hostinger.com.hk/redir/4840315
[意义]
无意义。

代码:
  1. <?php
  2. //ini_set("display_errors", 1);
  3. //ini_set("track_errors", 1);
  4. //ini_set("html_errors", 1);
  5. //error_reporting(E_ALL);

  6. //这玩意只能在Minecraft 1.7.X来食用

  7. $SERVER_IP = "你的服务器IP"; //IPIPIPIPIPIPIPIPIPIP
  8. $SERVER_PORT = "服务器端口号"; //读取各种东西的关键
  9. $QUERY_PORT = "Query端口"; //query.port=""在你的server.properties里面

  10. $HEADS = "3D"; //"normal" / "3D"
  11. $show_max = "unlimited"; // how much playerheads should we display? "unlimited" / "10" / "53"/ ...
  12. $SHOW_FAVICON = "on"; //"off" / "on"

  13. $TITLE = "超级无敌服务器信息页";
  14. $TITLE_BLOCK_ONE = "信息";
  15. $TITLE_BLOCK_TWO = "玩家";

  16. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  17. $ping = json_decode(file_get_contents('http://api.minetools.eu/ping/' . $SERVER_IP . '/' . $SERVER_PORT . ''), true);
  18. $query = json_decode(file_get_contents('http://api.minetools.eu/query/' . $SERVER_IP . '/' . $QUERY_PORT . ''), true);


  19. if(empty($ping['error'])) {
  20.         $version = $ping['version']['name'];
  21.         $online = $ping['players']['online'];
  22.         $max = $ping['players']['max'];
  23.         $motd = $ping['description'];
  24.         $favicon = $ping['favicon'];
  25. }

  26. if(empty($query['error'])) {
  27.         $playerlist = $query['Playerlist'];
  28. }

  29. ?>
  30. <!DOCTYPE html>
  31. <html>
  32.         <head>
  33.         <meta charset="utf-8">
  34.         <title><?php echo htmlspecialchars($TITLE); ?></title>
  35.         <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
  36.             <link href='http://fonts.googleapis.com/css?family=Lato:300,400' rel='stylesheet' type='text/css'>
  37.             <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
  38.             <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
  39.             <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
  40.             <script language="javascript">
  41.                    jQuery(document).ready(function(){
  42.                          $("[rel='tooltip']").tooltip();
  43.              });
  44.                 </script>
  45.             <style>
  46.             /*Custom CSS Overrides*/
  47.             body {
  48.                       font-family: 'Lato', sans-serif !important;
  49.             }
  50.             </style>
  51.     </head>
  52.     <body>
  53.         <div class="container">
  54.         <h1><?php echo htmlspecialchars($TITLE); ?></h1><hr>      
  55.                 <div class="row">
  56.                         <div class="col-md-4">
  57.                                 <h3><?php echo htmlspecialchars($TITLE_BLOCK_ONE); ?></h3>
  58.                                 <table class="table table-striped">
  59.                                         <tbody>
  60.                                                 <tr>
  61.                                                         <td><b>IP</b></td>
  62.                                                         <td><?php echo $SERVER_IP; ?></td>
  63.                                                 </tr>
  64.                                         <?php if(empty($ping['error'])) { ?>
  65.                                                 <tr>
  66.                                                         <td><b>版本</b></td>
  67.                                                         <td><?php echo $version; ?></td>
  68.                                                 </tr>
  69.                                         <?php } ?>
  70.                                         <?php if(empty($ping['error'])) { ?>
  71.                                                 <tr>
  72.                                                         <td><b>玩家</b></td>
  73.                                                         <td><?php echo "".$online." / ".$max."";?></td>
  74.                                                 </tr>
  75.                                         <?php } ?>
  76.                                                 <tr>
  77.                                                         <td><b>状态</b></td>
  78.                                                         <td><?php if(empty($ping['error'])) { echo "<i class=\"fa fa-check-circle\"></i> 服务器在线"; } else { echo "<i class=\"fa fa-times-circle\"></i> 服务器不在线";}?></td>
  79.                                                 </tr>
  80.                                         <?php if(empty($ping['error'])) { ?>
  81.                                         <?php if(!empty($favicon)) { ?>
  82.                                         <?php if ($SHOW_FAVICON == "on") { ?>
  83.                                                 <tr>
  84.                                                         <td><b>图标</b></td>
  85.                                                         <td><img src='<?php echo $favicon; ?>' width="64px" height="64px" style="float:left;"/></td>
  86.                                                 </tr>
  87.                                         <?php } ?>
  88.                                         <?php } ?>
  89.                                         <?php } ?>
  90.                                         </tbody>
  91.                                 </table>
  92.                         </div>
  93.                         <div class="col-md-8" style="font-size:0px;">
  94.                                 <h3><?php echo htmlspecialchars($TITLE_BLOCK_TWO); ?></h3>
  95.                                 <?php
  96.                                 if($HEADS == "3D") {
  97.                                         $url = "https://cravatar.eu/helmhead/";
  98.                                 } else {
  99.                                         $url = "https://cravatar.eu/helmavatar/";
  100.                                 }

  101.                                 if(empty($query['error'])) {
  102.                                         if($playerlist != "null") { //1
  103.                                                 $shown = "0";
  104.                                                 foreach ($playerlist as $player) {
  105.                                                         $shown++;
  106.                                                         if($shown < $show_max + 1 || $show_max == "unlimited") {
  107.                                                 ?>
  108.                                                                 <a data-placement="top" rel="tooltip" style="display: inline-block;" title="<?php echo $player;?>">
  109.                                                                 <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>
  110.                                         <?php         }
  111.                                                 }
  112.                                                 if($shown > $show_max && $show_max != "unlimited") {
  113.                                                         echo '<div class="col-md-8" style="font-size:16px; margin-left: 0px;">';
  114.                                                         echo "and " . (count($playerlist) - $show_max) . " more ...";
  115.                                                         echo '</div>';
  116.                                                 }
  117.                                         } else {
  118.                                                 echo "<div class=\"alert alert-info\" style=\"font-size:16px;\"> There are no players online at the moment! <i class=\"fa fa-frown-o\"></i></div>";
  119.                                         }
  120.                                 } else {
  121.                                         echo "<div class=\"alert alert-danger\" style=\"font-size:16px;\"> 你的服务器尚未开启query端口,请在server.properties里面开启 <i class=\"fa fa-meh-o\"></i></div>";
  122.                                 } ?>
  123.                         </div>
  124.                 </div>
  125.         </div>
  126.         </body>
  127. </html>
复制代码

作者: Wolverine    时间: 2014-12-30 04:38
不错,虽然我用不着
作者: 沉默    时间: 2014-12-30 13:22
免费空间地址已经挂掉
作者: zuimc    时间: 2014-12-31 10:16
这个需要开放Query哦
作者: 1150019436    时间: 2015-1-3 08:26
我在用,非常好
作者: lovemc    时间: 2015-1-3 23:38
Wolverine 发表于 2014-12-30 04:38
不错,虽然我用不着

吐槽。。 为什么我笑了?  
作者: 17102317    时间: 2015-2-10 19:53
zuimc 发表于 2014-12-31 10:16
这个需要开放Query哦

服务器状态条我本地生成可以,放服务器生就提示需要GD
作者: Query端口    时间: 2015-11-28 16:39
怎么搞啊!楼主你QQ多少
作者: li_ning    时间: 2016-2-18 11:24
1.7.2的MOD不能获取




欢迎光临 最MC论坛 (http://www.zuimc.com/) Powered by Discuz! X3.2