1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | use Time::HiRes; |
3 | use Time::HiRes; |
4 | use Net::IRC3::Client::Connection; |
4 | use AnyEvent::IRC::Client; |
|
|
5 | use AnyEvent::IRC::Util; |
5 | |
6 | |
6 | # requires: commands.ext |
7 | # requires: commands.ext |
7 | |
8 | |
8 | return unless exists $cf::CFG{irc_server}; |
9 | return unless exists $cf::CFG{irc_server}; |
9 | |
10 | |
… | |
… | |
21 | |
22 | |
22 | sub do_notice { |
23 | sub do_notice { |
23 | my ($msg) = @_; |
24 | my ($msg) = @_; |
24 | |
25 | |
25 | utf8::encode $msg; |
26 | utf8::encode $msg; |
26 | $CON->send_chan ($BOTCHAN, NOTICE => $msg, $BOTCHAN) |
27 | $CON->send_chan ($BOTCHAN, NOTICE => $BOTCHAN, $msg) |
27 | if $CON; |
28 | if $CON; |
28 | } |
29 | } |
29 | |
30 | |
30 | sub users { |
31 | sub users { |
31 | $CON |
32 | $CON |
… | |
… | |
47 | |
48 | |
48 | if (my $other = cf::player::find_active $target) { |
49 | if (my $other = cf::player::find_active $target) { |
49 | |
50 | |
50 | if ($tmsg) { |
51 | if ($tmsg) { |
51 | if ($me eq $target) { |
52 | if ($me eq $target) { |
52 | $CON->send_chan ($BOTCHAN, NOTICE => "$me: You are talking to yourself, you freak!", $BOTCHAN); |
53 | $CON->send_chan ($BOTCHAN, NOTICE => $BOTCHAN, "$me: You are talking to yourself, you freak!"); |
53 | } elsif ($other->ob->{ext_ignore_tell}{$me} >= time) { |
54 | } elsif ($other->ob->{ext_ignore_tell}{$me} >= time) { |
54 | $CON->send_chan ($BOTCHAN, NOTICE => "$me: $target ignores what you say. Give up on it.", $BOTCHAN); |
55 | $CON->send_chan ($BOTCHAN, NOTICE => $BOTCHAN, "$me: $target ignores what you say. Give up on it."); |
55 | } else { |
56 | } else { |
56 | cf::LOG cf::llevDebug, sprintf "TELL [%s/%s>%s] %s\n", $name, $me, $target, $tmsg; |
57 | cf::LOG cf::llevDebug, sprintf "TELL [%s/%s>%s] %s\n", $name, $me, $target, $tmsg; |
57 | |
58 | |
58 | $other->ns->send_msg (ext::chat::tell_channel ("$name/$me"), "$name/$me tells you: $tmsg", cf::NDI_DK_ORANGE | cf::NDI_DEF); |
59 | $other->ns->send_msg (ext::chat::tell_channel ("$name/$me"), "$name/$me tells you: $tmsg", cf::NDI_DK_ORANGE | cf::NDI_DEF); |
59 | } |
60 | } |
… | |
… | |
66 | } |
67 | } |
67 | |
68 | |
68 | sub check_connection { |
69 | sub check_connection { |
69 | return if $CON; |
70 | return if $CON; |
70 | |
71 | |
71 | $CON = Net::IRC3::Client::Connection->new; |
72 | $CON = AnyEvent::IRC::Client->new; |
72 | $CON->connect ($BOTSERVER, $BOTPORT); |
73 | $CON->connect ($BOTSERVER, $BOTPORT, { |
|
|
74 | nick => $BOTNAME, |
|
|
75 | user => $BOTNAME, |
|
|
76 | real => 'deliantra server' |
|
|
77 | }); |
73 | $CON->send_srv (JOIN => undef, $BOTCHAN); |
78 | $CON->send_srv (JOIN => undef, $BOTCHAN); |
74 | $CON->register ($BOTNAME, $BOTNAME, 'crossfire connection'); |
|
|
75 | $CON->reg_cb ( |
79 | $CON->reg_cb ( |
76 | #d# 'irc_*' => sub { warn "IRC $_[1]->{trailing}\n"; 1 }, |
|
|
77 | irc_privmsg => sub { |
80 | irc_privmsg => sub { |
78 | my ($con, $msg) = @_; |
81 | my ($con, $msg) = @_; |
79 | my $name = 'irc'; |
82 | my $name = 'irc'; |
80 | my $nick = Net::IRC3::Util::prefix_nick ($msg); |
83 | my $nick = AnyEvent::IRC::Util::prefix_nick ($msg); |
81 | my $NOW = Time::HiRes::time; |
84 | my $NOW = Time::HiRes::time; |
82 | |
85 | |
83 | my $tmsg = $msg->{trailing}; |
86 | my $tmsg = $msg->{params}->[-1]; |
84 | $tmsg =~ s/\x01[^\x01]*\x01//g; |
87 | $tmsg =~ s/\x01[^\x01]*\x01//g; |
85 | $tmsg =~ s/\015?\012/ /g; |
88 | $tmsg =~ s/\015?\012/ /g; |
86 | |
89 | |
87 | utf8::decode $tmsg; |
90 | utf8::decode $tmsg; |
88 | |
91 | |
… | |
… | |
92 | $_->ns->send_msg ($cf::CHAT_CHANNEL, |
95 | $_->ns->send_msg ($cf::CHAT_CHANNEL, |
93 | "$name/".$nick." chats: $tmsg", cf::NDI_BLUE | cf::NDI_DEF |
96 | "$name/".$nick." chats: $tmsg", cf::NDI_BLUE | cf::NDI_DEF |
94 | ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list; |
97 | ) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list; |
95 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", "$name/$nick", $tmsg; |
98 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", "$name/$nick", $tmsg; |
96 | } |
99 | } |
97 | 1; |
|
|
98 | }, |
100 | }, |
|
|
101 | connect => sub { |
|
|
102 | warn "IRC: connected to IRC server: $BOTSERVER:$BOTPORT\n"; |
|
|
103 | }, |
99 | # registered => sub { |
104 | registered => sub { |
100 | # 1; |
105 | warn "IRC: successfully logged into IRC server: $BOTSERVER:$BOTPORT\n"; |
101 | # }, |
106 | }, |
|
|
107 | error => sub { |
|
|
108 | my ($con, $code, $message) = @_; |
|
|
109 | warn "IRC: IRC ERROR ($code) $message\n"; |
|
|
110 | }, |
102 | disconnect => sub { |
111 | disconnect => sub { |
103 | my ($con, $reason) = @_; |
112 | my ($con, $reason) = @_; |
104 | warn "CFBOT: disconnect: $reason\n"; |
113 | warn "IRC: disconnect: $reason\n"; |
105 | undef $CON; |
114 | undef $CON; |
106 | 0; |
|
|
107 | } |
115 | } |
108 | ); |
116 | ); |
109 | } |
117 | } |
110 | |
118 | |
111 | our $RECONNECT = cf::periodic 30, Coro::unblock_sub { |
119 | our $RECONNECT = cf::periodic 30, Coro::unblock_sub { |