예제 #1
0
 /**
  * Overload the default detail process since this version is different
  *
  * @param \GameQ\Buffer $buffer
  *
  * @return array
  */
 protected function processDetails(Buffer $buffer)
 {
     // Set the result to a new result instance
     $result = new Result();
     $result->add('serverid', $buffer->readInt32());
     // 0
     $result->add('serverip', $buffer->readPascalString(1));
     // empty
     $result->add('gameport', $buffer->readInt32());
     $result->add('queryport', $buffer->readInt32());
     // 0
     // We burn the first char since it is not always correct with the hostname
     $buffer->skip(1);
     // Read as a regular string since the length is incorrect (what we skipped earlier)
     $result->add('servername', utf8_encode($buffer->readString()));
     // The rest is read as normal
     $result->add('mapname', utf8_encode($buffer->readPascalString(1)));
     $result->add('gametype', $buffer->readPascalString(1));
     $result->add('numplayers', $buffer->readInt32());
     $result->add('maxplayers', $buffer->readInt32());
     $result->add('currentwave', $buffer->readInt32());
     unset($buffer);
     return $result->fetch();
 }
예제 #2
0
 /**
  * Process the response
  *
  * @return array
  */
 public function processResponse()
 {
     // Holds the processed packets
     $processed = [];
     // Iterate over the packets
     foreach ($this->packets_response as $response) {
         // Make a buffer
         $buffer = new Buffer($response, Buffer::NUMBER_TYPE_BIGENDIAN);
         // Packet type = 0
         $buffer->readInt8();
         // Session Id
         $buffer->readInt32();
         // We need to burn the splitnum\0 because it is not used
         $buffer->skip(9);
         // Get the id
         $id = $buffer->readInt8();
         // Burn next byte not sure what it is used for
         $buffer->skip(1);
         // Add this packet to the processed
         $processed[$id] = $buffer->getBuffer();
         unset($buffer, $id);
     }
     // Sort packets, reset index
     ksort($processed);
     // Offload cleaning up the packets if they happen to be split
     $packets = $this->cleanPackets(array_values($processed));
     // Create a new buffer
     $buffer = new Buffer(implode('', $packets), Buffer::NUMBER_TYPE_BIGENDIAN);
     // Create a new result
     $result = new Result();
     // Parse the server details
     $this->processDetails($buffer, $result);
     // Parse the player and team information
     $this->processPlayersAndTeams($buffer, $result);
     unset($buffer);
     return $result->fetch();
 }
예제 #3
0
 /**
  * Decode the buffer into a usable format
  *
  * @param \GameQ\Buffer $buffer
  *
  * @return array
  */
 protected function decode(Buffer $buffer)
 {
     $items = [];
     // Get the number of words in this buffer
     $itemCount = $buffer->readInt32();
     // Loop over the number of items
     for ($i = 0; $i < $itemCount; $i++) {
         // Length of the string
         $buffer->readInt32();
         // Just read the string
         $items[$i] = $buffer->readString();
     }
     return $items;
 }
예제 #4
0
 /**
  * Handles processing the player data into a usable format
  *
  * @param \GameQ\Buffer $buffer
  *
  * @return array
  */
 protected function processPlayers(Buffer $buffer)
 {
     // Set the result to a new result instance
     $result = new Result();
     // Number of players
     $result->add('num_players', $buffer->readInt16());
     // Run until we run out of buffer
     while ($buffer->getLength()) {
         $result->addPlayer('id', $buffer->readInt8());
         $result->addPlayer('name', $buffer->readPascalString());
         $result->addPlayer('score', $buffer->readInt32());
         $result->addPlayer('ping', $buffer->readInt32());
     }
     unset($buffer);
     return $result->fetch();
 }