gamespy_query 0.1.1 → 0.1.2

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.
@@ -69,9 +69,7 @@ module GamespyQuery
69
69
  end
70
70
 
71
71
  # Parse player_data
72
- unless player_data.empty?
73
- data[:players] = parse_player_data(player_data)
74
- end
72
+ data[:players] = parse_player_data(player_data)
75
73
 
76
74
  data
77
75
  end
@@ -137,7 +135,7 @@ module GamespyQuery
137
135
  # This will add the broken info header to the previous info list (name for team, team for score, score for deaths)
138
136
  # However the resulting arrays are limited to num_players, so the info is discared anyway.
139
137
  # TODO: Cleaner implementation!
140
- data =~ /(^|[^\x01])#{str}_\x00\x00/ ? STR_X0 : :"#{str}_\x00\x00"
138
+ data =~ /(^|[^\x01])#{Regexp.escape(str)}_\x00\x00/ ? STR_X0 : :"#{str}_\x00\x00"
141
139
  else
142
140
  STR_SIX_X0
143
141
  end
@@ -26,7 +26,7 @@ module GamespyQuery
26
26
 
27
27
  def socket_close(*params)
28
28
  Tools.debug {"Closing socket #{params}"}
29
- _socket_close(*params)
29
+ @s.close
30
30
  end
31
31
 
32
32
  if RUBY_PLATFORM =~ /mswin32/
@@ -48,10 +48,8 @@ module GamespyQuery
48
48
  @s.Receive(@ip_end_point)
49
49
  end
50
50
 
51
- def _socket_close
52
- @s.close
53
- end
54
51
  else
52
+
55
53
  def _create_socket(host, port)
56
54
  @s = UDPSocket.new
57
55
  @s.connect(host, port)
@@ -67,22 +65,21 @@ module GamespyQuery
67
65
  @s.recvfrom(RECEIVE_SIZE)
68
66
  end
69
67
  rescue Timeout::Error
70
- #socket_close
71
68
  raise TimeoutError
69
+ ensure
70
+ @s.close
72
71
  end
73
72
  end
74
-
75
- def _socket_close
76
- @s.close
77
- end
78
73
  end
79
74
  end
80
75
 
81
76
  class Socket < UDPSocket
77
+ include Funcs
78
+
82
79
  DEFAULT_TIMEOUT = 3
83
80
  MAX_PACKETS = 7
84
81
 
85
- ID_PACKET = [0x04, 0x05, 0x06, 0x07].pack("c*") # TODO: Randomize
82
+ ID_PACKET = [0x04, 0x05, 0x06, 0x07].pack("c*") # TODO: Randomize?
86
83
  BASE_PACKET = [0xFE, 0xFD, 0x00].pack("c*")
87
84
  CHALLENGE_PACKET = [0xFE, 0xFD, 0x09].pack("c*")
88
85
 
@@ -116,7 +113,6 @@ module GamespyQuery
116
113
 
117
114
  # TODO: Support pings
118
115
  # TODO: Handle .NET native sockets
119
- include Funcs
120
116
  STATE_INIT, STATE_SENT_CHALLENGE, STATE_RECEIVED_CHALLENGE, STATE_SENT_CHALLENGE_RESPONSE, STATE_RECEIVE_DATA, STATE_READY = 0, 1, 2, 3, 4, 5
121
117
 
122
118
  attr_accessor :addr, :data, :state, :stamp, :needs_challenge, :max_packets, :failed
@@ -142,7 +138,7 @@ module GamespyQuery
142
138
  case self.state
143
139
  when STATE_INIT
144
140
  Tools.debug {"Write (0): #{self.inspect}"}
145
- # Send Challenge
141
+ # Send Challenge request
146
142
  self.puts @packet
147
143
  self.state = STATE_SENT_CHALLENGE
148
144
  when STATE_RECEIVED_CHALLENGE
@@ -257,7 +253,7 @@ module GamespyQuery
257
253
  # Supports challenge/response and multi-packet
258
254
  def sync reply = self.fetch
259
255
  game_data, key = {}, nil
260
- return game_data if reply.nil?
256
+ return game_data if reply.nil? || reply.empty?
261
257
 
262
258
  parser = Parser.new(reply)
263
259
  data = parser.parse
@@ -1,3 +1,3 @@
1
1
  module GamespyQuery
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
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.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-23 00:00:00.000000000 Z
12
+ date: 2012-02-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ''
15
15
  email: