Phpcraft
|
Public Member Functions | |
__construct ($stream, int $protocol_version) | |
sendHandshake (string $hostname, int $port, int $next_state, array $join_specs=[]) | |
login (Account $account) | |
startPacket ($packet) | |
getName () | |
sendMessage ($message) | |
sendAdminBroadcast ($message, string $permission="everything") | |
hasPermission (string $permission) | |
hasPosition () | |
getPosition () | |
hasServer () | |
getServer () | |
Public Member Functions inherited from Phpcraft\Connection | |
__construct (int $protocol_version=-1, $stream=null) | |
isOpen () | |
setReadBuffer (string $buffer) | |
hasRemainingData () | |
getRemainingData () | |
writeChat (ChatComponent $value) | |
writeString (string $value) | |
writeRaw (string $value) | |
writeFloat (float $value) | |
writePosition (Point3D $pos) | |
writeGMP ($value, int $bytes, int $bits, bool $signed, int $gmp_export_options=GMP_MSW_FIRST|GMP_BIG_ENDIAN) | |
writeLong ($value) | |
writePrecisePosition (Point3D $pos) | |
writeDouble (float $value) | |
writeFixedPointPosition (Point3D $pos) | |
writeInt ($value) | |
writeSlot (Slot $slot) | |
writeBoolean (bool $value) | |
writeShort ($value) | |
writeVarInt ($value) | |
writeByte (int $value) | |
writeUnsignedShort ($value) | |
writeUnsignedByte (int $value) | |
writeAngle (float $value) | |
writeUUID (UUID $uuid) | |
send (bool $raw=false) | |
close () | |
readRawPacket (float $timeout=3.000, int $bytes=0) | |
getRemoteAddress () | |
readPacket (float $timeout=3.000) | |
readVarInt () | |
readUnsignedByte () | |
readAngle () | |
readByte () | |
readChat () | |
readString (int $maxLength=32767, int $minLength=-1) | |
readPosition () | |
readGMP (int $bytes, int $bits, bool $signed, int $gmp_import_options=GMP_MSW_FIRST|GMP_BIG_ENDIAN) | |
readPrecisePosition () | |
readDouble () | |
readFixedPointPosition () | |
readInt () | |
readUUID () | |
readSlot (bool $additional_processing=true) | |
readBoolean () | |
readShort () | |
readNBT (int $type=0) | |
readRaw (int $bytes) | |
readLong () | |
readFloat () | |
readUnsignedShort () | |
ignoreBytes (int $bytes) | |
Static Public Member Functions | |
static | connect (string $hostname, int $port, ?int $protocol_version=null, ?int $handshake_next_state=null, float $timeout=3.000) |
static | toAddress (string $address, ?int $protocol_version=null, ?int $handshake_next_state=null, float $timeout=3.000) |
static | negotiateProtocolVersion (string $hostname, int $port, float $timeout=3.000) |
static | resolveAddress (string $address) |
static | getStatus (string $hostname, int $port=25565, float $timeout=3.000, int $method=ServerConnection::METHOD_ALL) |
Static Public Member Functions inherited from Phpcraft\Connection | |
static | varInt ($value) |
Public Attributes | |
const | METHOD_ALL = 0 |
const | METHOD_MODERN = 1 |
const | METHOD_LEGACY = 2 |
$username | |
$uuid | |
$pos | |
Public Attributes inherited from Phpcraft\Connection | |
const | STATE_HANDSHAKE = 0 |
const | STATE_STATUS = 1 |
const | STATE_LOGIN = 2 |
const | STATE_PLAY = 3 |
const | LENIENCY_LENIENT = 1 |
const | LENIENCY_VANILLA = 0 |
const | LENIENCY_STRICT = -1 |
$protocol_version | |
$stream | |
$compression_threshold = -1 | |
$state | |
$write_buffer = "" | |
$lenient = false | |
$leniency = self::LENIENCY_VANILLA | |
$read_buffer = "" | |
$read_buffer_offset = 0 | |
Additional Inherited Members | |
Static Public Attributes inherited from Phpcraft\Connection | |
static | $zero |
static | $pow2 = [] |
A client-to-server connection.
Phpcraft\ServerConnection::__construct | ( | $stream, | |
int | $protocol_version | ||
) |
resource | $stream | A stream created by fsockopen. |
int | $protocol_version |
|
static |
string | $hostname | |
int | $port | |
null | int | $protocol_version | If null, server will be list pinged to get a protocol version. |
null | int | $handshake_next_state | If null, no handshake will be sent. Otherway, this may be Connection::STATE_STATUS for list ping or Connection::STATE_LOGIN for login to play. |
float | $timeout | Timeout in seconds. Note that in case of $protocol_version === null, two connections will be opened using the same timeout. |
IOException |
Phpcraft\ServerConnection::getName | ( | ) |
Implements Phpcraft\Command\CommandSender.
Phpcraft\ServerConnection::getPosition | ( | ) |
Implements Phpcraft\Command\CommandSender.
Phpcraft\ServerConnection::getServer | ( | ) |
Available in accordance with the CommandSender interface.
Implements Phpcraft\Command\CommandSender.
|
static |
Returns the server list ping as multi-dimensional array with the addition of the "ping" value which is in seconds. In an error case, an empty array is returned. Here's an example:
[ "version" => [ "name" => "1.12.2", "protocol" => 340 ], "players" => [ "online" => 1, "max" => 20, "sample" => [ [ "name" => "timmyRS", "id" => "e0603b59-2edc-45f7-acc7-b0cccd6656e1" ] ] ], "description" => [ "text" => "A Minecraft Server" ], "favicon" => "data:image/png;base64,<data>", "ping" => 0.068003177642822 ]
Note that a server might not present all of these values, so always check with isset
or array_key_exists
first. description
should always be a valid chat component.
string | $hostname | |
int | $port | |
float | $timeout | The amount of seconds to wait for a response with each method. |
int | $method |
IOException |
Phpcraft\ServerConnection::hasPermission | ( | string | $permission | ) |
Phpcraft\ServerConnection::hasPosition | ( | ) |
Implements Phpcraft\Command\CommandSender.
Phpcraft\ServerConnection::hasServer | ( | ) |
Available in accordance with the CommandSender interface.
Implements Phpcraft\Command\CommandSender.
Phpcraft\ServerConnection::login | ( | Account | $account | ) |
Logs in to the server using the given account. This has to be called even when joining an offline mode server.
Account | $account |
IOException |
|
static |
string | $hostname | |
int | $port | |
float | $timeout | Timeout in seconds. |
IOException |
|
static |
; Resolves the given address.
string | $address | The server address, e.g. localhost |
Phpcraft\ServerConnection::sendAdminBroadcast | ( | $message, | |
string | $permission = "everything" |
||
) |
Prints a message to the console. Available in accordance with the CommandSender interface.
array | string | null | ChatComponent | $message | |
string | $permission |
Implements Phpcraft\Command\CommandSender.
Phpcraft\ServerConnection::sendHandshake | ( | string | $hostname, |
int | $port, | ||
int | $next_state, | ||
array | $join_specs = [] |
||
) |
Sends a handshake to the server. If $next_state is 2, you should call ServerConnection::login() after this, even when joining an offline mode server.
string | $hostname | |
int | $port | |
int | $next_state | May be Connection::STATE_STATUS for list ping or Connection::STATE_LOGIN for login to play. |
array<string> | $join_specs Additional data to provide, e.g. "FML" is in this array for Forge clients. |
IOException |
Phpcraft\ServerConnection::sendMessage | ( | $message | ) |
Prints a message to the console. Available in accordance with the CommandSender interface.
array | string | null | ChatComponent | $message |
Implements Phpcraft\Command\CommandSender.
Phpcraft\ServerConnection::startPacket | ( | $packet | ) |
Clears the write buffer and starts a new packet.
string | integer | $packet | The name or ID of the new packet. |
Reimplemented from Phpcraft\Connection.
|
static |
string | $address | |
null | int | $protocol_version | If null, server will be list pinged to get a protocol version. |
null | int | $handshake_next_state | If null, no handshake will be sent. Otherway, this may be Connection::STATE_STATUS for list ping or Connection::STATE_LOGIN for login to play. |
float | $timeout | Timeout in seconds. Note that in case of $protocol_version === null, two connections will be opened using the same timeout. |
IOException |
Point3D Phpcraft\ServerConnection::$pos |
Our position on the server.
string null Phpcraft\ServerConnection::$username |
The username assigned to us by the server after login. Null before that.
UUID null Phpcraft\ServerConnection::$uuid |
The UUID assigned to us by the server after login. Null before that.
const Phpcraft\ServerConnection::METHOD_ALL = 0 |
Modern list ping. Legacy if that fails.
const Phpcraft\ServerConnection::METHOD_LEGACY = 2 |
const Phpcraft\ServerConnection::METHOD_MODERN = 1 |