add_timer('ChanServ Expire', 10, __PACKAGE__, 'chanserv::check_expired_bans');
$get_expired_bans->execute();
- while (my ($cn, $ban) = $get_expired_bans->fetchrow_array()) {
+ while (my ($cn, $ban) = $get_expired_bans->fetchrow_array()) {
my $chan = {CHAN=>$cn};
ircd::setmode(agent($chan), $cn, '-b', $ban);
ircd::flushmodes();
sub tempban($$;$) {
my ($chan, $bansref, $expiresref) = @_;
- my $cn = $chan->{CHAN};
- my @bans = @$bansref;
- my @expires = @$expiresref;
+ my $cn = $chan->{CHAN};
+ my @bans = @$bansref;
+ my @expires = @$expiresref;
- foreach my $ban (@bans) {
- my $expiry = shift @expires;
- $add_tempban->execute($cn, $ban, $expiry);
- }
+ foreach my $ban (@bans) {
+ my $expiry = shift @expires;
+ $add_tempban->execute($cn, $ban, $expiry);
+ }
ircd::ban_list(agent($chan), $cn, +1, 'b', @bans) if (scalar(@bans));
}
my $nick = $user->{NICK};
$get_host_inchan->execute(get_user_id($user), $cn);
my ($joined) = $get_host_inchan->fetchrow_array;
- $get_host_inchan->finish();
+ $get_host_inchan->finish();
- if ($joined) {
+ if ($joined) {
return $joined;
}
-
- return 0;
+
+ return 0;
}
sub dispatch($$$) {
my ($src, $dst, $msg) = @_;
}
}
elsif ($cmd =~ /^t((e)?mp)?b(an)?$/i) {
- my @args = split (/\s+/, $msg, 2);
-
- my (undef, $args) = @args;
+ my @args = split (/\s+/, $msg, 2);
+
+ my (undef, $args) = @args;
cs_tempban ($user, $args);
}
-
-
elsif($cmd =~ /^(?:[uvhas]op|co?f(ounder)?)$/i) {
my ($cn, $cmd2) = splice(@args, 0, 2);
my $chan = { CHAN => $cn };
-
+
if($cmd2 =~ /^add$/i) {
if(@args == 1) {
cs_xop_add($user, $chan, $cmd, $args[0]);
undef($enforcers{lc $cn});
botserv::bot_part_if_needed(undef(), $chan, "Channel dropped.");
}
-#my ($bansref, $unbansref, $expires) = get_bans ($user, $chan, '', @targets, 1, $default_expiry);
-#my ($bansref, $unbansref, $expires) = get_bans ($user, $chan, '', @targets, 1, $expiry);
-sub get_bans($$$$;$$) {
- my ($user, $chan, $type, $targetsref, $temp, $expiry) = (@_);
- my (@bans, @unbans, @expires);
- my ($nick, $override);
- my @targets = @$targetsref;
- my $cn = $chan->{CHAN};
- my $src = get_user_nick($user);
- my $srclevel = get_best_acc($user, $chan);
-
- ($nick, $override) = can_do($chan, 'BAN', $user, { ACC => $srclevel });
- return unless $nick;
-
- my @errors = (
+#my ($bansref, $unbansref, $expires) = parse_bans ($user, $chan, '', @targets, 1, $default_expiry);
+#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 ($nick, $override);
+
+ my @targets = @$targetsref;
+ my $cn = $chan->{CHAN};
+ my $src = get_user_nick($user);
+ my $srclevel = get_best_acc($user, $chan);
+
+ ($nick, $override) = can_do($chan, 'BAN', $user, { ACC => $srclevel });
+ return unless $nick;
+
+ my @errors = (
["I'm sorry, $src, I'm afraid I can't do that."],
["They are not in \002$cn\002."],
[$err_deny],
["User not found"],
);
- foreach my $target (@targets) {
- my $tuser;
-
- if ($target =~ /\+/ && $temp) {
- $expiry = $target;
- next;
- }
- if(ref($target)) {
- $tuser = $target;
- }
- elsif($target =~ /\,/) {
- push @targets, split(',', $target);
- next;
- }
- elsif($target eq '') {
- # Should never happen
- # but it could, given the split above
- next;
- }
- elsif($target =~ /^-/) {
- $target =~ s/^\-//;
- push @unbans, $target;
- next;
- }
- elsif($target =~ /[!@]+/) {
- $target = normalize_hostmask($target);
- push @bans, $target;
- if ($temp) {
- push @expires, $expiry;
- }
- next;
- }
- elsif(valid_nick($target)) {
- $tuser = { NICK => $target };
- }
- elsif($target = validate_ban($target)) {
- push @bans, $target;
- if ($temp) {
- push @expires, $expiry;
- }
- next;
- } else {
- notice($user, "Not a valid ban target: $target");
- next;
- }
-
- my $targetlevel = get_best_acc($tuser, $chan);
-
- if(lc $target eq lc agent($chan) or adminserv::is_service($tuser)) {
- push @{$errors[0]}, get_user_nick($tuser);
- next;
- }
-
- unless(get_user_id($tuser)) {
- push @{$errors[1]}, get_user_nick($tuser);
- next;
- }
-
- if( $srclevel <= $targetlevel and not ($override && check_override($user, 'BAN', "BAN $cn $target")) ) {
- push @{$errors[2]}, $target;
- next;
- }
-
- push @bans, make_banmask($chan, $tuser, $type);
- if ($temp) {
- push @expires, $expiry;
- }
- }
-
- if (!is_registered($chan)) {
- notice ($user,
- "$cn is not registered"
- );
- return;
- }
-
- foreach my $errlist (@errors) {
- if(@$errlist > 1) {
- my $msg = shift @$errlist;
-
- foreach my $e (@$errlist) { $e = "\002$e\002" }
-
- notice($user,
- "Cannot ban ".
- enum("or", @$errlist).
- ": $msg"
- );
- }
- }
-
- return (\@bans, \@unbans, \@expires, $chan);
+ foreach my $target (@targets) {
+ my $tuser;
+
+ if ($target =~ /\+/ && $temp) {
+ $expiry = $target;
+ next;
+ }
+ if(ref($target)) {
+ $tuser = $target;
+ }
+ elsif($target =~ /\,/) {
+ push @targets, split(',', $target);
+ next;
+ }
+ elsif($target eq '') {
+ # Should never happen
+ # but it could, given the split above
+ next;
+ }
+ elsif($target =~ /^-/) {
+ $target =~ s/^\-//;
+ push @unbans, $target;
+ next;
+ }
+ elsif($target =~ /[!@]+/) {
+ $target = normalize_hostmask($target);
+ push @bans, $target;
+ if ($temp) {
+ push @expires, $expiry;
+ }
+ next;
+ }
+ elsif(valid_nick($target)) {
+ $tuser = { NICK => $target };
+ }
+ elsif($target = validate_ban($target)) {
+ push @bans, $target;
+ if ($temp) {
+ push @expires, $expiry;
+ }
+ next;
+ } else {
+ notice($user, "Not a valid ban target: $target");
+ next;
+ }
+
+ my $targetlevel = get_best_acc($tuser, $chan);
+
+ if(lc $target eq lc agent($chan) or adminserv::is_service($tuser)) {
+ push @{$errors[0]}, get_user_nick($tuser);
+ next;
+ }
+
+ unless(get_user_id($tuser)) {
+ push @{$errors[1]}, get_user_nick($tuser);
+ next;
+ }
+
+ if( $srclevel <= $targetlevel and not ($override && check_override($user, 'BAN', "BAN $cn $target")) ) {
+ push @{$errors[2]}, $target;
+ next;
+ }
+
+ push @bans, make_banmask($chan, $tuser, $type);
+ if ($temp) {
+ push @expires, $expiry;
+ }
+ }
+
+ if (!is_registered($chan)) {
+ notice ($user,
+ "$cn is not registered"
+ );
+ return;
+ }
+
+ foreach my $errlist (@errors) {
+ if(@$errlist > 1) {
+ my $msg = shift @$errlist;
+
+ foreach my $e (@$errlist) { $e = "\002$e\002" }
+
+ notice($user,
+ "Cannot ban ".
+ enum("or", @$errlist).
+ ": $msg"
+ );
+ }
+ }
+
+ return (\@bans, \@unbans, \@expires, $chan);
}
sub cs_tempban($$) {
- my ($user, $args) = @_;
- my ( $expiry, $cn, $chan );
-
- my @args = split(/ /, $args);
- my $length = @args;
-
- for (my $i = 0; $i < $length; $i++) {
- if ($args[$i] =~ /\#/) {
- $cn = $args[$i];
- $chan = { CHAN => $cn };
- splice (@args, $i, 1);
- }
- }
-
- if ($chan eq '') {
- notice ($user, "No channel given. The channel name \002must\002 include the # character.");
- return;
- }
-
- if ($args[-1] =~ /\+/) { #expire time is last arguement
- $expiry = pop @args;
- $expiry = parse_time($expiry);
- } else { #expire time is somewhere else (if given), get default expiry for now.
- $get_bantime->execute($cn);
- ($expiry) = $get_bantime->fetchrow_array();
- $get_bantime->finish();
- }
-
- my @targets;
-
- foreach my $arg (@args) {
- if ($arg =~ /\,/) {
- push @targets, split(/\,/, $arg);
- next;
- } else {
- push @targets, $arg;
- }
- }
-
- my $src = get_user_nick($user);
-
- my ($bansref, $unbansref, $expires, $chan) = get_bans ($user, $chan, '', \@targets, 1, $expiry);
-
- if (!$bansref && !$unbansref) {
- return;
- }
-
- my (@bans, @unbans) = (@$bansref, @$unbansref);
-
- tempban ($chan, $bansref, $expires);
-
- ircd::notice(agent($chan), $cn, "$src used TEMPBAN ".join(' ', @bans))
- if (lc $user->{AGENT} eq lc $csnick) and (cr_chk_flag($chan, CRF_VERBOSE) and scalar(@bans));
- cs_unban($user, $chan, @unbans) if scalar(@unbans);
+ my ($user, $args) = @_;
+ my ( $expiry, $cn, $chan );
+
+ my @args = split(/ /, $args);
+ my $length = @args;
+
+ for (my $i = 0; $i < $length; $i++) {
+ if ($args[$i] =~ /\#/) {
+ $cn = $args[$i];
+ $chan = { CHAN => $cn };
+ splice (@args, $i, 1);
+ }
+ }
+
+ if ($chan eq '') {
+ notice ($user, "No channel given. The channel name \002must\002 include the # character.");
+ return;
+ }
+
+ if ($args[-1] =~ /\+/) { #expire time is last arguement
+ $expiry = pop @args;
+ $expiry = parse_time($expiry);
+ } else { #expire time is somewhere else (if given), get default expiry for now.
+ $get_bantime->execute($cn);
+ ($expiry) = $get_bantime->fetchrow_array();
+ $get_bantime->finish();
+ }
+
+ my @targets;
+
+ foreach my $arg (@args) {
+ if ($arg =~ /\,/) {
+ push @targets, split(/\,/, $arg);
+ next;
+ } else {
+ push @targets, $arg;
+ }
+ }
+
+ my $src = get_user_nick($user);
+
+ my ($bansref, $unbansref, $expires, $chan) = parse_bans ($user, $chan, '', \@targets, 1, $expiry);
+
+ if (!$bansref && !$unbansref) {
+ return;
+ }
+
+ tempban ($chan, $bansref, $expires);
+
+ 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);
}
sub cs_kick($$$;$$) {
my $cmd = ($ban ? 'KICKBAN' : 'KICK');
my $perm = ($ban ? 'BAN' : 'KICK');
-
- if(ref($chan) ne 'HASH' || !defined($chan->{CHAN})) {
+
+ if(ref($chan) ne 'HASH' || !defined($chan->{CHAN})) {
notice($user, "Invalid $cmd command, no channel specified");
return;
}
sub cs_ban($$$@) {
my ($user, $chan, $type, @targets) = @_;
- my $src = get_user_nick ($user);
+ my $src = get_user_nick ($user);
- my $cn = $chan->{CHAN};
-
- my ($bansref, $unbansref) = get_bans ($user, $chan, $type, \@targets);
-
- if (!$bansref && !$unbansref) {
- return;
- }
-
- my (@bans, @unbans) = (@$bansref, @$unbansref);
+ my $cn = $chan->{CHAN};
- ircd::ban_list(agent($chan), $cn, +1, 'b', @bans) if (scalar(@bans));
+ my ($bansref, $unbansref) = parse_bans ($user, $chan, $type, \@targets);
+
+ if (!$bansref && !$unbansref) {
+ return;
+ }
+
+ my (@bans, @unbans) = (@$bansref, @$unbansref);
+
+ ircd::ban_list(agent($chan), $cn, +1, 'b', @bans) if (scalar(@bans));
ircd::notice(agent($chan), $cn, "$src used BAN ".join(' ', @bans))
if (lc $user->{AGENT} eq lc $csnick) and (cr_chk_flag($chan, CRF_VERBOSE) and scalar(@bans));
cs_unban($user, $chan, @unbans) if scalar(@unbans);
}
sub cs_alist($$;$) {
- my ($user, $chan, $mask) = @_;
+ my ($user, $chan, $mask) = @_;
my $cn = $chan->{CHAN};
chk_registered($user, $chan) or return;
- my $slevel = get_best_acc($user, $chan);
+ my $slevel = get_best_acc($user, $chan);
can_do($chan, 'ACCLIST', $user, { ACC => $slevel }) or return;
} elsif(!(get_op($user, $chan2) & ($opmodes{o} | $opmodes{a} | $opmodes{q}))) {
# This would be preferred to be a 'opmode_mask' or something
# However that might be misleading due to hop not being enough to register
- notice($user, "You must have channel operator status to register \002$cn2\002.");
+ notice($user, "You must have channel operator status to register \002$cn2\002.");
return;
} else {
cs_copy_chan_all($user, $chan1, $chan2);