Skip to content

Commit

Permalink
Added support for SSL connections.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern authored and vangberg committed Dec 21, 2009
1 parent 7b9369f commit 4a76cc9
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions lib/isaac/bot.rb
Expand Up @@ -3,15 +3,15 @@
module Isaac
VERSION = '0.2.1'

Config = Struct.new(:server, :port, :password, :nick, :realname, :version, :environment, :verbose)
Config = Struct.new(:server, :port, :ssl, :password, :nick, :realname, :version, :environment, :verbose)

class Bot
attr_accessor :config, :irc, :nick, :channel, :message, :user, :host, :match,
:error

def initialize(&b)
@events = {}
@config = Config.new("localhost", 6667, nil, "isaac", "Isaac", 'isaac', :production, false)
@config = Config.new("localhost", 6667, false, nil, "isaac", "Isaac", 'isaac', :production, false)

instance_eval(&b) if block_given?
end
Expand Down Expand Up @@ -125,7 +125,29 @@ def initialize(bot, config)
end

def connect
@socket = TCPSocket.open(@config.server, @config.port)
tcp_socket = TCPSocket.open(@config.server, @config.port)

if @config.ssl
begin
require 'openssl'
rescue ::LoadError
raise(RuntimeError,"unable to require 'openssl'",caller)
end

ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE

unless @config.environment == :test
puts "Using SSL with #{config.server}:#{config.port}"
end

@socket = OpenSSL::SSL::SSLSocket.new(tcp_socket, ssl_context)
@socket.sync = true
@socket.connect
else
@socket = tcp_socket
end

@queue = Queue.new(@socket, @bot.config.server)
message "PASS #{@config.password}" if @config.password
message "NICK #{@config.nick}"
Expand Down

0 comments on commit 4a76cc9

Please sign in to comment.