Ejemplo n.º 1
0
 /**
  * Specific player parse for The Ship
  *
  * Player response has unknown data after the last real player
  *
  * @param \GameQ\Buffer $buffer
  *
  * @return array
  */
 protected function processPlayers(Buffer $buffer)
 {
     // Set the result to a new result instance
     $result = new Result();
     // We need to read the number of players because this response has other data at the end usually
     $num_players = $buffer->readInt8();
     // Player count
     $result->add('num_players', $num_players);
     // No players, no work
     if ($num_players == 0) {
         return $result->fetch();
     }
     // Players list
     for ($player = 0; $player < $num_players; $player++) {
         $result->addPlayer('id', $buffer->readInt8());
         $result->addPlayer('name', $buffer->readString());
         $result->addPlayer('score', $buffer->readInt32Signed());
         $result->addPlayer('time', $buffer->readFloat32());
     }
     // Extra data
     if ($buffer->getLength() > 0) {
         for ($player = 0; $player < $num_players; $player++) {
             $result->addPlayer('deaths', $buffer->readInt32Signed());
             $result->addPlayer('money', $buffer->readInt32Signed());
         }
     }
     unset($buffer);
     return $result->fetch();
 }
Ejemplo n.º 2
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();
 }
Ejemplo n.º 3
0
 /**
  * Handles processing the details data into a usable format
  *
  * @param string        $data
  * @param \GameQ\Result $result
  */
 protected function processDetails($data, Result &$result)
 {
     // Offload the parsing for these values
     $properties = $this->processProperties($data);
     // Always dedicated
     $result->add('dedicated', 1);
     // Iterate over the properties
     foreach ($properties as $key => $value) {
         $result->add($key, $value);
     }
     // We need to manually figure out the number of players
     $result->add('numplayers', $properties['virtualserver_clientsonline'] - $properties['virtualserver_queryclientsonline']);
     unset($data, $properties, $key, $value);
 }
Ejemplo n.º 4
0
 /**
  * Process the response
  *
  * @return array
  * @throws \GameQ\Exception\Protocol
  */
 public function processResponse()
 {
     // Try to json_decode, make it into an array
     if (($data = json_decode(implode('', $this->packets_response), true)) === null) {
         throw new Exception(__METHOD__ . " Unable to decode JSON data.");
     }
     // Set the result to a new result instance
     $result = new Result();
     // Always dedicated
     $result->add('dedicated', 1);
     // Let's iterate over the response items, there are a lot
     foreach ($data as $key => $value) {
         // Ignore root for now, that is where all of the channel/player info is housed
         if (in_array($key, ['root'])) {
             continue;
         }
         // Add them as is
         $result->add($key, $value);
     }
     // Offload the channel and user parsing
     $this->processChannelsAndUsers($data['root'], $result);
     unset($data);
     // Manually set the number of players
     $result->add('numplayers', count($result->get('players')));
     return $result->fetch();
 }
Ejemplo n.º 5
0
 /**
  * Handles processing the player data into a usable format
  *
  * @param Buffer $buffer
  *
  * @return array
  */
 protected function processPlayers(Buffer $buffer)
 {
     // Set the result to a new result instance
     $result = new Result();
     // Get the number of players
     $result->add('numplayers', $buffer->readInt16());
     // Parse players
     while ($buffer->getLength()) {
         // Player id
         if (($id = $buffer->readInt16()) !== 0) {
             // Add the results
             $result->addPlayer('id', $id);
             $result->addPlayer('name', utf8_encode($buffer->readPascalString()));
         }
     }
     unset($buffer, $id);
     return $result->fetch();
 }
Ejemplo n.º 6
0
 /**
  * Handles processing the details data into a usable format
  *
  * @param \GameQ\Buffer $buffer
  * @param \GameQ\Result $result
  */
 protected function processDetails(Buffer &$buffer, Result &$result)
 {
     // We go until we hit an empty key
     while ($buffer->getLength()) {
         $key = $buffer->readString();
         if (strlen($key) == 0) {
             break;
         }
         $result->add($key, utf8_encode($buffer->readString()));
     }
 }
Ejemplo n.º 7
0
 /**
  * Process the server version
  *
  * @param \GameQ\Buffer $buffer
  *
  * @return array
  */
 protected function processVersion(Buffer $buffer)
 {
     // Decode into items
     $items = $this->decode($buffer);
     // Set the result to a new result instance
     $result = new Result();
     $result->add('version', $items[2]);
     unset($buffer, $items);
     return $result->fetch();
 }
Ejemplo n.º 8
0
 /**
  * Handles processing the rules data into a usable format
  *
  * @param \GameQ\Buffer $buffer
  *
  * @return array
  */
 protected function processRules(Buffer $buffer)
 {
     // Set the result to a new result instance
     $result = new Result();
     // Number of rules
     $result->add('num_rules', $buffer->readInt16());
     // Run until we run out of buffer
     while ($buffer->getLength()) {
         $result->add($buffer->readPascalString(), $buffer->readPascalString());
     }
     unset($buffer);
     return $result->fetch();
 }
Ejemplo n.º 9
0
 /**
  * Handles processing the rules data into a usable format
  *
  * @param \GameQ\Buffer $buffer
  *
  * @return mixed
  */
 protected function processRules(Buffer $buffer)
 {
     // Set the result to a new result instance
     $result = new Result();
     // Count the number of rules
     $num_rules = $buffer->readInt16Signed();
     // Add the count of the number of rules this server has
     $result->add('num_rules', $num_rules);
     // Rules
     while ($buffer->getLength()) {
         $result->add($buffer->readString(), $buffer->readString());
     }
     unset($buffer);
     return $result->fetch();
 }
Ejemplo n.º 10
0
 /**
  * Handles processing the details data into a usable format
  *
  * @param string        $data
  * @param \GameQ\Result $result
  */
 protected function processDetails($data, Result &$result)
 {
     // Create a buffer
     $buffer = new Buffer($data);
     // Always dedicated
     $result->add('dedicated', 1);
     // Let's loop until we run out of data
     while ($buffer->getLength()) {
         // Grab the row, which is an item
         $row = trim($buffer->readString("\n"));
         // Split out the information
         list($key, $value) = explode('=', $row, 2);
         // Add this to the result
         $result->add($key, utf8_encode($value));
     }
     unset($data, $buffer, $row, $key, $value);
 }
Ejemplo n.º 11
0
 /**
  * Handles processing the extra key/value pairs for server settings
  *
  * @param \GameQ\Buffer $buffer
  * @param \GameQ\Result $result
  */
 protected function processKeyValuePairs(Buffer &$buffer, Result &$result)
 {
     // Key / value pairs
     while ($buffer->getLength()) {
         $key = $buffer->readPascalString(1, true);
         // If we have an empty key, we've reached the end
         if (empty($key)) {
             break;
         }
         // Otherwise, add the pair
         $result->add($key, $buffer->readPascalString(1, true));
     }
     unset($key);
 }
Ejemplo n.º 12
0
 /**
  * Handle processing details since they are different than BF3
  *
  * @param \GameQ\Buffer $buffer
  *
  * @return array
  */
 protected function processDetails(Buffer $buffer)
 {
     // Decode into items
     $items = $this->decode($buffer);
     // Set the result to a new result instance
     $result = new Result();
     // Server is always dedicated
     $result->add('dedicated', 1);
     // These are the same no matter what mode the server is in
     $result->add('hostname', $items[1]);
     $result->add('num_players', (int) $items[2]);
     $result->add('max_players', (int) $items[3]);
     $result->add('gametype', $items[4]);
     $result->add('map', $items[5]);
     $result->add('roundsplayed', (int) $items[6]);
     $result->add('roundstotal', (int) $items[7]);
     $result->add('num_teams', (int) $items[8]);
     // Set the current index
     $index_current = 9;
     // Pull the team count
     $teamCount = $result->get('num_teams');
     // Loop for the number of teams found, increment along the way
     for ($id = 1; $id <= $teamCount; $id++, $index_current++) {
         // Shows the tickets
         $result->addTeam('tickets', $items[$index_current]);
         // We add an id so we know which team this is
         $result->addTeam('id', $id);
     }
     // Get and set the rest of the data points.
     $result->add('targetscore', (int) $items[$index_current]);
     $result->add('online', 1);
     // Forced true, it seems $words[$index_current + 1] is always empty
     $result->add('ranked', (int) $items[$index_current + 2]);
     $result->add('punkbuster', (int) $items[$index_current + 3]);
     $result->add('password', (int) $items[$index_current + 4]);
     $result->add('uptime', (int) $items[$index_current + 5]);
     $result->add('roundtime', (int) $items[$index_current + 6]);
     $result->add('ip_port', $items[$index_current + 7]);
     $result->add('punkbuster_version', $items[$index_current + 8]);
     $result->add('join_queue', (int) $items[$index_current + 9]);
     $result->add('region', $items[$index_current + 10]);
     $result->add('pingsite', $items[$index_current + 11]);
     $result->add('country', $items[$index_current + 12]);
     //$result->add('quickmatch', (int) $items[$index_current + 13]); Supposed to be here according to R42 but is not
     $result->add('blaze_player_count', (int) $items[$index_current + 13]);
     $result->add('blaze_game_state', (int) $items[$index_current + 14]);
     unset($items, $index_current, $teamCount, $buffer);
     return $result->fetch();
 }
Ejemplo n.º 13
0
 /**
  * Handle processing the status buffer
  *
  * @param Buffer $buffer
  *
  * @return array
  */
 protected function processStatus(Buffer $buffer)
 {
     // Set the result to a new result instance
     $result = new Result();
     // By default dedicted
     $result->add('dedicated', 1);
     // Lets peek and see if the data starts with a \
     if ($buffer->lookAhead(1) == '\\') {
         // Burn the first one
         $buffer->skip(1);
     }
     // Explode the data
     $data = explode('\\', $buffer->getBuffer());
     // No longer needed
     unset($buffer);
     // Init some vars
     $numPlayers = 0;
     $numTeams = 0;
     $itemCount = count($data);
     // Now lets loop the array
     for ($x = 0; $x < $itemCount; $x += 2) {
         // Set some local vars
         $key = $data[$x];
         $val = $data[$x + 1];
         // Check for <variable>_<count> variable (i.e players)
         if (($suffix = strrpos($key, '_')) !== false && is_numeric(substr($key, $suffix + 1))) {
             // See if this is a team designation
             if (substr($key, 0, $suffix) == 'teamname') {
                 $result->addTeam('teamname', $val);
                 $numTeams++;
             } else {
                 // Its a player
                 if (substr($key, 0, $suffix) == 'playername') {
                     $numPlayers++;
                 }
                 $result->addPlayer(substr($key, 0, $suffix), utf8_encode($val));
             }
         } else {
             // Regular variable so just add the value.
             $result->add($key, $val);
         }
     }
     // Add the player and team count
     $result->add('num_players', $numPlayers);
     $result->add('num_teams', $numTeams);
     // Unset some stuff to free up memory
     unset($data, $key, $val, $suffix, $x, $itemCount);
     // Return the result
     return $result->fetch();
 }