/** * Specific player parse for The Ship * * Player response has unknown data after the last real player * * @param \GameQ\Buffer $buffer * * @return array */ protected function processPlayers(Buffer $buffer) { // Set the result to a new result instance $result = new Result(); // We need to read the number of players because this response has other data at the end usually $num_players = $buffer->readInt8(); // Player count $result->add('num_players', $num_players); // No players, no work if ($num_players == 0) { return $result->fetch(); } // Players list for ($player = 0; $player < $num_players; $player++) { $result->addPlayer('id', $buffer->readInt8()); $result->addPlayer('name', $buffer->readString()); $result->addPlayer('score', $buffer->readInt32Signed()); $result->addPlayer('time', $buffer->readFloat32()); } // Extra data if ($buffer->getLength() > 0) { for ($player = 0; $player < $num_players; $player++) { $result->addPlayer('deaths', $buffer->readInt32Signed()); $result->addPlayer('money', $buffer->readInt32Signed()); } } unset($buffer); return $result->fetch(); }
/** * Process the response * * @return array */ public function processResponse() { // Holds the processed packets $processed = []; // Iterate over the packets foreach ($this->packets_response as $response) { // Make a buffer $buffer = new Buffer($response, Buffer::NUMBER_TYPE_BIGENDIAN); // Packet type = 0 $buffer->readInt8(); // Session Id $buffer->readInt32(); // We need to burn the splitnum\0 because it is not used $buffer->skip(9); // Get the id $id = $buffer->readInt8(); // Burn next byte not sure what it is used for $buffer->skip(1); // Add this packet to the processed $processed[$id] = $buffer->getBuffer(); unset($buffer, $id); } // Sort packets, reset index ksort($processed); // Offload cleaning up the packets if they happen to be split $packets = $this->cleanPackets(array_values($processed)); // Create a new buffer $buffer = new Buffer(implode('', $packets), Buffer::NUMBER_TYPE_BIGENDIAN); // Create a new result $result = new Result(); // Parse the server details $this->processDetails($buffer, $result); // Parse the player and team information $this->processPlayersAndTeams($buffer, $result); unset($buffer); return $result->fetch(); }
/** * Handles processing the player data into a usable format * * @param \GameQ\Buffer $buffer * * @return array */ protected function processPlayers(Buffer $buffer) { // Set the result to a new result instance $result = new Result(); // Number of players $result->add('num_players', $buffer->readInt16()); // Run until we run out of buffer while ($buffer->getLength()) { $result->addPlayer('id', $buffer->readInt8()); $result->addPlayer('name', $buffer->readPascalString()); $result->addPlayer('score', $buffer->readInt32()); $result->addPlayer('ping', $buffer->readInt32()); } unset($buffer); return $result->fetch(); }
/** * Handles processing the player data into a usable format * * @param \GameQ\Buffer $buffer * * @return mixed */ protected function processPlayers(Buffer $buffer) { // Set the result to a new result instance $result = new Result(); // Pull out the number of players $num_players = $buffer->readInt8(); // Player count $result->add('num_players', $num_players); // No players so no need to look any further if ($num_players == 0) { return $result->fetch(); } // Players list while ($buffer->getLength()) { $result->addPlayer('id', $buffer->readInt8()); $result->addPlayer('name', $buffer->readString()); $result->addPlayer('score', $buffer->readInt32Signed()); $result->addPlayer('time', $buffer->readFloat32()); } unset($buffer); return $result->fetch(); }
/** * 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) { // Players and team info while ($buffer->getLength()) { // Get the flags $flags = $buffer->readInt8(); // Get data according to the flags if ($flags & 1) { $result->addPlayer('name', $buffer->readPascalString(1, true)); } if ($flags & 2) { $result->addPlayer('team', $buffer->readPascalString(1, true)); } if ($flags & 4) { $result->addPlayer('skin', $buffer->readPascalString(1, true)); } if ($flags & 8) { $result->addPlayer('score', $buffer->readPascalString(1, true)); } if ($flags & 16) { $result->addPlayer('ping', $buffer->readPascalString(1, true)); } if ($flags & 32) { $result->addPlayer('time', $buffer->readPascalString(1, true)); } } }