/** * Handles processing the player and team data into a usable format * * @param \GameQ\Buffer $buffer * @param \GameQ\Result $result */ protected function processPlayersAndTeams(Buffer &$buffer, Result &$result) { /* * Explode the data into groups. First is player, next is team (item_t) * Each group should be as follows: * * [0] => item_ * [1] => information for item_ * ... */ $data = explode("", $buffer->getBuffer()); // By default item_group is blank, this will be set for each loop thru the data $item_group = ''; // By default the item_type is blank, this will be set on each loop $item_type = ''; // Loop through all of the $data for information and pull it out into the result for ($x = 0; $x < count($data) - 1; $x++) { // Pull out the item $item = $data[$x]; // If this is an empty item, move on if ($item == '' || $item == "") { continue; } /* * Left as reference: * * Each block of player_ and team_t have preceding junk chars * * player_ is actually \x01player_ * team_t is actually \x00\x02team_t * * Probably a by-product of the change to exploding the data from the original. * * For now we just strip out these characters */ // Check to see if $item has a _ at the end, this is player info if (substr($item, -1) == '_') { // Set the item group $item_group = 'players'; // Set the item type, rip off any trailing stuff and bad chars $item_type = rtrim(str_replace("", '', $item), '_'); } elseif (substr($item, -2) == '_t') { // Check to see if $item has a _t at the end, this is team info // Set the item group $item_group = 'teams'; // Set the item type, rip off any trailing stuff and bad chars $item_type = rtrim(str_replace(["", ""], '', $item), '_t'); } else { // We can assume it is data belonging to a previously defined item // Make a temp buffer so we have easier access to the data $buf_temp = new Buffer($item, Buffer::NUMBER_TYPE_BIGENDIAN); // Get the values while ($buf_temp->getLength()) { // No value so break the loop, end of string if (($val = $buf_temp->readString()) === '') { break; } // Add the value to the proper item in the correct group $result->addSub($item_group, $item_type, utf8_encode(trim($val))); } // Unset our buffer unset($buf_temp); } } // Free up some memory unset($data, $item, $item_group, $item_type, $val); }