Changeset 416241f for perl


Ignore:
Timestamp:
Dec 28, 2009, 12:25:00 AM (14 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.10, release-1.6, release-1.7, release-1.8, release-1.9
Children:
85fa6e4
Parents:
3acab0e
git-author:
Nelson Elhage <nelhage@mit.edu> (12/23/09 12:28:51)
git-committer:
Nelson Elhage <nelhage@mit.edu> (12/28/09 00:25:00)
Message:
IRC: irc-disconnect on a pending reconnect should cancel it.
Location:
perl/modules/IRC/lib/BarnOwl/Module
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/IRC/lib/BarnOwl/Module/IRC.pm

    r54b4a87 r416241f  
    161161with C<CHANNEL_ARG>.
    162162
     163=item C<ALLOW_DISCONNECTED>
     164
     165C<IRC-CONNECTION> may be a disconnected connection object that is
     166currently pending a reconnect.
     167
    163168=back
    164169
     
    167172use constant CHANNEL_ARG        => 1;
    168173use constant CHANNEL_OPTIONAL   => 2;
     174
     175use constant ALLOW_DISCONNECTED => 4;
    169176
    170177sub register_commands {
     
    195202
    196203    BarnOwl::new_command(
    197         'irc-disconnect' => mk_irc_command( \&cmd_disconnect ),
     204        'irc-disconnect' => mk_irc_command( \&cmd_disconnect, ALLOW_DISCONNECTED ),
    198205        {
    199206            summary => 'Disconnect from an IRC server',
     
    421428    my $cmd = shift;
    422429    my $conn = shift;
    423     $conn->conn->disconnect;
    424     return;
     430    if ($conn->conn->connected) {
     431        $conn->conn->disconnect;
     432    } elsif ($reconnect{$conn->alias}) {
     433        BarnOwl::admin_message('IRC',
     434                               "[" . $conn->alias . "] Reconnect cancelled");
     435        $conn->cancel_reconnect;
     436    }
    425437}
    426438
     
    589601
    590602        if(defined($alias)) {
    591             $conn = get_connection_by_alias($alias);
     603            $conn = get_connection_by_alias($alias,
     604                                            $flags & ALLOW_DISCONNECTED);
    592605        }
    593606        if($flags & CHANNEL_ARG) {
     
    612625        if(!$conn) {
    613626            if($m && $m->type eq 'IRC') {
    614                 $conn = get_connection_by_alias($m->network);
     627                $conn = get_connection_by_alias($m->network,
     628                                               $flags & ALLOW_DISCONNECTED);
    615629            }
    616630        }
     
    631645sub get_connection_by_alias {
    632646    my $key = shift;
    633     die("No such ircnet: $key\n") unless exists $ircnets{$key};
    634     return $ircnets{$key};
     647    my $allow_disconnected = shift;
     648
     649    return $ircnets{$key} if exists $ircnets{$key};
     650    return $reconnect{$key} if $allow_disconnected && exists $reconnect{$key};
     651    die("No such ircnet: $key\n")
    635652}
    636653
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm

    r3acab0e r416241f  
    328328}
    329329
     330sub cancel_reconnect {
     331    my $self = shift;
     332    delete $BarnOwl::Module::IRC::reconnect{$self->alias};
     333    delete $self->{reconnect_timer};
     334}
     335
    330336sub connected {
    331337    my $self = shift;
    332338    my $msg = shift;
    333339    BarnOwl::admin_message("IRC", $msg);
    334     delete $BarnOwl::Module::IRC::reconnect{$self->alias};
    335     delete $self->{reconnect_timer};
     340    $self->cancel_reconnect;
    336341    $BarnOwl::Module::IRC::ircnets{$self->alias} = $self;
    337342    my $fd = $self->getSocket()->fileno();
Note: See TracChangeset for help on using the changeset viewer.