/** * Queries server status. * * <p> * Sends 'info' packet to OTS server and return output. Returns {@link OTS_InfoRespond OTS_InfoRespond} (wrapper for XML data) with results or <var>false</var> if server is online. * </p> * * <p> * Note: Since 0.1.4 version this method is static so you can call it staticly, but it is also still possible to call it in dynamic context. * </p> * * @version 0.1.4 * @since 0.0.2 * @param string $server Server IP/domain. * @param int $port OTServ port. * @return OTS_InfoRespond|bool Respond content document (false when server is offline). * @throws DOMException On DOM operation error. * @example examples/info.php info.php * @tutorial POT/Server_status.pkg * @deprecated 0.1.4 Use OTS_ServerInfo->status(). */ public static function serverStatus($server, $port) { $status = new OTS_ServerInfo($server, $port); return $status->status(); }
<?php // to not repeat all that stuff include 'quickstart.php'; // server and port $server = '127.0.0.1'; $port = 7171; // queries server of status info $info = new OTS_ServerInfo($server, $port); $status = $info->status(); // offline if (!$status) { echo 'Server ', $server, ' is offline.', "\n"; } else { echo 'Server name: ', $status->getName(), "\n"; echo 'Server owner: ', $status->getOwner(), "\n"; echo 'Players online: ', $status->getOnlinePlayers(), "\n"; echo 'Maximum allowed number of players: ', $status->getMaxPlayers(), "\n"; echo 'Required client version: ', $status->getClientVersion(), "\n"; echo 'All monsters: ', $status->getMonstersCount(), "\n"; echo 'Server message: ', $status->getMOTD(), "\n"; }