class BotnetV2::Worker
Public Class Methods
new(password, host, port = 8008, ssl = true)
click to toggle source
# File lib/BotnetV2/Worker.rb, line 11 def initialize(password, host, port = 8008, ssl = true) @exit = false @onReady = Hash.new @onReady['worker_onReady'] = SecureRandom.hex @onReady['verify'] = password begin network = BotNetwork.new network.connect host, port if ssl network.connect_no_ssl host, port unless ssl @connection = BotConnection.new network.socket, network @t = Thread.start do @connection.on_message_handler_loop(Proc.new do |msg| on_message(msg, @connection) end) end rescue => e puts e end @connection.send @onReady end
Public Instance Methods
exit!()
click to toggle source
# File lib/BotnetV2/Worker.rb, line 50 def exit! @exit = true begin @connection.close rescue => e # nothing ensure @t.kill end end
on_message(message, connection)
click to toggle source
# File lib/BotnetV2/Worker.rb, line 33 def on_message (message, connection) result = Hash.new if message['onWork'] != nil result['onResult'] = Hash.new result['onResult']['task_id'] = message['onWork']['task_id'] result['onResult']['clientId'] = message['onWork']['clientId'] begin result['onResult']['result'] = eval message['onWork']['src'] rescue => error result['onResult']['error'] = error end end result['worker_onReady'] = @onReady['worker_onReady'] unless @exit connection.send result end