Example #1
0
 /**
  * Reads info from respond packet.
  * 
  * <p>
  * Note: Since 0.2.0+SVN this field is protected instead of private.
  * </p>
  * 
  * @version 0.2.0+SVN
  * @since 0.1.4
  * @param OTS_Buffer $info Information packet.
  */
 public function __construct(OTS_Buffer $info)
 {
     // skips packet length
     $info->getShort();
     while ($info->isValid()) {
         switch ($info->getChar()) {
             case self::RESPOND_BASIC_SERVER_INFO:
                 $this->name = $info->getString();
                 $this->ip = $info->getString();
                 $this->port = (int) $info->getString();
                 break;
             case self::RESPOND_OWNER_SERVER_INFO:
                 $this->owner = $info->getString();
                 $this->eMail = $info->getString();
                 break;
             case self::RESPOND_MISC_SERVER_INFO:
                 $this->motd = $info->getString();
                 $this->location = $info->getString();
                 $this->url = $info->getString();
                 $this->uptime = $info->getLong() << 32;
                 $this->uptime += $info->getLong();
                 break;
             case self::RESPOND_PLAYERS_INFO:
                 $this->online = $info->getLong();
                 $this->max = $info->getLong();
                 $this->peak = $info->getLong();
                 break;
             case self::RESPOND_MAP_INFO:
                 $this->map = $info->getString();
                 $this->author = $info->getString();
                 $this->width = $info->getShort();
                 $this->height = $info->getShort();
                 break;
             case self::RESPOND_EXT_PLAYERS_INFO:
                 $count = $info->getLong();
                 for ($i = 0; $i < $count; $i++) {
                     $name = $info->getString();
                     $this->players[$name] = $info->getLong();
                 }
                 break;
             case self::RESPOND_SERVER_SOFTWARE_INFORMATION:
                 $this->serverType = $info->getString();
                 $this->serverVersion = $info->getString();
                 $this->clientVersion = $info->getString();
                 break;
         }
     }
 }
Example #2
0
 /**
  * Sends COMMAND_SAVE_SERVER command.
  * 
  * <p>
  * Proceeds server save.
  * </p>
  * 
  * @version 0.1.6
  * @since 0.1.6
  * @throws E_OTS_ErrorCode If failure respond received.
  * @throws E_OTS_OutOfBuffer When there is read attemp after end of packet stream.
  */
 public function save()
 {
     // sends message
     $buffer = new OTS_Buffer();
     $buffer->putChar(self::COMMAND_SAVE_SERVER);
     $this->sendCommand($buffer);
 }
Example #3
0
 /**
  * Checks player online status.
  * 
  * <p>
  * This method uses binary info protocol.
  * </p>
  * 
  * @param string $name Player name.
  * @return bool True if player is online, false if player or server is online.
  * @throws E_OTS_OutOfBuffer When there is read attemp after end of packet stream.
  * @example examples/server.php info.php
  * @tutorial POT/Server_status.pkg
  */
 public function playerStatus($name)
 {
     // request packet
     $request = new OTS_Buffer();
     $request->putChar(255);
     $request->putChar(1);
     $request->putShort(OTS_ServerStatus::REQUEST_PLAYER_STATUS_INFO);
     $request->putString($name);
     $status = $this->send($request);
     // checks if server is online
     if ($status) {
         $status->getChar();
         return (bool) $status->getChar();
     }
     // offline
     return false;
 }
Example #4
0
 /**
  * Magic PHP5 method.
  * 
  * @version 0.1.2
  * @since 0.1.0
  * @param string $name Property name.
  * @param mixed $value Property value.
  * @throws OutOfBoundsException For non-supported properties.
  */
 public function __set($name, $value)
 {
     switch ($name) {
         // simple properties
         case 'next':
         case 'child':
         case 'type':
             $this->{$name} = $value;
             break;
         default:
             parent::__set($name, $value);
     }
 }