teamspeak-ruby 0.0.1
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 +7 -0
- data/lib/teamspeak-ruby.rb +108 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a55847ab2637859db32f600104f717aeef20ed5e
|
4
|
+
data.tar.gz: 7e9e26543808affce26636263d7a6a1a97ba9423
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e140e389af04191ac52db1f89e4cd3670fc770b0da12d0b407aee0c9f60b79cffe6e6906892e671c48d27569a1dce68d7f83ec3bc22f76d50d281465badbac0
|
7
|
+
data.tar.gz: f987dbbc9a5802440e3188a2858b8469baacc84dcc395892de0dcd1e345ef7401169ee0f55b2ea79ed91593281ce35d520d9255b3203683ea697e44e065fa813
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
class Teamspeak
|
4
|
+
def initialize(host = 'localhost', port = 10011)
|
5
|
+
connect(host, port)
|
6
|
+
end
|
7
|
+
|
8
|
+
def connect(host = 'localhost', port = 10011)
|
9
|
+
@sock = TCPSocket.new(host, port)
|
10
|
+
|
11
|
+
# Check if the response is the same as a normal teamspeak 3 server.
|
12
|
+
if @sock.gets.strip != 'TS3'
|
13
|
+
puts 'This is not responding as a TeamSpeak 3 server.'
|
14
|
+
|
15
|
+
return false
|
16
|
+
end
|
17
|
+
|
18
|
+
# Remove useless text from the buffer.
|
19
|
+
@sock.gets
|
20
|
+
end
|
21
|
+
|
22
|
+
def disconnect
|
23
|
+
@sock.puts 'quit'
|
24
|
+
@sock.close
|
25
|
+
end
|
26
|
+
|
27
|
+
def login(user, pass)
|
28
|
+
self.command('login', {'client_login_name' => user, 'client_login_password' => pass})
|
29
|
+
end
|
30
|
+
|
31
|
+
def command(cmd, params = {}, options = '')
|
32
|
+
out = ''
|
33
|
+
response = ''
|
34
|
+
|
35
|
+
out += cmd
|
36
|
+
|
37
|
+
params.each_pair do |key, value|
|
38
|
+
out += " #{key}=#{encode_param(value.to_s)}"
|
39
|
+
end
|
40
|
+
|
41
|
+
out += ' ' + options
|
42
|
+
|
43
|
+
@sock.puts out
|
44
|
+
|
45
|
+
while true
|
46
|
+
response += @sock.gets
|
47
|
+
|
48
|
+
if response.index('msg=')
|
49
|
+
break
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
return parse_response(response)
|
54
|
+
end
|
55
|
+
|
56
|
+
def parse_response(response)
|
57
|
+
out = []
|
58
|
+
|
59
|
+
response = response.split('error id=').first
|
60
|
+
|
61
|
+
response.split('|').each do |key|
|
62
|
+
data = {}
|
63
|
+
|
64
|
+
key.split(' ').each do |key|
|
65
|
+
value = key.split('=')
|
66
|
+
|
67
|
+
data[value[0]] = decode_param(value[1].to_s)
|
68
|
+
end
|
69
|
+
|
70
|
+
out.push(data)
|
71
|
+
end
|
72
|
+
|
73
|
+
return out
|
74
|
+
end
|
75
|
+
|
76
|
+
def decode_param(param)
|
77
|
+
param = param.gsub('\\\\', '\\')
|
78
|
+
param = param.gsub('\\/', '/')
|
79
|
+
param = param.gsub('\\s', ' ')
|
80
|
+
param = param.gsub('\\p', '|')
|
81
|
+
param = param.gsub('\\a', '\a')
|
82
|
+
param = param.gsub('\\b', '\b')
|
83
|
+
param = param.gsub('\\f', '\f')
|
84
|
+
param = param.gsub('\\n', '\n')
|
85
|
+
param = param.gsub('\\r', '\r')
|
86
|
+
param = param.gsub('\\t', '\t')
|
87
|
+
param = param.gsub('\\v', '\v')
|
88
|
+
|
89
|
+
return param
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
def encode_param(param)
|
94
|
+
param = param.gsub('\\', '\\\\')
|
95
|
+
param = param.gsub('/', '\\/')
|
96
|
+
param = param.gsub(' ', '\\s')
|
97
|
+
param = param.gsub('|', '\\p')
|
98
|
+
param = param.gsub('\a', '\\a')
|
99
|
+
param = param.gsub('\b', '\\b')
|
100
|
+
param = param.gsub('\f', '\\f')
|
101
|
+
param = param.gsub('\n', '\\n')
|
102
|
+
param = param.gsub('\r', '\\r')
|
103
|
+
param = param.gsub('\t', '\\t')
|
104
|
+
param = param.gsub('\v', '\\v')
|
105
|
+
|
106
|
+
return param
|
107
|
+
end
|
108
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: teamspeak-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Harrison
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: justin@pyrohail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/teamspeak-ruby.rb
|
20
|
+
homepage: http://pyrohail.com
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.0.14
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Ruby interface for TeamSpeak 3's server query api.
|
44
|
+
test_files: []
|