Class: GoldSrcSocket
- Inherits:
-
Object
- Object
- GoldSrcSocket
- Includes:
- SteamSocket
- Defined in:
- lib/steam/sockets/goldsrc_socket.rb
Overview
The SourceSocket class is a sub class of SteamSocket respecting the specifications of the Source query protocol.
Instance Method Summary collapse
-
#initialize(ipaddress, port_number = 27015, is_hltv = false) ⇒ GoldSrcSocket
constructor
A new instance of GoldSrcSocket.
- #rcon_challenge ⇒ Object
- #rcon_exec(password, command) ⇒ Object
- #rcon_send(command) ⇒ Object
-
#reply ⇒ Object
Reads a packet from the channel.
Methods included from SteamSocket
#close, #receive_packet, #send, timeout=
Constructor Details
#initialize(ipaddress, port_number = 27015, is_hltv = false) ⇒ GoldSrcSocket
Returns a new instance of GoldSrcSocket.
19 20 21 22 |
# File 'lib/steam/sockets/goldsrc_socket.rb', line 19 def initialize(ipaddress, port_number = 27015, is_hltv = false) super ipaddress, port_number @is_hltv = is_hltv end |
Instance Method Details
#rcon_challenge ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/steam/sockets/goldsrc_socket.rb', line 96 def rcon_challenge rcon_send 'challenge rcon' response = reply.response.strip if response == 'You have been banned from this server.' raise RCONBanException end @rcon_challenge = response[14..-1] end |
#rcon_exec(password, command) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/steam/sockets/goldsrc_socket.rb', line 67 def rcon_exec(password, command) rcon_challenge if @rcon_challenge.nil? or @is_hltv rcon_send "rcon #{@rcon_challenge} #{password} #{command}" rcon_send "rcon #{@rcon_challenge} #{password}" if @is_hltv begin response = reply.response rescue TimeoutException response = '' end else response = reply.response end if response.strip == 'Bad rcon_password.' raise RCONNoAuthException elsif response.strip == 'You have been banned from this server.' raise RCONBanException end begin response_part = reply.response response << response_part end while response_part.size > 0 response end |
#rcon_send(command) ⇒ Object
107 108 109 |
# File 'lib/steam/sockets/goldsrc_socket.rb', line 107 def rcon_send(command) send RCONGoldSrcRequest.new(command) end |
#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.
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 |
# File 'lib/steam/sockets/goldsrc_socket.rb', line 28 def reply bytes_read = receive_packet 1400 if @buffer.long == 0xFFFFFFFE split_packets = [] begin # Parsing of split packet headers request_id = @buffer.long packet_number_and_count = @buffer.byte packet_count = packet_number_and_count & 0xF packet_number = (packet_number_and_count >> 4) + 1 # 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 packet = SteamPacketFactory.reassemble_packet(split_packets) else packet = SteamPacketFactory.packet_from_data(@buffer.get) end puts "Got reply of type \"#{packet.class.to_s}\"." if $DEBUG packet end |