Class: TeamSpeak3::VirtualServer
- Inherits:
-
Object
- Object
- TeamSpeak3::VirtualServer
- Defined in:
- lib/virtual_server.rb
Instance Attribute Summary collapse
-
#autostart ⇒ Object
readonly
Returns the value of attribute autostart.
-
#clients_online ⇒ Object
readonly
Returns the value of attribute clients_online.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#query_clients_online ⇒ Object
readonly
Returns the value of attribute query_clients_online.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#slots ⇒ Object
readonly
Returns the value of attribute slots.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
-
#uptime ⇒ Object
readonly
Returns the value of attribute uptime.
Instance Method Summary collapse
- #==(target) ⇒ Object
- #channels ⇒ Object
- #clients ⇒ Object
- #destroy! ⇒ Object
- #execute(command, params = {}) ⇒ Object
-
#initialize(server, params) ⇒ VirtualServer
constructor
A new instance of VirtualServer.
- #send_message(message) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(server, params) ⇒ VirtualServer
Returns a new instance of VirtualServer.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/virtual_server.rb', line 16 def initialize(server, params) @server = server @id = params[:virtualserver_id].to_i @name = params[:virtualserver_name] @port = params[:virtualserver_port].to_i @status = params[:virtualserver_status].to_sym @clients_online = params[:virtualserver_clientsonline].to_i @query_clients_online = params[:virtualserver_queryclientsonline].to_i @slots = params[:virtualserver_maxclients].to_i @uptime = Time.now - params[:virtualserver_uptime].to_i @autostart = params[:virtualserver_uptime].to_i == 1 @uid = params[:virtualserver_unique_identifier] end |
Instance Attribute Details
#autostart ⇒ Object (readonly)
Returns the value of attribute autostart.
13 14 15 |
# File 'lib/virtual_server.rb', line 13 def autostart @autostart end |
#clients_online ⇒ Object (readonly)
Returns the value of attribute clients_online.
9 10 11 |
# File 'lib/virtual_server.rb', line 9 def clients_online @clients_online end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/virtual_server.rb', line 5 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/virtual_server.rb', line 6 def name @name end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
7 8 9 |
# File 'lib/virtual_server.rb', line 7 def port @port end |
#query_clients_online ⇒ Object (readonly)
Returns the value of attribute query_clients_online.
10 11 12 |
# File 'lib/virtual_server.rb', line 10 def query_clients_online @query_clients_online end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
3 4 5 |
# File 'lib/virtual_server.rb', line 3 def server @server end |
#slots ⇒ Object (readonly)
Returns the value of attribute slots.
11 12 13 |
# File 'lib/virtual_server.rb', line 11 def slots @slots end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/virtual_server.rb', line 8 def status @status end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
14 15 16 |
# File 'lib/virtual_server.rb', line 14 def uid @uid end |
#uptime ⇒ Object (readonly)
Returns the value of attribute uptime.
12 13 14 |
# File 'lib/virtual_server.rb', line 12 def uptime @uptime end |
Instance Method Details
#==(target) ⇒ Object
93 94 95 |
# File 'lib/virtual_server.rb', line 93 def ==(target) @id == target end |
#channels ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/virtual_server.rb', line 60 def channels channels_list = ChannelCollection.new(self) channels = execute :channellist, options: [:topic, :flags, :voice, :limits, :icon] channels[:data].each do |channel| channels_list << Channel.new(self, channel) end channels_list end |
#clients ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/virtual_server.rb', line 71 def clients clients_list = [] clients = execute :clientlist, options: [:uid, :away, :voice, :times, :groups, :info, :icon, :country] clients[:data].each do |client| clients_list << TeamSpeak3::Client.new(self, client) end clients_list end |
#destroy! ⇒ Object
31 32 33 34 35 36 |
# File 'lib/virtual_server.rb', line 31 def destroy! execute :serverstop, sid: @id, allow_to_fail: true, ignore_active_server: true execute :serverdelete, sid: @id, ignore_active_server: true true end |
#execute(command, params = {}) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/virtual_server.rb', line 86 def execute(command, params = {}) check_active_server unless params[:ignore_active_server] params.delete(:ignore_active_server) @server.execute(command, params) end |
#send_message(message) ⇒ Object
82 83 84 |
# File 'lib/virtual_server.rb', line 82 def () server.(self, ) end |
#start ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/virtual_server.rb', line 38 def start begin execute :serverstart, sid: @id, ignore_active_server: true rescue Exceptions::CommandExecutionFailed => err raise Exceptions::VirtualServerAlreadyRunning.new(@id) if err. =~ /server got an invalid status/ && status == :online raise end true end |
#stop ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/virtual_server.rb', line 49 def stop begin execute :serverstop, sid: @id, ignore_active_server: true rescue Exceptions::CommandExecutionFailed => err raise Exceptions::VirtualServerNotRunning.new(@id) if err. =~ /server is not running/ raise end true end |