Project

General

Profile

« Previous | Next » 

Revision 050eca43

Added by Marc Dequènes over 14 years ago

  • ID 050eca4311568af6c8919040c5ea547f99bf6f41

[evol] first raw cyborg API exposure implementation for MapMaker (refs #31)

View differences:

lib/cyborghood/cyborg/server.rb
class BotServer
private_class_method :new
def self.build
def self.build(interface)
case Config.instance.botnet.connection_type
when 'unix_socket'
return BotServerUNIXSocket.new
return BotServerUNIXSocket.new(interface)
else
raise CyberError.new(:unrecoverable, "config", "Unknown botnet connection type")
end
end
def initialize
def initialize(interface)
@interface = interface
@config = Config.instance
end
......
class BotServerUNIXSocket < BotServer
public_class_method :new
def initialize
super
def initialize(interface)
super(interface)
@socket = File.join(Config::RUN_DIR, @config.bot_name.downcase + ".sock")
at_exit { remove_socket_file }
......
def run
super do
EventMachine.start_unix_domain_server(@socket, ConversationUNIXSocket)
EventMachine.start_unix_domain_server(@socket, ConversationUNIXSocket, @interface)
end
end
......
class Conversation < EventMachine::Protocols::LineAndTextProtocol
private_class_method :new
def initialize(*args)
def initialize(interface)
@interface = interface
super
@config = Config.instance
......
def receive_line(data)
logger.debug "Received [#{identifier}]: #{data}"
send_line @interface.instance.call(data)
end
def receive_error(msg)

Also available in: Unified diff