Class: Six::Query::GamespyMaster
- Defined in:
- lib/six-updater-web/vendor/plugins/six-query/lib/six/query/gamespy_master.rb
Constant Summary collapse
- PARAMS =
[:hostname, :gamever, :gametype, :gamemode, :numplayers, :maxplayers, :password, :equalModRequired, :mission, :mapname, :mod, :signatures, :verifysignatures, :gamestate, :dedicated, :platform, :sv_battleeye, :language, :difficulty]
- DELIMIT =
case RUBY_PLATFORM when /-mingw32$/, /-mswin32$/ "\\" else "\\\\" end
- GEOIP_PATH =
case RUBY_PLATFORM when /-mingw32$/, /-mswin32$/ File.join(RAILS_ROOT, "config").gsub("/", "\\") else File.join(RAILS_ROOT, "config") end
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(geo = nil, game = "arma2oapc") ⇒ GamespyMaster
constructor
A new instance of GamespyMaster.
- #process ⇒ Object
- #read ⇒ Object
- #to_hash(ar) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(geo = nil, game = "arma2oapc") ⇒ GamespyMaster
Returns a new instance of GamespyMaster.
20 21 22 |
# File 'lib/six-updater-web/vendor/plugins/six-query/lib/six/query/gamespy_master.rb', line 20 def initialize(geo = nil, game = "arma2oapc") @geo, @game = geo, game end |
Instance Method Details
#process ⇒ Object
24 25 26 27 |
# File 'lib/six-updater-web/vendor/plugins/six-query/lib/six/query/gamespy_master.rb', line 24 def process @list = Hash.new self.to_hash(self.read) end |
#read ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/six-updater-web/vendor/plugins/six-query/lib/six/query/gamespy_master.rb', line 29 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}" -n #{@game} #{geo}-X #{PARAMS.clone.map{|e| "#{DELIMIT}#{e}"}.join("")}] reply.gsub!("\\\\\\", "") if geo reply.split("\n") end |
#to_hash(ar) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/six-updater-web/vendor/plugins/six-query/lib/six/query/gamespy_master.rb', line 41 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 e[:gamedata] ? e[:gamedata].merge!(Hash[*content]) : e[:gamedata] = Hash[*content] end @list end |