Changeset 5c6d661 for perl/modules/IRC
- Timestamp:
- Apr 3, 2011, 3:06:02 PM (13 years ago)
- Branches:
- master, release-1.10, release-1.8, release-1.9
- Children:
- 736835d
- Parents:
- ab6d8f0
- git-author:
- Nelson Elhage <nelhage@mit.edu> (03/24/11 19:09:05)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (04/03/11 15:06:02)
- Location:
- perl/modules/IRC/lib/BarnOwl/Module
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/IRC/lib/BarnOwl/Module/IRC.pm
rdace02a r5c6d661 394 394 my $conn = shift; 395 395 if ($conn->conn->{socket}) { 396 $conn->did_quit(1); 396 397 $conn->conn->disconnect("Goodbye!"); 397 398 } elsif ($conn->{reconnect_timer}) { -
perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
rab6d8f0 r5c6d661 21 21 use base qw(Class::Accessor); 22 22 use Exporter 'import'; 23 __PACKAGE__->mk_accessors(qw(conn alias motd names_tmp whois_tmp server autoconnect_channels)); 23 __PACKAGE__->mk_accessors(qw(conn alias motd names_tmp whois_tmp 24 server autoconnect_channels 25 connect_args backoff did_quit)); 24 26 our @EXPORT_OK = qw(is_private); 25 27 … … 42 44 $self->motd(""); 43 45 $self->names_tmp(0); 46 $self->backoff(0); 44 47 $self->whois_tmp(""); 48 $self->did_quit(0); 45 49 46 50 if(delete $args->{SSL}) { 47 51 $conn->enable_ssl; 48 52 } 53 $self->connect_args([$host, $port, $args]); 49 54 $conn->connect($host, $port, $args); 50 55 $conn->{heap}{parent} = $self; … … 94 99 nick_change => on("nick"), 95 100 ctcp_action => on("ctcp_action"), 96 'irc_*' => sub { BarnOwl::debug("IRC: " . $_[1]->{command} . 101 'irc_*' => sub { BarnOwl::debug("IRC: " . $_[1]->{command} . " " . 97 102 join(" ", @{$_[1]->{params}})) }); 98 103 … … 244 249 sub disconnect { 245 250 my $self = shift; 246 delete $BarnOwl::Module::IRC::ircnets{$self->alias}; 247 for my $k (keys %BarnOwl::Module::IRC::channels) { 248 my @conns = grep {$_ ne $self} @{$BarnOwl::Module::IRC::channels{$k}}; 249 if(@conns) { 250 $BarnOwl::Module::IRC::channels{$k} = \@conns; 251 } else { 252 delete $BarnOwl::Module::IRC::channels{$k}; 253 } 254 } 255 $self->motd(""); 251 $self->conn->disconnect; 256 252 } 257 253 … … 259 255 my ($self, $why) = @_; 260 256 BarnOwl::admin_message('IRC', 261 "[" . $self->alias . "] Disconnected from server ");262 $self-> disconnect;263 if ( $why && $why =~ m{error in connection}) {257 "[" . $self->alias . "] Disconnected from server: $why"); 258 $self->motd(""); 259 if (!$self->did_quit) { 264 260 $self->schedule_reconnect; 261 } else { 262 delete $BarnOwl::Module::IRC::ircnets{$self->alias}; 265 263 } 266 264 } … … 400 398 sub schedule_reconnect { 401 399 my $self = shift; 402 my $interval = shift || 5; 400 my $interval = $self->backoff; 401 if ($interval) { 402 $interval *= 2; 403 $interval = 60*5 if $interval > 60*5; 404 } else { 405 $interval = 5; 406 } 407 $self->backoff($interval); 403 408 404 409 my $weak = $self; … … 443 448 } 444 449 $self->conn->enable_ping(60, sub { 445 $self-> disconnect("Connection timed out.");450 $self->on_disconnect("Connection timed out."); 446 451 $self->schedule_reconnect; 447 452 }); 453 $self->backoff(0); 448 454 } 449 455 450 456 sub reconnect { 451 457 my $self = shift; 452 my $backoff = shift;458 my $backoff = $self->backoff; 453 459 454 460 $self->autoconnect_channels([keys(%{$self->{channel_list}})]); 455 $self->conn->connect; 456 if ($self->conn->connected) { 457 $self->connected("Reconnected to ".$self->alias); 458 return; 459 } 460 461 $backoff *= 2; 462 $backoff = 60*5 if $backoff > 60*5; 463 $self->schedule_reconnect( $backoff ); 461 $self->conn->connect(@{$self->connect_args}); 464 462 } 465 463
Note: See TracChangeset
for help on using the changeset viewer.