gamespy_query 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/gamespy_query/master.rb +25 -8
- data/lib/gamespy_query/version.rb +1 -1
- metadata +1 -1
data/lib/gamespy_query/master.rb
CHANGED
@@ -34,24 +34,35 @@ module GamespyQuery
|
|
34
34
|
self.to_hash(self.read)
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
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
|
-
|
41
|
-
addrs
|
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
|
-
|
53
|
-
|
54
|
-
|
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
|