Project

General

Profile

« Previous | Next » 

Revision 3d653143

Added by Marc Dequènes over 13 years ago

  • ID 3d6531438e6a06725813d9635002e83d9b0e6444

[evol] conversation/bot protocol rework §5 (refs #30)

View differences:

lib/cyborghood/cyborg/conversation.rb
class ConversationThread
attr_reader :conversation, :name, :id, :session
def initialized(conversation, id, name)
def initialize(conversation, id, name)
@conversation = conversation
@name = name
@id = id
......
attr_reader :conv_thread, :action_code, :action_parameters, :action_id
def initialized(conv_thread, action_code, action_parameters = nil, action_id = nil)
def initialize(conv_thread, action_code, action_parameters = nil, action_id = nil)
@conv_thread = conv_thread
@action_code = action_code
@action_parameters = action_parameters
......
MAXIMUM_ERROR_COUNT = 3
MAXIMUM_LINES = 1024
attr_reader :interface
attr_reader :bot
def initialize(interface)
@interface = interface
def initialize(bot)
@bot = bot
super
......
def unbind
logger.debug "Conversation finished with #{identifier}"
@bot.register_communication @peer_id unless @peer_id.nil?
@conv_threads.each_values {|s| s.close }
end
def bye
send_quit_leaving
end
def set_peer_info(id, capabilities)
@peer_id = id
@peer_capabilities = capabilities || []
@bot.register_communication @peer_id, self
end
def set_error_status(fatal = false)
lib/cyborghood/cyborg/server.rb
class BotServer
private_class_method :new
attr_reader :interface
def self.build(interface)
case Config.instance.botnet.connection_type
when 'unix_socket'
......
@interface = interface
@config = Config.instance
@comm_list = {}
end
def run
......
end
def stop
@comm_list.values.each {|conv| conv.bye }
EventMachine.stop
end
# used to quit properly and later to reuse communication channels
def register_communication(peer, conversation)
@comm_list[peer] = conversation
end
def unregister_communication(peer)
@comm_list.delete(peer)
end
end
class BotServerUNIXSocket < BotServer
......
def run
super do
EventMachine.start_unix_domain_server(@socket, ConversationUNIXSocket, @interface)
EventMachine.start_unix_domain_server(@socket, ConversationUNIXSocket, self)
end
end

Also available in: Unified diff