Phpcraft
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Phpcraft\LanInterface Class Reference

Public Member Functions

 __construct ()
 
 discover ()
 

Static Public Member Functions

static announce (string $motd, $port)
 

Public Attributes

const MSG_REGEX = '/^\[MOTD\]([^\[\]]+)\[\/MOTD\]\[AD\]([0-9]{4,5})\[\/AD\]$/'
 
 $servers = []
 

Constructor & Destructor Documentation

◆ __construct()

Phpcraft\LanInterface::__construct ( )

Constructs a LanInterface to ->discover LAN servers. Unlike LanInterface::announce, this requires the "sockets" extension.

Exceptions
IOException

Member Function Documentation

◆ announce()

static Phpcraft\LanInterface::announce ( string  $motd,
  $port 
)
static

Announces a LAN server. Minecraft does this every 1.5 seconds and once a host:port has been sent, it is added to the server list until the server list is refreshed, and can't be updated.

Parameters
string$motdSupports ยง format for colour.
int | string$portAlthough this is supposed to be an integer, Minecraft accepts and displays any string but connects to :25565 if this is not a valid port. Do with that as you wish.
Returns
void
Exceptions
IOException

◆ discover()

Phpcraft\LanInterface::discover ( )

Checks for worlds/servers on the local network and updates $this->servers. Unlike Minecraft, Phpcraft dynamically updates the server list including MOTD changes and requires a server to be announced regularly, otherwise it will be removed. This function only needs to be called every 1-2 seconds (optimally every 1.5 seconds). If you want all servers at the time of execution, initiate a LanInterface instance, wait 1.5 to 2 seconds, then call discover, and finally access its -&gtservers.

Returns
void

Member Data Documentation

◆ $servers

Phpcraft\LanInterface::$servers = []

◆ MSG_REGEX

const Phpcraft\LanInterface::MSG_REGEX = '/^\[MOTD\]([^\[\]]+)\[\/MOTD\]\[AD\]([0-9]{4,5})\[\/AD\]$/'