def build_response_packet
      rpacket = Packet::Source.new
      total_size = 0
      request_id = 0
      type = 0
      response = ""
      message = ""
    

      loop do
        break unless IO.select([@socket], nil, nil, 10)

        #
        # TODO: clean this up - read everything and then unpack.
        #

        tmp = @socket.recv(14)
        if tmp.nil?
          return nil
        end
        size, request_id, type, message = tmp.unpack("VVVa*")
        total_size += size
      
        # special case for authentication
        break if message.sub! /\x00\x00$/, ""

        response << message

        # the 'size - 10' here accounts for the fact that we've snarfed 14 bytes,
        # the size (which is 4 bytes) is not counted, yet represents the rest
        # of the packet (which we have already taken 10 bytes from)

        tmp = @socket.recv(size - 10)
        response << tmp
        response.sub! /\x00\x00$/, ""
      end
    
      rpacket.packet_size = total_size
      rpacket.request_id = request_id
      rpacket.command_type = type
    
      # strip nulls (this is actually the end of string1 and string2)
      rpacket.string1 = response.sub /\x00\x00$/, ""
      return rpacket
    end
def build_response_packet
      rpacket = Packet::Source.new
      total_size = 0
      request_id = 0
      type = 0
      response = ""
      message = ""
    

      loop do
        break unless IO.select([@socket], nil, nil, 10)

        #
        # TODO: clean this up - read everything and then unpack.
        #

        tmp = @socket.recv(14)
        if tmp.nil?
          return nil
        end
        size, request_id, type, message = tmp.unpack("VVVa*")
        total_size += size
      
        # special case for authentication
        break if message.sub! /\x00\x00$/, ""

        response << message

        # the 'size - 10' here accounts for the fact that we've snarfed 14 bytes,
        # the size (which is 4 bytes) is not counted, yet represents the rest
        # of the packet (which we have already taken 10 bytes from)

        tmp = @socket.recv(size - 10)
        response << tmp
        response.sub! /\x00\x00$/, ""
      end
    
      rpacket.packet_size = total_size
      rpacket.request_id = request_id
      rpacket.command_type = type
    
      # strip nulls (this is actually the end of string1 and string2)
      rpacket.string1 = response.sub /\x00\x00$/, ""
      return rpacket
    end
Builds a Packet::Source packet based on the response
 given by the server.