X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FIRC%2FIrcHelpers.pl;h=1ee2835238e137b12360daf594d77d59f4803fcf;hb=713936c7c3292e16e3a21efe827bcfd040ccbfc2;hp=c4e4530535f976193be07ef202227cc2a228c05e;hpb=bb9e3127fe594248efa7d4733e0be24dba8e579e;p=infobot.git diff --git a/src/IRC/IrcHelpers.pl b/src/IRC/IrcHelpers.pl index c4e4530..1ee2835 100644 --- a/src/IRC/IrcHelpers.pl +++ b/src/IRC/IrcHelpers.pl @@ -6,19 +6,19 @@ # NOTE: Based on code by Kevin Lenzo & Patrick Cole (c) 1997 # -if (&IsParam("useStrict")) { use strict; } - ####################################################################### ####### IRC HOOK HELPERS IRC HOOK HELPERS IRC HOOK HELPERS ######## ####################################################################### ##### -# Usage: &hookMode($chan, $modes, @targets); +# Usage: &hookMode($nick, $modes, @targets); sub hookMode { - my ($chan, $modes, @targets) = @_; + my ($nick, $modes, @targets) = @_; my $parity = 0; - $chan = lc $chan; # !!!. + if ($chan =~ tr/A-Z/a-z/) { + &VERB("hookMode: cased $chan.",2); + } my $mode; foreach $mode (split(//, $modes)) { @@ -45,6 +45,16 @@ sub hookMode { if ($mode =~ /[bov]/) { $channels{$chan}{$mode}{$target}++ if $parity; delete $channels{$chan}{$mode}{$target} if !$parity; + + # lets do some custom stuff. + if ($mode eq "o" and $parity) { + if ($nick eq "ChanServ" and $target =~ /^\Q$ident\E$/i) { + &VERB("hookmode: chanserv deopped us! asking",2); + &chanServCheck($chan); + } + + &chanLimitVerify($chan); + } } if ($mode =~ /[l]/) { @@ -85,7 +95,7 @@ sub hookMsg { # addressing revamped by the xk. ### below needs to be fixed... if (&IsParam("addressCharacter")) { - if ($message =~ s/^$param{'addressCharacter'}//) { + if ($message =~ s/^\Q$param{'addressCharacter'}\E//) { $addrchar = 1; $addressed = 1; } @@ -113,7 +123,7 @@ sub hookMsg { &DEBUG("FIXME: floodwho = ???"); } - my $val = &getChanConfDefault("floodRepeat", "2:10", $c); + my $val = &getChanConfDefault("floodRepeat", "2:5", $c); my ($count, $interval) = split /:/, $val; # flood repeat protection. @@ -177,17 +187,19 @@ sub hookMsg { # flood overflow protection. if ($addressed) { - foreach (keys %{$flood{$floodwho}}) { + foreach (keys %{ $flood{$floodwho} }) { next unless (time() - $flood{$floodwho}{$_} > $interval); delete $flood{$floodwho}{$_}; } - my $i = scalar keys %{$flood{$floodwho}}; + my $i = scalar keys %{ $flood{$floodwho} }; if ($i > $count) { - &msg($who,"overflow of messages ($i > $count)"); + my $expire = $param{'ignoreAutoExpire'} || 5; + +# &msg($who,"overflow of messages ($i > $count)"); + &msg($who,"Too many queries from you, ignoring for $expire minutes."); &status("FLOOD overflow detected from $floodwho; ignoring"); - my $expire = $param{'ignoreAutoExpire'} || 5; &ignoreAdd("*!$uh", $chan, $expire, "flood overflow auto-detected."); return; } @@ -227,7 +239,14 @@ sub hookMsg { foreach (@ignore) { s/\*/\\S*/g; - next unless (eval { $nuh =~ /^$_$/i }); + next unless (eval { $nuh =~ /^$_$/i } ); + + # better to ignore an extra message than to allow one to get + # through, although it would be better to go through ignore + # checking again. + if (time() - ($cache{ignoreCheckTime} || 0) > 60) { + &ignoreCheck(); + } &status("IGNORE <$who> $message"); return; @@ -247,34 +266,97 @@ sub hookMsg { # &DEBUG("IrcHooks: process returned '$_'."); } + # hack to remove +o from ppl with +O flag. + if (exists $users{$userHandle} && exists $users{$userHandle}{FLAGS} && + $users{$userHandle}{FLAGS} =~ /O/ + ) { + $users{$userHandle}{FLAGS} =~ s/o//g; + } + return; } +# this is basically run on on_join or on_quit sub chanLimitVerify { - my($chan) = @_; + my($c) = @_; + $chan = $c; my $l = $channels{$chan}{'l'}; + return unless (&IsChanConf("chanlimitcheck")); + + if (scalar keys %netsplit) { + &WARN("clV: netsplit active (1, chan = $chan); skipping."); + return; + } + + if (!defined $l) { + &DEBUG("$chan: running chanlimitCheck from chanLimitVerify."); + &chanlimitCheck(); + return; + } + # only change it if it's not set. - if (defined $l and &IsChanConf("chanlimitcheck")) { - my $plus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan); - my $count = scalar(keys %{ $channels{$chan}{''} }); - &DEBUG("plus = $plus, count = $count"); - my $delta = $count + $plus - $l; - $delta =~ s/^\-//; - &DEBUG(" delta => $delta"); - - if ($plus <= 3) { - &WARN("clc: stupid to have plus at $plus, fix it!"); - } + my $plus = &getChanConfDefault("chanlimitcheckPlus", 5, $chan); + my $count = scalar(keys %{ $channels{$chan}{''} }); + my $int = &getChanConfDefault("chanlimitcheckInterval", 10, $chan); + + my $delta = $count + $plus - $l; +# $delta =~ s/^\-//; - ### todo: check if we have ops. - ### todo: if not, check if nickserv/chanserv is avail. - ### todo: unify code with chanlimitcheck() - if ($delta > 5) { - &status("clc: big change in limit; changing."); - &rawout("MODE $chan +l ".($count+$plus) ); + if ($plus <= 3) { + &WARN("clc: stupid to have plus at $plus, fix it!"); + } + + if (exists $cache{chanlimitChange}{$chan}) { + if (time() - $cache{chanlimitChange}{$chan} < $int*60) { + return; } } + + &chanServCheck($chan); + + ### todo: unify code with chanlimitcheck() + return if ($delta > 5); + + &status("clc: big change in limit for $chan ($delta);". + "going for it. (was: $l; now: ".($count+$plus).")"); + + $conn->mode($chan, "+l", $count+$plus); + $cache{chanlimitChange}{$chan} = time(); +} + +sub chanServCheck { + ($chan) = @_; + + if (!defined $chan or $chan =~ /^\s*$/) { + &WARN("chanServCheck: chan == NULL."); + return 0; + } + + if ($chan =~ tr/A-Z/a-z/) { + &DEBUG("chanServCheck: lowercased chan ($chan)"); + } + + if (! &IsChanConf("chanServ_ops") ) { + return 0; + } + + &VERB("chanServCheck($chan) called.",2); + + if ( &IsParam("nickServ_pass") and !$nickserv) { + $conn->who("NickServ"); + return 0; + } + + # check for first hash then for next hash. + # todo: a function for &ischanop()? &isvoice()? + if (exists $channels{$chan} and exists $channels{$chan}{'o'}{$ident}) { + return 0; + } + + &status("ChanServ ==> Requesting ops for $chan. (chanServCheck)"); + &rawout("PRIVMSG ChanServ :OP $chan $ident"); + return 1; } 1;