host = $host; $this->port = $port; $this->timeout = $timeout; if ($resolveSRV) { $this->resolveSRV(); } } public static function fromAddress(string $host, $timeout = 2, $resolveSRV = true): self { $addressParts = explode(':', $host); $host = $addressParts[0]; if (count($addressParts) > 1) { $port = (int) $addressParts[1]; } else { $port = 25565; } return new self($host, $port, $timeout, $resolveSRV); } /** * @throws MinecraftQueryException */ public function getResult(bool $tryOldQueryProtocolPre17 = false): MinecraftQueryResult { return MinecraftQueryResult::fromRawData($this->getRawData($tryOldQueryProtocolPre17)); } /** * @throws MinecraftQueryException */ public function getRawData(bool $tryOldQueryProtocolPre17 = false): array { if ($this->rawData === null) { try { $this->retrieveData(); } catch (MinecraftQueryException $e) { if (!$tryOldQueryProtocolPre17) { throw $e; } } } if ($tryOldQueryProtocolPre17 && $this->rawData === null) { $this->retrieveDataPre17(); } return $this->rawData; } /** * @throws MinecraftQueryException */ public function retrieveData(): void { $timeStart = microtime(true); $socket = $this->createSocket(); stream_set_timeout($socket, $this->timeout); $preparedData = "\x00"; $preparedData .= "\x04"; $preparedData .= pack('c', strlen($this->host)) . $this->host; $preparedData .= pack('n', $this->port); $preparedData .= "\x01"; $preparedData = pack('c', strlen($preparedData)) . $preparedData; fwrite($socket, $preparedData); fwrite($socket, "\x01\x00"); $length = $this->readPacketLength($socket); fgetc($socket); $length = $this->readPacketLength($socket); $jsonData = ''; do { $remainder = $length - strlen($jsonData); $block = fread($socket, $remainder); $jsonData .= $block; } while (strlen($jsonData) < $length); fclose($socket); $timeEnd = microtime(true); $this->rawData = (array) json_decode($jsonData, true); $this->rawData['latency'] = (int) ($timeEnd * 1000 - $timeStart * 1000); } /** * @throws MinecraftQueryException */ public function retrieveDataPre17(): void { $timeStart = microtime(true); $socket = $this->createSocket(); fwrite($socket, "\xFE\x01"); $data = fread($socket, 512); $len = strlen($data); $data = substr($data, 3 ); $data = iconv('UTF-16BE', 'UTF-8', $data); fclose($socket); $timeEnd = microtime(true); if ($data[1] === "\xA7" && $data[2] === "\x31") { $data = explode("\x00", $data); $this->rawData = [ 'version' => [ 'protocol' => (string) $data[1], 'name' => (string) $data[2] ], 'description' => [ 'text' => (string) $data[3] ], 'players' => [ 'online' => (int) $data[4], 'max' => (int) $data[5] ] ]; } else { $data = explode("\xA7", $data); $this->rawData = [ 'version' => [ 'protocol' => 39, 'name' => '1.3' ], 'description' => [ 'text' => substr((string) $data[0], 0, -1) ], 'players' => [ 'online' => isset($data[1]) ? (int) $data[1] : 0, 'max' => isset($data[2]) ? (int) $data[2] : 0 ] ]; } $this->rawData['latency'] = (int) ($timeEnd * 1000 - $timeStart * 1000); } /** * @throws MinecraftQueryException * @return resource */ private function createSocket() { $socket = @fsockopen($this->host, $this->port, $errNo, $errStr, $this->timeout); return $socket; } /** * @param resource $socket * @throws MinecraftQueryException */ private function readPacketLength($socket): int { $i = 0; $j = 0; while (true) { $k = @fgetc($socket); if ($k === false) { return 0; } $k = ord($k); $i |= ($k & 0x7F) << $j++ * 7; if (($k & 0x80) != 128) { break; } } return $i; } private function resolveSRV(): void { if (filter_var($this->host, FILTER_VALIDATE_IP)) { return; } $dnsRecord = @dns_get_record('_minecraft._tcp.' . $this->host, DNS_SRV); if (!$dnsRecord || count($dnsRecord) === 0) { return; } if (isset($dnsRecord[0]['target'])) { $this->host = $dnsRecord[0]['target']; } if (isset($dnsRecord[0]['port'])) { $this->port = $dnsRecord[0]['port']; } } } namespace MinecraftQuery; class MinecraftQueryResult { /** @var string */ private $version; /** @var int */ private $protocolVersion; /** @var int */ private $onlinePlayers; /** @var int */ private $maxPlayers; /** @var array */ private $playersSample; /** @var string */ private $messageOfTheDay; /** @var string */ private $favicon; /** @var int */ private $latency; public function __construct( string $version, int $protocolVersion, int $onlinePlayers, int $maxPlayers, array $playersSample, string $messageOfTheDay, int $latency, ?string $favicon ) { $this->version = $version; $this->protocolVersion = $protocolVersion; $this->onlinePlayers = $onlinePlayers; $this->maxPlayers = $maxPlayers; $this->playersSample = $playersSample; $this->messageOfTheDay = $messageOfTheDay; $this->latency = $latency; $this->favicon = $favicon; } public function getVersion(): string { return $this->version; } public function getProtocolVersion(): int { return $this->protocolVersion; } public function getOnlinePlayers(): int { return $this->onlinePlayers; } public function getMaxPlayers(): int { return $this->maxPlayers; } public function getPlayersSample(): array { return $this->playersSample; } public function getMessageOfTheDay(): string { return $this->messageOfTheDay; } public function getFavicon(): ?string { return $this->favicon; } public function getLatency(): int { return $this->latency; } public static function fromRawData(array $rawData): self { return new self( isset($rawData['version']['name']) ? $rawData['version']['name'] : 'Unknown version', isset($rawData['version']['protocol']) ? (int) $rawData['version']['protocol'] : 0, isset($rawData['players']['online']) ? (int) $rawData['players']['online'] : 0, isset($rawData['players']['max']) ? (int) $rawData['players']['max'] : 0, isset($rawData['players']['sample']) ? (array) $rawData['players']['sample'] : [], isset($rawData['description']) ? (is_array($rawData['description']) ? self::readMessageOfTheDay($rawData['description']) : (string) $rawData['description']) : '', (int) $rawData['latency'], isset($rawData['favicon']) ? (string) $rawData['favicon'] : null ); } private static function readMessageOfTheDay(array $description): string { $messageOfTheDay = ''; if (isset($description['extra'])) { foreach ($description['extra'] as $extra) { if (isset($extra['extra'])) { $messageOfTheDay .= self::readMessageOfTheDay($extra); } $messageOfTheDay .= ($extra['text'] ?? ''); } } return $messageOfTheDay . ($description['text'] ?? ''); } } require_once 'includes/db_connect.php'; require_once 'includes/functions.php'; require_once 'includes/pdo_bk_connect.php'; require_once 'includes/pdo_connect.php'; error_reporting(0); sec_session_start(); ?>
';echo$result->getMessageOfTheDay();echo'
';echo$row['plugins'];echo'
';echo$row['mods'];echo'
';echo$row['forge'];echo'
';echo$result->getVersion();echo'
— Josh Anderson (@TheMcListingVic) March 25, 2018Top Video Games
Vote Sites |
---|
minecraftservers.org |
planetminecraft |
Vote on pixelmonservers.com |
topg |
minecraftforum |
pixelmonmod.com |
theminecraftlisting.com |
Just join. It's the most fun you'll have in Minecraft since your first day in game! ^-^ |
---|
Get the best out of joinning. Commenting, A full Homepage, and Bidding options.
Comment on an article. Add a new minecraft server. Full Homepage Options. Bidding on premium Ad space.
There is no need to login or register,, just keep track of your security code and come back to edit your minecraft server at any time.
Don't be leftout, connecting with a community is always good times. Join our forum and get introduced :) Forum