/** * 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(); }
/** * Process the channel listing * * @param string $data * @param \GameQ\Result $result */ protected function processChannels($data, Result &$result) { // We need to split the data at the pipe $channels = explode('|', $data); // Iterate over the channels foreach ($channels as $channel) { // Offload the parsing for these values $properties = $this->processProperties($channel); // Iterate over the properties foreach ($properties as $key => $value) { $result->addTeam($key, $value); } } unset($data, $channel, $channels, $properties, $key, $value); }
/** * Handles processing the the channels and user info * * @param array $data * @param \GameQ\Result $result */ protected function processChannelsAndUsers(array $data, Result &$result) { // Let's add all of the channel information foreach ($data as $key => $value) { // We will handle these later if (in_array($key, ['channels', 'users'])) { // skip continue; } // Add the channel property as a team $result->addTeam($key, $value); } // Itereate over the users in this channel foreach ($data['users'] as $user) { foreach ($user as $key => $value) { $result->addPlayer($key, $value); } } // Offload more channels to parse foreach ($data['channels'] as $channel) { $this->processChannelsAndUsers($channel, $result); } }
/** * Process the channel listing * * @param string $data * @param \GameQ\Result $result */ protected function processChannels($data, Result &$result) { // Create a buffer $buffer = new Buffer($data); // The first line holds the column names, data returned is in column/row format $columns = explode("\t", trim($buffer->readString("\n")), 9); // Loop through the rows until we run out of information while ($buffer->getLength()) { // Grab the row, which is a tabbed list of items $row = trim($buffer->readString("\n")); // Explode and merge the data with the columns, then parse $data = array_combine($columns, explode("\t", $row, 9)); foreach ($data as $key => $value) { // Now add the data to the result $result->addTeam($key, utf8_encode($value)); } } unset($data, $buffer, $row, $columns, $key, $value); }
/** * 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(); }