Sha256: 7a37c66ffea13000fccbf8221db8c80c9ef67db520bee0850e451c28fc428f51
Contents?: true
Size: 1.88 KB
Versions: 13
Compression:
Stored size: 1.88 KB
Contents
module Six module Query class GamespyMaster < Base PARAMS = [:hostname, :gamever, :gametype, :gamemode, :numplayers, :maxplayers, :password, :equalModRequired, :mission, :mapname, :mod, :signatures, :verifysignatures, :gamestate, :dedicated, :platform, :sv_battleeye, :language, :difficulty] LINUX, WIN = "\\\\", "\\" # TODO: Autodetect? GEOIP_PATH = File.join(RAILS_ROOT, "config") def initialize(geo = nil) @list = Hash.new @geo = geo end def process self.to_hash(self.read) end def read geo = @geo ? @geo : "-Q 8 " unless File.exists?(File.join(GEOIP_PATH, "GeoIP.dat")) puts puts "Warning: GeoIP.dat database missing. Can't parse countries. #{GEOIP_PATH}" geo = nil end reply = %x[gslist -p "#{GEOIP_PATH.gsub("/", "\\")}" -n arma2pc #{geo}-X #{PARAMS.clone.map{|e| "#{WIN}#{e}"}.join("")}] reply.gsub!("\\\\\\", "") if geo reply.split("\n") end def to_hash(ar) ar.each_with_index do |entry, index| str = entry[/\A([\.0-9]*):([0-9]*) *\\(.*)/] next unless str ip, port, content = $1, $2, $3 content = content.split("\\") content << "" unless (content.size % 2 == 0) i = 0; content.map! do |e| i += 1 i % 2 == 0 ? e : clean(e) end addr = "#{ip}:#{port}" if @list.has_key?(addr) e = @list[addr] else e = Hash.new e[:ip] = ip e[:port] = port @list[addr] = e end if e[:gamedata] e[:gamedata].merge!(Hash[*content]) else e[:gamedata] = Hash[*content] end end @list end end end end
Version data entries
13 entries across 13 versions & 1 rubygems