Class: RCONSocket
Instance Method Summary
collapse
#receive_packet, timeout=
Constructor Details
#initialize(ip, port) ⇒ RCONSocket
Returns a new instance of RCONSocket.
19
20
21
22
23
24
25
|
# File 'lib/steam/sockets/rcon_socket.rb', line 19
def initialize(ip, port)
ip = IPSocket.getaddress(ip) unless ip.is_a? IPAddr
@ip = ip
@port = port
@socket = nil
end
|
Instance Method Details
#close ⇒ Object
Closes the underlying socket if it exists
28
29
30
|
# File 'lib/steam/sockets/rcon_socket.rb', line 28
def close
super unless @socket.nil?
end
|
#connect ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/steam/sockets/rcon_socket.rb', line 32
def connect
begin
timeout(@@timeout / 1000.0) { @socket = TCPSocket.new @ip, @port }
rescue Timeout::Error
raise TimeoutException
end
end
|
#reply ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/steam/sockets/rcon_socket.rb', line 46
def reply
raise RCONBanException if receive_packet(4) == 0
@buffer.rewind
remaining_bytes = @buffer.long
packet_data = ''
begin
received_bytes = receive_packet remaining_bytes
remaining_bytes -= received_bytes
packet_data << @buffer.get
end while remaining_bytes > 0
RCONPacketFactory.packet_from_data(packet_data)
end
|
#send(data_packet) ⇒ Object
40
41
42
43
44
|
# File 'lib/steam/sockets/rcon_socket.rb', line 40
def send(data_packet)
connect if @socket.nil? || @socket.closed?
super
end
|