Minecraft servers status php

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Minecraft Serverstatus and -info script for PHP

License

Veilo/Minecraft-Server-Status

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

readme.md

Minecraft Server Status Script for PHP

This is a lightweight script, which reads the server infos of Minecraft servers.
The simple script (MinecraftServerStatusSimple.class.php) supports Minecraft server beta 1.8 or higher.
The newer one (MinecraftServerStatus.class.php) uses the query method and supports Minecraft servers beginning with Minecraft 1.0.0.

  • Query the server if «enable-query» is activated and parse the server infos.
    The simple one read and parse the build-in server infos from minecraft beta 1.8 or higher servers.
  • OOPHP
  • Handles some errors
  • Easy to use
  • Lightweight
  • Fallback
  • PHP 5.4.0 (You need to edit the scripts, if you want to use older php versions)
  • PHP allowed stream sockets (stream_socket_client, fwrite, fread, fclose)

Make sure in your server.properties are the following lines:

 require_once('MinecraftServerStatus.class.php'); $Server = new MinecraftServerStatus('example-minecraft-host.com'); ?>
MinecraftServerStatus($Host, $Port = 25565, $Timeout = 1)

You can easily check if the server is online or offline:

This will return a boolean, if it’s true, the server is online else false.

echo $Server->Get('numplayers').' / '.$Server->Get('maxplayers');

Get a list of online players

foreach($Server->Get('players') as $Player) echo $Player.'
'
;

Get the whole info / status

The most of these hooks are only available if the server has query enabled or the server is not vanilla.

‘hostname’
‘gametype’
‘game_id’
‘version’
‘plugins’
‘map’
‘numplayers’
‘maxplayers’
‘hostport’
‘hostip’
‘online’
‘software’
note to check if $Server->Get(‘hook’); return the expected value (No hook = false).

You can just use the «MinecraftServerStatus.class.php» file without the simple one, but if you want a fallback (fewer server infos but works everytime if the requested server is ok) you also should have the «MinecraftServerStatusSimple.class.php» in the same folder.

About

Minecraft Serverstatus and -info script for PHP

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Lightweight Minecraft server status PHP library

License

noxifoxi/minecraft-server-status

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

readme.md

Lightweight Minecraft server status script for PHP

This lightweight script queries the server information from Minecraft java servers.

  • MinecraftServer.php (Minecraft 1.0.0+) uses the query method and supports all servers with enabled queries.
  • MinecraftServerBasic.php (Minecraft Beta 1.8+) can be used as a fallback if the server does not permit queries, if something else goes wrong or just a simple request is required.
  • Queries the server if the server setting enable-query is enabled and parses the server infos.
  • Fallback to read and parse the build-in server infos from Minecraft Beta 1.8+ servers.
  • Lightweight and fast
  • Simple error handling
  • Easy to use

In order to fetch advanced server information the server’s server.properties has to have the following settings:

enable-query=true query.port=25565

If enable-query is disabled ( false ) only basic information can be retrieved, methods of MinecraftServerBasic.php will be used then.

This is the suggested method for using this class to fetch server information:

try < require_once('MinecraftServer.php'); $server = new MinecraftServer('example-minecraft-host.com'); > catch (Exception $e) < // handle errors >

If the script throws an Exception it’s safe to assume that the server is offline (for you).

MinecraftServer(string $host, int $port = 25565, int $timeout = 1)
  • host — IP or domain
  • port — Port where the Minecraft server is listening (Defaut: 25565 )
  • timeout — how long is the script allowed try connecting to the server before it times out in seconds (Default: 1 second)

If the server is online the return value is 1 otherwise it’s 0 .

echo $server->numplayers . ' / ' . $server->maxplayers;

Get a list of the online players names

foreach($server->players as $player) echo $player . '
'
;

Note: $server->players returns an array of strings.

$serverStatus = $server->getInfoArray();

Returns an array with all information the sever sent or the script was able to fetch.

Default server properties

Some of these properties are only available when server query is enabled, properties marked with «(Simple)» are always available via the Simple class or fallback — if the server is online:

Servers can add more than these default properties, check the keys of Get everything if you are unsure.

MinecraftServer.php automatically falls back using MinecraftServerBasic.php if the file is present in the same folder.

About

Lightweight Minecraft server status PHP library

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

PHP library to check Minecraft Servers Status

License

Lukasss93/minecraft-server-status

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

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:

You can install this library with composer:

composer require lukasss93/minecraft-server-status

 //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.

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

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
 //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()); ?>

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

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

All notable changes to this project will be documented here.

Источник

Читайте также:  background-attachment
Оцените статью