Class: Q2ServerQuery::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/q2_server_query/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address, port) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
# File 'lib/q2_server_query/client.rb', line 9

def initialize(address, port)
  @socket   = UDPSocket.new
  @timeout  = 2
  @address  = address
  @port     = port
  @msg      = "\xff\xff\xff\xffstatus\x00"
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



6
7
8
# File 'lib/q2_server_query/client.rb', line 6

def address
  @address
end

#parsed_responseObject (readonly)

Returns the value of attribute parsed_response.



7
8
9
# File 'lib/q2_server_query/client.rb', line 7

def parsed_response
  @parsed_response
end

#players_listObject (readonly)

Returns the value of attribute players_list.



7
8
9
# File 'lib/q2_server_query/client.rb', line 7

def players_list
  @players_list
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/q2_server_query/client.rb', line 6

def port
  @port
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



7
8
9
# File 'lib/q2_server_query/client.rb', line 7

def raw_response
  @raw_response
end

#socketObject (readonly)

Returns the value of attribute socket.



7
8
9
# File 'lib/q2_server_query/client.rb', line 7

def socket
  @socket
end

Instance Method Details

#statusObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/q2_server_query/client.rb', line 17

def status
  response = status_query
  return nil if response.nil?

  @parsed_response = response.first.split("\\")
  response_header  = @parsed_response.shift[4..8]

  return if response_header != "print"

  build_status(@parsed_response)
end