teamspeak-ruby 1.0.2 → 1.0.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.
- checksums.yaml +4 -4
- data/lib/teamspeak-ruby.rb +3 -3
- data/lib/teamspeak-ruby/client.rb +178 -146
- data/lib/teamspeak-ruby/exceptions.rb +18 -18
- data/lib/teamspeak-ruby/version.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48a7dab7b91961d54bacdea425abe4a996dc24f0
|
4
|
+
data.tar.gz: 03f19e56293c044f8fb44e416f6d03ce245072e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acc5f352ce5c12942d29d498aa0cb68bcc241295ed2dd469fc3ef2c991afe5a6fbedd158149d3634e59f18e62f08711a90107a35517de64e42bb7b79c18b988e
|
7
|
+
data.tar.gz: 5e7cfecfc5f0bca28bac5a8e3034f1c76299fbd6d88879614b06809ac501ee9a7de6c82661bba11081e8a789920664c69b27e92173f5c2be091653989676f603
|
data/lib/teamspeak-ruby.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
require 'teamspeak-ruby/client'
|
2
|
-
require 'teamspeak-ruby/exceptions'
|
3
|
-
require 'teamspeak-ruby/version'
|
1
|
+
require 'teamspeak-ruby/client'
|
2
|
+
require 'teamspeak-ruby/exceptions'
|
3
|
+
require 'teamspeak-ruby/version'
|
@@ -1,146 +1,178 @@
|
|
1
|
-
require 'socket'
|
2
|
-
|
3
|
-
module Teamspeak
|
4
|
-
class Client
|
5
|
-
#
|
6
|
-
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# connect('voice.domain.com', 88888)
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@
|
25
|
-
end
|
26
|
-
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
#
|
43
|
-
def
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
param
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module Teamspeak
|
4
|
+
class Client
|
5
|
+
# Should commands be throttled? Default is true
|
6
|
+
attr_writer(:flood_protection)
|
7
|
+
# Number of commands within flood_time before pausing. Default is 10
|
8
|
+
attr_writer(:flood_limit)
|
9
|
+
# Length of time before flood_limit is reset in seconds. Default is 3
|
10
|
+
attr_writer(:flood_time)
|
11
|
+
|
12
|
+
# Initializes Client
|
13
|
+
#
|
14
|
+
# connect('voice.domain.com', 88888)
|
15
|
+
def initialize(host = 'localhost', port = 10011)
|
16
|
+
connect(host, port)
|
17
|
+
|
18
|
+
# Throttle commands by default unless connected to localhost
|
19
|
+
@flood_protection = true unless host
|
20
|
+
@flood_limit = 10
|
21
|
+
@flood_time = 3
|
22
|
+
|
23
|
+
@flood_timer = Time.new
|
24
|
+
@flood_current = 0
|
25
|
+
end
|
26
|
+
|
27
|
+
# Connects to a TeamSpeak 3 server
|
28
|
+
#
|
29
|
+
# connect('voice.domain.com', 88888)
|
30
|
+
def connect(host = 'localhost', port = 10011)
|
31
|
+
@sock = TCPSocket.new(host, port)
|
32
|
+
|
33
|
+
# Check if the response is the same as a normal teamspeak 3 server.
|
34
|
+
if @sock.gets.strip != 'TS3'
|
35
|
+
raise InvalidServer, 'Server is not responding as a normal TeamSpeak 3 server.'
|
36
|
+
end
|
37
|
+
|
38
|
+
# Remove useless text from the buffer.
|
39
|
+
@sock.gets
|
40
|
+
end
|
41
|
+
|
42
|
+
# Disconnects from the TeamSpeak 3 server
|
43
|
+
def disconnect
|
44
|
+
@sock.puts 'quit'
|
45
|
+
@sock.close
|
46
|
+
end
|
47
|
+
|
48
|
+
# Authenticates with the TeamSpeak 3 server
|
49
|
+
#
|
50
|
+
# login('serveradmin', 'H8YlK1f9')
|
51
|
+
def login(user, pass)
|
52
|
+
command('login', {'client_login_name' => user, 'client_login_password' => pass})
|
53
|
+
end
|
54
|
+
|
55
|
+
# Sends command to the TeamSpeak 3 server and returns the response
|
56
|
+
#
|
57
|
+
# command('use', {'sid' => 1}, '-away')
|
58
|
+
def command(cmd, params = {}, options = '')
|
59
|
+
if @flood_protection
|
60
|
+
@flood_current += 1
|
61
|
+
|
62
|
+
flood_time_reached = Time.now - @flood_timer < @flood_time
|
63
|
+
flood_limit_reached = @flood_current == @flood_limit
|
64
|
+
|
65
|
+
if flood_time_reached && flood_limit_reached
|
66
|
+
sleep(@flood_time)
|
67
|
+
end
|
68
|
+
|
69
|
+
if flood_limit_reached
|
70
|
+
# Reset flood protection
|
71
|
+
@flood_timer = Time.now
|
72
|
+
@flood_current = 0
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
out = ''
|
77
|
+
response = ''
|
78
|
+
|
79
|
+
out += cmd
|
80
|
+
|
81
|
+
params.each_pair do |key, value|
|
82
|
+
out += " #{key}=#{encode_param(value.to_s)}"
|
83
|
+
end
|
84
|
+
|
85
|
+
out += ' ' + options
|
86
|
+
|
87
|
+
@sock.puts out
|
88
|
+
|
89
|
+
while true
|
90
|
+
response += @sock.gets
|
91
|
+
|
92
|
+
if response.index(' msg=')
|
93
|
+
break
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Array of commands that are expected to return as an array.
|
98
|
+
# Not sure - clientgetids
|
99
|
+
should_be_array = [
|
100
|
+
'bindinglist', 'serverlist', 'servergrouplist', 'servergroupclientlist',
|
101
|
+
'servergroupsbyclientid', 'servergroupclientlist', 'logview', 'channellist',
|
102
|
+
'channelfind', 'channelgrouplist', 'channelgrouppermlist', 'channelpermlist', 'clientlist',
|
103
|
+
'clientfind', 'clientdblist', 'clientdbfind', 'channelclientpermlist', 'permissionlist',
|
104
|
+
'permoverview', 'privilegekeylist', 'messagelist', 'complainlist', 'banlist', 'ftlist',
|
105
|
+
'custominfo'
|
106
|
+
]
|
107
|
+
|
108
|
+
parsed_response = parse_response(response)
|
109
|
+
|
110
|
+
return should_be_array.include?(cmd) ? parsed_response : parsed_response.first
|
111
|
+
end
|
112
|
+
|
113
|
+
def parse_response(response)
|
114
|
+
out = []
|
115
|
+
|
116
|
+
response.split('|').each do |key|
|
117
|
+
data = {}
|
118
|
+
|
119
|
+
key.split(' ').each do |key|
|
120
|
+
value = key.split('=', 2)
|
121
|
+
|
122
|
+
data[value[0]] = decode_param(value[1])
|
123
|
+
end
|
124
|
+
|
125
|
+
out.push(data)
|
126
|
+
end
|
127
|
+
|
128
|
+
check_response_error(out)
|
129
|
+
|
130
|
+
out
|
131
|
+
end
|
132
|
+
|
133
|
+
def decode_param(param)
|
134
|
+
return nil unless param
|
135
|
+
# Return as integer if possible
|
136
|
+
return param.to_i if param.to_i.to_s == param
|
137
|
+
|
138
|
+
param.gsub!('\\\\', '\\')
|
139
|
+
param.gsub!('\\/', '/')
|
140
|
+
param.gsub!('\\s', ' ')
|
141
|
+
param.gsub!('\\p', '|')
|
142
|
+
param.gsub!('\\a', '\a')
|
143
|
+
param.gsub!('\\b', '\b')
|
144
|
+
param.gsub!('\\f', '\f')
|
145
|
+
param.gsub!('\\n', '\n')
|
146
|
+
param.gsub!('\\r', '\r')
|
147
|
+
param.gsub!('\\t', '\t')
|
148
|
+
param.gsub!('\\v', '\v')
|
149
|
+
|
150
|
+
param
|
151
|
+
end
|
152
|
+
|
153
|
+
def encode_param(param)
|
154
|
+
param.gsub!('\\', '\\\\')
|
155
|
+
param.gsub!('/', '\\/')
|
156
|
+
param.gsub!(' ', '\\s')
|
157
|
+
param.gsub!('|', '\\p')
|
158
|
+
param.gsub!('\a', '\\a')
|
159
|
+
param.gsub!('\b', '\\b')
|
160
|
+
param.gsub!('\f', '\\f')
|
161
|
+
param.gsub!('\n', '\\n')
|
162
|
+
param.gsub!('\r', '\\r')
|
163
|
+
param.gsub!('\t', '\\t')
|
164
|
+
param.gsub!('\v', '\\v')
|
165
|
+
|
166
|
+
param
|
167
|
+
end
|
168
|
+
|
169
|
+
def check_response_error(response)
|
170
|
+
id = response.first['id'] || 0
|
171
|
+
message = response.first['msg'] || 0
|
172
|
+
|
173
|
+
raise ServerError.new(id, message) unless id == 0
|
174
|
+
end
|
175
|
+
|
176
|
+
private(:parse_response, :decode_param, :encode_param, :check_response_error)
|
177
|
+
end
|
178
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
module Teamspeak
|
2
|
-
# Raised when the connected server does not respond as a normal TeamSpeak 3 would.
|
3
|
-
#
|
4
|
-
# raise InvalidServer, 'Server is not responding as a normal TeamSpeak 3 server.'
|
5
|
-
class InvalidServer < StandardError; end
|
6
|
-
|
7
|
-
# Raised when the server returns an error code other than 0.
|
8
|
-
#
|
9
|
-
# raise ServerError.new(1, 'Some generic error message')
|
10
|
-
class ServerError < StandardError
|
11
|
-
attr_reader(:code, :message)
|
12
|
-
|
13
|
-
def initialize(code, message)
|
14
|
-
@code = code
|
15
|
-
@message = message
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
1
|
+
module Teamspeak
|
2
|
+
# Raised when the connected server does not respond as a normal TeamSpeak 3 would.
|
3
|
+
#
|
4
|
+
# raise InvalidServer, 'Server is not responding as a normal TeamSpeak 3 server.'
|
5
|
+
class InvalidServer < StandardError; end
|
6
|
+
|
7
|
+
# Raised when the server returns an error code other than 0.
|
8
|
+
#
|
9
|
+
# raise ServerError.new(1, 'Some generic error message')
|
10
|
+
class ServerError < StandardError
|
11
|
+
attr_reader(:code, :message)
|
12
|
+
|
13
|
+
def initialize(code, message)
|
14
|
+
@code = code
|
15
|
+
@message = message
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module Teamspeak
|
2
|
-
VERSION = '1.0.
|
3
|
-
end
|
1
|
+
module Teamspeak
|
2
|
+
VERSION = '1.0.3'
|
3
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teamspeak-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Harrison
|
@@ -16,10 +16,10 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- lib/teamspeak-ruby.rb
|
19
20
|
- lib/teamspeak-ruby/client.rb
|
20
21
|
- lib/teamspeak-ruby/exceptions.rb
|
21
22
|
- lib/teamspeak-ruby/version.rb
|
22
|
-
- lib/teamspeak-ruby.rb
|
23
23
|
homepage: http://pyrohail.com
|
24
24
|
licenses:
|
25
25
|
- MIT
|
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
version: '0'
|
41
41
|
requirements: []
|
42
42
|
rubyforge_project:
|
43
|
-
rubygems_version: 2.
|
43
|
+
rubygems_version: 2.2.2
|
44
44
|
signing_key:
|
45
45
|
specification_version: 4
|
46
46
|
summary: Ruby interface for TeamSpeak 3's server query api.
|