class BotnetV2::Client
Public Class Methods
new(password, client_id, host, port = 8008, ssl = true)
click to toggle source
# File lib/BotnetV2/Client.rb, line 11 def initialize(password, client_id, host, port = 8008, ssl = true) @exit = false @callbacks = Hash.new @onReady = Hash.new @onReady['client_onReady'] = client_id @onReady['verify'] = password 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) end) end @connection.send @onReady end
Public Instance Methods
execute(task_src, callback)
click to toggle source
# File lib/BotnetV2/Client.rb, line 37 def execute (task_src, callback) message = Hash.new message['onWork'] = Hash.new message['onWork']['task_id'] = SecureRandom.hex message['onWork']['clientId'] = @onReady['client_onReady'] message['onWork']['src'] = task_src @callbacks[message['onWork']['task_id']] = callback @connection.send message end
exit!()
click to toggle source
# File lib/BotnetV2/Client.rb, line 62 def exit! begin @connection.close rescue => e # nothing ensure @t.kill end message = Hash.new message['client_onDisconnect'] = @onReady['client_onReady'] @connection.send message end
net_status(callback)
click to toggle source
# File lib/BotnetV2/Client.rb, line 30 def net_status(callback) message = Hash.new message['status'] = SecureRandom.hex @callbacks[message['status']] = callback @connection.send message end
on_message(message)
click to toggle source
# File lib/BotnetV2/Client.rb, line 47 def on_message (message) if message['onResult'] != nil error = false res = message['onResult']['result'] if message['onResult']['error'] != nil res = message['onResult']['error'] error = true if message['onResult']['error'] end @callbacks[message['onResult']['task_id']].call(res, error) end if message['status'] != nil @callbacks[message['status']['task_id']].call(message['status']) end end