summaryrefslogtreecommitdiffstats
path: root/scripts/redirect.pl
blob: 8fa3ad60256b8bd204b5c671c055eb2b7250dd33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# handle 005 and 010 server messages and reconnect to that server
#
# 2002 Thomas Graf <irssi@reeler.org>

use strict;
use Irssi;
use Irssi::Irc;
use vars qw($VERSION %IRSSI);

$VERSION = "0.1";
%IRSSI = (
    authors     => 'Thomas Graf',
    contact     => 'irssi@reeler.org',
    name        => 'redirect',
    description => 'handle 005 and 010 server messages and reconnect to that server',
    license     => 'GNU GPLv2 or later',
    url         => 'http://irssi.reeler.org/',
);

sub sig_servermsg
{
    my ($server, $line) = @_;

    if ( $line =~ /^005\s.*Try\sserver\s(.*?),.*port\s(.*?)$/ ||
         $line =~ /^010\s.*?\s(.*?)\s(.*?)\s/ ) {

        my $redirect = $1;
        my $port = $2;

        Irssi::print "Server suggests to redirect to $redirect $port";

        if ( Irssi::settings_get_bool("follow_redirect") ) {
            $server->command("SERVER $redirect $port");
        }
    }
}

Irssi::settings_add_bool("server", "follow_redirect", 1);

Irssi::signal_add_last('server event', 'sig_servermsg');