protected function parsePlayers(GameQ_Buffer &$buf, GameQ_Result &$result) { while (($id = $buf->readInt8()) != 32) { $result->addPlayer('id', $id); $result->addPlayer('ping', $buf->readInt16()); $result->addPlayer('rate', $buf->readInt32()); $result->addPlayer('name', $buf->readString()); $result->addPlayer('clantag', $buf->readString()); } return true; }
/** * Overloaded for Killing Floor servername issue, could be all unreal2 games though * * @see GameQ_Protocols_Unreal2::process_details() */ protected function process_details() { // Make sure we have a valid response if (!$this->hasValidResponse(self::PACKET_DETAILS)) { return array(); } // Set the result to a new result instance $result = new GameQ_Result(); // Let's preprocess the rules $data = $this->preProcess_details($this->packets_response[self::PACKET_DETAILS]); // Create a buffer $buf = new GameQ_Buffer($data); $result->add('serverid', $buf->readInt32()); // 0 $result->add('serverip', $buf->readPascalString(1)); // empty $result->add('gameport', $buf->readInt32()); $result->add('queryport', $buf->readInt32()); // 0 // We burn the first char since it is not always correct with the hostname $buf->skip(1); // Read as a regular string since the length is incorrect (what we skipped earlier) $result->add('servername', $buf->readString()); // The rest is read as normal $result->add('mapname', $buf->readPascalString(1)); $result->add('gametype', $buf->readPascalString(1)); $result->add('playercount', $buf->readInt32()); $result->add('maxplayers', $buf->readInt32()); $result->add('ping', $buf->readInt32()); // 0 // @todo: There is extra data after this point (~9 bytes), cant find any reference on what it is unset($buf); // Return the result return $result->fetch(); }
/** * Decode words from the response * * @param GameQ_Buffer $buf */ protected function decodeWords(GameQ_Buffer &$buf) { $result = array(); $num_words = $buf->readInt32(); for ($i = 0; $i < $num_words; $i++) { $len = $buf->readInt32(); $result[] = $buf->read($len); $buf->read(1); /* 0x00 string ending */ } return $result; }
/** * 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(); }
/** * 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(); }