27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/query/query.rb', line 27
def self.simpleQuery(addr = 'localhost', port = 25565)
@addr = addr
@port = port
init
begin
timeout(1) do
query = @sock.send("\xFE\xFD\x00\x01\x02\x03\x04".force_encoding(Encoding::ASCII_8BIT) + @key.to_s, 0)
data = @sock.recvfrom(1460)[0]
buffer = data[5...-1]
@val[:motd], @val[:gametype], @val[:map], @val[:numplayers], @val[:maxplayers], @buf = buffer.split("\x00", 6)
if @sock != nil
@sock.close
end
end
return @val
rescue StandardError => e
return e
end
end
|