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

Public Member Functions

 __construct (array $streams=[], $private_key=null)
 
 isOpen ()
 
 setGroups (array $groups)
 
 getGroup (string $name)
 
 isListening ()
 
 getPorts ()
 
 getMotd ()
 
 isOnlineMode ()
 
 broadcast ($msg, int $position=ChatPosition::SYSTEM)
 
 getPlayers ()
 
 adminBroadcast ($msg, string $permission="everything")
 
 permissionBroadcast (string $permission, $msg, int $position=ChatPosition::SYSTEM)
 
 sendAdminBroadcast ($message, string $permission="everything")
 
 getOfflinePlayer (string $name_or_uuid)
 
 getPlayer ($name_or_uuid)
 
 getName ()
 
 sendMessage ($message)
 
 close ($reason=null)
 
 softClose ()
 
 hasPermission (string $permission)
 
 hasServer ()
 
 getServer ()
 
 hasPosition ()
 
 getPosition ()
 

Public Attributes

 $streams
 
 $private_key
 
 $clients
 
 $persist_configs = false
 
 $compression_threshold = 256
 
 $groups = []
 
 $join_function = null
 
 $packet_function = null
 
 $disconnect_function = null
 
 $list_ping_function = null
 
 $allow_incompatible_versions = false
 
 $open_condition
 
- Public Attributes inherited from Phpcraft\BareServer
 $worlds = []
 
 $eidCounter
 

Protected Attributes

 $tick_loop
 

Detailed Description

A basic Minecraft server. This deals with connections, configurations, handshakes, status requests, keep alive packets, and teleportation confirmations. This does not include implementing an entire server; that is what packet_function and IntegratedServer are for.

Constructor & Destructor Documentation

◆ __construct()

Phpcraft\Server::__construct ( array  $streams = [],
  $private_key = null 
)
Parameters
array<resource>$streams An array of streams created by stream_socket_server to listen for clients on.
resource | null$private_keyA private key generated using openssl_pkey_new(["private_key_bits" => 1024, "private_key_type" => OPENSSL_KEYTYPE_RSA]) to use for online mode, or null to use offline mode.

Member Function Documentation

◆ adminBroadcast()

Phpcraft\Server::adminBroadcast (   $msg,
string  $permission = "everything" 
)

Sends a message to the server console and all players with the given permission, e.g. "everything" for administrators.

Parameters
array | string | null | ChatComponent$msg
string$permission
Returns
Server

◆ broadcast()

Phpcraft\Server::broadcast (   $msg,
int  $position = ChatPosition::SYSTEM 
)

Sends a message to all players and prints it to the console.

Parameters
array | string | null | ChatComponent$msg
int$position
Returns
Server $this

◆ close()

Phpcraft\Server::close (   $reason = null)

Closes all server listen sockets and client connections.

Parameters
array | string | null | ChatComponent$reasonThe reason for closing the server, sent to clients before disconnecting them.
Returns
void

◆ getGroup()

Phpcraft\Server::getGroup ( string  $name)

Returns the group with the given name or null if not found.

Parameters
string$name
Returns
Group|null

◆ getMotd()

Phpcraft\Server::getMotd ( )

Returns the "description" key from $this->list_ping_function's return array, cast to ChatComponent.

Returns
ChatComponent
See also
Server::$list_ping_function

◆ getName()

Phpcraft\Server::getName ( )
Returns
string

Implements Phpcraft\Command\CommandSender.

◆ getOfflinePlayer()

Phpcraft\Server::getOfflinePlayer ( string  $name_or_uuid)

Gets the ClientConfiguration of a player who might be offline.

Parameters
string | UUID$name_or_uuid
Returns
ClientConfiguration|null

◆ getPlayer()

Phpcraft\Server::getPlayer (   $name_or_uuid)

Returns a client in state 3 (playing) with the given name or UUID, or null if not found.

Parameters
string | UUID$name_or_uuid
Returns
ClientConnection|null

◆ getPlayers()

Phpcraft\Server::getPlayers ( )

Returns all clients in state 3 (playing).

Returns
ClientConnection[]

Reimplemented in Phpcraft\ProxyServer.

◆ getPorts()

Phpcraft\Server::getPorts ( )

Returns the ports the server is listening on.

Returns
array<int>

◆ getPosition()

Phpcraft\Server::getPosition ( )
Returns
Point3D|null

Implements Phpcraft\Command\CommandSender.

◆ getServer()

Phpcraft\Server::getServer ( )

Available in accordance with the CommandSender interface.

Returns
Server $this

Implements Phpcraft\Command\CommandSender.

◆ hasPermission()

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

Implements Phpcraft\Command\CommandSender.

◆ hasPosition()

Phpcraft\Server::hasPosition ( )
Returns
bool

Implements Phpcraft\Command\CommandSender.

◆ hasServer()

Phpcraft\Server::hasServer ( )

Available in accordance with the CommandSender interface.

Returns
bool true

Implements Phpcraft\Command\CommandSender.

◆ isListening()

Phpcraft\Server::isListening ( )

Returns true if the server has at least one socket to listen for new connections.

Returns
bool

◆ isOnlineMode()

Phpcraft\Server::isOnlineMode ( )

Returns true if the server is in online mode.

Returns
bool

◆ isOpen()

Phpcraft\Server::isOpen ( )

Returns true if the server has at least one socket to listen for new connections on or at least one client.

Returns
bool

◆ permissionBroadcast()

Phpcraft\Server::permissionBroadcast ( string  $permission,
  $msg,
int  $position = ChatPosition::SYSTEM 
)

Sends a message to all clients in playing state with the given permission.

Parameters
string$permission
array | string | null | ChatComponent$msg
int$position
Returns
Server $this

◆ sendAdminBroadcast()

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

Sends a message to the server console and "[Server: $message]" to all players with the given permission.

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

Implements Phpcraft\Command\CommandSender.

◆ sendMessage()

Phpcraft\Server::sendMessage (   $message)

Prints a message to the console. Available in accordance with the CommandSender interface. If you want to print to console specifically, just use PHP's echo.

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

Implements Phpcraft\Command\CommandSender.

◆ setGroups()

Phpcraft\Server::setGroups ( array  $groups)
Parameters
array<string,array<string,string|array<string>>>$groups
Returns
Server

◆ softClose()

Phpcraft\Server::softClose ( )

Closes all server listen sockets but keeps connected clients.

Returns
void

Member Data Documentation

◆ $allow_incompatible_versions

bool Phpcraft\Server::$allow_incompatible_versions = false

If true, clients using incompatible versions will not be prevented from logging in.

Since
0.5 Inverted from $deny_incompatible_versions

◆ $clients

SplObjectStorage Phpcraft\Server::$clients

A ClientConnection array of all clients that are connected to the server.

See also
Server::getPlayers()

◆ $compression_threshold

int Phpcraft\Server::$compression_threshold = 256

The amount of bytes at which a packet will be compressed. This applies bi-directionally, but the server decides on the value. Use -1 to disable compression.

◆ $disconnect_function

callable Phpcraft\Server::$disconnect_function = null

The function called when a client's disconnected from the server with the ClientConnection as argument.

◆ $groups

array< Group > Phpcraft\Server::$groups = []

◆ $join_function

callable Phpcraft\Server::$join_function = null

The function called when a client has entered state 3 (playing) with the ClientConnection as argument.

◆ $list_ping_function

callable Phpcraft\Server::$list_ping_function = null

The function called when to get the server's response to a list ping request with the ClientConnection as argument or null if called internally to get list ping information, e.g. in a plugin. See the documentation of ServerConnection::getStatus for an example of all the data a server may respond with (excluding "ping"), or if you return null, the list ping won't be completed. Additionally, if you set "no_ping", the client will show "(no connection)" where usually the ping in ms would be.

◆ $open_condition

Condition Phpcraft\Server::$open_condition
Since
0.2.1

◆ $packet_function

callable Phpcraft\Server::$packet_function = null

The function called when the server receives a packet from a client in state 3 (playing) unless it's a keep alive response with the ClientConnection and ServerboundPacketId as arguments.

◆ $persist_configs

bool Phpcraft\Server::$persist_configs = false

True if you'd like every client's config to be persisted across connections from the same client. This is true by default on the IntegratedServer.

◆ $private_key

resource Phpcraft\Server::$private_key

A private key generated using openssl_pkey_new(["private_key_bits" => 1024, "private_key_type" => OPENSSL_KEYTYPE_RSA]) to use for online mode, or null to use offline mode.

◆ $streams

array< resource > Phpcraft\Server::$streams

The streams the server listens for new connections on.

◆ $tick_loop

Phpcraft\Server::$tick_loop
protected