master bc6a98c6cdb3 cached
9 files
10.3 KB
2.9k tokens
15 symbols
1 requests
Download .txt
Repository: FunnyItsElmo/PHP-Minecraft-Server-Status-Query
Branch: master
Commit: bc6a98c6cdb3
Files: 9
Total size: 10.3 KB

Directory structure:
gitextract_1ch6nddx/

├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── example/
│   └── index.php
└── src/
    ├── MinecraftServerStatus.php
    └── Packets/
        ├── HandshakePacket.php
        ├── Packet.php
        └── PingPacket.php

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
composer.lock
composer.phar
vendor
.project
.settings
.buildpath


================================================
FILE: LICENSE
================================================
MIT License

Copyright (c) 2021 Julian Spravil

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


================================================
FILE: README.md
================================================
# Minecraft Server Status Query [Discontinued]

[![Latest Stable Version](https://poser.pugx.org/funnyitselmo/minecraftserverstatus/v/stable)](https://packagist.org/packages/funnyitselmo/minecraftserverstatus) [![Total Downloads](https://poser.pugx.org/funnyitselmo/minecraftserverstatus/downloads)](https://packagist.org/packages/funnyitselmo/minecraftserverstatus) [![Latest Unstable Version](https://poser.pugx.org/funnyitselmo/minecraftserverstatus/v/unstable)](https://packagist.org/packages/funnyitselmo/minecraftserverstatus) [![License](https://poser.pugx.org/funnyitselmo/minecraftserverstatus/license)](https://packagist.org/packages/funnyitselmo/minecraftserverstatus)

Minecraft Server Status Query, written in PHP, with online players, motd, favicon and more server related informations without plugins and enable-query.

*Tested with Spigot 1.9 and Bungeecord 1.9 & 1.8*

### Installation
```
composer require funnyitselmo/minecraftserverstatus
```
### Tutorial
```Java
use MinecraftServerStatus\MinecraftServerStatus;

require '../vendor/autoload.php';

$response = MinecraftServerStatus::query('lostforce.com', 25565);

if (! $response) {
    echo "The Server is offline!";
} else {
    echo "<img width=\"64\" height=\"64\" src=\"" . $response['favicon'] . "\" /> <br>
		The Server " . $response['hostname'] . " is running on " . $response['version'] . " and is online,
		currently are " . $response['players'] . " players online
		of a maximum of " . $response['max_players'] . ". The motd of the server is '" . $response['description'] . "'.
		The server has a ping of " . $response['ping'] . " milliseconds.";
}
```
If the server is offline MinecraftServerStatus::query returns false else it returns an array which contains the server informations.

### Variables
The following table contains the available variables the response can contain. The default value of each variable is false.

<table border="0">
<tr>
<th>Array Index</th>
<th>Description</th>
</tr>
<tr>
<td><pre>'hostname'</pre></td>
<td>Exact server address in 127.0.0.1 format</td>
</tr>
<tr>
<td><pre>'port'</pre></td>
<td>The servers port for example 25565</td>
</tr>
<tr>
<td><pre>'ping'</pre></td>
<td>The time in ms the server needs to answer</td>
</tr>
<tr>
<td><pre>'version'</pre></td>
<td>The server version <br>(for example: 1.9)</td>
</tr>
<tr>
<td><pre>'protocol'</pre></td>
<td>The server protocol <br>(for example: 107)</td>
</tr>
<tr>
<td><pre>'players'</pre></td>
<td>Amount of players who are currently online</td>
</tr>
<tr>
<td><pre>'max_players'</pre></td>
<td>Number of the slots of the server</td>
</tr>
<tr>
<td><pre>'description'</pre></td>
<td>The message of the day of the server </td>
</tr>
<tr>
<td><pre>'description_raw'</pre></td>
<td>The raw version of description <br>(contains color codes etc.)</td>
</tr>
<tr>
<td><pre>'favicon'</pre></td>
<td>The favicon of the server in a base64 string <br>(Can be displayed with the html img tag by setting the string as src)</td>
</tr>
<tr>
<td><pre>'modinfo'</pre></td>
<td>Informations about the plugins</td>
</tr>
</table>




================================================
FILE: composer.json
================================================
{
	"name" : "funnyitselmo/minecraftserverstatus",
	"type" : "library",
	"description" : "Minecraft Server Status Query, written in PHP, with online players, motd, favicon and more server related informations without plugins and enable-query.",
	"keywords" : [
		"minecraft",
		"server",
		"status"
	],
	"license" : "BSD",
	"repositories" : [{
			"type" : "vcs",
			"url" : "https://github.com/FunnyItsElmo/PHP-Minecraft-Server-Status-Query.git"
		}
	],
	"autoload" : {
		"psr-4" : {
			"MinecraftServerStatus\\" : "src/",
			"MinecraftServerStatus\\Packets\\" : "src/Packets/"
		}
	},
	"authors" : [{
			"name" : "Julian Spravil",
			"email" : "julian.spr@t-online.de"
		}
	]
}


================================================
FILE: example/index.php
================================================
<?php
use MinecraftServerStatus\MinecraftServerStatus;

require '../vendor/autoload.php';

$response = MinecraftServerStatus::query('lostforce.com', 25565);

if (! $response) {
    echo "The Server is offline!";
} else {
    echo "<img width=\"64\" height=\"64\" src=\"" . $response['favicon'] . "\" /> <br>
		The Server " . $response['hostname'] . " is running on " . $response['version'] . " and is online,
		currently are " . $response['players'] . " players online
		of a maximum of " . $response['max_players'] . ". The motd of the server is '" . $response['description'] . "'.
		The server has a ping of " . $response['ping'] . " milliseconds.";
}


================================================
FILE: src/MinecraftServerStatus.php
================================================
<?php
namespace MinecraftServerStatus;
use MinecraftServerStatus\Packets\HandshakePacket;
use MinecraftServerStatus\Packets\PingPacket;

class MinecraftServerStatus {

    /**
     * Queries the server and returns the servers information
     *
     * @param string $host            
     * @param number $port            
     */
    public static function query ($host = '127.0.0.1', $port = 25565) {
        // check if the host is in ipv4 format
        $host = filter_var($host, FILTER_VALIDATE_IP) ? $host : gethostbyname($host);
        
        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        if (! @socket_connect($socket, $host, $port)) {
            return false;
        }
        
        // create the handshake and ping packet
        $handshakePacket = new HandshakePacket($host, $port, 107, 1);
        $pingPacket = new PingPacket();
        
        $handshakePacket->send($socket);
        
        // high five
        $start = microtime(true);
        $pingPacket->send($socket);
        $length = self::readVarInt($socket);
        $ping = round((microtime(true) - $start) * 1000);
        
        // read the requested data
        $data = socket_read($socket, $length, PHP_NORMAL_READ);
        $data = strstr($data, '{');
        $data = json_decode($data);
        
        $descriptionRaw = isset($data->description) ? $data->description : false;
        $description = $descriptionRaw;
        
        // colorize the description if it is supported
        if (gettype($descriptionRaw) == 'object') {
            $description = '';
            
            if (isset($descriptionRaw->text)) {
                $color = isset($descriptionRaw->color) ? $descriptionRaw->color : '';
                $description = '<font color="' . $color . '">' . $descriptionRaw->text . '</font>';
            }
            
            if (isset($descriptionRaw->extra)) {
                foreach ($descriptionRaw->extra as $item) {
                    $description .= isset($item->bold) && $item->bold ? '<b>' : '';
                    $description .= isset($item->color) ? '<font color="' . $item->color . '">' . $item->text . '</font>' : '';
                    $description .= isset($item->bold) && $item->bold ? '</b>' : '';
                }
            }
        }
        
        return array(
                'hostname' => $host,
                'port' => $port,
                'ping' => $ping,
                'version' => isset($data->version->name) ? $data->version->name : false,
                'protocol' => isset($data->version->protocol) ? $data->version->protocol : false,
                'players' => isset($data->players->online) ? $data->players->online : false,
                'max_players' => isset($data->players->max) ? $data->players->max : false,
                'description' => $description,
                'description_raw' => $descriptionRaw,
                'favicon' => isset($data->favicon) ? $data->favicon : false,
                'modinfo' => isset($data->modinfo) ? $data->modinfo : false
        );
    }

    private static function readVarInt ($socket) {
        $a = 0;
        $b = 0;
        while (true) {
            $c = socket_read($socket, 1);
            if (! $c) {
                return 0;
            }
            $c = Ord($c);
            $a |= ($c & 0x7F) << $b ++ * 7;
            if ($b > 5) {
                return false;
            }
            if (($c & 0x80) != 128) {
                break;
            }
        }
        return $a;
    }
}


================================================
FILE: src/Packets/HandshakePacket.php
================================================
<?php
namespace MinecraftServerStatus\Packets;

class HandshakePacket extends Packet {

    public function __construct ($host, $port, $protocol, $nextState) {
        parent::__construct(0);
        $this->addUnsignedChar($protocol);
        $this->addString($host);
        $this->addUnsignedShort($port);
        $this->addUnsignedChar($nextState);
    }
}


================================================
FILE: src/Packets/Packet.php
================================================
<?php
namespace MinecraftServerStatus\Packets;

class Packet {

    protected $packetID;

    protected $data;

    public function __construct ($packetID) {
        $this->packetID = $packetID;
        $this->data = pack('C', $packetID);
    }

    public function addSignedChar ($data) {
        $this->data .= pack('c', $data);
    }

    public function addUnsignedChar ($data) {
        $this->data .= pack('C', $data);
    }

    public function addSignedShort ($data) {
        $this->data .= pack('s', $data);
    }

    public function addUnsignedShort ($data) {
        $this->data .= pack('S', $data);
    }

    public function addString ($data) {
        $this->data .= pack('C', strlen($data));
        $this->data .= $data;
    }

    public function send ($socket) {
        $this->data = pack('C', strlen($this->data)) . $this->data;
        socket_send($socket, $this->data, strlen($this->data), 0);
    }
}


================================================
FILE: src/Packets/PingPacket.php
================================================
<?php
namespace MinecraftServerStatus\Packets;

class PingPacket extends Packet {

    public function __construct () {
        parent::__construct(0);
    }
}
Download .txt
gitextract_1ch6nddx/

├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── example/
│   └── index.php
└── src/
    ├── MinecraftServerStatus.php
    └── Packets/
        ├── HandshakePacket.php
        ├── Packet.php
        └── PingPacket.php
Download .txt
SYMBOL INDEX (15 symbols across 4 files)

FILE: src/MinecraftServerStatus.php
  class MinecraftServerStatus (line 6) | class MinecraftServerStatus {
    method query (line 14) | public static function query ($host = '127.0.0.1', $port = 25565) {
    method readVarInt (line 76) | private static function readVarInt ($socket) {

FILE: src/Packets/HandshakePacket.php
  class HandshakePacket (line 4) | class HandshakePacket extends Packet {
    method __construct (line 6) | public function __construct ($host, $port, $protocol, $nextState) {

FILE: src/Packets/Packet.php
  class Packet (line 4) | class Packet {
    method __construct (line 10) | public function __construct ($packetID) {
    method addSignedChar (line 15) | public function addSignedChar ($data) {
    method addUnsignedChar (line 19) | public function addUnsignedChar ($data) {
    method addSignedShort (line 23) | public function addSignedShort ($data) {
    method addUnsignedShort (line 27) | public function addUnsignedShort ($data) {
    method addString (line 31) | public function addString ($data) {
    method send (line 36) | public function send ($socket) {

FILE: src/Packets/PingPacket.php
  class PingPacket (line 4) | class PingPacket extends Packet {
    method __construct (line 6) | public function __construct () {
Condensed preview — 9 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (11K chars).
[
  {
    "path": ".gitignore",
    "chars": 65,
    "preview": "composer.lock\ncomposer.phar\nvendor\n.project\n.settings\n.buildpath\n"
  },
  {
    "path": "LICENSE",
    "chars": 1071,
    "preview": "MIT License\n\nCopyright (c) 2021 Julian Spravil\n\nPermission is hereby granted, free of charge, to any person obtaining a "
  },
  {
    "path": "README.md",
    "chars": 3085,
    "preview": "# Minecraft Server Status Query [Discontinued]\n\n[![Latest Stable Version](https://poser.pugx.org/funnyitselmo/minecrafts"
  },
  {
    "path": "composer.json",
    "chars": 678,
    "preview": "{\n\t\"name\" : \"funnyitselmo/minecraftserverstatus\",\n\t\"type\" : \"library\",\n\t\"description\" : \"Minecraft Server Status Query, "
  },
  {
    "path": "example/index.php",
    "chars": 654,
    "preview": "<?php\nuse MinecraftServerStatus\\MinecraftServerStatus;\n\nrequire '../vendor/autoload.php';\n\n$response = MinecraftServerSt"
  },
  {
    "path": "src/MinecraftServerStatus.php",
    "chars": 3542,
    "preview": "<?php\nnamespace MinecraftServerStatus;\nuse MinecraftServerStatus\\Packets\\HandshakePacket;\nuse MinecraftServerStatus\\Pack"
  },
  {
    "path": "src/Packets/HandshakePacket.php",
    "chars": 360,
    "preview": "<?php\nnamespace MinecraftServerStatus\\Packets;\n\nclass HandshakePacket extends Packet {\n\n    public function __construct "
  },
  {
    "path": "src/Packets/Packet.php",
    "chars": 926,
    "preview": "<?php\nnamespace MinecraftServerStatus\\Packets;\n\nclass Packet {\n\n    protected $packetID;\n\n    protected $data;\n\n    publ"
  },
  {
    "path": "src/Packets/PingPacket.php",
    "chars": 160,
    "preview": "<?php\nnamespace MinecraftServerStatus\\Packets;\n\nclass PingPacket extends Packet {\n\n    public function __construct () {\n"
  }
]

About this extraction

This page contains the full source code of the FunnyItsElmo/PHP-Minecraft-Server-Status-Query GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 9 files (10.3 KB), approximately 2.9k tokens, and a symbol index with 15 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!