Nothing important: tabs

This commit is contained in:
slawkens 2025-05-23 15:58:23 +02:00
parent 4a30fb495d
commit 2ea549002a

View File

@ -26,14 +26,14 @@ class OTS_ServerInfo
* *
* @var string * @var string
*/ */
private $server; private $server;
/** /**
* Connection port. * Connection port.
* *
* @var int * @var int
*/ */
private $port; private $port;
/** /**
* Creates handler for new server. * Creates handler for new server.
@ -41,11 +41,11 @@ class OTS_ServerInfo
* @param string $server Server IP/domain. * @param string $server Server IP/domain.
* @param int $port OTServ port. * @param int $port OTServ port.
*/ */
public function __construct($server, $port) public function __construct($server, $port)
{ {
$this->server = $server; $this->server = $server;
$this->port = $port; $this->port = $port;
} }
/** /**
* Sends packet to server. * Sends packet to server.
@ -54,46 +54,46 @@ class OTS_ServerInfo
* @return OTS_Buffer|null Respond buffer (null if server is offline). * @return OTS_Buffer|null Respond buffer (null if server is offline).
* @throws E_OTS_OutOfBuffer When there is read attemp after end of packet stream. * @throws E_OTS_OutOfBuffer When there is read attemp after end of packet stream.
*/ */
private function send(OTS_Buffer $packet) private function send(OTS_Buffer $packet)
{ {
// connects to server // connects to server
$socket = @fsockopen($this->server, $this->port, $error, $message, setting('core.status_timeout')); $socket = @fsockopen($this->server, $this->port, $error, $message, setting('core.status_timeout'));
// if connected then checking statistics // if connected then checking statistics
if($socket) if($socket)
{ {
// sets 5 second timeout for reading and writing // sets 5 second timeout for reading and writing
stream_set_timeout($socket, 5); stream_set_timeout($socket, 5);
// creates real packet // creates real packet
$packet = $packet->getBuffer(); $packet = $packet->getBuffer();
$packet = pack('v', strlen($packet) ) . $packet; $packet = pack('v', strlen($packet) ) . $packet;
// sends packet with request // sends packet with request
// 06 - length of packet, 255, 255 is the comamnd identifier, 'info' is a request // 06 - length of packet, 255, 255 is the comamnd identifier, 'info' is a request
fwrite($socket, $packet); fwrite($socket, $packet);
// reads respond // reads respond
//$data = stream_get_contents($socket); //$data = stream_get_contents($socket);
$data = ''; $data = '';
while (!feof($socket)) while (!feof($socket))
$data .= fgets($socket, 1024); $data .= fgets($socket, 1024);
// closing connection to current server // closing connection to current server
fclose($socket); fclose($socket);
// sometimes server returns empty info // sometimes server returns empty info
if( empty($data) ) if( empty($data) )
{ {
// returns offline state // returns offline state
return false; return false;
} }
return new OTS_Buffer($data); return new OTS_Buffer($data);
} }
return false; return false;
} }
/** /**
* Queries server status. * Queries server status.
@ -108,30 +108,30 @@ class OTS_ServerInfo
* @example examples/info.php info.php * @example examples/info.php info.php
* @tutorial POT/Server_status.pkg * @tutorial POT/Server_status.pkg
*/ */
public function status() public function status()
{ {
// request packet // request packet
$request = new OTS_Buffer(); $request = new OTS_Buffer();
$request->putChar(255); $request->putChar(255);
$request->putChar(255); $request->putChar(255);
$request->putString('info', false); $request->putString('info', false);
$status = $this->send($request); $status = $this->send($request);
// checks if server is online // checks if server is online
if($status) if($status)
{ {
// loads respond XML // loads respond XML
$info = new OTS_InfoRespond(); $info = new OTS_InfoRespond();
if(!$info->loadXML( $status->getBuffer())) if(!$info->loadXML( $status->getBuffer()))
return false; return false;
return $info; return $info;
} }
// offline // offline
return false; return false;
} }
/** /**
* Queries server information. * Queries server information.
@ -146,26 +146,26 @@ class OTS_ServerInfo
* @example examples/server.php info.php * @example examples/server.php info.php
* @tutorial POT/Server_status.pkg * @tutorial POT/Server_status.pkg
*/ */
public function info($flags) public function info($flags)
{ {
// request packet // request packet
$request = new OTS_Buffer(); $request = new OTS_Buffer();
$request->putChar(255); $request->putChar(255);
$request->putChar(1); $request->putChar(1);
$request->putShort($flags); $request->putShort($flags);
$status = $this->send($request); $status = $this->send($request);
// checks if server is online // checks if server is online
if($status) if($status)
{ {
// loads respond // loads respond
return new OTS_ServerStatus($status); return new OTS_ServerStatus($status);
} }
// offline // offline
return false; return false;
} }
/** /**
* Checks player online status. * Checks player online status.
@ -180,27 +180,27 @@ class OTS_ServerInfo
* @example examples/server.php info.php * @example examples/server.php info.php
* @tutorial POT/Server_status.pkg * @tutorial POT/Server_status.pkg
*/ */
public function playerStatus($name) public function playerStatus($name)
{ {
// request packet // request packet
$request = new OTS_Buffer(); $request = new OTS_Buffer();
$request->putChar(255); $request->putChar(255);
$request->putChar(1); $request->putChar(1);
$request->putShort(OTS_ServerStatus::REQUEST_PLAYER_STATUS_INFO); $request->putShort(OTS_ServerStatus::REQUEST_PLAYER_STATUS_INFO);
$request->putString($name); $request->putString($name);
$status = $this->send($request); $status = $this->send($request);
// checks if server is online // checks if server is online
if($status) if($status)
{ {
$status->getChar(); $status->getChar();
return (bool) $status->getChar(); return (bool) $status->getChar();
} }
// offline // offline
return false; return false;
} }
/** /**
* Magic PHP5 method. * Magic PHP5 method.
@ -210,20 +210,20 @@ class OTS_ServerInfo
* @throws OutOfBoundsException For non-supported properties. * @throws OutOfBoundsException For non-supported properties.
* @throws E_OTS_OutOfBuffer When there is read attemp after end of packet stream. * @throws E_OTS_OutOfBuffer When there is read attemp after end of packet stream.
*/ */
public function __get($name) public function __get($name)
{ {
switch($name) switch($name)
{ {
case 'status': case 'status':
return $this->status(); return $this->status();
case 'info': case 'info':
return $this->info(OTS_ServerStatus::REQUEST_BASIC_SERVER_INFO | OTS_ServerStatus::REQUEST_OWNER_SERVER_INFO | OTS_ServerStatus::REQUEST_MISC_SERVER_INFO | OTS_ServerStatus::REQUEST_PLAYERS_INFO | OTS_ServerStatus::REQUEST_MAP_INFO | OTS_ServerStatus::REQUEST_PLAYER_STATUS_INFO); return $this->info(OTS_ServerStatus::REQUEST_BASIC_SERVER_INFO | OTS_ServerStatus::REQUEST_OWNER_SERVER_INFO | OTS_ServerStatus::REQUEST_MISC_SERVER_INFO | OTS_ServerStatus::REQUEST_PLAYERS_INFO | OTS_ServerStatus::REQUEST_MAP_INFO | OTS_ServerStatus::REQUEST_PLAYER_STATUS_INFO);
default: default:
throw new OutOfBoundsException(); throw new OutOfBoundsException();
} }
} }
} }
/**#@-*/ /**#@-*/