Minecraft Query Class
Synopsis:
General Usage:
include('mcquery.class.php');
$q = new MCQuery('121.45.193.22');
$q->connect();
print_r($q->basic_status());
version | 1.0.0 |
---|---|
author | Shannon Wynter (http://fremnet.net/contact) |
copyright | Copyright (c) 2013, Shannon Wynter (Fremnet) |
license | GPL 2.0 or greater |
package | Fremnet |
subpackage | Minecraft |
__construct(string $host, integer $port, integer $max_retries, integer $read_timeout)
string
the host to connect to
integer
set to null to take the default of 25565
integer
set to null to take the default of 3 retries
integer
set to null to take the default read timeout of 2 seconds
basic_status()
Retrieve basic server status
Example output Array ( [motd] => A Minecraft Server [gametype] => SMP [map] => world [numplayers] => 2 [maxplayers] => 20 [hostname] => 127.0.0.1 [port] => 25565 )
returns | array associative array of name => value |
---|
\MCNotConnectedException |
|
---|---|
\MCNoChallengeException |
disconnect()
full_status() : array
Retrieve the full server status including player list
Example output Array ( [motd] => A Minecraft Server [gametype] => SMP [game_id] => MINECRAFT [version] => 1.4.7 [plugins] => [map] => world [numplayers] => 2 [maxplayers] => 20 [hostport] => 25565 [hostip] => 127.0.0.1 [players] => Array ( [0] => fredblogs [1] => maryblogs ) )
\MCNotConnectedException |
|
---|---|
\MCNoChallengeException |
array
associative array of server datahandshake()
Perform the MCQuery protocol handshake described on dinnerbone's website
see | \http://dinnerbone.com/blog/2011/10/14/minecraft-19-has-rcon-and-query/ |
---|
\MCNotConnectedException |
---|
array_mutate(array $array) : array
Quickly convert any given array of name, value into an associative array of name => value.
NB: Not really sutable for large arrays.
array
even [name, value] array
\LengthException |
---|
array
associative array of [name => value]read_packet() : array
Really when hooked up to smart udp read it's going to read as much as it can, not just one packet.
Read and unpack the basic information from a MCQuery packet
array
Type of packet, Id of packet, Buffersmart_udp_read() : string
Face it, when it comes to reading UDP packets, PHP is rather dumb This gives us a slightly smarter udp read that waits for the socket to be unblocked and keeps reading until there's no more waiting data.
\MCNotConnectedException |
---|
string
write_packet(integer $type, mixed $payload)
Send a MCQuery packet to the server
$type would be PACKET_TYPE_STATUS or PACKET_TYPE_CHALLENGE
integer
type of packet to send
mixed
usually a string to send as a payload
$challenge
$host
$id
$max_retries
$prot
$read_timeout
$retries
$socket
PACKET_TYPE_CHALLENGE
PACKET_TYPE_STATUS