teamspeak-ruby 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5293306a7bf6d98ffcd5bd9b7147d8d336636d1
4
- data.tar.gz: 4f587d29775bd5d368c85529f965d3785da38049
3
+ metadata.gz: a9cecd16ae10abd107bf8f9b49cc9bc46c9412f2
4
+ data.tar.gz: 80bf427a1277df9993d68ab8003f532199378a05
5
5
  SHA512:
6
- metadata.gz: c9ce3a70837d0945f47ac485386ad64ccc0a125705871b0bcac7ebf44775fa52b68082bd4be7c2a18efc11567d27156718dbba035c37a890f0b175752ae2be30
7
- data.tar.gz: a1c1aed6910489fd9fab73ba9f9fbc32c407cf71bdd1d72182fdac4ef70870da0d82a72312fb8a6292c71f8c3c43fc150191b6faa1611f02f4d289bfacde3bed
6
+ metadata.gz: 02c93f35ad458f72604b2df92adc9974be475e7b90b5887e3744ed68d1e9eff453e1d8ff722aedf10ee8cf45a0b199526c9a5beca8f3a1472af7f07b80a34581
7
+ data.tar.gz: 12bd82d09e6238b37559d3e3733964e1973885e7cf39b3376112d601f19a784b989380244ec152e14d168f56657b7dfbce55b3ed60bf6101514727b003a92475
@@ -9,10 +9,25 @@ module Teamspeak
9
9
  # Length of time before flood_limit is reset in seconds. Default is 3
10
10
  attr_writer(:flood_time)
11
11
 
12
+ # First is escaped char, second is real char.
13
+ SPECIAL_CHARS = [
14
+ ['\\\\', '\\'],
15
+ ['\\/', '/'],
16
+ ['\\s', ' '],
17
+ ['\\p', '|'],
18
+ ['\\a', '\a'],
19
+ ['\\b', '\b'],
20
+ ['\\f', '\f'],
21
+ ['\\n', '\n'],
22
+ ['\\r', '\r'],
23
+ ['\\t', '\t'],
24
+ ['\\v', '\v']
25
+ ].freeze
26
+
12
27
  # Initializes Client
13
28
  #
14
29
  # connect('voice.domain.com', 88888)
15
- def initialize(host = 'localhost', port = 10011)
30
+ def initialize(host = 'localhost', port = 10_011)
16
31
  connect(host, port)
17
32
 
18
33
  # Throttle commands by default unless connected to localhost
@@ -27,12 +42,13 @@ module Teamspeak
27
42
  # Connects to a TeamSpeak 3 server
28
43
  #
29
44
  # connect('voice.domain.com', 88888)
30
- def connect(host = 'localhost', port = 10011)
45
+ def connect(host = 'localhost', port = 10_011)
31
46
  @sock = TCPSocket.new(host, port)
32
47
 
33
48
  # Check if the response is the same as a normal teamspeak 3 server.
34
49
  if @sock.gets.strip != 'TS3'
35
- raise InvalidServer, 'Server is not responding as a normal TeamSpeak 3 server.'
50
+ msg = 'Server is not responding as a normal TeamSpeak 3 server.'
51
+ raise InvalidServer, msg
36
52
  end
37
53
 
38
54
  # Remove useless text from the buffer.
@@ -49,9 +65,9 @@ module Teamspeak
49
65
  #
50
66
  # login('serveradmin', 'H8YlK1f9')
51
67
  def login(user, pass)
52
- command('login', {'client_login_name' => user, 'client_login_password' => pass})
68
+ command('login', client_login_name: user, client_login_password: pass)
53
69
  end
54
-
70
+
55
71
  # Sends command to the TeamSpeak 3 server and returns the response
56
72
  #
57
73
  # command('use', {'sid' => 1}, '-away')
@@ -72,32 +88,30 @@ module Teamspeak
72
88
  @sock.puts out
73
89
 
74
90
  if cmd == 'servernotifyregister'
75
- 2.times {response += @sock.gets}
91
+ 2.times { response += @sock.gets }
76
92
  return parse_response(response)
77
93
  end
78
94
 
79
- while true
95
+ loop do
80
96
  response += @sock.gets
81
-
82
- if response.index(' msg=')
83
- break
84
- end
97
+
98
+ break if response.index(' msg=')
85
99
  end
86
100
 
87
101
  # Array of commands that are expected to return as an array.
88
102
  # Not sure - clientgetids
89
- should_be_array = [
90
- 'bindinglist', 'serverlist', 'servergrouplist', 'servergroupclientlist',
91
- 'servergroupsbyclientid', 'servergroupclientlist', 'logview', 'channellist',
92
- 'channelfind', 'channelgrouplist', 'channelgrouppermlist', 'channelpermlist', 'clientlist',
93
- 'clientfind', 'clientdblist', 'clientdbfind', 'channelclientpermlist', 'permissionlist',
94
- 'permoverview', 'privilegekeylist', 'messagelist', 'complainlist', 'banlist', 'ftlist',
95
- 'custominfo'
96
- ]
103
+ should_be_array = %w(
104
+ bindinglist serverlist servergrouplist servergroupclientlist
105
+ servergroupsbyclientid servergroupclientlist logview channellist
106
+ channelfind channelgrouplist channelgrouppermlist channelpermlist
107
+ clientlist clientfind clientdblist clientdbfind channelclientpermlist
108
+ permissionlist permoverview privilegekeylist messagelist complainlist
109
+ banlist ftlist custominfo permfind
110
+ )
97
111
 
98
112
  parsed_response = parse_response(response)
99
113
 
100
- return should_be_array.include?(cmd) ? parsed_response : parsed_response.first
114
+ should_be_array.include?(cmd) ? parsed_response : parsed_response.first
101
115
  end
102
116
 
103
117
  def parse_response(response)
@@ -106,8 +120,8 @@ module Teamspeak
106
120
  response.split('|').each do |key|
107
121
  data = {}
108
122
 
109
- key.split(' ').each do |key|
110
- value = key.split('=', 2)
123
+ key.split(' ').each do |inner_key|
124
+ value = inner_key.split('=', 2)
111
125
 
112
126
  data[value[0]] = decode_param(value[1])
113
127
  end
@@ -125,33 +139,17 @@ module Teamspeak
125
139
  # Return as integer if possible
126
140
  return param.to_i if param.to_i.to_s == param
127
141
 
128
- param.gsub!('\\\\', '\\')
129
- param.gsub!('\\/', '/')
130
- param.gsub!('\\s', ' ')
131
- param.gsub!('\\p', '|')
132
- param.gsub!('\\a', '\a')
133
- param.gsub!('\\b', '\b')
134
- param.gsub!('\\f', '\f')
135
- param.gsub!('\\n', '\n')
136
- param.gsub!('\\r', '\r')
137
- param.gsub!('\\t', '\t')
138
- param.gsub!('\\v', '\v')
142
+ SPECIAL_CHARS.each do |pair|
143
+ param.gsub!(pair[0], pair[1])
144
+ end
139
145
 
140
146
  param
141
147
  end
142
148
 
143
149
  def encode_param(param)
144
- param.gsub!('\\', '\\\\')
145
- param.gsub!('/', '\\/')
146
- param.gsub!(' ', '\\s')
147
- param.gsub!('|', '\\p')
148
- param.gsub!('\a', '\\a')
149
- param.gsub!('\b', '\\b')
150
- param.gsub!('\f', '\\f')
151
- param.gsub!('\n', '\\n')
152
- param.gsub!('\r', '\\r')
153
- param.gsub!('\t', '\\t')
154
- param.gsub!('\v', '\\v')
150
+ SPECIAL_CHARS.each do |pair|
151
+ param.gsub!(pair[1], pair[0])
152
+ end
155
153
 
156
154
  param
157
155
  end
@@ -170,9 +168,7 @@ module Teamspeak
170
168
  flood_time_reached = Time.now - @flood_timer < @flood_time
171
169
  flood_limit_reached = @flood_current == @flood_limit
172
170
 
173
- if flood_time_reached && flood_limit_reached
174
- sleep(@flood_time)
175
- end
171
+ sleep(@flood_time) if flood_time_reached && flood_limit_reached
176
172
 
177
173
  if flood_limit_reached
178
174
  # Reset flood protection
@@ -183,8 +179,8 @@ module Teamspeak
183
179
  end
184
180
 
185
181
  private(
186
- :parse_response, :decode_param, :encode_param,
187
- :check_response_error, :flood_control
182
+ :parse_response, :decode_param, :encode_param,
183
+ :check_response_error, :flood_control
188
184
  )
189
185
  end
190
186
  end
@@ -1,7 +1,9 @@
1
1
  module Teamspeak
2
- # Raised when the connected server does not respond as a normal TeamSpeak 3 would.
2
+ # Raised when the connected server does not respond as a normal
3
+ # TeamSpeak 3 would.
3
4
  #
4
- # raise InvalidServer, 'Server is not responding as a normal TeamSpeak 3 server.'
5
+ # msg = 'Server is not responding as a normal TeamSpeak 3 server.'
6
+ # raise InvalidServer, msg
5
7
  class InvalidServer < StandardError; end
6
8
 
7
9
  # Raised when the server returns an error code other than 0.
@@ -1,3 +1,3 @@
1
1
  module Teamspeak
2
- VERSION = '1.0.5'
2
+ VERSION = '1.0.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teamspeak-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Harrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-01 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2016-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.8'
13
27
  description:
14
28
  email: justin@pyrohail.com
15
29
  executables: []
@@ -40,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
54
  version: '0'
41
55
  requirements: []
42
56
  rubyforge_project:
43
- rubygems_version: 2.2.2
57
+ rubygems_version: 2.5.1
44
58
  signing_key:
45
59
  specification_version: 4
46
60
  summary: Ruby interface for TeamSpeak 3's server query api.