Changeset 851a0e0 for perl/modules
- Timestamp:
- Apr 3, 2011, 3:06:01 PM (14 years ago)
- Branches:
- master, release-1.10, release-1.8, release-1.9
- Children:
- 249bbbe
- Parents:
- 4787581
- git-author:
- Nelson Elhage <nelhage@mit.edu> (02/26/11 20:06:50)
- git-committer:
- Nelson Elhage <nelhage@mit.edu> (04/03/11 15:06:01)
- Location:
- perl/modules/IRC/lib/BarnOwl/Module
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/modules/IRC/lib/BarnOwl/Module/IRC.pm
r8ba9313 r851a0e0 389 389 timeout => sub {0} 390 390 }); 391 $ircnets{$alias} = $conn; 391 392 return; 392 393 } … … 395 396 my $cmd = shift; 396 397 my $conn = shift; 397 if ($conn->conn-> is_connected) {398 if ($conn->conn->{socket}) { 398 399 $conn->conn->disconnect("Goodbye!"); 399 400 } elsif ($reconnect{$conn->alias}) { -
perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm
r4787581 r851a0e0 35 35 my $nick = $args->{nick}; 36 36 my $conn = AnyEvent::IRC::Client->new(); 37 if(delete $args->{SSL}) {38 $conn->enable_ssl;39 }40 $conn->connect($host, $port, $args);41 37 my $self = bless({}, $class); 42 38 $self->conn($conn); … … 48 44 $self->whois_tmp(""); 49 45 46 if(delete $args->{SSL}) { 47 $conn->enable_ssl; 48 } 49 $conn->connect($host, $port, $args); 50 $conn->{heap}{parent} = $self; 51 weaken($conn->{heap}{parent}); 52 53 sub on { 54 my $meth = "on_" . shift; 55 return sub { 56 my $conn = shift; 57 return unless $conn->{heap}{parent}; 58 $conn->{heap}{parent}->$meth(@_); 59 } 60 } 61 50 62 # $self->conn->add_default_handler(sub { shift; $self->on_event(@_) }); 51 $self->conn->reg_cb(registered => sub { shift; $self->connected("Connected to $alias as $nick") },52 connfail => sub { shift;BarnOwl::error("Connection to $host failed!") },53 disconnect => sub { shift; $self->on_disconnect(@_) },54 publicmsg => sub { shift; $self->on_msg(@_) },55 privatemsg => sub { shift; $self->on_msg(@_) });63 $self->conn->reg_cb(registered => on("connected"), 64 connfail => sub { BarnOwl::error("Connection to $host failed!") }, 65 disconnect => on("disconnect"), 66 publicmsg => on("msg"), 67 privatemsg => on("msg")); 56 68 for my $m (qw(welcome yourhost created 57 69 luserclient luserop luserchannels luserme 58 70 error)) { 59 $self->conn->reg_cb("irc_$m" => sub { shift; $self->on_admin_msg(@_) });60 } 61 $self->conn->reg_cb(irc_375 => sub { shift; $self->on_motdstart(@_) },62 irc_372 => sub { shift; $self->on_motd(@_) },63 irc_376 => sub { shift; $self->on_endofmotd(@_) },64 irc_join => sub { shift; $self->on_join(@_) },65 irc_part => sub { shift; $self->on_part(@_) },66 irc_quit => sub { shift; $self->on_quit(@_) },67 irc_433 => sub { shift; $self->on_nickinuse(@_) },68 channel_topic => sub { shift; $self->on_topic(@_) },69 irc_333 => sub { shift; $self->on_topicinfo(@_) },70 irc_353 => sub { shift; $self->on_namreply(@_) },71 irc_366 => sub { shift; $self->on_endofnames(@_) },72 irc_311 => sub { shift; $self->on_whois(@_) },73 irc_312 => sub { shift; $self->on_whois(@_) },74 irc_319 => sub { shift; $self->on_whois(@_) },75 irc_320 => sub { shift; $self->on_whois(@_) },76 irc_318 => sub { shift; $self->on_endofwhois(@_) },77 irc_mode => sub { shift; $self->on_mode(@_) },78 irc_401 => sub { shift; $self->on_nosuch(@_) },79 irc_402 => sub { shift; $self->on_nosuch(@_) },80 irc_403 => sub { shift; $self->on_nosuch(@_) },81 nick_change => sub { shift; $self->on_nick(@_); },71 $self->conn->reg_cb("irc_$m" => on("admin_msg")); 72 } 73 $self->conn->reg_cb(irc_375 => on("motdstart"), 74 irc_372 => on("motd"), 75 irc_376 => on("endofmotd"), 76 irc_join => on("join"), 77 irc_part => on("part"), 78 irc_quit => on("quit"), 79 irc_433 => on("nickinuse"), 80 channel_topic => on("topic"), 81 irc_333 => on("topicinfo"), 82 irc_353 => on("namreply"), 83 irc_366 => on("endofnames"), 84 irc_311 => on("whois"), 85 irc_312 => on("whois"), 86 irc_319 => on("whois"), 87 irc_320 => on("whois"), 88 irc_318 => on("endofwhois"), 89 irc_mode => on("mode"), 90 irc_401 => on("nosuch"), 91 irc_402 => on("nosuch"), 92 irc_403 => on("nosuch"), 93 nick_change => on("nick"), 82 94 'irc_*' => sub { BarnOwl::debug("IRC: " . $_[1]->{command}) }); 83 95 … … 203 215 sub disconnect { 204 216 my $self = shift; 205 delete $BarnOwl::Module::IRC::ircnets{$self->alias};206 217 for my $k (keys %BarnOwl::Module::IRC::channels) { 207 218 my @conns = grep {$_ ne $self} @{$BarnOwl::Module::IRC::channels{$k}}; … … 344 355 my $self = shift; 345 356 my $interval = shift || 5; 346 delete $BarnOwl::Module::IRC::ircnets{$self->alias};347 357 $BarnOwl::Module::IRC::reconnect{$self->alias} = $self; 348 358 my $weak = $self; … … 370 380 } 371 381 382 sub on_connect { 383 my $self = shift; 384 $self->connected("Connected to $self->alias as $self->nick") 385 } 386 372 387 sub connected { 373 388 my $self = shift; … … 375 390 BarnOwl::admin_message("IRC", $msg); 376 391 $self->cancel_reconnect; 377 $BarnOwl::Module::IRC::ircnets{$self->alias} = $self;378 392 if ($self->autoconnect_channels) { 379 393 for my $c (@{$self->autoconnect_channels}) {
Note: See TracChangeset
for help on using the changeset viewer.