Phpcraft
Public Member Functions | Public Attributes | List of all members
Phpcraft\ServerConnection Class Reference
Inheritance diagram for Phpcraft\ServerConnection:
Inheritance graph
[legend]
Collaboration diagram for Phpcraft\ServerConnection:
Collaboration graph
[legend]

Public Member Functions

 __construct ($stream, int $protocol_version)
 
 sendHandshake (string $server_name, int $server_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)
 
 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)
 

Public Attributes

 $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 Member Functions inherited from Phpcraft\Connection
static varInt ($value)
 
- Static Public Attributes inherited from Phpcraft\Connection
static $zero
 
static $pow2 = []
 

Detailed Description

A client-to-server connection.

Constructor & Destructor Documentation

◆ __construct()

Phpcraft\ServerConnection::__construct (   $stream,
int  $protocol_version 
)
Parameters
resource$streamA stream created by fsockopen.
int$protocol_version

Member Function Documentation

◆ getName()

Phpcraft\ServerConnection::getName ( )
Returns
string

Implements Phpcraft\Command\CommandSender.

◆ getPosition()

Phpcraft\ServerConnection::getPosition ( )

◆ getServer()

Phpcraft\ServerConnection::getServer ( )

Available in accordance with the CommandSender interface.

Returns
Server|null null

Implements Phpcraft\Command\CommandSender.

◆ hasPermission()

Phpcraft\ServerConnection::hasPermission ( string  $permission)
Parameters
string$permission
Returns
bool

Implements Phpcraft\Command\CommandSender.

◆ hasPosition()

Phpcraft\ServerConnection::hasPosition ( )
Returns
bool

Implements Phpcraft\Command\CommandSender.

◆ hasServer()

Phpcraft\ServerConnection::hasServer ( )

Available in accordance with the CommandSender interface.

Returns
bool false

Implements Phpcraft\Command\CommandSender.

◆ login()

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.

Parameters
Account$account
Returns
string|null The error message or null on success.
Exceptions
IOException

◆ sendAdminBroadcast()

Phpcraft\ServerConnection::sendAdminBroadcast (   $message,
string  $permission = "everything" 
)

Prints a message to the console. Available in accordance with the CommandSender interface.

Parameters
array | string | null | ChatComponent$message
string$permission
Returns
void

Implements Phpcraft\Command\CommandSender.

◆ sendHandshake()

Phpcraft\ServerConnection::sendHandshake ( string  $server_name,
int  $server_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.

Parameters
string$server_name
int$server_port
int$next_stateMay be Connection::STATE_STATUS (1) for list ping or Connection::STATE_LOGIN (2) for login to play.
array<string>$join_specs Additional data to provide, e.g. "FML" is in this array for Forge clients.
Returns
ServerConnection $this
Exceptions
IOException

◆ sendMessage()

Phpcraft\ServerConnection::sendMessage (   $message)

Prints a message to the console. Available in accordance with the CommandSender interface.

Parameters
array | string | null | ChatComponent$message
Returns
void

Implements Phpcraft\Command\CommandSender.

◆ startPacket()

Phpcraft\ServerConnection::startPacket (   $packet)

Clears the write buffer and starts a new packet.

Parameters
string | integer$packetThe name or ID of the new packet.
Returns
Connection $this

Reimplemented from Phpcraft\Connection.

Member Data Documentation

◆ $pos

Point3D Phpcraft\ServerConnection::$pos

Our position on the server.

◆ $username

string null Phpcraft\ServerConnection::$username

The username assigned to us by the server after login. Null before that.

◆ $uuid

UUID null Phpcraft\ServerConnection::$uuid

The UUID assigned to us by the server after login. Null before that.