]> jfr.im git - irc/SurrealServices/srsv.git/commitdiff
cleanups and reformatting of various tempban code
authortabris <redacted>
Mon, 26 Mar 2012 01:10:57 +0000 (01:10 +0000)
committertabris <redacted>
Mon, 26 Mar 2012 01:10:57 +0000 (01:10 +0000)
git-svn-id: http://svn.tabris.net/repos/srsv@3587 70d4eda1-72e9-0310-a436-91e5bd24443c

branches/0.4.3/modules/serviceslibs/chanserv.pm

index de72f8ed64e87f09c23f2a0aa05bc3a56883e73b..c8d1659e11022ce9f03708a03c9e1231bdb9bbe6 100644 (file)
@@ -553,24 +553,32 @@ sub check_expired_bans() {
        $get_expired_bans->execute();
 
        while (my ($cn, $ban) = $get_expired_bans->fetchrow_array()) {
-               my $chan = {CHAN=>$cn};
+               my $chan = { CHAN => $cn };
                ircd::setmode(agent($chan), $cn, '-b', $ban);
-               ircd::flushmodes();
        }
+       ircd::flushmodes();
 }
-sub tempban($$;$) {
-       my ($chan, $bansref, $expiresref) = @_;
-       
-       my $cn = $chan->{CHAN}; 
+sub tempban($$) {
+       my ($chan, $bansref) = @_;
+
+       my $cn = $chan->{CHAN};
        my @bans = @$bansref;
-       my @expires = @$expiresref;
+       return unless scalar(@bans);
 
        foreach my $ban (@bans) {
-       my $expiry = shift @expires;
-               $add_tempban->execute($cn, $ban, $expiry);
+               my ($mask, $expiry);
+               if(ref($ban)) {
+                       ($mask, $expiry) = @$ban;
+               } else {
+                       $mask = $ban;
+               }
+               if($expiry) {
+                       $add_tempban->execute($cn, $mask, $expiry);
+                       $add_tempban->finish();
+               }
        }
 
-    ircd::ban_list(agent($chan), $cn, +1, 'b', @bans) if (scalar(@bans));
+       ircd::ban_list(agent($chan), $cn, +1, 'b', map { ref($_) ? $_->[0] : $_ } @bans);
 }
 sub clones_exist ($$) {
        my ($user, $chan) = @_;
@@ -621,8 +629,7 @@ sub dispatch($$$) {
        elsif ($cmd =~ /^t((e)?mp)?b(an)?$/i) {
                my @args = split (/\s+/, $msg, 2);
 
-               my (undef, $args) = @args;
-               cs_tempban ($user, $args);
+               cs_tempban ($user, $args[1]);
        }
        elsif($cmd =~ /^(?:[uvhas]op|co?f(ounder)?)$/i) {
                my ($cn, $cmd2) = splice(@args, 0, 2);
@@ -2348,7 +2355,7 @@ sub cs_drop($$) {
 #my ($bansref, $unbansref, $expires) = parse_bans ($user, $chan, '', @targets, 1, $expiry);
 sub parse_bans($$$$;$$) {
        my ($user, $chan, $type, $targetsref, $temp, $expiry) = (@_);
-       my (@bans, @unbans, @expires);
+       my (@bans, @unbans);
        my ($nick, $override);
 
        my @targets = @$targetsref;
@@ -2392,9 +2399,10 @@ sub parse_bans($$$$;$$) {
                }
                elsif($target =~ /[!@]+/) {
                        $target = normalize_hostmask($target);
-                       push @bans, $target;
                        if ($temp) {
-                               push @expires, $expiry;
+                               push @bans, [$target, $expiry];
+                       } else {
+                               push @bans, $target;
                        }
                        next;
                }
@@ -2402,9 +2410,10 @@ sub parse_bans($$$$;$$) {
                        $tuser = { NICK => $target };
                }
                elsif($target = validate_ban($target)) {
-                       push @bans, $target;
                        if ($temp) {
-                               push @expires, $expiry;
+                               push @bans, [$target, $expiry];
+                       } else {
+                               push @bans, $target;
                        }
                        next;
                } else {
@@ -2429,9 +2438,10 @@ sub parse_bans($$$$;$$) {
                        next;
                }
 
-               push @bans, make_banmask($chan, $tuser, $type);
                if ($temp) {
-                       push @expires, $expiry;
+                       push @bans, [make_banmask($chan, $tuser, $type), $expiry];
+               } else {
+                       push @bans, make_banmask($chan, $tuser, $type);
                }
        }
 
@@ -2456,17 +2466,17 @@ sub parse_bans($$$$;$$) {
                }
        }
 
-       return (\@bans, \@unbans, \@expires, $chan);
+       return (\@bans, \@unbans);
 }
 
 sub cs_tempban($$) {
-       my ($user, $args) = @_;
-       my ( $expiry, $cn, $chan ); 
+       my ($user, $argstring) = @_;
+       my ( $expiry, $cn, $chan );
 
-       my @args = split(/ /, $args);
-       my $length = @args;
+       my @args = split(/ /, $argstring);
+       my $numargs = scalar @args;
 
-       for (my $i = 0; $i < $length; $i++) {
+       for (my $i = 0; $i < $numargs; $i++) {
                if ($args[$i] =~ /\#/) {
                        $cn = $args[$i];
                        $chan = { CHAN => $cn };
@@ -2474,7 +2484,7 @@ sub cs_tempban($$) {
                }
        }
 
-       if ($chan eq '') {
+       if (!defined($cn) or !length($cn)) {
                notice ($user, "No channel given. The channel name \002must\002 include the # character.");
                return;
        }
@@ -2501,16 +2511,18 @@ sub cs_tempban($$) {
 
        my $src = get_user_nick($user);
 
-       my ($bansref, $unbansref, $expires, $chan) = parse_bans ($user, $chan, '', \@targets, 1, $expiry);
+       my ($bansref, $unbansref) = parse_bans ($user, $chan, '', \@targets, 1, $expiry);
 
        if (!$bansref && !$unbansref) {
                return;
        }
 
-       tempban ($chan, $bansref, $expires);
+       if(scalar @$bansref) {
+               tempban ($chan, $bansref);
 
-       ircd::notice(agent($chan), $cn, "$src used TEMPBAN ".join(' ', @$bansref))
-               if (lc $user->{AGENT} eq lc $csnick) and (cr_chk_flag($chan, CRF_VERBOSE) and scalar(@$bansref));
+               ircd::notice(agent($chan), $cn, "$src used TEMPBAN ".join(' ', @$bansref))
+                       if (lc $user->{AGENT} eq lc $csnick) and (cr_chk_flag($chan, CRF_VERBOSE) and scalar(@$bansref));
+       }
        cs_unban($user, $chan, @$unbansref) if scalar(@$unbansref);
 }
 
@@ -3889,13 +3901,13 @@ sub do_status($$;$) {
        my ($acc, $root) = get_best_acc($user, $chan, 2);
        my ($accnick, $override) = can_do($chan, 'JOIN', $user, { ACC => $acc, NOREPLY => 1 });
        unless ($acc > 0 || $override) {
-               if (clones_exist ($user, $chan)) {
-            my $mask = make_banmask($chan, $user);
+               if (clones_exist ($user, $chan) && !adminserv::is_service($user)) {
+                       my $mask = make_banmask($chan, $user);
                        my $cn = $chan->{CHAN};
 
-            tempban($chan, [ $mask ], "+60s");
+                       tempban($chan, [ $mask, 60 ]);
 
-            ircd::kick(agent($chan), $cn, $nick, "No clones allowed in this channel.") unless adminserv::is_service($user);
+                       ircd::kick(agent($chan), $cn, $nick, "No clones allowed in this channel.");
                }
        }