html/redirect.pl
1 # handle 005 and 010 server messages and reconnect to that server
2 #
3 # 2002 Thomas Graf <irssi@reeler.org>
4
5 use Irssi;
6 use Irssi::Irc;
7
8 $VERSION = "0.1";
9 %IRSSI = (
10 authors => 'Thomas Graf',
11 contact => 'irssi@reeler.org',
12 name => 'redirect',
13 description => 'handle 005 and 010 server messages and reconnect to that server',
14 license => 'GNU GPLv2 or later',
15 url => 'http://irssi.reeler.org/',
16 );
17
18 sub sig_servermsg
19 {
20 my ($server, $line) = @_;
21
22 if ( $line =~ /^005\s.*Try\sserver\s(.*?),.*port\s(.*?)$/ ||
23 $line =~ /^010\s.*?\s(.*?)\s(.*?)\s/ ) {
24
25 my $redirect = $1;
26 my $port = $2;
27
28 Irssi::print "Server suggests to redirect to $redirect $port";
29
30 if ( Irssi::settings_get_bool("follow_redirect") ) {
31 $server->command("SERVER $redirect $port");
32 }
33 }
34 }
35
36 Irssi::settings_add_bool("server", "follow_redirect", 1);
37
38 Irssi::signal_add_last('server event', 'sig_servermsg');