2 # UserDCC.pl: User Commands, DCC CHAT.
4 # Version: v0.2 (20010119)
5 # Created: 20000707 (from UserExtra.pl)
10 use vars qw(%users %ignore %sched %bans %mask %cache %channels %param
12 use vars qw($who $chan $message $msgType $user $chnick $conn $ident
13 $verifyUser $ucount_userfile $utime_userfile $lobotomized
14 $utime_chanfile $ucount_chanfile);
15 use vars qw(@backlog);
23 if ($message =~ /^(exit|quit)$/i) {
24 # do ircII clients support remote close? if so, cool!
25 &status("userDCC: quit called. FIXME");
27 &status("userDCC: after dcc_close!");
33 if ($message =~ /^who$/) {
34 my $count = scalar(keys %{ $dcc{'CHAT'} });
35 my $dccCHAT = $message;
37 &pSReply("Start of who ($count users).");
38 foreach (keys %{ $dcc{'CHAT'} }) {
41 &pSReply("End of who.");
46 ### for those users with enough flags.
48 if ($message =~ /^tellme(\s+(.*))?$/i) {
50 if ($args =~ /^\s*$/) {
55 my $result = &doQuestion($args);
62 if ($message =~ /^4op(\s+($mask{chan}))?$/i) {
63 return unless (&hasFlag("o"));
72 if (!$channels{$chan}{'o'}{$ident}) {
73 &msg($who, "i don't have ops on $chan to do that.");
77 # on non-4mode(<4) servers, this may be exploited.
78 if ($channels{$chan}{'o'}{$who}) {
79 rawout("MODE $chan -o+o-o+o". (" $who" x 4));
81 rawout("MODE $chan +o-o+o-o". (" $who" x 4));
88 if ($message =~ /^backlog(\s+(.*))?$/i) {
89 return unless (&hasFlag("o"));
90 return unless (&hasParam("backlog"));
92 my $max = $param{'backlog'};
97 } elsif ($num !~ /^\d+/) {
98 &msg($who, "error: argument is not positive integer.");
100 } elsif ($num > $max or $num < 0) {
101 &msg($who, "error: argument is out of range (max $max).");
105 &msg($who, "Start of backlog...");
107 sleep 1 if ($_ % 4 == 0 and $_ != 0);
108 $conn->privmsg($who, "[".($_+1)."]: $backlog[$max-$num+$_]");
110 &msg($who, "End of backlog.");
116 if ($message =~ /^dumpvars$/i) {
117 return unless (&hasFlag("o"));
118 return unless (&IsParam("dumpvars"));
120 &status("Dumping all variables...");
127 if ($message =~ /^symdump$/i) {
128 return unless (&hasFlag("o"));
129 return unless (&IsParam("symdump"));
131 &status("Dumping all variables...");
138 if ($message =~ /^kick(\s+(.*?))$/) {
139 return unless (&hasFlag("o"));
147 my @args = split(/\s+/, $arg);
148 my ($nick,$chan,$reason) = @args;
150 if (&validChan($chan) == 0) {
151 &msg($who,"error: invalid channel \002$chan\002");
155 if (&IsNickInChan($nick,$chan) == 0) {
156 &msg($who,"$nick is not in $chan.");
160 &kick($nick,$chan,$reason);
166 if ($message =~ /^mode(\s+(.*))?$/) {
167 return unless (&hasFlag("n"));
168 my ($chan,$mode) = split /\s+/,$2,2;
175 if (&validChan($chan) == 0) {
176 &msg($who,"error: invalid channel \002$chan\002");
180 if (!$channels{$chan}{o}{$ident}) {
181 &msg($who,"error: don't have ops on \002$chan\002");
191 if ($message =~ /^part(\s+(\S+))?$/i) {
192 return unless (&hasFlag("o"));
195 if ($jchan !~ /^$mask{chan}$/) {
196 &msg($who, "error, invalid chan.");
201 if (!&validChan($jchan)) {
202 &msg($who, "error, I'm not on that chan.");
206 &msg($jchan, "Leaving. (courtesy of $who).");
211 # lobotomy. sometimes we want the bot to be _QUIET_.
212 if ($message =~ /^(lobotomy|bequiet)$/i) {
213 return unless (&hasFlag("o"));
216 &performReply("i'm already lobotomized");
218 &performReply("i have been lobotomized");
226 if ($message =~ /^(unlobotomy|benoisy)$/i) {
227 return unless (&hasFlag("o"));
230 &performReply("i have been unlobotomized, woohoo");
232 delete $cache{lobotomy};
233 # undef $cache{lobotomy}; # ??
235 &performReply("i'm not lobotomized");
242 if ($message =~ /^op(\s+(.*))?$/i) {
243 return unless (&hasFlag("o"));
248 if ($opee =~ /^(\S+)\s+(\S+)$/) {
251 if (!&validChan($2)) {
252 &msg($who,"error: invalid chan ($2).");
256 &msg($who,"error: invalid params.");
260 @chans = keys %channels;
266 next unless (&IsNickInChan($opee,$_));
268 if ($channels{$_}{'o'}{$opee}) {
269 &pSReply("op: $opee already has ops on $_");
274 &pSReply("opping $opee on $_");
279 &pSReply("op: opped on all possible channels.");
281 &DEBUG("op: found => '$found'.");
282 &DEBUG("op: op => '$op'.");
289 if ($message =~ /^deop(\s+(.*))?$/i) {
290 return unless (&hasFlag("o"));
295 if ($opee =~ /^(\S+)\s+(\S+)$/) {
298 if (!&validChan($2)) {
299 &msg($who,"error: invalid chan ($2).");
303 &msg($who,"error: invalid params.");
307 @chans = keys %channels;
313 next unless (&IsNickInChan($opee,$_));
315 if (!exists $channels{$_}{'o'}{$opee}) {
316 &status("deop: $opee already has no ops on $_");
321 &status("deopping $opee on $_ at ${who}'s request");
326 &status("deop: deopped on all possible channels.");
328 &DEBUG("deop: found => '$found'.");
329 &DEBUG("deop: op => '$op'.");
336 if ($message =~ s/^say\s+(\S+)\s+(.*)//) {
337 return unless (&hasFlag("o"));
338 my ($chan,$msg) = (lc $1, $2);
339 &DEBUG("chan => '$1', msg => '$msg'.");
341 if (&validChan($chan)) {
344 &msg($who,"i'm not on \002$chan\002, sorry.");
350 if ($message =~ /^die$/) {
351 return unless (&hasFlag("n"));
355 &status("Dying by $who\'s request");
359 # global factoid substitution.
360 if ($message =~ m|^s([/,#])(.+?)\1(.*?)\1;?\s*$|) {
361 my ($delim,$op,$np) = ($1, $2, $3);
362 return unless (&hasFlag("n"));
363 ### TODO: support flags to do full-on global.
366 if ($np =~ /$delim/) {
367 &performReply("looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
371 ### TODO: fix up $op to support mysql/sqlite/pgsql
372 ### TODO: => add db/sql specific function to fix this.
373 my @list = &searchTable("factoids", "factoid_key",
374 "factoid_value", $op);
377 &performReply("Expression didn't match anything.");
381 if (scalar @list > 100) {
382 &performReply("regex found more than 100 matches... not doing.");
386 &status("gsubst: going to alter ".scalar(@list)." factoids.");
387 &performReply("going to alter ".scalar(@list)." factoids.");
393 next if (&IsLocked($faqtoid) == 1);
394 my $result = &getFactoid($faqtoid);
396 &DEBUG("was($faqtoid) => '$was'.");
399 # we could support global local (once off).
400 if ($result =~ s/\Q$op/$np/gi) {
401 if (length $result > $param{'maxDataSize'}) {
402 &performReply("that's too long (or was long)");
405 &setFactInfo($faqtoid, "factoid_value", $result);
406 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
408 &WARN("subst: that's weird... thought we found the string ($op) in '$faqtoid'.");
414 &ERROR("Some warnings/errors?");
417 &performReply("Ok... did s/$op/$np/ for ".
418 (scalar(@list) - $error)." factoids");
424 if ($message =~ /^jump(\s+(\S+))?$/i) {
425 return unless (&hasFlag("n"));
433 if ($2 =~ /^(\S+)(:(\d+))?$/) {
437 &msg($who,"invalid format.");
441 &status("jumping servers... $server...");
442 $conn->quit("jumping to $server");
444 if (&irc($server,$port) == 0) {
450 if ($message =~ /^reload$/i) {
451 return unless (&hasFlag("n"));
453 &status("USER reload $who");
454 &pSReply("reloading...");
456 &pSReply("reloaded.");
462 if ($message =~ /^reset$/i) {
463 return unless (&hasFlag("n"));
465 &msg($who,"resetting...");
467 foreach ( keys %channels, keys %chanconf ) {
469 next if (grep /^\Q$c\E$/i, @done);
476 &DEBUG("before clearircvars");
478 &DEBUG("before joinnextchan");
480 &DEBUG("after joinnextchan");
482 &status("USER reset $who");
483 &msg($who,"resetted");
489 if ($message =~ /^rehash$/) {
490 return unless (&hasFlag("n"));
492 &msg($who,"rehashing...");
494 &status("USER rehash $who");
495 &msg($who,"rehashed");
501 ##### USER//CHAN SPECIFIC CONFIGURATION COMMANDS
504 if ($message =~ /^chaninfo(\s+(.*))?$/) {
505 my @args = split /[\s\t]+/, $2; # hrm.
507 if (scalar @args != 1) {
512 if (!exists $chanconf{$args[0]}) {
513 &pSReply("no such channel $args[0]");
517 &pSReply("showing channel conf.");
518 foreach (sort keys %{ $chanconf{$args[0]} }) {
519 &pSReply("$chan: $_ => $chanconf{$args[0]}{$_}");
521 &pSReply("End of chaninfo.");
527 if ($message =~ /^(chanset|\+chan)(\s+(.*?))?$/) {
532 if (!defined $args) {
538 while ($args =~ s/^($mask{chan})\s*//) {
539 push(@chans, lc($1));
542 if (!scalar @chans) {
543 push(@chans, "_default");
547 my($what,$val) = split /[\s\t]+/, $args, 2;
549 ### TODO: "cannot set values without +m".
550 return unless (&hasFlag("n"));
553 if (defined $what and $what !~ /^[-+]/ and !defined $val and $no_chan) {
554 &pSReply("Showing $what values on all channels...");
557 foreach (keys %chanconf) {
559 if (defined $chanconf{$_}{$what}) {
560 $val = $chanconf{$_}{$what};
567 foreach (keys %vals) {
568 &pSReply(" $what = $_: ".join(' ', keys %{ $vals{$_} } ) );
571 &pSReply("End of list.");
576 ### TODO: move to UserDCC again.
577 if ($cmd eq "chanset" and !defined $what) {
578 &DEBUG("showing channel conf.");
580 foreach $chan (@chans) {
581 &pSReply("chan: $chan (will also use _default)");
584 foreach (sort keys %{ $chanconf{$chan} }) {
585 my $newstr = join(', ', @items);
586 ### TODO: make length use channel line limit?
587 if (length $newstr > 400) {
592 push(@items, "$_ => $chanconf{$chan}{$_}");
594 &pSReply(" $str") if (@items);
599 $cache{confvars}{$what} = $val;
603 &chanSet($cmd, $_, $what, $val);
609 if ($message =~ /^(chanunset|\-chan)(\s+(.*))?$/) {
610 return unless (&hasFlag("n"));
614 if (!defined $args) {
621 if ($args =~ s/^(\-)?($mask{chan})\s*//) {
623 $delete = ($1) ? 1 : 0;
625 &VERB("no chan arg; setting to default.",2);
630 if (!exists $chanconf{$chan}) {
631 &pSReply("no such channel $chan");
637 if (!&getChanConf($args,$chan)) {
638 &pSReply("$args does not exist for $chan");
642 my @chans = &ChanConfList($args);
643 &DEBUG("scalar chans => ".scalar(@chans) );
644 if (scalar @chans == 1 and $chans[0] eq "_default" and !$no_chan) {
645 &psReply("ok, $args was set only for _default; unsetting for _defaul but setting for other chans.");
647 my $val = $chanconf{$_}{_default};
648 foreach (keys %chanconf) {
649 $chanconf{$_}{$args} = $val;
651 delete $chanconf{_default}{$args};
652 $cache{confvars}{$args} = 0;
658 if ($no_chan and !exists($chanconf{_default}{$args})) {
659 &pSReply("ok, $args for _default does not exist, removing from all chans.");
661 foreach (keys %chanconf) {
662 next unless (exists $chanconf{$_}{$args});
663 &DEBUG("delete chanconf{$_}{$args};");
664 delete $chanconf{$_}{$args};
666 $cache{confvars}{$args} = 0;
672 &pSReply("Unsetting channel ($chan) option $args. (was $chanconf{$chan}{$args})");
673 delete $chanconf{$chan}{$args};
679 &pSReply("Deleting channel $chan for sure!");
680 $utime_chanfile = time();
684 &pSReply("Leaving $chan...");
686 delete $chanconf{$chan};
688 &pSReply("Prefix channel with '-' to delete for sure.");
694 if ($message =~ /^newpass(\s+(.*))?$/) {
695 my(@args) = split /[\s\t]+/, $2 || '';
697 if (scalar @args != 1) {
702 my $u = &getUser($who);
703 my $crypt = &mkcrypt($args[0]);
705 &pSReply("Set your passwd to '$crypt'");
706 $users{$u}{PASS} = $crypt;
708 $utime_userfile = time();
714 if ($message =~ /^chpass(\s+(.*))?$/) {
715 my(@args) = split /[\s\t]+/, $2 || '';
722 if (!&IsUser($args[0])) {
723 &pSReply("user $args[0] is not valid.");
727 my $u = &getUser($args[0]);
729 &pSReply("Internal error, u = NULL.");
733 if (scalar @args == 1) { # del pass.
734 if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
735 &pSReply("cannot remove passwd of others.");
739 if (!exists $users{$u}{PASS}) {
740 &pSReply("$u does not have pass set anyway.");
744 &pSReply("Deleted pass from $u.");
746 $utime_userfile = time();
749 delete $users{$u}{PASS};
754 my $crypt = &mkcrypt($args[1]);
755 &pSReply("Set $u's passwd to '$crypt'");
756 $users{$u}{PASS} = $crypt;
758 $utime_userfile = time();
764 if ($message =~ /^chattr(\s+(.*))?$/) {
765 my(@args) = split /[\s\t]+/, $2 || '';
774 if ($args[0] =~ /^$mask{nick}$/i) { # <nick>
775 $user = &getUser($args[0]);
778 $user = &getUser($who);
779 &DEBUG("user $who... nope.") unless (defined $user);
780 $user = &getUser($verifyUser);
784 if (!defined $user) {
785 &pSReply("user does not exist.");
789 my $flags = $users{$user}{FLAGS};
790 if (!defined $chflag) {
791 &pSReply("Flags for $user: $flags");
795 &DEBUG("who => $who");
796 &DEBUG("verifyUser => $verifyUser");
797 if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
798 &pSReply("cannto change attributes of others.");
804 foreach (split //, $chflag) {
805 if ($_ eq "+") { $state = 1; next; }
806 if ($_ eq "-") { $state = 0; next; }
808 if (!defined $state) {
809 &pSReply("no initial + or - was found in attr.");
814 next if ($flags =~ /\Q$_\E/);
817 if (&IsParam("owner")
818 and $param{owner} =~ /^\Q$user\E$/i
819 and $flags =~ /[nmo]/
821 &pSReply("not removing flag $_ for $user.");
824 next unless ($flags =~ s/\Q$_\E//);
831 $utime_userfile = time();
833 &pSReply("Current flags: $flags");
834 $users{$user}{FLAGS} = $flags;
836 &pSReply("No flags changed: $flags");
842 if ($message =~ /^chnick(\s+(.*))?$/) {
843 my(@args) = split /[\s\t]+/, $2 || '';
845 if ($who eq "_default") {
846 &WARN("$who or verifyuser tried to run chnick.");
850 if (!scalar @args or scalar @args > 2) {
855 if (scalar @args == 1) { # 1
856 $user = &getUser($who);
857 &DEBUG("nope, not $who.") unless (defined $user);
858 $user ||= &getUser($verifyUser);
861 $user = &getUser($args[0]);
865 if (!defined $user) {
866 &pSReply("user $who or $args[0] does not exist.");
870 if ($user =~ /^\Q$chnick\E$/i) {
871 &pSReply("user == chnick. why should I do that?");
875 if (&getUser($chnick)) {
876 &pSReply("user $chnick is already used!");
880 if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
881 &pSReply("cannto change nick of others.");
882 return "REPLY" if ($who eq "_default");
886 foreach (keys %{ $users{$user} }) {
887 $users{$chnick}{$_} = $users{$user}{$_};
888 delete $users{$user}{$_};
890 undef $users{$user}; # ???
892 $utime_userfile = time();
895 &pSReply("Changed '$user' to '$chnick' successfully.");
900 if ($message =~ /^([-+])host(\s+(.*))?$/) {
902 my(@args) = split /[\s\t]+/, $3 || '';
903 my $state = ($1 eq "+") ? 1 : 0;
910 if ($who eq "_default") {
911 &WARN("$who or verifyuser tried to run $cmd.");
916 if ($args[0] =~ /^$mask{nick}$/i) { # <nick>
917 return unless (&hasFlag("n"));
918 $user = &getUser($args[0]);
921 # who or verifyUser. FIXME (don't remember why)
922 $user = &getUser($who);
926 if (!defined $user) {
927 &pSReply("user $user does not exist.");
931 if (!defined $mask) {
933 &pSReply("Hostmasks for $user: $users{$user}{HOSTS}");
938 if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
939 &pSReply("cannto change masks of others.");
943 if ($mask !~ /^$mask{nuh}$/) {
944 &pSReply("error: mask ($mask) is not a real hostmask.");
948 my $count = scalar keys %{ $users{$user}{HOSTS} };
951 if (exists $users{$user}{HOSTS}{$mask}) {
952 &pSReply("mask $mask already exists.");
956 ### TODO: override support.
957 $users{$user}{HOSTS}{$mask} = 1;
959 &pSReply("Added $mask to list of masks.");
963 if (!exists $users{$user}{HOSTS}{$mask}) {
964 &pSReply("mask $mask does not exist.");
968 ### TODO: wildcard support. ?
969 delete $users{$user}{HOSTS}{$mask};
971 if (scalar keys %{ $users{$user}{HOSTS} } != $count) {
972 &pSReply("Removed $mask from list of masks.");
974 &pSReply("error: could not find $mask in list of masks.");
979 $utime_userfile = time();
985 if ($message =~ /^([-+])ban(\s+(.*))?$/) {
988 my(@args) = split /[\s\t]+/, $3 || '';
989 my $state = ($1 eq "+") ? 1 : 0;
996 my($mask,$chan,$time,$reason);
998 if ($flatarg =~ s/^($mask{nuh})\s*//) {
1001 &DEBUG("arg does not contain nuh mask?");
1004 if ($flatarg =~ s/^($mask{chan})\s*//) {
1007 $chan = "*"; # _default instead?
1010 if ($state == 0) { # delete.
1011 my @c = &banDel($mask);
1018 &pSReply("Removed $mask from chans: @c");
1020 &pSReply("$mask was not found in ban list.");
1031 if ($flatarg =~ s/^(\d+)\s*//) {
1033 &DEBUG("time = $time.");
1035 &pSReply("error: time cannot be negatime?");
1042 if ($flatarg =~ s/^(.*)$//) { # need length?
1046 if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
1047 &pSReply("cannto change masks of others.");
1051 if ($mask !~ /^$mask{nuh}$/) {
1052 &pSReply("error: mask ($mask) is not a real hostmask.");
1056 if ( &banAdd($mask,$chan,$time,$reason) == 2) {
1057 &pSReply("ban already exists; overwriting.");
1059 &pSReply("Added $mask for $chan (time => $time, reason => $reason)");
1064 if ($message =~ /^whois(\s+(.*))?$/) {
1067 if (!defined $arg) {
1072 my $user = &getUser($arg);
1073 if (!defined $user) {
1074 &pSReply("whois: user $user does not exist.");
1078 ### TODO: better (eggdrop-like) output.
1079 &pSReply("user: $user");
1080 foreach (keys %{ $users{$user} }) {
1081 my $ref = ref $users{$user}{$_};
1083 if ($ref eq "HASH") {
1085 ### DOES NOT WORK???
1086 foreach (keys %{ $users{$user}{$type} }) {
1087 &pSReply(" $type => $_");
1092 &pSReply(" $_ => $users{$user}{$_}");
1094 &pSReply("End of USER whois.");
1099 if ($message =~ /^bans(\s+(.*))?$/) {
1103 if ($arg ne "_default" and !&validChan($arg) ) {
1104 &pSReply("error: chan $chan is invalid.");
1109 if (!scalar keys %bans) {
1110 &pSReply("Ban list is empty.");
1115 &pSReply(" mask: expire, time-added, count, who-by, reason");
1116 foreach $c (keys %bans) {
1117 next unless (!defined $arg or $arg =~ /^\Q$c\E$/i);
1120 foreach (keys %{ $bans{$c} }) {
1121 my $val = $bans{$c}{$_};
1123 if (ref $val eq "ARRAY") {
1124 my @array = @{ $val };
1125 &pSReply(" $_: @array");
1127 &DEBUG("unknown ban: $val");
1131 &pSReply("END of bans.");
1136 if ($message =~ /^banlist(\s+(.*))?$/) {
1139 if (defined $arg and $arg !~ /^$mask{chan}$/) {
1140 &pSReply("error: chan $chan is invalid.");
1144 &DEBUG("bans for global or arg => $arg.");
1145 foreach (keys %bans) { #CHANGE!!!
1146 &DEBUG(" $_ => $bans{$_}.");
1149 &DEBUG("End of bans.");
1150 &pSReply("END of bans.");
1155 if ($message =~ /^save$/) {
1156 return unless (&hasFlag("o"));
1165 $message =~ s/^addignore/+ignore/;
1166 $message =~ s/^(del|un)ignore/-ignore/;
1169 if ($message =~ /^(\+|\-)ignore(\s+(.*))?$/i) {
1170 return unless (&hasFlag("o"));
1171 my $state = ($1 eq "+") ? 1 : 0;
1172 my $str = $1."ignore";
1180 my($mask,$chan,$time,$comment);
1183 if ($args =~ s/^($mask{nuh})\s*//) {
1186 &ERROR("no NUH mask?");
1190 if (!$state) { # delignore.
1191 if ( &ignoreDel($mask) ) {
1192 &pSReply("ok, deleted ignores for $mask.");
1194 &pSReply("could not find $mask in ignore list.");
1204 if ($args =~ s/^($mask{chan}|\*)\s*//) {
1211 if ($args =~ s/^(\d+)\s*//) {
1212 $time = $1; # time is in minutes
1221 $comment = "added by $who";
1224 if ( &ignoreAdd($mask, $chan, $time, $comment) > 1) {
1225 &pSReply("warn: $mask already in ignore list; written over anyway. FIXME");
1227 &pSReply("added $mask to ignore list.");
1233 if ($message =~ /^ignore(\s+(.*))?$/) {
1237 if ($arg !~ /^$mask{chan}$/) {
1238 &pSReply("error: chan $chan is invalid.");
1242 if (!&validChan($arg)) {
1243 &pSReply("error: chan $arg is invalid.");
1247 &pSReply("Showing bans for $arg only.");
1250 if (!scalar keys %ignore) {
1251 &pSReply("Ignore list is empty.");
1255 ### TODO: proper (eggdrop-like) formatting.
1257 &pSReply(" mask: expire, time-added, who, comment");
1258 foreach $c (keys %ignore) {
1259 next unless (!defined $arg or $arg =~ /^\Q$c\E$/i);
1262 foreach (keys %{ $ignore{$c} }) {
1263 my $ref = ref $ignore{$c}{$_};
1264 if ($ref eq "ARRAY") {
1265 my @array = @{ $ignore{$c}{$_} };
1266 &pSReply(" $_: @array");
1268 &DEBUG("unknown ignore line?");
1272 &pSReply("END of ignore.");
1278 if ($message =~ /^(\+|\-|add|del)user(\s+(.*))?$/i) {
1280 my $strstr = $1."user";
1281 my @args = split /\s+/, $3 || '';
1283 my $state = ($str =~ /^(\+|add)$/) ? 1 : 0;
1285 if (!scalar @args) {
1291 if (scalar @args != 2) {
1292 &pSReply(".+host requires hostmask argument.");
1295 } elsif (scalar @args != 1) {
1296 &pSReply("too many arguments.");
1300 if ($state) { # adduser.
1301 if (scalar @args == 1) {
1302 $args[1] = &getHostMask($args[0]);
1303 &pSReply("Attemping to guess $args[0]'s hostmask...");
1305 # crude hack... crappy Net::IRC
1306 $conn->schedule(5, sub {
1307 # hopefully this is right.
1308 my $nick = (keys %{ $cache{nuhInfo} })[0];
1309 if (!defined $nick) {
1310 &pSReply("couldn't get nuhinfo... adding user without a hostmask.");
1315 my $mask = &makeHostMask( $cache{nuhInfo}{$nick}{NUH} );
1317 if ( &userAdd($nick, $mask) ) { # success.
1318 &pSReply("Added $nick with flags $users{$nick}{FLAGS}");
1319 my @hosts = keys %{ $users{$nick}{HOSTS} };
1320 &pSReply("hosts: @hosts");
1326 &DEBUG("args => @args");
1327 if ( &userAdd(@args) ) { # success.
1328 &pSReply("Added $args[0] with flags $users{$args[0]}{FLAGS}");
1329 my @hosts = keys %{ $users{$args[0]}{HOSTS} };
1330 &pSReply("hosts: @hosts");
1333 &pSReply("User $args[0] already exists");
1338 if ( &userDel($args[0]) ) { # success.
1339 &pSReply("Deleted $args[0] successfully.");
1342 &pSReply("User $args[0] does not exist.");
1349 if ($message =~ /^sched$/) {
1354 foreach (keys %sched) {
1355 next unless (exists $sched{$_}{TIME});
1356 $time{ $sched{$_}{TIME}-time() }{$_} = 1;
1359 next unless (exists $sched{$_}{RUNNING});
1364 foreach (sort { $a <=> $b } keys %time) {
1365 my $str = join(", ", sort keys %{ $time{$_} });
1366 &DEBUG("time => $_, str => $str");
1367 push(@time, "$str (".&Time2String($_).")");
1370 &pSReply( &formListReply(0, "Schedulers: ", @time ) );
1371 &pSReply( &formListReply(0, "Scheds to run: ", sort @list ) );
1372 &pSReply( &formListReply(0, "Scheds running(should not happen?) ", sort @run ) );
1377 # quite a cool hack: reply in DCC CHAT.
1378 $msgType = "chat" if (exists $dcc{'CHAT'}{$who});
1381 $done++ if &parseCmdHook("main", $message);
1382 $done++ if &parseCmdHook("extra", $message);
1383 $done++ unless (&Modules());
1386 &DEBUG("running non DCC CHAT command inside DCC CHAT!");