randomhost/mcstat

从Minecraft服务器检索状态信息。

0.0.2 2016-10-03 21:11 UTC

This package is auto-updated.

Last update: 2024-09-25 05:43:32 UTC


README

Build Status

randomhost/mcstat

PHP类、网页、CLI工具和Munin插件,用于从Minecraft服务器获取信息。

此包是从winny-/mcstat分叉的,它清理了包并添加了Composer支持,以便可以在其他Composer包中使用。

协议支持

mcstat支持从1.7版本及以后和1.5.2版本中看到的服务器列表ping,而1.5.2的服务器列表ping适用于较老的Minecraft服务器(一直追溯到1.4.2),而1.7的服务器列表ping应用于较新的设置。mcstat还支持UDP完整和基本查询协议。

用法

minecraft_users_ — Munin插件

Screenshot of the minecraft_users_ plugin

像安装其他Munin插件一样安装minecraft_users_

# compile stand-alone minecraft_users_ script
make

# copy the compiled script file to the munin plugins directory
cp src/bin/minecraft_users_ /usr/share/munin/plugins/minecraft_users_

# ensure that munin can execute the script
chmod 755 /usr/share/munin/plugins/minecraft_users

# create symlinks for the desired Minecraft server hostname and port
export hostname="localhost"
export port=25565
ln -s /usr/share/munin/plugins/minecraft_users_ \
    /etc/munin/plugins/minecraft_users_${hostname}:${port}
    
# reload munin service
service munin-node reload

不需要配置,因为minecraft_users_是一个通配符插件。

作为程序使用mcstat

src/bin/mcstat.php是一个用于查询Minecraft服务器的脚本。您可以像这样安装独立版本

make
cp src/bin/mcstat ~/bin/mcstat

它非常简单,可以完成任务

mcstat play.gotpvp.com

这将输出指定服务器的状态,如下所示

play.gotpvp.com 1.7.4 2714/5000 131ms
Uberminecraft Cloud | 22 Games
1.7 Play Now!

请注意:TERM必须设置为已知的终端,否则PHP将无条件地发送stderr。

stat.php

src/www/stat.php是一个简单的网页,允许用户查询指定的服务器。

注意:stat.php不应该在公共服务器上使用,因为它没有得到很好的测试!

Screenshot of stat.php

作为PHP类的使用

<?php
namespace randomhost\Minecraft;

require_once realpath(__DIR__ . '/../../vendor') . '/autoload.php';

$status = new Status('play.gotpvp.com');
var_dump($status->ping());

以下是以以下格式输出服务器信息

array(6) {
    ["player_count"]=>
    string(3) "162"
    ["player_max"]=>
    string(4) "5000"
    ["motd"]=>
    string(182) "§f§f       §f§m-§a§m-§c§m-§d§m-§b§m] §b§l    GotPVP-Network    §b§m-[§d§m-§c§m-§a§m-§e§m-§f"
    ["server_version"]=>
    string(31) "BungeeCord 1.8.x, 1.9.x, 1.10.x"
    ["protocol_version"]=>
    string(3) "127"
    ["latency"]=>
    float(293)
}

测试

测试脚本需要bashphpunitjava。测试是在运行在本地的服务器上进行的。

以下是如何运行脚本

make test

默认情况下,src/tests/unit-tests/bin/testrunner.sh对从1.4.2版本开始的全部服务器版本进行测试。

可以像这样覆盖它

env Versions='1.7.4 1.7.5' make test