ts3query 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +4 -2
- data/README.rdoc +0 -6
- data/Rakefile +3 -16
- data/features/step_definitions/run_command_steps.rb +12 -12
- data/features/support/env.rb +1 -1
- data/lib/ts3query.rb +9 -16
- data/lib/ts3query/client_connection.rb +4 -4
- data/lib/ts3query/escaping.rb +29 -0
- data/lib/ts3query/server_connection.rb +8 -8
- data/lib/ts3query/ts3_connection.rb +31 -20
- data/lib/ts3query/version.rb +3 -0
- metadata +8 -6
- data/init.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ffb041073ad0ffbb8603c59f7032564e9988575
|
4
|
+
data.tar.gz: 0bc3615838b731249dda3c7a81acb6367b46d1cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9615ce48e25e229fd6a88cb86229083f8cc4ace175ad781acacae8f39d507ae217611d48b93233eabb669c5c09a6484bfa7705fa4c9ccca988a06d7d65cc67e
|
7
|
+
data.tar.gz: f3d53ab0f3d84fff85cdae06c3f916087ba52a30ec0be99d675441410e499688802d64c5e0706a887f81a72135484dc7686ddb200321f4ad4a7b4443344fe81b
|
data/LICENSE.txt
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2015 TnT Web Solutions GbR
|
2
|
+
|
3
|
+
MIT License
|
2
4
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
6
|
a copy of this software and associated documentation files (the
|
@@ -17,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -6,25 +6,11 @@ begin
|
|
6
6
|
Bundler.setup(:default, :development)
|
7
7
|
rescue Bundler::BundlerError => e
|
8
8
|
$stderr.puts e.message
|
9
|
-
$stderr.puts
|
9
|
+
$stderr.puts 'Run `bundle install` to install missing gems'
|
10
10
|
exit e.status_code
|
11
11
|
end
|
12
12
|
require 'rake'
|
13
13
|
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "TS3Query"
|
18
|
-
gem.homepage = "support@tnt-web-solutions.de"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{Simple TS3 Query Library.}
|
21
|
-
gem.description = %Q{Simple TS3 Query Library to connect to the query port of a teamspeak 3 server.}
|
22
|
-
gem.email = "tbraun@tnt-web-solutions.de"
|
23
|
-
gem.authors = ["Torsten Braun"]
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
27
|
-
|
28
14
|
require 'rspec/core'
|
29
15
|
require 'rspec/core/rake_task'
|
30
16
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
@@ -41,12 +27,13 @@ Cucumber::Rake::Task.new(:features)
|
|
41
27
|
|
42
28
|
task :default => :spec
|
43
29
|
|
30
|
+
require 'ts3query/version'
|
44
31
|
require 'rdoc/task'
|
45
32
|
Rake::RDocTask.new do |rdoc|
|
46
33
|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
34
|
|
48
35
|
rdoc.rdoc_dir = 'rdoc'
|
49
|
-
rdoc.title = "TS3Query #{
|
36
|
+
rdoc.title = "TS3Query #{TS3Query::VERSION}"
|
50
37
|
rdoc.rdoc_files.include('README*')
|
51
38
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
39
|
end
|
@@ -8,10 +8,10 @@ When /^I run the command version$/ do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
When /^I run the command serverlist with the options (.+)$/ do |options|
|
11
|
-
options = options.split(
|
11
|
+
options = options.split(' ')
|
12
12
|
@result = @query.serverlist do |opt|
|
13
13
|
options.each do |current|
|
14
|
-
current[0] =
|
14
|
+
current[0] = ''
|
15
15
|
opt.send(current)
|
16
16
|
end
|
17
17
|
end
|
@@ -19,26 +19,26 @@ When /^I run the command serverlist with the options (.+)$/ do |options|
|
|
19
19
|
end
|
20
20
|
|
21
21
|
When /^I run the command use with the parameters (.+)$/ do |parameters|
|
22
|
-
parameters = parameters.split(
|
22
|
+
parameters = parameters.split(' ')
|
23
23
|
params = {}
|
24
24
|
parameters.each do |current|
|
25
|
-
params[current.split(
|
25
|
+
params[current.split('=')[0]] = current.split('=')[1]
|
26
26
|
end
|
27
27
|
@result = @query.use params
|
28
28
|
@query.disconnect
|
29
29
|
end
|
30
30
|
|
31
31
|
When /^I run the command use with the options (.+) and the parameters (.+)$/ do |options, parameters|
|
32
|
-
parameters = parameters.split(
|
32
|
+
parameters = parameters.split(' ')
|
33
33
|
params = {}
|
34
34
|
parameters.each do |current|
|
35
|
-
params[current.split(
|
35
|
+
params[current.split('=')[0]] = current.split('=')[1]
|
36
36
|
end
|
37
37
|
|
38
|
-
options = options.split(
|
38
|
+
options = options.split(' ')
|
39
39
|
@result = @query.use params do |opt|
|
40
40
|
options.each do |current|
|
41
|
-
current[0] =
|
41
|
+
current[0] = ''
|
42
42
|
opt.send(current)
|
43
43
|
end
|
44
44
|
end
|
@@ -49,16 +49,16 @@ Then /^I should get a hash with (.+)$/ do |data|
|
|
49
49
|
list = []
|
50
50
|
hash = {}
|
51
51
|
|
52
|
-
data.split(
|
53
|
-
hash[entity.split(
|
52
|
+
data.split(' ').each do |entity|
|
53
|
+
hash[entity.split('=')[0]] = entity.split('=')[1]
|
54
54
|
end
|
55
55
|
list << hash
|
56
|
-
list << {
|
56
|
+
list << {'id' => '0', 'msg' => 'ok'}
|
57
57
|
|
58
58
|
@result.should eq(list)
|
59
59
|
end
|
60
60
|
|
61
61
|
Then /^I should get a hash$/ do
|
62
|
-
list = [{
|
62
|
+
list = [{'id' => '0', 'msg' => 'ok'}]
|
63
63
|
@result.should eq(list)
|
64
64
|
end
|
data/features/support/env.rb
CHANGED
data/lib/ts3query.rb
CHANGED
@@ -2,29 +2,22 @@ require 'ts3query/server_connection'
|
|
2
2
|
require 'ts3query/client_connection'
|
3
3
|
|
4
4
|
module TS3Query
|
5
|
-
|
6
|
-
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:username => "serveradmin"
|
5
|
+
DEFAULT_SERVER_PARAMS = {
|
6
|
+
address: '127.0.0.1',
|
7
|
+
port: '10011',
|
8
|
+
username: 'serveradmin'
|
10
9
|
}
|
11
10
|
|
12
|
-
|
13
|
-
:
|
14
|
-
:
|
11
|
+
DEFAULT_CLIENT_PARAMS = {
|
12
|
+
address: '127.0.0.1',
|
13
|
+
port: '25639'
|
15
14
|
}
|
16
15
|
|
17
|
-
def self.connect(params = {})
|
18
|
-
warn "DEPRECATED(#{Kernel.caller.first}) use TS3Query.server_connect instead of TS3Query.connect"
|
19
|
-
server_connect params
|
20
|
-
end
|
21
|
-
|
22
16
|
def self.server_connect(params = {})
|
23
|
-
ServerConnection.new
|
17
|
+
ServerConnection.new(DEFAULT_SERVER_PARAMS.merge(params))
|
24
18
|
end
|
25
19
|
|
26
20
|
def self.client_connect(params = {})
|
27
|
-
ClientConnection.new
|
21
|
+
ClientConnection.new(DEFAULT_CLIENT_PARAMS.merge(params))
|
28
22
|
end
|
29
|
-
|
30
23
|
end
|
@@ -6,11 +6,11 @@ module TS3Query
|
|
6
6
|
|
7
7
|
def connect(params)
|
8
8
|
begin
|
9
|
-
@connection = Net::Telnet::new(
|
10
|
-
@connection.waitfor(
|
11
|
-
|
9
|
+
@connection = Net::Telnet::new('Host' => params[:address], 'Port' => params[:port])
|
10
|
+
@connection.waitfor('Match' => /TS3 Client\n(.*)\n/,
|
11
|
+
'Timeout' => 3)
|
12
12
|
rescue
|
13
|
-
raise
|
13
|
+
raise(ConnectionRefused, 'client not available')
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module TS3Query
|
2
|
+
module Escaping
|
3
|
+
DECODER_PATTERNS = {
|
4
|
+
'\\\\' => '\\',
|
5
|
+
'\/' => '/',
|
6
|
+
'\s' => ' ',
|
7
|
+
'\p' => '|',
|
8
|
+
'\a' => '\a',
|
9
|
+
'\b' => '\b',
|
10
|
+
'\f' => '\f',
|
11
|
+
'\n' => '\n',
|
12
|
+
'\r' => '\r',
|
13
|
+
'\t' => '\t',
|
14
|
+
'\v' => '\v',
|
15
|
+
}
|
16
|
+
|
17
|
+
ENCODER_PATTERNS = DECODER_PATTERNS.invert
|
18
|
+
DECODER_REGEXP = /\\[#{Regexp.escape(DECODER_PATTERNS.keys.map{|k| k[1]}.join)}]/
|
19
|
+
ENCODER_REGEXP = /[#{Regexp.escape(DECODER_PATTERNS.values.join)}]/
|
20
|
+
|
21
|
+
def self.encode(str)
|
22
|
+
str.gsub(ENCODER_REGEXP, ENCODER_PATTERNS)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.decode(str)
|
26
|
+
str.gsub(DECODER_REGEXP, DECODER_PATTERNS)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -6,19 +6,19 @@ module TS3Query
|
|
6
6
|
|
7
7
|
def connect(params)
|
8
8
|
begin
|
9
|
-
@connection = Net::Telnet::new(
|
10
|
-
@connection.waitfor(
|
11
|
-
|
9
|
+
@connection = Net::Telnet::new('Host' => params[:address], 'Port' => params[:port])
|
10
|
+
@connection.waitfor('Match' => /TS3\n(.*)\n/,
|
11
|
+
'Timeout' => 3)
|
12
12
|
rescue
|
13
|
-
raise
|
13
|
+
raise(ConnectionRefused, 'server not available')
|
14
14
|
end
|
15
15
|
|
16
16
|
begin
|
17
|
-
@connection.cmd(
|
18
|
-
|
19
|
-
|
17
|
+
@connection.cmd('String' => "login client_login_name=#{params[:username]} client_login_password=#{params[:password]}\r",
|
18
|
+
'Match' => /error id=0 msg=ok\n/,
|
19
|
+
'Timeout' => 3)
|
20
20
|
rescue
|
21
|
-
raise
|
21
|
+
raise(ConnectionRefused, 'wrong user data')
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'net/telnet'
|
2
|
+
require 'stringio'
|
2
3
|
require 'ts3query/errors'
|
3
4
|
require 'ts3query/query_options'
|
5
|
+
require 'ts3query/escaping'
|
4
6
|
|
5
7
|
module TS3Query
|
6
8
|
class TS3Connection
|
@@ -13,9 +15,10 @@ module TS3Query
|
|
13
15
|
end
|
14
16
|
|
15
17
|
def method_missing(meth, *args, &block)
|
18
|
+
buffer = StringIO.new
|
16
19
|
result = []
|
17
|
-
options =
|
18
|
-
params =
|
20
|
+
options = ''
|
21
|
+
params = ''
|
19
22
|
|
20
23
|
if block
|
21
24
|
query_options = QueryOptions.new
|
@@ -28,28 +31,36 @@ module TS3Query
|
|
28
31
|
|
29
32
|
if args.first
|
30
33
|
args.first.each do |key, value|
|
31
|
-
params += " #{key}=#{value}"
|
34
|
+
params += " #{key}=#{value.is_a?(String) ? Escaping.encode(value) : value}"
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
35
|
-
@connection.cmd(
|
36
|
-
|
37
|
-
|
38
|
-
data
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
38
|
+
@connection.cmd('String' => "#{meth}#{params}#{options}\r",
|
39
|
+
'Match' => /error id=0 msg=ok\n/,
|
40
|
+
'Timeout' => 3) do |data|
|
41
|
+
buffer << data
|
42
|
+
end
|
43
|
+
|
44
|
+
data = buffer.string
|
45
|
+
data.force_encoding 'UTF-8'
|
46
|
+
|
47
|
+
data.split('|').each do |current|
|
48
|
+
current_data = {}
|
49
|
+
|
50
|
+
current.split(' ').each do |entity|
|
51
|
+
key, value = entity.split '='
|
52
|
+
current_data[key] = value.is_a?(String) ? Escaping.decode(value) : nil
|
50
53
|
end
|
51
|
-
|
52
|
-
|
54
|
+
|
55
|
+
current_data.delete('error')
|
56
|
+
current_data.delete('id')
|
57
|
+
current_data.delete('msg')
|
58
|
+
|
59
|
+
result << current_data
|
60
|
+
end
|
61
|
+
|
62
|
+
result << {'id' => '0', 'msg' => 'ok'}
|
63
|
+
|
53
64
|
result.delete({})
|
54
65
|
result
|
55
66
|
end
|
metadata
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ts3query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TnT Web Solutions
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Simple TS3 Query Library to connect to the query port of a
|
13
|
+
description: Simple TS3 Query Library to connect to the query port of a Teamspeak
|
14
14
|
3 server.
|
15
|
-
email:
|
15
|
+
email: tbraun@tnt-web-solutions.de
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
@@ -26,15 +26,17 @@ files:
|
|
26
26
|
- features/step_definitions/connection_steps.rb
|
27
27
|
- features/step_definitions/run_command_steps.rb
|
28
28
|
- features/support/env.rb
|
29
|
-
- init.rb
|
30
29
|
- lib/ts3query.rb
|
31
30
|
- lib/ts3query/client_connection.rb
|
32
31
|
- lib/ts3query/errors.rb
|
32
|
+
- lib/ts3query/escaping.rb
|
33
33
|
- lib/ts3query/query_options.rb
|
34
34
|
- lib/ts3query/server_connection.rb
|
35
35
|
- lib/ts3query/ts3_connection.rb
|
36
|
+
- lib/ts3query/version.rb
|
36
37
|
homepage: https://github.com/tntwebsolutions/ts3query
|
37
|
-
licenses:
|
38
|
+
licenses:
|
39
|
+
- MIT
|
38
40
|
metadata: {}
|
39
41
|
post_install_message:
|
40
42
|
rdoc_options: []
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'ts3query'
|