--- deliantra/server/ext/irc.ext 2008/09/23 14:41:26 1.14 +++ deliantra/server/ext/irc.ext 2010/01/05 08:35:25 1.18 @@ -2,18 +2,18 @@ use Time::HiRes; use AnyEvent::IRC::Client; -use AnyEvent::IRC::Util; +use AnyEvent::IRC::Util qw/filter_colors/; # requires: commands.ext return unless exists $cf::CFG{irc_server}; -my $BOTSERVER = $cf::CFG{irc_server} || "localhost"; -my $BOTPORT = $cf::CFG{irc_port} || 6667; -my $BOTNAME = $cf::CFG{irc_nick} || "server"; -my $BOTCHAN = $cf::CFG{irc_chan} || "cf"; +our $BOTSERVER = $cf::CFG{irc_server}; +our $BOTPORT = $cf::CFG{irc_port}; +our $BOTNAME = $cf::CFG{irc_nick}; +our $BOTCHAN = $cf::CFG{irc_chan}; -my $CON; # the connection +our $CON; # the connection sub unload { $CON->disconnect if $CON; @@ -70,6 +70,10 @@ return if $CON; $CON = AnyEvent::IRC::Client->new; + $CON->set_exception_cb (sub { + my ($exp, $ev) = @_; + warn "IRC: IRC EXCEPTION (event $ev): $exp\n"; + }); $CON->connect ($BOTSERVER, $BOTPORT, { nick => $BOTNAME, user => $BOTNAME, @@ -83,7 +87,7 @@ my $nick = AnyEvent::IRC::Util::prefix_nick ($msg); my $NOW = Time::HiRes::time; - my $tmsg = $msg->{params}->[-1]; + my $tmsg = filter_colors ($msg->{params}->[-1]); $tmsg =~ s/\x01[^\x01]*\x01//g; $tmsg =~ s/\015?\012/ /g; @@ -99,7 +103,15 @@ } }, connect => sub { - warn "IRC: connected to IRC server: $BOTSERVER:$BOTPORT\n"; + my ($con, $error) = @_; + + if ($error) { + warn "IRC: CONNECT ERROR to IRC server: $BOTSERVER:$BOTPORT: $error\n"; + undef $CON; + + } else { + warn "IRC: connected to IRC server: $BOTSERVER:$BOTPORT\n"; + } }, registered => sub { warn "IRC: successfully logged into IRC server: $BOTSERVER:$BOTPORT\n"; @@ -116,7 +128,7 @@ ); } -our $RECONNECT = cf::periodic 30, Coro::unblock_sub { +our $RECONNECT = length $BOTSERVER && cf::periodic 30, Coro::unblock_sub { check_connection; };