lib/McQuery.rb in McQuery-0.1.2 vs lib/McQuery.rb in McQuery-0.2.0

- old
+ new

@@ -1,38 +1,5 @@ -require 'socket' +require "McQuery/version" +require "McQuery/ping" module McQuery - class Ping - - def initialize(hostname, port) - @hostname = hostname - @port = port - end - -# Querys the Minecraft server -# -# @return [Hash] Items returned by the server. - def doPing - s = TCPSocket.open(@hostname, @port) - - s.puts "\xFE\x01" - repl = s.gets - s.close - if repl[0] == "\xFF" - #Got kick continuing... - # length = repl[1,2].unpack('n').first - qstring = repl[3,repl.length].force_encoding("utf-16be").encode("utf-8") - qarray = qstring.split("\0") - qdict = {} - qdict[:pversion] = qarray[1] - qdict[:sversion] = qarray[2] - qdict[:motd] = qarray[3] - qdict[:players] = {:online => qarray[4], :max => qarray[5]} - return qdict - else - #Got wierd packet! - return nil - end - end - - end -end \ No newline at end of file +end