protected function process_all() { if (!$this->hasValidResponse(self::PACKET_ALL)) { return array(); } $data = $this->packets_response[self::PACKET_ALL][0]; $buf = new GameQ_Buffer($data); $result = new GameQ_Result(); // Grab the header $header = $buf->read(4); // Header does not match if ($header !== 'EYE1') { throw new GameQException("Exepcted header to be 'EYE1' but got '{$header}' instead."); } // Variables $result->add('gamename', $buf->readPascalString(1, true)); $result->add('port', $buf->readPascalString(1, true)); $result->add('servername', $buf->readPascalString(1, true)); $result->add('gametype', $buf->readPascalString(1, true)); $result->add('map', $buf->readPascalString(1, true)); $result->add('version', $buf->readPascalString(1, true)); $result->add('password', $buf->readPascalString(1, true)); $result->add('num_players', $buf->readPascalString(1, true)); $result->add('max_players', $buf->readPascalString(1, true)); // Key / value pairs while ($buf->getLength()) { // If we have an empty key, we've reached the end $key = $buf->readPascalString(1, true); if (empty($key)) { break; } // Otherwise, add the pair $result->add($key, $buf->readPascalString(1, true)); } // Players while ($buf->getLength()) { // Get the flags $flags = $buf->readInt8(); // Get data according to the flags if ($flags & 1) { $result->addPlayer('name', $buf->readPascalString(1, true)); } if ($flags & 2) { $result->addPlayer('team', $buf->readPascalString(1, true)); } if ($flags & 4) { $result->addPlayer('skin', $buf->readPascalString(1, true)); } if ($flags & 8) { $result->addPlayer('score', $buf->readPascalString(1, true)); } if ($flags & 16) { $result->addPlayer('ping', $buf->readPascalString(1, true)); } if ($flags & 32) { $result->addPlayer('time', $buf->readPascalString(1, true)); } } return $result->fetch(); }
/** * Process the player return data */ protected function process_players() { // Make sure we have a valid response if (!$this->hasValidResponse(self::PACKET_PLAYERS)) { return array(); } // Set the result to a new result instance $result = new GameQ_Result(); // Let's preprocess the rules $data = $this->preProcess_players($this->packets_response[self::PACKET_PLAYERS]); // Make a new buffer $buf = new GameQ_Buffer($data); // Parse players while ($buf->getLength()) { // Player id if (($id = $buf->readInt32()) === 0) { break; } $result->addPlayer('id', $id); $result->addPlayer('name', $this->_readUnrealString($buf)); $result->addPlayer('ping', $buf->readInt32()); $result->addPlayer('score', $buf->readInt32()); $buf->skip(4); } unset($buf, $id); // Return the result return $result->fetch(); }
/** * Verify the header of the returned response packet * * @param GameQ_Buffer $buffer * @throws GameQ_ProtocolsException */ protected function verify_header(GameQ_Buffer &$buffer) { // Check length if ($buffer->getLength() < 6) { throw new GameQ_ProtocolsException(__METHOD__ . ": Length of buffer is not long enough"); return FALSE; } // Check to make sure the header is correct if (($type = $buffer->readString("\n")) != 'TS3') { throw new GameQ_ProtocolsException(__METHOD__ . ": Header returned did not match. Returned {$type}"); return FALSE; } // Burn the welcome msg $buffer->readString("\n"); // Verify the response and return return $this->verify_response(trim($buffer->readString("\n"))); }
/** * Process the server details * * @throws GameQ_ProtocolsException */ protected function process_all() { // Make sure we have a valid response if (!$this->hasValidResponse(self::PACKET_ALL)) { return array(); } // Set the result to a new result instance $result = new GameQ_Result(); // Always dedicated $result->add('dedicated', TRUE); // Preprocess and make buffer $buf = new GameQ_Buffer($this->preProcess($this->packets_response[self::PACKET_ALL])); // Pull out the server information // Note the length information is incorrect, we correct using offset options in pascal method $result->add('servername', $buf->readPascalString(1, TRUE)); $result->add('num_players', $buf->readPascalString(1, TRUE)); $result->add('max_players', $buf->readPascalString(1, TRUE)); $result->add('gamemode', $buf->readPascalString(1, TRUE)); $result->add('password', (bool) $buf->readInt8()); // Read the player info, it's in the same query response for some odd reason. while ($buf->getLength()) { // Check to see if we ran out of info if ($buf->getLength() <= 1) { break; } // Only player information is available $result->addPlayer('name', $buf->readPascalString(1, TRUE)); } unset($buf); return $result->fetch(); }
/** * Process the players * * NOTE: There is a restriction on the SAMP server side that if there are too many players * the player return will be empty. Nothing can really be done about this unless you bug * the game developers to fix it. */ protected function process_players() { // Make sure we have a valid response if (!$this->hasValidResponse(self::PACKET_PLAYERS)) { return array(); } // Set the result to a new result instance $result = new GameQ_Result(); // Preprocess and make buffer $buf = new GameQ_Buffer($this->preProcess($this->packets_response[self::PACKET_PLAYERS])); // Number of players $result->add('num_players', $buf->readInt16()); // Run until we run out of buffer while ($buf->getLength()) { $result->addPlayer('id', $buf->readInt8()); $result->addPlayer('name', $buf->readPascalString()); $result->addPlayer('score', $buf->readInt32()); $result->addPlayer('ping', $buf->readInt32()); } // Free some memory unset($buf); // Return the result return $result->fetch(); }