public function preprocess($packets) { $result = array(); // Get packet index, remove header foreach ($packets as $packet) { $p = new GameQ_Buffer($packet); $p->skip(14); $cur_packet = $p->readInt16(); $result[$cur_packet] = $p->getBuffer(); } // Sort packets, reset index ksort($result); $result = array_values($result); // Compare last var of current packet with first var of next packet // On a partial match, remove last var from current packet, // variable header from next packet for ($i = 0, $x = count($result); $i < $x - 1; $i++) { // First packet $fst = substr($result[$i], 0, -1); // Second packet $snd = $result[$i + 1]; // Get last variable from first packet $fstvar = substr($fst, strrpos($fst, "") + 1); // Get first variable from last packet $snd = substr($snd, strpos($snd, "") + 2); $sndvar = substr($snd, 0, strpos($snd, "")); // Check if fstvar is a substring of sndvar // If so, remove it from the first string if (strpos($sndvar, $fstvar) !== false) { $result[$i] = preg_replace("#(\\x00[^\\x00]+\\x00)\$#", "", $result[$i]); } } // Join packets return implode("", $result); }
protected function parsePlayerTeamInfoNew(GameQ_Buffer &$buf, GameQ_Result &$result) { // Read the buffer and replace the team_ sub-section under the players section becasue it is broke $buf_fixed = preg_replace('/team_(.*)score_/m', 'score_', $buf->getBuffer()); // Replace the buffer with the "fixed" buffer $buf = new GameQ_Buffer($buf_fixed); unset($buf_fixed); // Now we continue on with the parent return parent::parsePlayerTeamInfo($buf, $result); }
/** * Process the server status * * @throws GameQ_ProtocolsException */ protected function process_status() { // Make sure we have a valid response if (!$this->hasValidResponse(self::PACKET_STATUS)) { return array(); } // Set the result to a new result instance $result = new GameQ_Result(); // Lets pre process and make sure these things are in the proper order by id $data = $this->preProcess($this->packets_response[self::PACKET_STATUS]); // Create a new buffer $buf = new GameQ_Buffer($data); // Lets peek and see if the data starts with a \ if ($buf->lookAhead(1) == '\\') { // Burn the first one $buf->skip(1); } // Explode the data $data = explode('\\', $buf->getBuffer()); // Remove the last 2 "items" as it should be final\ array_pop($data); array_pop($data); // Init some vars $num_players = 0; $num_teams = 0; // Now lets loop the array for ($x = 0; $x < count($data); $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); $num_teams++; } else { if (substr($key, 0, $suffix) == 'playername') { $num_players++; } $result->addPlayer(substr($key, 0, $suffix), $val); } } else { $result->add($key, $val); } } // Add the player and team count $result->add('num_players', $num_players); $result->add('num_teams', $num_teams); unset($buf, $data, $key, $val, $suffix, $x); return $result->fetch(); }
/** * Pre-process the server details data that was returned. * * @param array $packets */ protected function preProcess($packets) { // Make buffer so we can check this out $buf = new GameQ_Buffer(implode('', $packets)); // Grab the header $header = $buf->read(4); // Now lets verify the header if ($header != "M2MP") { throw new GameQ_ProtocolsException('Unable to match M2MP response header. Header: ' . $header); return FALSE; } // Return the data with the header stripped, ready to go. return $buf->getBuffer(); }