Class: SourceSocket
- Inherits:
-
Object
- Object
- SourceSocket
- Includes:
- SteamSocket
- Defined in:
- lib/steam/sockets/source_socket.rb
Overview
The SourceSocket class is a sub class of SteamSocket respecting the specifications of the Source query protocol.
Instance Method Summary collapse
-
#reply ⇒ Object
Reads a packet from the channel.
Methods included from SteamSocket
#close, #initialize, #receive_packet, #send, timeout=
Instance Method Details
#reply ⇒ Object
Reads a packet from the channel. The Source query protocol specifies a maximum packet size of 1400 byte. Greater packets will be split over several UDP packets. This method reassembles split packets into single packet objects.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/steam/sockets/source_socket.rb', line 19 def reply bytes_read = receive_packet 1400 is_compressed = false if @buffer.long == 0xFFFFFFFE split_packets = [] begin # Parsing of split packet headers request_id = @buffer.long is_compressed = ((request_id & 0x80000000) != 0) packet_count = @buffer.byte packet_number = @buffer.byte + 1 if is_compressed @buffer.long packet_checksum = @buffer.long else @buffer.short end # Caching of split packet data split_packets[packet_number - 1] = @buffer.get puts "Received packet #{packet_number} of #{packet_count} for request ##{request_id}" if $DEBUG # Receiving the next packet if split_packets.size < packet_count begin bytes_read = receive_packet rescue TimeoutException bytes_read = 0 end else bytes_read = 0 end end while bytes_read > 0 && @buffer.long == 0xFFFFFFFE if is_compressed packet = SteamPacketFactory.reassemble_packet(split_packets, true, packet_checksum) else packet = SteamPacketFactory.reassemble_packet(split_packets) end else packet = SteamPacketFactory.packet_from_data(@buffer.get) end if is_compressed puts "Got compressed reply of type \"#{packet.class.to_s}\"." if $DEBUG else puts "Got reply of type \"#{packet.class.to_s}\"." if $DEBUG end packet end |