#######################################################################
#####
-# 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)) {
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]/) {
# 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;
}
&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.
# 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)");
&status("FLOOD overflow detected from $floodwho; ignoring");
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;
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("running chanlimitCheck from chanLimitVerify; FIXME! (chan = $chan)");
+ &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}{''} });
+ 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/^\-//;
+ my $delta = $count + $plus - $l;
+# $delta =~ s/^\-//;
- if ($plus <= 3) {
- &WARN("clc: stupid to have plus at $plus, fix it!");
- }
+ if ($plus <= 3) {
+ &WARN("clc: stupid to have plus at $plus, fix it!");
+ }
- if (exists $cache{chanlimitChange_$chan}) {
- if (time() - $cache{chanlimitChange_$chan} < 60) {
- &DEBUG("not going to change chanlimit!");
- return;
- }
- delete $cache{chanlimitChange_$chan};
+ if (exists $cache{chanlimitChange}{$chan}) {
+ if (time() - $cache{chanlimitChange}{$chan} < $int*60) {
+ return;
}
+ }
- ### 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) );
- }
+ &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).")");
+
+ &rawout("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) {
+ &DEBUG("chanServ_ops($chan): nickserv enabled but not alive? (ircCheck)");
+ &rawout("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;