diff options
author | Dmitry Kim <dmitry point kim at gmail point com> | 2007-03-17 19:42:48 +0000 |
---|---|---|
committer | Dmitry Kim <dmitry point kim at gmail point com> | 2007-03-17 19:42:48 +0000 |
commit | 4667198ec577276892f501ae37efc8f64c66c003 (patch) | |
tree | ff7250a7b49b554ea655879f4efe2436d78188c2 /lib/rbot/ircsocket.rb | |
parent | 9e743517a8a8a7455d4186d63d545b34dd5419e8 (diff) |
+ added support for multiple servers to try (round-robin) for unreliable ircnets
* changed server.name/port to server.list (with config upgrade automation, too)
Diffstat (limited to 'lib/rbot/ircsocket.rb')
-rw-r--r-- | lib/rbot/ircsocket.rb | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/rbot/ircsocket.rb b/lib/rbot/ircsocket.rb index 5163e0ef..e3586b70 100644 --- a/lib/rbot/ircsocket.rb +++ b/lib/rbot/ircsocket.rb @@ -262,6 +262,9 @@ module Irc # all incoming data and @filter.out(data) for all outgoing data attr_reader :filter + # normalized uri of the current server + attr_reader :server_uri + # default trivial filter class class IdentityFilter def in(x) @@ -278,17 +281,17 @@ module Irc @filter = f || IdentityFilter.new end - # server:: server to connect to - # port:: IRCd port + # server_list:: list of servers to connect to # host:: optional local host to bind to (ruby 1.7+ required) # create a new IrcSocket - def initialize(server, port, host, sendq_delay=2, sendq_burst=4, opts={}) + def initialize(server_list, host, sendq_delay=2, sendq_burst=4, opts={}) @timer = Timer::Timer.new @timer.add(0.2) do spool end - @server = server.dup - @port = port.to_i + @server_list = server_list.dup + @server_uri = nil + @conn_count = 0 @host = host @sock = nil @filter = IdentityFilter.new @@ -327,18 +330,25 @@ module Irc warning "reconnecting while connected" return end + srv_uri = @server_list[@conn_count % @server_list.size].dup + srv_uri = 'irc://' + srv_uri if !srv_uri =~ /:\/\// + @conn_count += 1 + @server_uri = URI.parse(srv_uri) + @server_uri.port = 6667 if !@server_uri.port + debug "connection attempt \##{@conn_count} (#{@server_uri.host}:#{@server_uri.port})" + if(@host) begin - @sock=TCPSocket.new(@server, @port, @host) + @sock=TCPSocket.new(@server_uri.host, @server_uri.port, @host) rescue ArgumentError => e error "Your version of ruby does not support binding to a " error "specific local address, please upgrade if you wish " error "to use HOST = foo" error "(this option has been disabled in order to continue)" - @sock=TCPSocket.new(@server, @port) + @sock=TCPSocket.new(@server_uri.host, @server_uri.port) end else - @sock=TCPSocket.new(@server, @port) + @sock=TCPSocket.new(@server_uri.host, @server_uri.port) end if(@ssl) require 'openssl' |