• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Lukasss93/minecraft-server-status: PHP library to check Minecraft Servers Status

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

Lukasss93/minecraft-server-status

开源软件地址(OpenSource Url):

https://github.com/Lukasss93/minecraft-server-status

开源编程语言(OpenSource Language):

PHP 100.0%

开源软件介绍(OpenSource Introduction):

Minecraft Server Status

Latest Stable Version Total Downloads License PHP

This library can be used to check Minecraft Servers Status for some basic information.

Please do not create issues when you are unable to retrieve information from a server, unless you can prove that there is a bug within the library.

Differences between Ping and Query

There are two methods of retrieving information about a Minecraft server.

  • Ping

    Ping protocol was added in Minecraft 1.7 and is used to query the server for minimal amount of information (hostname, motd, icon, and a sample of players). This is easier to use and doesn't require extra setup on server side. It uses TCP protocol on the same port as you would connect to your server an optional parameter IsOld17 which can be used to query servers on version 1.6 or older. N.B.: this method doesn't work with Minecraft: Bedrock Edition

  • Query

    This method uses GameSpy4 protocol, and requires enabling query listener in your server.properties like this:

    enable-query=true

    query.port=25565

    Query allows to request a full list of servers' plugins and players, however this method is more prone to breaking, so if you don't need all this information, stick to the ping method as it's more reliable.

Requirements

  • PHP >= 5.6
  • Json Extension
  • Iconv Extension

Installation

You can install this library with composer:

composer require lukasss93/minecraft-server-status

Using

MCPing

Using

<?php
	//using the class
	use MCServerStatus\MCPing;
	
	//include composer autoload
	require_once('../vendor/autoload.php');
	
	//checking account
	$response=MCPing::check('hostname or IP');
	
	//get informations from object
	var_dump($response);
	
	//or from array
	var_dump($response->toArray());
?>

If you want to get ping info from a server that uses a version older than Minecraft 1.7, then add true parameter after $timeout.

Please note that this library does resolve SRV records too.

Input

The check() method has 4 optional parameters:

# Parameter Type Default Description
1 host string 127.0.0.1 Server Hostname or IP address
2 port int 25565 Server port
3 timeout int 2 Timeout (in seconds)
4 isOld17 bool false Boolean value to find informations on servers that uses a version older than Minecraft 1.7

Output

The check() method return an object with the following properties:

Key Type Description
online bool Returns true if the server is online else false
error string Returns any error message
hostname string Returns the server hostname or IP address
address string Returns server IP address
port int Returns the server port
ping int Returns server ping
version string Returns the server version
protocol int Returns the server protocol
players int Returns the number of online players
max_players int Returns the maximum number of players that can enter the server
sample_player_list array Returns a partial list of online players
motd string Returns server description
favicon string Returns an image in Base64 string
mods array Returns a list of installed mods on the server

You can use the following methods after check() method:

Method Description
toArray() Return the object properties as an array
getMotdToText() Get the motd without the format codes
getMotdToHtml() Get the motd as HTML

MCQuery

Using

<?php
	//using the class
	use MCServerStatus\MCQuery;
	
	//include composer autoload
	require_once('../vendor/autoload.php');
	
	//checking account
	$response=MCQuery::check('hostname or IP');
	
	//get informations from object
	var_dump($response);
	
	//or from array
	var_dump($response->toArray());
?>

Input

The check() method has 4 optional parameters:

# Parameter Type Default Description
1 host string 127.0.0.1 Server Hostname or IP address
2 port int 25565 Server query port
3 timeout int 2 Timeout (in seconds)
4 resolveSRV bool true Resolve SRV record

Output

The check() method return an array with the following properties:

Key Type Description
online bool Returns true if the server is online else false
error string Returns any error message
hostname string Returns the server hostname or IP address
address string Returns server IP address
port int Returns the server port
version string Returns the server version
software string Returns the server software
game_type string Returns the server software type
game_name string Return the server software name
players int Returns the number of online players
max_players int Returns the maximum number of players that can enter the server
player_list array Returns a list of online players
motd string Returns server description
map string Returns the server map name
plugins array Returns a list of installed plugins on the server

You can use the following methods after check() method:

Method Description
toArray() Return the object properties as an array
getMotdToText() Get the motd without the format codes
getMotdToHtml() Get the motd as HTML

Changelog

All notable changes to this project will be documented here.

Recent changes

[2.0]

  • First release



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap