]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/UserDCC.pl
ignore case on autojoin
[infobot.git] / src / Modules / UserDCC.pl
index 6d19ac192837f096b1a58be5ebb7ee4f83c38c9c..0a3bbfd2e13c9788cb98e8d7e72f390986131da0 100644 (file)
@@ -5,7 +5,14 @@
 #     Created: 20000707 (from UserExtra.pl)
 #
 
-if (&IsParam("useStrict")) { use strict; }
+use strict;
+
+use vars qw(%users %ignore %sched %bans %mask %cache %channels %param
+       %chanconf %dcc);
+use vars qw($who $chan $message $msgType $user $chnick $conn $ident
+       $verifyUser $ucount_userfile $utime_userfile $lobotomized
+       $utime_chanfile $ucount_chanfile);
+use vars qw(@backlog);
 
 sub userDCC {
     # hrm...
@@ -15,29 +22,42 @@ sub userDCC {
     # quit.
     if ($message =~ /^(exit|quit)$/i) {
        # do ircII clients support remote close? if so, cool!
-       &status("userDCC: quit called. FIXME");
+       &FIXME("userDCC: quit called.");
        &dcc_close($who);
-       &status("hrmm....");
+       &status("userDCC: after dcc_close!");
 
        return;
     }
 
     # who.
     if ($message =~ /^who$/) {
-       my $count = scalar(keys %{$dcc{'CHAT'}});
+       my $count = scalar(keys %{ $dcc{'CHAT'} });
        my $dccCHAT = $message;
 
-       &pSReply("Start of who ($count users).");
-       foreach (keys %{$dcc{'CHAT'}}) {
-           &pSReply("=> $_");
+       &performStrictReply("Start of who ($count users).");
+       foreach (keys %{ $dcc{'CHAT'} }) {
+           &performStrictReply("=> $_");
        }
-       &pSReply("End of who.");
+       &performStrictReply("End of who.");
 
        return;
     }
 
     ### for those users with enough flags.
 
+    if ($message =~ /^tellme(\s+(.*))?$/i) {
+       my $args = $2;
+       if ($args =~ /^\s*$/) {
+           &help("tellme");
+           return;
+       }
+
+       my $result = &doQuestion($args);
+       &performStrictReply($result);
+
+       return;
+    }
+
     # 4op.
     if ($message =~ /^4op(\s+($mask{chan}))?$/i) {
        return unless (&hasFlag("o"));
@@ -64,10 +84,28 @@ sub userDCC {
        return;
     }
 
+    # opme.
+    if ($message =~ /^opme(\s+($mask{chan}))?$/i) {
+       return unless (&hasFlag("o"));
+       return unless (&hasFlag("A"));
+
+       my $chan = $2;
+
+       if ($chan eq "") {
+           &help("4op");
+           return;
+       }
+
+       # can this be exploited?
+       rawout("MODE $chan +o $who");
+
+       return;
+    }
+
     # backlog.
     if ($message =~ /^backlog(\s+(.*))?$/i) {
        return unless (&hasFlag("o"));
-       return unless (&hasParam("backlog"));
+       return unless (&IsParam("backlog"));
        my $num = $2;
        my $max = $param{'backlog'};
 
@@ -95,7 +133,7 @@ sub userDCC {
     # dump variables.
     if ($message =~ /^dumpvars$/i) {
        return unless (&hasFlag("o"));
-       return '' unless (&IsParam("dumpvars"));
+       return unless (&IsParam("DumpVars"));
 
        &status("Dumping all variables...");
        &dumpallvars();
@@ -103,15 +141,29 @@ sub userDCC {
        return;
     }
 
+    # dump variables ][.
+    if ($message =~ /^symdump$/i) {
+       return unless (&hasFlag('o'));
+       return unless (&IsParam('DumpVars2'));
+
+       &status("Dumping all variables...");
+       &symdumpAllFile();
+
+       return;
+    }
+
     # kick.
-    if ($message =~ /^kick(\s+(\S+)(\s+(\S+))?)?/) {
+    if ($message =~ /^kick(\s+(.*?))$/) {
        return unless (&hasFlag("o"));
-       my ($nick,$chan) = (lc $2,lc $4);
 
-       if ($nick eq "") {
+       my $arg = $2;
+
+       if ($arg eq "") {
            &help("kick");
            return;
        }
+       my @args = split(/\s+/, $arg);
+       my ($nick,$chan,$reason) = @args;
 
        if (&validChan($chan) == 0) {
            &msg($who,"error: invalid channel \002$chan\002");
@@ -123,14 +175,14 @@ sub userDCC {
            return;
        }
 
-       &kick($nick,$chan);
+       &kick($nick,$chan,$reason);
 
        return;
     }
 
-    # kick.
+    # mode.
     if ($message =~ /^mode(\s+(.*))?$/) {
-       return unless (&hasFlag("m"));
+       return unless (&hasFlag("n"));
        my ($chan,$mode) = split /\s+/,$2,2;
 
        if ($chan eq "") {
@@ -191,12 +243,16 @@ sub userDCC {
     # unlobotomy.
     if ($message =~ /^(unlobotomy|benoisy)$/i) {
        return unless (&hasFlag("o"));
+
        if ($lobotomized) {
            &performReply("i have been unlobotomized, woohoo");
            $lobotomized = 0;
+           delete $cache{lobotomy};
+#          undef $cache{lobotomy};     # ??
        } else {
            &performReply("i'm not lobotomized");
        }
+
        return;
     }
 
@@ -228,21 +284,20 @@ sub userDCC {
            next unless (&IsNickInChan($opee,$_));
            $found++;
            if ($channels{$_}{'o'}{$opee}) {
-               &status("op: $opee already has ops on $_");
+               &performStrictReply("op: $opee already has ops on $_");
                next;
            }
            $op++;
 
-           &status("opping $opee on $_ at ${who}'s request");
-           &pSReply("opping $opee on $_");
+           &performStrictReply("opping $opee on $_");
            &op($_, $opee);
        }
 
        if ($found != $op) {
-           &status("op: opped on all possible channels.");
+           &performStrictReply("op: opped on all possible channels.");
        } else {
-           &DEBUG("found => '$found'.");
-           &DEBUG("op => '$op'.");
+           &DEBUG("op: found => '$found'.");
+           &DEBUG("op:    op => '$op'.");
        }
 
        return;
@@ -299,13 +354,33 @@ sub userDCC {
     if ($message =~ s/^say\s+(\S+)\s+(.*)//) {
        return unless (&hasFlag("o"));
        my ($chan,$msg) = (lc $1, $2);
+
+       &DEBUG("chan => '$1', msg => '$msg'.");
+
+       # TODO: add nick destination.
+       if (&validChan($chan)) {
+           &msg($chan, $msg);
+       } else {
+           &msg($who,"i'm not on \002$chan\002, sorry.");
+       }
+
+       return;
+    }
+
+    # do.
+    if ($message =~ s/^do\s+(\S+)\s+(.*)//) {
+       return unless (&hasFlag("o"));
+       my ($chan,$msg) = (lc $1, $2);
+
        &DEBUG("chan => '$1', msg => '$msg'.");
 
+       # TODO: add nick destination.
        if (&validChan($chan)) {
-           &msg($chan, $2);
+           &action($chan, $msg);
        } else {
-           &msg($who,"i'm not on \002$1\002, sorry.");
+           &msg($who,"i'm not on \002$chan\002, sorry.");
        }
+
        return;
     }
 
@@ -331,7 +406,7 @@ sub userDCC {
            return;
        }
 
-       ### TODO: fix up $op to support mysql/pgsql/dbm(perl)
+       ### TODO: fix up $op to support mysql/sqlite/pgsql
        ### TODO: => add db/sql specific function to fix this.
        my @list = &searchTable("factoids", "factoid_key",
                        "factoid_value", $op);
@@ -402,7 +477,7 @@ sub userDCC {
        }
 
        &status("jumping servers... $server...");
-       &rawout("QUIT :jumping to $server");
+       $conn->quit("jumping to $server");
 
        if (&irc($server,$port) == 0) {
            &ircloop();
@@ -414,9 +489,36 @@ sub userDCC {
        return unless (&hasFlag("n"));
 
        &status("USER reload $who");
-       &pSReply("reloading...");
+       &performStrictReply("reloading...");
        &reloadAllModules();
-       &pSReply("reloaded.");
+       &performStrictReply("reloaded.");
+
+       return;
+    }
+
+    # reset.
+    if ($message =~ /^reset$/i) {
+       return unless (&hasFlag("n"));
+
+       &msg($who,"resetting...");
+       my @done;
+       foreach ( keys %channels, keys %chanconf ) {
+           my $c = $_;
+           next if (grep /^\Q$c\E$/i, @done);
+
+           &part($_);
+
+           push(@done, $_);
+           sleep 1;
+       }
+       &DEBUG("before clearircvars");
+       &clearIRCVars();
+       &DEBUG("before joinnextchan");
+       &joinNextChan();
+       &DEBUG("after joinnextchan");
+
+       &status("USER reset $who");
+       &msg($who,"reset complete");
 
        return;
     }
@@ -446,113 +548,110 @@ sub userDCC {
        }
 
        if (!exists $chanconf{$args[0]}) {
-           &pSReply("no such channel $args[0]");
+           &performStrictReply("no such channel $args[0]");
            return;
        }
 
-       &pSReply("showing channel conf.");
+       &performStrictReply("showing channel conf.");
        foreach (sort keys %{ $chanconf{$args[0]} }) {
-           &pSReply("$chan: $_ => $chanconf{$args[0]}{$_}");
+           &performStrictReply("$chan: $_ => $chanconf{$args[0]}{$_}");
        }
-       &pSReply("End of chaninfo.");
+       &performStrictReply("End of chaninfo.");
 
        return;
     }
 
     # +chan.
     if ($message =~ /^(chanset|\+chan)(\s+(.*?))?$/) {
-       my $cmd  = $1;
-       my $args = $3;
+       my $cmd         = $1;
+       my $args        = $3;
+       my $no_chan     = 0;
 
        if (!defined $args) {
            &help($cmd);
            return;
        }
 
-       my ($chan);
-       if ($args =~ s/^($mask{chan})\s*//) {
-           $chan       = $1;
-           &DEBUG("chan => $chan.");
-       } else {
-           &DEBUG("no chan arg; setting to default.");
-           $chan       = "_default";
-       }
-
-       my($what,$val) = split /[\s\t]+/, $args, 2;
-
-       ### TODO: "cannot set values without +m".
-       return unless (&hasFlag("m"));
-
-       if ($cmd eq "+chan") {
-           &DEBUG("setting _time_added...");
-           $chanconf{$chan}{_time_added}       = time();
-
-           &pSReply("Joining $chan...");
-           &joinchan($chan);
-
-           return;
+       my @chans;
+       while ($args =~ s/^($mask{chan})\s*//) {
+           push(@chans, lc($1));
        }
 
-       if (!exists $chanconf{$chan}) {
-           &pSReply("no such channel $chan");
-           return;
+       if (!scalar @chans) {
+           push(@chans, "_default");
+           $no_chan    = 1;
        }
 
-       my $update      = 0;
-       if ($what =~ /^\+(\S+)/) {
-           my $was     = $chanconf{$chan}{$1};
-           $was        = ($was) ? "; was '$was'" : "";
-           &pSReply("Setting $1 for $chan to '1'$was.");
-
-           $chanconf{$chan}{$1} = 1;
+       my($what,$val) = split /[\s\t]+/, $args, 2;
 
-           $update++;
-       } elsif ($what =~ /^\-(\S+)/) {
-           my $was     = $chanconf{$chan}{$1};
-           $was        = ($was) ? "; was '$was'" : "";
-           &pSReply("Setting $1 for $chan to '0'$was.");
+       ### TODO: "cannot set values without +m".
+       return unless (&hasFlag("n"));
 
-           $chanconf{$chan}{$1} = 0;
+       # READ ONLY.
+       if (defined $what and $what !~ /^[-+]/ and !defined $val and $no_chan) {
+           &performStrictReply("Showing $what values on all channels...");
 
-           $update++;
-       } elsif (defined $val) {
-           my $was     = $chanconf{$chan}{$what};
-           $was        = ($was) ? "; was '$was'" : "";
-           &pSReply("Setting $what for $chan to '$val'$was.");
+           my %vals;
+           foreach (keys %chanconf) {
+               my $val;
+               if (defined $chanconf{$_}{$what}) {
+                   $val = $chanconf{$_}{$what};
+               } else {
+                   $val = "NOT-SET";
+               }
+               $vals{$val}{$_} = 1;
+           }
 
-           $chanconf{$chan}{$what} = $val;
+           foreach (keys %vals) {
+               &performStrictReply("  $what = $_(" . scalar(keys %{$vals{$_}}) . "): ".join(' ', sort keys %{ $vals{$_} } ) );
+           }
 
-           $update++;
-       } elsif (defined $what) {
-           &pSReply("$what for $chan is '$chanconf{$chan}{$what}'");
-       }
+           &performStrictReply("End of list.");
 
-       if ($update) {
-           $utime_chanfile = time();
-           $ucount_chanfile++;
            return;
        }
 
+       ### TODO: move to UserDCC again.
        if ($cmd eq "chanset" and !defined $what) {
            &DEBUG("showing channel conf.");
 
-           foreach $chan ($chan, "_default") {
-               &pSReply("chan: $chan");
-               ### TODO: merge 2 or 3 per line.
+           foreach $chan (@chans) {
+               if ($chan eq '_default') {
+                   &performStrictReply("Default channel settings");
+               } else {
+                   &performStrictReply("chan: $chan (see _default also)");
+               }
+               my @items;
+               my $str = "";
                foreach (sort keys %{ $chanconf{$chan} }) {
-                   &pSReply("    $_ => $chanconf{$chan}{$_}");
+                   my $newstr = join(', ', @items);
+                   ### TODO: make length use channel line limit?
+                   if (length $newstr > 370) {
+                       &performStrictReply(" $str");
+                       @items = ();
+                   }
+                   $str = $newstr;
+                   push(@items, "$_ => $chanconf{$chan}{$_}");
                }
+               &performStrictReply(" $str") if (@items);
            }
-
            return;
        }
 
+       $cache{confvars}{$what} = $val;
+       &rehashConfVars();
+
+       foreach (@chans) {
+           &chanSet($cmd, $_, $what, $val);
+       }
+
        return;
     }
 
     if ($message =~ /^(chanunset|\-chan)(\s+(.*))?$/) {
-       return unless (&hasFlag("m"));
+       return unless (&hasFlag("n"));
        my $args        = $3;
+       my $no_chan     = 0;
 
        if (!defined $args) {
            &help("chanunset");
@@ -564,45 +663,95 @@ sub userDCC {
        if ($args =~ s/^(\-)?($mask{chan})\s*//) {
            $chan       = $2;
            $delete     = ($1) ? 1 : 0;
-           &DEBUG("chan => $chan.");
        } else {
-           &DEBUG("no chan arg; setting to default.");
+           &VERB("no chan arg; setting to default.",2);
            $chan       = "_default";
+           $no_chan    = 1;
        }
 
        if (!exists $chanconf{$chan}) {
-           &pSReply("no such channel $chan");
+           &performStrictReply("no such channel $chan");
            return;
        }
 
        if ($args ne "") {
-           if (&getChanConf($args,$chan)) {
-               &pSReply("Unsetting channel ($chan) option $args. (was $chanconf{$chan}{$args})");
-               undef $chanconf{$chan}{$args};
 
-           } else {
-               &pSReply("$args does not exist for $chan");
+           if (!&getChanConf($args,$chan)) {
+               &performStrictReply("$args does not exist for $chan");
+               return;
+           }
+
+           my @chans = &ChanConfList($args);
+           &DEBUG("scalar chans => ".scalar(@chans) );
+           if (scalar @chans == 1 and $chans[0] eq "_default" and !$no_chan) {
+               &performStrictReply("ok, $args was set only for _default; unsetting for _defaul but setting for other chans.");
+
+               my $val = $chanconf{$_}{_default};
+               foreach (keys %chanconf) {
+                   $chanconf{$_}{$args} = $val;
+               }
+               delete $chanconf{_default}{$args};
+               $cache{confvars}{$args} = 0;
+               &rehashConfVars();
+
+               return;
+           }
+
+           if ($no_chan and !exists($chanconf{_default}{$args})) {
+               &performStrictReply("ok, $args for _default does not exist, removing from all chans.");
+
+               foreach (keys %chanconf) {
+                   next unless (exists $chanconf{$_}{$args});
+                   &DEBUG("delete chanconf{$_}{$args};");
+                   delete $chanconf{$_}{$args};
+               }
+               $cache{confvars}{$args} = 0;
+               &rehashConfVars();
+
+               return;
            }
 
+           &performStrictReply("Unsetting channel ($chan) option $args. (was $chanconf{$chan}{$args})");
+           delete $chanconf{$chan}{$args};
+
            return;
        }
 
        if ($delete) {
-           &pSReply("Deleting channel $chan for sure!");
+           &performStrictReply("Deleting channel $chan for sure!");
            $utime_chanfile = time();
            $ucount_chanfile++;
 
            &part($chan);
-           &pSReply("Leaving $chan...");
+           &performStrictReply("Leaving $chan...");
 
            delete $chanconf{$chan};
        } else {
-           &pSReply("Prefix channel with '-' to delete for sure.");
+           &performStrictReply("Prefix channel with '-' to delete for sure.");
        }
 
        return;
     }
 
+    if ($message =~ /^newpass(\s+(.*))?$/) {
+       my(@args) = split /[\s\t]+/, $2 || '';
+
+       if (scalar @args != 1) {
+           &help("newpass");
+           return;
+       }
+
+       my $u = &getUser($who);
+       my $crypt = &mkcrypt($args[0]);
+
+       &performStrictReply("Set your passwd to '$crypt'");
+       $users{$u}{PASS} = $crypt;
+
+       $utime_userfile = time();
+       $ucount_userfile++;
+
+       return;
+    }
 
     if ($message =~ /^chpass(\s+(.*))?$/) {
        my(@args) = split /[\s\t]+/, $2 || '';
@@ -613,24 +762,29 @@ sub userDCC {
        }
 
        if (!&IsUser($args[0])) {
-           &pSReply("user $args[0] is not valid.");
+           &performStrictReply("user $args[0] is not valid.");
            return;
        }
 
-       my $u = &getUser($who);
+       my $u = &getUser($args[0]);
+       if (!defined $u) {
+           &performStrictReply("Internal error, u = NULL.");
+           return;
+       }
 
-       if (scalar @args == 1) {        # del pass.
-           if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
-               &pSReply("cannto remove passwd of others.");
+       if (scalar @args == 1) {
+           # del pass.
+           if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
+               &performStrictReply("cannot remove passwd of others.");
                return;
            }
 
            if (!exists $users{$u}{PASS}) {
-               &pSReply("$u does not have pass set anyway.");
+               &performStrictReply("$u does not have pass set anyway.");
                return;
            }
 
-           &pSReply("Deleted pass from $u.");
+           &performStrictReply("Deleted pass from $u.");
 
            $utime_userfile = time();
            $ucount_userfile++;
@@ -640,9 +794,8 @@ sub userDCC {
            return;
        }
 
-       my $salt = join '',('.','/',0..9,'A'..'Z','a'..'z')[rand 64, rand 64];
-       my $crypt = crypt($args[1], $salt);
-       &pSReply("Set $u's passwd to '$crypt'");
+       my $crypt       = &mkcrypt($args[1]);
+       &performStrictReply("Set $u's passwd to '$crypt'");
        $users{$u}{PASS} = $crypt;
 
        $utime_userfile = time();
@@ -659,11 +812,14 @@ sub userDCC {
            return;
        }
 
+       my $chflag;
        my $user;
-       if ($args[0] =~ /^$mask{nick}$/i) {     # <nick>
+       if ($args[0] =~ /^$mask{nick}$/i) {
+           # <nick>
            $user       = &getUser($args[0]);
            $chflag     = $args[1];
-       } else {                                # <flags>
+       } else {
+           # <flags>
            $user       = &getUser($who);
            &DEBUG("user $who... nope.") unless (defined $user);
            $user       = &getUser($verifyUser);
@@ -671,20 +827,20 @@ sub userDCC {
        }
 
        if (!defined $user) {
-           &pSReply("user $user does not exist.");
+           &performStrictReply("user does not exist.");
            return;
        }
 
        my $flags = $users{$user}{FLAGS};
        if (!defined $chflag) {
-           &pSReply("Flags for $user: $flags");
+           &performStrictReply("Flags for $user: $flags");
            return;
        }
 
        &DEBUG("who => $who");
        &DEBUG("verifyUser => $verifyUser");
-       if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
-           &pSReply("cannto change attributes of others.");
+       if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
+           &performStrictReply("cannto change attributes of others.");
            return "REPLY";
        }
 
@@ -695,7 +851,7 @@ sub userDCC {
            if ($_ eq "-") { $state = 0; next; }
 
            if (!defined $state) {
-               &pSReply("no initial + or - was found in attr.");
+               &performStrictReply("no initial + or - was found in attr.");
                return;
            }
 
@@ -707,7 +863,7 @@ sub userDCC {
                        and $param{owner} =~ /^\Q$user\E$/i
                        and $flags =~ /[nmo]/
                ) {
-                   &pSReply("not removing flag $_ for $user.");
+                   &performStrictReply("not removing flag $_ for $user.");
                    next;
                }
                next unless ($flags =~ s/\Q$_\E//);
@@ -719,10 +875,12 @@ sub userDCC {
        if ($change) {
            $utime_userfile = time();
            $ucount_userfile++;
-           &pSReply("Current flags: $flags");
+           #$flags.*FLAGS sort
+           $flags = join('', sort split('', $flags));
+           &performStrictReply("Current flags: $flags");
            $users{$user}{FLAGS} = $flags;
        } else {
-           &pSReply("No flags changed: $flags");
+           &performStrictReply("No flags changed: $flags");
        }
 
        return;
@@ -752,22 +910,22 @@ sub userDCC {
        }
 
        if (!defined $user) {
-           &pSReply("user $who or $args[0] does not exist.");
+           &performStrictReply("user $who or $args[0] does not exist.");
            return;
        }
 
        if ($user =~ /^\Q$chnick\E$/i) {
-           &pSReply("user == chnick. why should I do that?");
+           &performStrictReply("user == chnick. why should I do that?");
            return;
        }
 
        if (&getUser($chnick)) {
-           &pSReply("user $chnick is already used!");
+           &performStrictReply("user $chnick is already used!");
            return;
        }
 
-       if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
-           &pSReply("cannto change nick of others.");
+       if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
+           &performStrictReply("cannto change nick of others.");
            return "REPLY" if ($who eq "_default");
            return;
        }
@@ -781,7 +939,7 @@ sub userDCC {
        $utime_userfile = time();
        $ucount_userfile++;
 
-       &pSReply("Changed '$user' to '$chnick' successfully.");
+       &performStrictReply("Changed '$user' to '$chnick' successfully.");
 
        return;
     }
@@ -803,54 +961,52 @@ sub userDCC {
 
        my ($user,$mask);
        if ($args[0] =~ /^$mask{nick}$/i) {     # <nick>
-           return unless (&hasFlag("m"));
+           return unless (&hasFlag("n"));
            $user       = &getUser($args[0]);
            $mask       = $args[1];
        } else {                                # <mask>
-           # who or verifyUser. FIXME!!!
+           # FIXME: who or verifyUser. (don't remember why)
            $user       = &getUser($who);
            $mask       = $args[0];
        }
 
        if (!defined $user) {
-           &pSReply("user $user does not exist.");
+           &performStrictReply("user $user does not exist.");
            return;
        }
 
        if (!defined $mask) {
-           ### FIXME.
-           &pSReply("Hostmasks for $user: $users{$user}{HOSTS}");
-
+           &performStrictReply("Hostmasks for $user: " . join(" ", keys %{$users{$user}{HOSTS}}));
            return;
        }
 
-       if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
-           &pSReply("cannto change masks of others.");
-           return;
-       }
-
-       if ($mask !~ /^$mask{nuh}$/) {
-           &pSReply("error: mask ($mask) is not a real hostmask.");
+       if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
+           &performStrictReply("cannto change masks of others.");
            return;
        }
 
        my $count = scalar keys %{ $users{$user}{HOSTS} };
 
        if ($state) {                           # add.
+           if ($mask !~ /^$mask{nuh}$/) {
+               &performStrictReply("error: mask ($mask) is not a real hostmask.");
+               return;
+           }
+
            if (exists $users{$user}{HOSTS}{$mask}) {
-               &pSReply("mask $mask already exists.");
+               &performStrictReply("mask $mask already exists.");
                return;
            }
 
            ### TODO: override support.
            $users{$user}{HOSTS}{$mask} = 1;
 
-           &pSReply("Added $mask to list of masks.");
+           &performStrictReply("Added $mask to list of masks.");
 
        } else {                                # delete.
 
            if (!exists $users{$user}{HOSTS}{$mask}) {
-               &pSReply("mask $mask does not exist.");
+               &performStrictReply("mask $mask does not exist.");
                return;
            }
 
@@ -858,9 +1014,9 @@ sub userDCC {
            delete $users{$user}{HOSTS}{$mask};
 
            if (scalar keys %{ $users{$user}{HOSTS} } != $count) {
-               &pSReply("Removed $mask from list of masks.");
+               &performStrictReply("Removed $mask from list of masks.");
            } else {
-               &pSReply("error: could not find $mask in list of masks.");
+               &performStrictReply("error: could not find $mask in list of masks.");
                return;
            }
        }
@@ -897,12 +1053,16 @@ sub userDCC {
        }
 
        if ($state == 0) {              # delete.
-           my $c = join(' ', &banDel($mask) );
+           my @c = &banDel($mask);
 
-           if ($c) {
-               &pSReply("Removed $mask from chans: $c");
+           foreach (@c) {
+               &unban($mask, $_);
+           }
+
+           if (@c) {
+               &performStrictReply("Removed $mask from chans: @c");
            } else {
-               &pSReply("$mask was not found in ban list.");
+               &performStrictReply("$mask was not found in ban list.");
            }
 
            return;
@@ -917,7 +1077,7 @@ sub userDCC {
            $time = $1;
            &DEBUG("time = $time.");
            if ($time < 0) {
-               &pSReply("error: time cannot be negatime?");
+               &performStrictReply("error: time cannot be negatime?");
                return;
            }
        } else {
@@ -928,20 +1088,20 @@ sub userDCC {
            $reason     = $1;
        }
 
-       if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
-           &pSReply("cannto change masks of others.");
+       if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
+           &performStrictReply("cannto change masks of others.");
            return;
        }
 
        if ($mask !~ /^$mask{nuh}$/) {
-           &pSReply("error: mask ($mask) is not a real hostmask.");
+           &performStrictReply("error: mask ($mask) is not a real hostmask.");
            return;
        }
 
        if ( &banAdd($mask,$chan,$time,$reason) == 2) {
-           &pSReply("ban already exists; overwriting.");
+           &performStrictReply("ban already exists; overwriting.");
        }
-       &pSReply("Added $mask for $chan (time => $time, reason => $reason)");
+       &performStrictReply("Added $mask for $chan (time => $time, reason => $reason)");
 
        return;
     }
@@ -956,12 +1116,12 @@ sub userDCC {
 
        my $user = &getUser($arg);
        if (!defined $user) {
-           &pSReply("whois: user $user does not exist.");
+           &performStrictReply("whois: user $user does not exist.");
            return;
        }
 
        ### TODO: better (eggdrop-like) output.
-       &pSReply("user: $user");
+       &performStrictReply("user: $user");
        foreach (keys %{ $users{$user} }) {
            my $ref = ref $users{$user}{$_};
 
@@ -969,14 +1129,14 @@ sub userDCC {
                my $type = $_;
                ### DOES NOT WORK???
                foreach (keys %{ $users{$user}{$type} }) {
-                   &pSReply("    $type => $_");
+                   &performStrictReply("    $type => $_");
                }
                next;
            }
 
-           &pSReply("    $_ => $users{$user}{$_}");
+           &performStrictReply("    $_ => $users{$user}{$_}");
        }
-       &pSReply("End of USER whois.");
+       &performStrictReply("End of USER whois.");
 
        return;
     }
@@ -986,34 +1146,34 @@ sub userDCC {
 
        if (defined $arg) {
            if ($arg ne "_default" and !&validChan($arg) ) {
-               &pSReply("error: chan $chan is invalid.");
+               &performStrictReply("error: chan $chan is invalid.");
                return;
            }
        }
 
        if (!scalar keys %bans) {
-           &pSReply("Ban list is empty.");
+           &performStrictReply("Ban list is empty.");
            return;
        }
 
        my $c;
-       &pSReply("      expire, count, who-by, time-added, reason");
+       &performStrictReply("     mask: expire, time-added, count, who-by, reason");
        foreach $c (keys %bans) {
            next unless (!defined $arg or $arg =~ /^\Q$c\E$/i);
-           &pSReply("  $c:");
+           &performStrictReply("  $c:");
 
            foreach (keys %{ $bans{$c} }) {
                my $val = $bans{$c}{$_};
 
                if (ref $val eq "ARRAY") {
                    my @array = @{ $val };
-                   &pSReply("      @array");
+                   &performStrictReply("    $_: @array");
                } else {
                    &DEBUG("unknown ban: $val");
                }
            }
        }
-       &pSReply("END of bans.");
+       &performStrictReply("END of bans.");
 
        return;
     }
@@ -1021,8 +1181,8 @@ sub userDCC {
     if ($message =~ /^banlist(\s+(.*))?$/) {
        my $arg = $2;
 
-       if (defined $arg and $arg !~ /^$mask_chan$/) {
-           &pSReply("error: chan $chan is invalid.");
+       if (defined $arg and $arg !~ /^$mask{chan}$/) {
+           &performStrictReply("error: chan $chan is invalid.");
            return;
        }
 
@@ -1032,7 +1192,7 @@ sub userDCC {
        }
 
        &DEBUG("End of bans.");
-       &pSReply("END of bans.");
+       &performStrictReply("END of bans.");
 
        return;
     }
@@ -1042,6 +1202,7 @@ sub userDCC {
 
        &writeUserFile();
        &writeChanFile();
+       &performStrictReply("saved user and chan files");
 
        return;
     }
@@ -1074,9 +1235,9 @@ sub userDCC {
 
        if (!$state) {                  # delignore.
            if ( &ignoreDel($mask) ) {
-               &pSReply("ok, deleted X ignores.");
+               &performStrictReply("ok, deleted ignores for $mask.");
            } else {
-               &pSReply("could not find $mask in ignore list.");
+               &performStrictReply("could not find $mask in ignore list.");
            }
            return;
        }
@@ -1094,7 +1255,7 @@ sub userDCC {
 
        # time.
        if ($args =~ s/^(\d+)\s*//) {
-           $time = $1*60;      # ??
+           $time = $1; # time is in minutes
        } else {
            $time = 0;
        }
@@ -1107,9 +1268,9 @@ sub userDCC {
        }
 
        if ( &ignoreAdd($mask, $chan, $time, $comment) > 1) {
-           &pSReply("warn: $mask already in ignore list; written over anyway. FIXME");
+           &performStrictReply("FIXME: $mask already in ignore list; written over anyway.");
        } else {
-           &pSReply("added $mask to ignore list.");
+           &performStrictReply("added $mask to ignore list.");
        }
 
        return;
@@ -1120,91 +1281,112 @@ sub userDCC {
 
        if (defined $arg) {
            if ($arg !~ /^$mask{chan}$/) {
-               &pSReply("error: chan $chan is invalid.");
+               &performStrictReply("error: chan $chan is invalid.");
                return;
            }
 
            if (!&validChan($arg)) {
-               &pSReply("error: chan $arg is invalid.");
+               &performStrictReply("error: chan $arg is invalid.");
                return;
            }
 
-           &pSReply("Showing bans for $arg only.");
+           &performStrictReply("Showing bans for $arg only.");
        }
 
        if (!scalar keys %ignore) {
-           &pSReply("Ignore list is empty.");
+           &performStrictReply("Ignore list is empty.");
            return;
        }
 
        ### TODO: proper (eggdrop-like) formatting.
        my $c;
-       &pSReply("    expire, count, who, added, comment");
+       &performStrictReply("    mask: expire, time-added, who, comment");
        foreach $c (keys %ignore) {
            next unless (!defined $arg or $arg =~ /^\Q$c\E$/i);
-           &pSReply("  $c:");
+           &performStrictReply("  $c:");
 
            foreach (keys %{ $ignore{$c} }) {
                my $ref = ref $ignore{$c}{$_};
                if ($ref eq "ARRAY") {
                    my @array = @{ $ignore{$c}{$_} };
-                   &pSReply("      $_: @array");
+                   &performStrictReply("      $_: @array");
                } else {
                    &DEBUG("unknown ignore line?");
                }
            }
        }
-       &pSReply("END of ignore.");
+       &performStrictReply("END of ignore.");
 
        return;
     }
 
     # adduser/deluser.
-    if ($message =~ /^(\+|\-|add|del)user(\s+(.*))?$/i) {
+    if ($message =~ /^(add|del)user(\s+(.*))?$/i) {
        my $str         = $1;
        my $strstr      = $1."user";
        my @args        = split /\s+/, $3 || '';
        my $args        = $3;
-       my $state       = ($str =~ /^(\+|add)$/) ? 1 : 0;
+       my $state       = ($str =~ /^(add)$/) ? 1 : 0;
 
        if (!scalar @args) {
            &help($strstr);
            return;
        }
 
-       if ($str eq "+") {
+       if ($str eq 'add') {
            if (scalar @args != 2) {
-               &pSReply(".+host requires hostmask argument.");
+               &performStrictReply('adduser requires hostmask argument.');
                return;
            }
        } elsif (scalar @args != 1) {
-           &pSReply("too many arguments.");
+           &performStrictReply('too many arguments.');
            return;
        }
 
-       if ($state) {                   # adduser.
+       if ($state) {
+           # adduser.
            if (scalar @args == 1) {
                $args[1]        = &getHostMask($args[0]);
-               if (!defined $args[1]) {
-                   &ERROR("could not get hostmask?");
-                   return;
-               }
+               &performStrictReply("Attemping to guess $args[0]'s hostmask...");
+
+               # crude hack... crappy Net::IRC
+               $conn->schedule(5, sub {
+                   # hopefully this is right.
+                   my $nick = (keys %{ $cache{nuhInfo} })[0];
+                   if (!defined $nick) {
+                       &performStrictReply("couldn't get nuhinfo... adding user without a hostmask.");
+                       &userAdd($nick);
+                       return;
+                   }
+                   my $mask = &makeHostMask( $cache{nuhInfo}{$nick}{NUH} );
+
+                   if ( &userAdd($nick, $mask) ) {
+                       # success.
+                       &performStrictReply("Added $nick with flags $users{$nick}{FLAGS}");
+                       my @hosts = keys %{ $users{$nick}{HOSTS} };
+                       &performStrictReply("hosts: @hosts");
+                   }
+               });
+               return;
            }
 
+           &DEBUG("args => @args");
            if ( &userAdd(@args) ) {    # success.
-               &pSReply("Added $args[0]...");
+               &performStrictReply("Added $args[0] with flags $users{$args[0]}{FLAGS}");
+               my @hosts = keys %{ $users{$args[0]}{HOSTS} };
+               &performStrictReply("hosts: @hosts");
 
            } else {                    # failure.
-               &pSReply("User $args[0] already exists");
+               &performStrictReply("User $args[0] already exists");
            }
 
        } else {                        # deluser.
 
            if ( &userDel($args[0]) ) { # success.
-               &pSReply("Deleted $args[0] successfully.");
+               &performStrictReply("Deleted $args[0] successfully.");
 
            } else {                    # failure.
-               &pSReply("User $args[0] does not exist.");
+               &performStrictReply("User $args[0] does not exist.");
            }
 
        }
@@ -1214,17 +1396,40 @@ sub userDCC {
     if ($message =~ /^sched$/) {
        my @list;
        my @run;
+
+       my %time;
        foreach (keys %sched) {
            next unless (exists $sched{$_}{TIME});
+           $time{ $sched{$_}{TIME}-time() }{$_} = 1;
            push(@list,$_);
 
            next unless (exists $sched{$_}{RUNNING});
            push(@run,$_);
        }
 
-       &pSReply( &formListReply(0,"Scheds to run: ", sort @list ) );
-       &pSReply( &formListReply(0, "Scheds running(should not happen?) ", sort @run ) );
+       my @time;
+       foreach (sort { $a <=> $b } keys %time) {
+           my $str = join(", ", sort keys %{ $time{$_} });
+           &DEBUG("time => $_, str => $str");
+           push(@time, "$str (".&Time2String($_).")");
+       }
+
+       &performStrictReply( &formListReply(0, "Schedulers: ", @time ) );
+       &performStrictReply( &formListReply(0, "Scheds to run: ", sort @list ) );
+       &performStrictReply( &formListReply(0, "Scheds running(should not happen?) ", sort @run ) );
+
+       return;
+    }
+
+    # quite a cool hack: reply in DCC CHAT.
+    $msgType = "chat" if (exists $dcc{'CHAT'}{$who});
+
+    my $done = 0;
+    $done++ if &parseCmdHook($message);
+    $done++ unless (&Modules());
 
+    if ($done) {
+       &DEBUG("running non DCC CHAT command inside DCC CHAT!");
        return;
     }