ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/irc.ext
(Generate patch)

Comparing deliantra/server/ext/irc.ext (file contents):
Revision 1.14 by elmex, Tue Sep 23 14:41:26 2008 UTC vs.
Revision 1.19 by root, Thu Apr 29 07:52:01 2010 UTC

1#! perl 1#! perl
2 2
3use Time::HiRes; 3use Time::HiRes;
4use AnyEvent::IRC::Client; 4use AnyEvent::IRC::Client;
5use AnyEvent::IRC::Util; 5use AnyEvent::IRC::Util qw/filter_colors/;
6 6
7# requires: commands.ext 7# requires: commands.ext
8 8
9return unless exists $cf::CFG{irc_server}; 9return unless exists $cf::CFG{irc_server};
10 10
11my $BOTSERVER = $cf::CFG{irc_server} || "localhost"; 11our $BOTSERVER = $cf::CFG{irc_server};
12my $BOTPORT = $cf::CFG{irc_port} || 6667; 12our $BOTPORT = $cf::CFG{irc_port};
13my $BOTNAME = $cf::CFG{irc_nick} || "server"; 13our $BOTNAME = $cf::CFG{irc_nick};
14my $BOTCHAN = $cf::CFG{irc_chan} || "cf"; 14our $BOTCHAN = $cf::CFG{irc_chan};
15 15
16my $CON; # the connection 16our $CON; # the connection
17 17
18sub unload { 18sub unload {
19 $CON->disconnect if $CON; 19 $CON->disconnect if $CON;
20 undef $CON; 20 undef $CON;
21} 21}
68 68
69sub check_connection { 69sub check_connection {
70 return if $CON; 70 return if $CON;
71 71
72 $CON = AnyEvent::IRC::Client->new; 72 $CON = AnyEvent::IRC::Client->new;
73 $CON->set_exception_cb (sub {
74 my ($exp, $ev) = @_;
75 cf::error "IRC: IRC EXCEPTION (event $ev): $exp\n";
76 });
73 $CON->connect ($BOTSERVER, $BOTPORT, { 77 $CON->connect ($BOTSERVER, $BOTPORT, {
74 nick => $BOTNAME, 78 nick => $BOTNAME,
75 user => $BOTNAME, 79 user => $BOTNAME,
76 real => 'deliantra server' 80 real => 'deliantra server'
77 }); 81 });
81 my ($con, $msg) = @_; 85 my ($con, $msg) = @_;
82 my $name = 'irc'; 86 my $name = 'irc';
83 my $nick = AnyEvent::IRC::Util::prefix_nick ($msg); 87 my $nick = AnyEvent::IRC::Util::prefix_nick ($msg);
84 my $NOW = Time::HiRes::time; 88 my $NOW = Time::HiRes::time;
85 89
86 my $tmsg = $msg->{params}->[-1]; 90 my $tmsg = filter_colors ($msg->{params}->[-1]);
87 $tmsg =~ s/\x01[^\x01]*\x01//g; 91 $tmsg =~ s/\x01[^\x01]*\x01//g;
88 $tmsg =~ s/\015?\012/ /g; 92 $tmsg =~ s/\015?\012/ /g;
89 93
90 utf8::decode $tmsg; 94 utf8::decode $tmsg;
91 95
97 ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list; 101 ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list;
98 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", "$name/$nick", $tmsg; 102 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", "$name/$nick", $tmsg;
99 } 103 }
100 }, 104 },
101 connect => sub { 105 connect => sub {
106 my ($con, $error) = @_;
107
108 if ($error) {
109 cf::error "IRC: CONNECT ERROR to IRC server: $BOTSERVER:$BOTPORT: $error\n";
110 undef $CON;
111
112 } else {
102 warn "IRC: connected to IRC server: $BOTSERVER:$BOTPORT\n"; 113 cf::info "IRC: connected to IRC server: $BOTSERVER:$BOTPORT\n";
114 }
103 }, 115 },
104 registered => sub { 116 registered => sub {
105 warn "IRC: successfully logged into IRC server: $BOTSERVER:$BOTPORT\n"; 117 cf::info "IRC: successfully logged into IRC server: $BOTSERVER:$BOTPORT\n";
106 }, 118 },
107 error => sub { 119 error => sub {
108 my ($con, $code, $message) = @_; 120 my ($con, $code, $message) = @_;
109 warn "IRC: IRC ERROR ($code) $message\n"; 121 cf::error "IRC: IRC ERROR ($code) $message\n";
110 }, 122 },
111 disconnect => sub { 123 disconnect => sub {
112 my ($con, $reason) = @_; 124 my ($con, $reason) = @_;
113 warn "IRC: disconnect: $reason\n"; 125 cf::warn "IRC: disconnect: $reason\n";
114 undef $CON; 126 undef $CON;
115 } 127 }
116 ); 128 );
117} 129}
118 130
119our $RECONNECT = cf::periodic 30, Coro::unblock_sub { 131our $RECONNECT = length $BOTSERVER && cf::periodic 30, Coro::unblock_sub {
120 check_connection; 132 check_connection;
121}; 133};
122 134

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines