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.

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.

Источник

Game Q

Note: the examples on this page are a bit out of date, check example.php in the .zip for a more recent one.

GameQ is a library to query one or more gameservers using UDP and return the formatted results in an array. It’s object-oriented, and easily expandable.
GameQ has recently been completely rewritten, and is still in the alpha phase, so I’d appreciate any feedback and/or bugreports. You can contact me at tombuskens@users.sourceforge.net.

Currently over 170 games are supported.

Besides this page there is also the sourceforge project page.

2. Requirements

You’ll need PHP 5 to use the library. GameQ also needs permission to use UDP ports, since these are used to communicate with the gameservers.

3. Installation

Make sure you’ve got the latest version, which can be found here. Once you’ve downloaded the file, simply extract it. Alternatively you can get a working version from the cvs repository.

4. Basic Usage

Querying a server is pretty simple. First, you define the server(s) you want to query. For example, let’s say we want to query a quake and a battlefield server.

$servers['quakeserver'] = array('quake3', '192.168.0.1', '27962'); $servers['a bf server'] = array('bf', 'localhost');

As you can see, each entry consists of a game name, server address and optionally a query port. If you don’t specify a port, the default port for the game will be used.
To check which game name to use, look in the configuration file, which is located at path/to/GameQ/games.ini.

Secondly, we initialize the main class and add the servers.

require_once 'path/to/GameQ.php'; // Initialize the class $gq = new GameQ; // Add the servers we just defined $gq->addServers($servers);

// Request the data, and display it try < $data = $gq->requestData(); print_r($data); > // Catch any errors that might have occurred catch (GameQ_Exception $e)

Array ( [quakeserver] => Array ( [version] => Q3 1.32 linux-i386 Oct 7 2002 [dmflags] => 0 [fraglimit] => 35 [timelimit] => 20 [ggametype] => 4 [protocol] => 68 [mapname] => q3tourney6_ctf [svprivateClients] => 1 [svhostname] => My local quakeserver [svmaxclients] => 17 [svpunkbuster] => 0 [svmaxRate] => 15000 [svminPing] => 0 [svmaxPing] => 0 [svfloodProtect] => 1 [svallowDownload] => 0 [botminplayers] => 2 [capturelimit] => 8 [gamename] => baseq3 [gmaxGameClients] => 0 [gneedpass] => 0 [players] => Array ( [0] => Array ( [frags] => 20 [ping] => 0 [nick] => Bitterman ) [1] => Array ( [frags] => 28 [ping] => 0 [nick] => Razor ) [2] => Array ( [frags] => 5 [ping] => 0 [nick] => Patriot ) [3] => Array ( [frags] => 17 [ping] => 0 [nick] => Uriel ) ) [game] => baseq3 [punkbuster] => 0 [pure] => 1 [gametype] => 4 [clients] => 4 [address] => 192.168.0.1 [port] => 27960 ) [a bf server] => Array ( [hostname] => My local battlefield server [gamename] => battlefield2 [gamever] => 1.1.2965-797.0 [mapname] => Road To Jalalabad [gametype] => gpm_cq [gamevariant] => bf2 [numplayers] => 2 [maxplayers] => 32 [gamemode] => openplaying [password] => 0 [timelimit] => 3600 [roundtime] => 2 [hostport] => 16567 [bf2dedicated] => 1 [bf2ranked] => 1 [bf2anticheat] => 1 [bf2os] => linux [bf2autorec] => 0 [bf2didx] => [bf2ddl] => [bf2voip] => 1 [bf2autobalanced] => 1 [bf2friendlyfire] => 1 [bf2tkmode] => Punish [bf2startdelay] => 15 [bf2spawntime] => 15.000000 [bf2sponsortext] => Howdy [bf2scorelimit] => 0 [bf2ticketratio] => 100 [bf2teamratio] => 100.000000 [bf2team1] => MEC [bf2team2] => US [bf2bots] => 0 [bf2pure] => 1 [bf2mapsize] => 64 [bf2globalunlocks] => 1 [bf2fps] => 33.000000 [bf2plasma] => 0 [bf2reservedslots] => 0 [bf2coopbotratio] => [bf2coopbotcount] => [bf2coopbotdiff] => [bf2novehicles] => 0 [players] => Array ( [0] => Array ( [player] => Bob [score] => 36 [ping] => 30 [team] => 2 [deaths] => 6 [pid] => 47837808 [skill] => 11 [AIBot] => 0 ) [1] => Array ( [player] => Jimmy [score] => 36 [ping] => 28 [team] => 2 [deaths] => 7 [pid] => 68243063 [skill] => 9 [AIBot] => 0 ) ) [teams] => Array ( [0] => Array ( [teamt] => MEC [scoret] => 0 ) [1] => Array ( [teamt] => US [scoret] => 0 ) ) [address] => 192.168.0.1 [port] => 29900 ) )

The default timeout for the server response is 200 milliseconds. If you want to change this, see Setting Options.
That’s all there is to it. Of course, you’ll most likely need to display the received data in a proper way, instead of simply dumping the array, but I’ll leave that to your imagination.

5. Advanced Usage

5.1. Setting Options

  • timeout — integer, maximum time the script waits for server responses, in milliseconds
  • socket_count — integer, maximum number of sockets that are used simultaneously
  • socket_start — integer, start of port range to use
  • debug — boolean, enables detailed parsing output errors
  • raw — boolean, causes GameQ::requestData() to return unparsed («raw») data

You can set options using the GameQ::setOption() method.

// Set server timeout to 500ms and return only raw data $gq->setOption('timeout', 500); $gq->setOption('raw', true);

5.2. Using Filters

  • normalise:
    This filter makes sure a subset of data is always available, next to the normal data. If a variable is not available it’s value will be set to false.
  • stripcolor:
    This filter strips all quake-like color tags from all data returned.
// To use a filter, call setFilter before requestData $gq->setFilter('normalise'); // You can also remove the filters $gq->removeFilter('normalise');

Источник

Читайте также:  Run functions in python
Оцените статью