2 # IrcHooks.pl: IRC Hooks stuff.
6 # NOTE: Based on code by Kevin Lenzo & Patrick Cole (c) 1997
9 if (&IsParam("useStrict")) { use strict; }
11 #######################################################################
12 ####### IRC HOOK HELPERS IRC HOOK HELPERS IRC HOOK HELPERS ########
13 #######################################################################
16 # Usage: &hookMode($nick, $modes, @targets);
18 my ($nick, $modes, @targets) = @_;
21 if ($chan =~ tr/A-Z/a-z/) {
22 &VERB("hookMode: cased $chan.",2);
26 foreach $mode (split(//, $modes)) {
28 if ($mode =~ /[-+]/) {
29 $parity = 1 if ($mode eq "+");
30 $parity = 0 if ($mode eq "-");
35 if ($mode =~ /[bklov]/) {
36 my $target = shift @targets;
39 $chanstats{$chan}{'Op'}++ if ($mode eq "o");
40 $chanstats{$chan}{'Ban'}++ if ($mode eq "b");
42 $chanstats{$chan}{'Deop'}++ if ($mode eq "o");
43 $chanstats{$chan}{'Unban'}++ if ($mode eq "b");
46 # modes w/ target affecting nick => cache it.
47 if ($mode =~ /[bov]/) {
48 if ($mode eq "o" and $nick eq "ChanServ" and $target =~ /^\Q$ident\E$/i) {
49 &DEBUG("hookmode: chanserv deopped us! asking");
50 &chanServCheck($chan);
53 $channels{$chan}{$mode}{$target}++ if $parity;
54 delete $channels{$chan}{$mode}{$target} if !$parity;
58 $channels{$chan}{$mode} = $target if $parity;
59 delete $channels{$chan}{$mode} if !$parity;
63 # important channel modes, targetless.
64 if ($mode =~ /[mt]/) {
65 $channels{$chan}{$mode}++ if $parity;
66 delete $channels{$chan}{$mode} if !$parity;
72 ($msgType, $chan, $who, $message) = @_;
76 $orig{message} = $message;
80 $message =~ s/[\cA-\c_]//ig; # strip control characters
81 $message =~ s/^\s+//; # initial whitespaces.
82 $who =~ tr/A-Z/a-z/; # lowercase.
87 if ($msgType =~ /private/) {
92 # addressing revamped by the xk.
93 ### below needs to be fixed...
94 if (&IsParam("addressCharacter")) {
95 if ($message =~ s/^\Q$param{'addressCharacter'}\E//) {
101 if ($message =~ /^($mask{nick})([\;\:\>\, ]+) */) {
103 if ($1 =~ /^\Q$ident\E$/i) {
104 $message = $newmessage;
107 # ignore messages addressed to other people or unaddressed.
108 $skipmessage++ if ($2 ne "" and $2 !~ /^ /);
113 # Determine floodwho.
115 if ($msgType =~ /public/i) { # public.
116 $floodwho = $c = lc $chan;
117 } elsif ($msgType =~ /private/i) { # private.
120 &DEBUG("FIXME: floodwho = ???");
123 my $val = &getChanConfDefault("floodRepeat", "2:5", $c);
124 my ($count, $interval) = split /:/, $val;
126 # flood repeat protection.
128 my $time = $flood{$floodwho}{$message} || 0;
130 if ($msgType eq "public" and (time() - $time < $interval)) {
131 ### public != personal who so the below is kind of pointless.
133 foreach (keys %flood) {
134 next if (/^\Q$floodwho\E$/);
135 next if (defined $chan and /^\Q$chan\E$/);
137 push(@who, grep /^\Q$message\E$/i, keys %{ $flood{$_} });
140 return if ($lobotomized);
143 &msg($who, "you already said what ".
144 join(' ', @who)." have said.");
146 &msg($who,"Someone already said that ". (time - $time) ." seconds ago" );
149 ### TODO: delete old floodwarn{} keys.
151 if (!exists $floodwarn{$floodwho}) {
154 $floodwarn++ if (time() - $floodwarn{$floodwho} > $interval);
158 &status("FLOOD repetition detected from $floodwho.");
159 $floodwarn{$floodwho} = time();
166 &status("$b_cyan$who$ob is short-addressing me");
167 } elsif ($msgType eq "private") { # private.
168 &status("$b_cyan$who$ob is /msg'ing me");
170 &status("$b_cyan$who$ob is addressing me");
173 $flood{$floodwho}{$message} = time();
174 } elsif ($msgType eq "public" and &IsChanConf("kickOnRepeat")) {
175 # unaddressed, public only.
177 ### TODO: use a separate "short-time" hash.
179 @data = keys %{ $flood{$floodwho} } if (exists $flood{$floodwho});
182 $val = &getChanConfDefault("floodMessages", "5:30", $c);
183 ($count, $interval) = split /:/, $val;
185 # flood overflow protection.
187 foreach (keys %{ $flood{$floodwho} }) {
188 next unless (time() - $flood{$floodwho}{$_} > $interval);
189 delete $flood{$floodwho}{$_};
192 my $i = scalar keys %{ $flood{$floodwho} };
194 &msg($who,"overflow of messages ($i > $count)");
195 &status("FLOOD overflow detected from $floodwho; ignoring");
197 my $expire = $param{'ignoreAutoExpire'} || 5;
198 &ignoreAdd("*!$uh", $chan, $expire, "flood overflow auto-detected.");
202 $flood{$floodwho}{$message} = time();
206 if ($msgType =~ /public/i) { # public.
207 $talkchannel = $chan;
208 &status("<$orig{who}/$chan> $orig{message}");
209 push(@ignore, keys %{ $ignore{$chan} }) if (exists $ignore{$chan});
210 } elsif ($msgType =~ /private/i) { # private.
211 &status("[$orig{who}] $orig{message}");
212 $talkchannel = undef;
215 &DEBUG("unknown msgType => $msgType.");
217 push(@ignore, keys %{ $ignore{"*"} }) if (exists $ignore{"*"});
219 if ((!$skipmessage or &IsChanConf("seenStoreAll")) and
220 &IsChanConf("seen") and
223 $seencache{$who}{'time'} = time();
224 $seencache{$who}{'nick'} = $orig{who};
225 $seencache{$who}{'host'} = $uh;
226 $seencache{$who}{'chan'} = $talkchannel;
227 $seencache{$who}{'msg'} = $orig{message};
228 $seencache{$who}{'msgcount'}++;
231 return if ($skipmessage);
232 return unless (&IsParam("minVolunteerLength") or $addressed);
237 next unless (eval { $nuh =~ /^$_$/i });
239 &status("IGNORE <$who> $message");
244 if (!defined $userHandle) {
245 &DEBUG("line 1074: need verifyUser?");
246 &verifyUser($who, $nuh);
249 &DEBUG("hookMsg: 'nuh' not defined?");
252 ### For extra debugging purposes...
253 if ($_ = &process()) {
254 # &DEBUG("IrcHooks: process returned '$_'.");
260 sub chanLimitVerify {
262 my $l = $channels{$chan}{'l'};
264 &DEBUG("cLV: netsplitservers: ".scalar(keys %netsplitservers) );
265 &DEBUG("cLV: netsplit: ".scalar(keys %netsplit) );
267 if (scalar keys %netsplit) {
268 &WARN("clV: netsplit active (1); skipping.");
272 # only change it if it's not set.
273 if (defined $l and &IsChanConf("chanlimitcheck")) {
274 my $plus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan);
275 my $count = scalar(keys %{ $channels{$chan}{''} });
276 my $int = &getChanConfDefault("chanlimitcheckInterval", 10, $chan);
278 my $delta = $count + $plus - $l;
282 &WARN("clc: stupid to have plus at $plus, fix it!");
285 if (exists $cache{chanlimitChange}{$chan}) {
286 if (time() - $cache{chanlimitChange}{$chan} < $int*60) {
291 &chanServCheck($chan);
293 ### todo: unify code with chanlimitcheck()
295 &status("clc: big change in limit; going for it.");
296 &rawout("MODE $chan +l ".($count+$plus) );
297 $cache{chanlimitChange}{$chan} = time();
305 if (!defined $chan or $chan =~ /^$/) {
306 &WARN("chanServCheck: chan == NULL.");
310 if ($chan =~ tr/A-Z/a-z/) {
311 &DEBUG("chanServCheck: lowercased chan ($chan)");
314 if (! &IsChanConf("chanServ_ops") ) {
318 &VERB("chanServCheck($chan) called.",2);
320 if ( &IsParam("nickServ_pass") and !$nickserv) {
321 &DEBUG("chanServ_ops($chan): nickserv enabled but not alive? (ircCheck)");
322 &rawout("WHO NickServ");
325 return 0 if (exists $channels{$chan}{'o'}{$ident});
327 &status("ChanServ ==> Requesting ops for $chan. (chanServCheck)");
328 &rawout("PRIVMSG ChanServ :OP $chan $ident");