Class: Flamethrower::EventServer

Inherits:
Object
  • Object
show all
Defined in:
lib/flamethrower/server/event_server.rb

Constant Summary collapse

ASCII_DEFAULTS =
{
  'enabled' => true
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ EventServer

Returns a new instance of EventServer.



30
31
32
33
34
35
36
37
38
39
# File 'lib/flamethrower/server/event_server.rb', line 30

def initialize(options = {})
  @host = options['host'] || "0.0.0.0"
  @port = options['port'] || 6667
  @domain = options['domain']
  @token = options['token']
  @ascii_conversion = options['ascii_conversion'] ?
    ASCII_DEFAULTS.merge(options['ascii_conversion']) :
    ASCII_DEFAULTS
  @connections = []
end

Instance Attribute Details

#ascii_conversionObject (readonly)

Returns the value of attribute ascii_conversion.



25
26
27
# File 'lib/flamethrower/server/event_server.rb', line 25

def ascii_conversion
  @ascii_conversion
end

#campfire_connectionObject (readonly)

Returns the value of attribute campfire_connection.



25
26
27
# File 'lib/flamethrower/server/event_server.rb', line 25

def campfire_connection
  @campfire_connection
end

#connectionsObject (readonly)

Returns the value of attribute connections.



25
26
27
# File 'lib/flamethrower/server/event_server.rb', line 25

def connections
  @connections
end

#hostObject (readonly)

Returns the value of attribute host.



25
26
27
# File 'lib/flamethrower/server/event_server.rb', line 25

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



25
26
27
# File 'lib/flamethrower/server/event_server.rb', line 25

def port
  @port
end

Instance Method Details

#startObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/flamethrower/server/event_server.rb', line 41

def start
  EventMachine::run do
    FLAMETHROWER_LOGGER.info "Flamethrower started at #{@host}:#{@port} on domain #{@domain}"
    @signature = EventMachine::start_server(@host, @port, EventConnection) do |connection|
      @connections << connection
      connection.server = self
      connection.campfire_connection = Flamethrower::Campfire::Connection.new(@domain, @token, connection)
    end
  end
end

#stopObject



52
53
54
55
56
57
58
59
60
# File 'lib/flamethrower/server/event_server.rb', line 52

def stop
  FLAMETHROWER_LOGGER.info("Killing room threads")
  @connections.each do |connection|
    connection.stop
    connection.close_connection
  end
  EventMachine.stop_server(@signature)
  EventMachine.add_periodic_timer(0.2) { die_safely }
end