Ejemplo n.º 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;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Sends OTAdmin packet.
  * 
  * @version 0.1.2
  * @since 0.1.2
  * @param OTS_Buffer $message Packet to be sent.
  * @return OTS_Buffer Server respond.
  * @throws E_OTS_ErrorCode When receive RESPOND_ERROR message.
  * @throws E_OTS_OutOfBuffer When there is read attemp after end of packet stream.
  */
 public function send(OTS_Buffer $message)
 {
     $message = $message->getBuffer();
     // encrypts message if required
     if (isset($this->cipher)) {
         $message = $this->cipher->encrypt($message);
     }
     $message = pack('v', strlen($message)) . $message;
     fputs($this->socket, $message);
     // reads respond length
     $length = unpack('v', fgets($this->socket, 3));
     $buffer = fgets($this->socket, $length[1] + 1);
     // decrypts buffer if required
     if (isset($this->cipher)) {
         $buffer = $this->cipher->decrypt($buffer);
     }
     // checks for error code
     $respond = new OTS_Buffer($buffer);
     if ($respond->getChar() == self::RESPOND_ERROR) {
         throw new E_OTS_ErrorCode(self::RESPOND_ERROR, $respond->getString());
     }
     // returns respond
     $respond->setPos(0);
     return $respond;
 }