Module: Tkellem::IrcServerConnection

Includes:
EM::Protocols::LineText2
Defined in:
lib/tkellem/irc_server.rb

Defined Under Namespace

Classes: ConnectionState

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.connector(bouncer, network) ⇒ Object



120
121
122
# File 'lib/tkellem/irc_server.rb', line 120

def self.connector(bouncer, network)
  ConnectionState.new(bouncer, network)
end

Instance Method Details

#connection_completedObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tkellem/irc_server.rb', line 22

def connection_completed
  if @ssl
    @bouncer.failsafe(:connection_completed) do
      @bouncer.debug "starting TLS"
      # TODO: support strict cert checks
      start_tls :verify_peer => false
    end
  else
    ssl_handshake_completed
  end
end

#initialize(connection_state, bouncer, do_ssl) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/tkellem/irc_server.rb', line 14

def initialize(connection_state, bouncer, do_ssl)
  set_delimiter "\r\n"
  @bouncer = bouncer
  @ssl = do_ssl
  @connection_state = connection_state
  @connected = false
end

#receive_line(line) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/tkellem/irc_server.rb', line 41

def receive_line(line)
  @bouncer.failsafe(:receive_line) do
    line.force_encoding Encoding::UTF_8
    @bouncer.trace "from server: #{line}"
    return if line.blank?
    msg = IrcMessage.parse(line)
    @bouncer.server_msg(msg)
  end
end

#ssl_handshake_completedObject



34
35
36
37
38
39
# File 'lib/tkellem/irc_server.rb', line 34

def ssl_handshake_completed
  @bouncer.failsafe(:ssl_handshake_completed) do
    @connected = true
    @bouncer.connection_established(self)
  end
end

#unbindObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/tkellem/irc_server.rb', line 51

def unbind
  @bouncer.failsafe(:unbind) do
    if @connected
      @bouncer.disconnected!
    else
      @bouncer.debug "Connection failed, trying next"
      @connection_state.connect!
    end
  end
end