Class: GoldSrcSocket

Inherits:
Object
  • Object
show all
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

Methods included from SteamSocket

#finalize, #receive_packet, #send, timeout=

Constructor Details

#initialize(ipaddress, port_number = 27015, is_hltv = false) ⇒ GoldSrcSocket

Returns a new instance of GoldSrcSocket.



17
18
19
20
# File 'lib/steam/sockets/goldsrc_socket.rb', line 17

def initialize(ipaddress, port_number = 27015, is_hltv = false)
  super ipaddress, port_number
  @is_hltv = is_hltv
end

Instance Method Details

#rcon_challengeObject



94
95
96
97
98
99
100
101
# File 'lib/steam/sockets/goldsrc_socket.rb', line 94

def rcon_challenge
  rcon_send 'challenge rcon'
  response = reply.response.strip

  raise RCONNoAuthException if response == 'You have been banned from this server.'

  @rcon_challenge = response[14..-1]
end

#rcon_exec(password, command) ⇒ Object



65
66
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
# File 'lib/steam/sockets/goldsrc_socket.rb', line 65

def rcon_exec(password, command)
  rcon_challenge if @rcon_challenge.nil? or @is_hltv

  rcon_send "rcon #{@rcon_challenge} #{password} #{command}"
  if @is_hltv
    begin
      response = reply.response
    rescue TimeoutException
      response = ''
    end
  else
    response = reply.response
  end

  if response.strip == 'Bad rcon_password.' or response.strip == 'You have been banned from this server.'
    raise RCONNoAuthException
  end

  begin
    loop do
      response_part = reply.response
      response << response_part
    end
  rescue TimeoutException
  end

  response
end

#rcon_send(command) ⇒ Object



103
104
105
# File 'lib/steam/sockets/goldsrc_socket.rb', line 103

def rcon_send(command)
  send RCONGoldSrcRequest.new(command)
end

#replyObject

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.



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
# File 'lib/steam/sockets/goldsrc_socket.rb', line 26

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