loper/minecraft-query-client

Minecraft Query Client,通过TCP和UDP协议。

v1.1.0 2024-07-10 12:09 UTC

This package is auto-updated.

Last update: 2024-09-10 12:31:15 UTC


README

简单的服务器列表ping查询实现,用于获取Minecraft服务器的状态。

安装

composer require loper/minecraft-query-client

示例

服务器列表ping

examples/java-ping.php

#!/usr/bin/env php
<?php

declare(strict_types=1);

use Loper\Minecraft\Protocol\Struct\JavaProtocolVersion;
use Loper\MinecraftQueryClient\MinecraftQuery;

require_once __DIR__ . '/bootstrap.php';

return static function (string $host, int $port) {
    var_dump(MinecraftQuery::javaPing(
        host: $host,
        port: $port,
        protocol: JavaProtocolVersion::JAVA_1_7_1
    ));
};

查询

examples/java-query.php

#!/usr/bin/env php
<?php

declare(strict_types=1);

use Loper\Minecraft\Protocol\Struct\JavaProtocolVersion;
use Loper\MinecraftQueryClient\MinecraftQuery;

require_once __DIR__ . '/bootstrap.php';

return static function (string $host, int $port) {
    var_dump(MinecraftQuery::queryPing(
        host: $host,
        port: $port,
        protocol: JavaProtocolVersion::JAVA_1_7_1
    ));
};

查询协议和Minecraft服务器ping的聚合结果

examples/java-both.php

#!/usr/bin/env php
<?php

declare(strict_types=1);

use Loper\Minecraft\Protocol\Struct\JavaProtocolVersion;
use Loper\MinecraftQueryClient\MinecraftQuery;

require_once __DIR__ . '/bootstrap.php';

return static function (string $host, int $port) {
    var_dump(MinecraftQuery::javaQueryPing(
        host: $host,
        port: $port,
        protocol: JavaProtocolVersion::JAVA_1_7_1
    ));
};

基岩

examples/bedrock-ping.php

#!/usr/bin/env php
<?php

declare(strict_types=1);

use Loper\Minecraft\Protocol\Struct\BedrockProtocolVersion;
use Loper\MinecraftQueryClient\MinecraftQuery;

require_once __DIR__ . '/bootstrap.php';

return static function (string $host, int $port) {
    var_dump(MinecraftQuery::bedrockPing(
            host: $host,
            port: $port,
            protocol: BedrockProtocolVersion::BEDROCK_1_20_15
    ));
};

鸣谢