gamespy_query 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,24 +34,35 @@ module GamespyQuery
34
34
  self.to_hash(self.read)
35
35
  end
36
36
 
37
- def get_server_list list = nil
37
+ def get_params
38
+ PARAMS.clone.map{|e| "#{DELIMIT}#{e}"}.join("")
39
+ end
40
+
41
+ def get_server_list list = nil, include_data = false, geo = nil
38
42
  addrs = []
39
- list = %x[gslist -n #{@game}] if list.nil?
40
- list.split("\n").each do |line|
41
- addrs << "#{$1}:#{$2}" if line =~ RX_ADDR_LINE
43
+ list = %x[gslist -p "#{geoip_path}"#{" #{geo}-X #{get_params}" if include_data} -n #{@game}] if list.nil?
44
+ if include_data
45
+ addrs = handle_data(list, geo)
46
+ else
47
+ list.split("\n").each do |line|
48
+ addrs << "#{$1}:#{$2}" if line =~ RX_ADDR_LINE
49
+ end
42
50
  end
43
51
  addrs
44
52
  end
45
53
 
46
54
  def read
47
55
  geo = @geo ? @geo : "-Q 11 "
48
- unless File.exists?(File.join(geoip_path, "GeoIP.dat"))
56
+ unless geo.nil? || geo.empty? || File.exists?(File.join(geoip_path, "GeoIP.dat"))
49
57
  Tools.logger.warn "Warning: GeoIP.dat database missing. Can't parse countries. #{geoip_path}"
50
58
  geo = nil
51
59
  end
52
- reply = %x[gslist -p "#{geoip_path}" -n #{@game} #{geo}-X #{PARAMS.clone.map{|e| "#{DELIMIT}#{e}"}.join("")}]
53
- reply.gsub!("\\\\\\", "") if geo
54
- reply.split("\n")
60
+ get_server_list(nil, true, geo)
61
+ end
62
+
63
+ def handle_data(reply, geo = nil)
64
+ reply = reply.gsub("\\\\\\", "") if geo
65
+ reply.split("\n").select{|line| line =~ RX_ADDR_LINE }
55
66
  end
56
67
 
57
68
  RX_H = /\A([\.0-9]*):([0-9]*) *\\(.*)/
@@ -87,3 +98,9 @@ module GamespyQuery
87
98
  end
88
99
  end
89
100
  end
101
+
102
+ if $0 == __FILE__
103
+ master = GamespyQuery::Master.new
104
+ r = master.read
105
+ puts r
106
+ end
@@ -1,3 +1,3 @@
1
1
  module GamespyQuery
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gamespy_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: