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 &FIXME("userDCC: quit called.");
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);
340 &DEBUG("chan => '$1', msg => '$msg'.");
342 # TODO: add nick destination.
343 if (&validChan($chan)) {
346 &msg($who,"i'm not on \002$chan\002, sorry.");
353 if ($message =~ /^die$/) {
354 return unless (&hasFlag("n"));
358 &status("Dying by $who\'s request");
362 # global factoid substitution.
363 if ($message =~ m|^s([/,#])(.+?)\1(.*?)\1;?\s*$|) {
364 my ($delim,$op,$np) = ($1, $2, $3);
365 return unless (&hasFlag("n"));
366 ### TODO: support flags to do full-on global.
369 if ($np =~ /$delim/) {
370 &performReply("looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
374 ### TODO: fix up $op to support mysql/sqlite/pgsql
375 ### TODO: => add db/sql specific function to fix this.
376 my @list = &searchTable("factoids", "factoid_key",
377 "factoid_value", $op);
380 &performReply("Expression didn't match anything.");
384 if (scalar @list > 100) {
385 &performReply("regex found more than 100 matches... not doing.");
389 &status("gsubst: going to alter ".scalar(@list)." factoids.");
390 &performReply("going to alter ".scalar(@list)." factoids.");
396 next if (&IsLocked($faqtoid) == 1);
397 my $result = &getFactoid($faqtoid);
399 &DEBUG("was($faqtoid) => '$was'.");
402 # we could support global local (once off).
403 if ($result =~ s/\Q$op/$np/gi) {
404 if (length $result > $param{'maxDataSize'}) {
405 &performReply("that's too long (or was long)");
408 &setFactInfo($faqtoid, "factoid_value", $result);
409 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
411 &WARN("subst: that's weird... thought we found the string ($op) in '$faqtoid'.");
417 &ERROR("Some warnings/errors?");
420 &performReply("Ok... did s/$op/$np/ for ".
421 (scalar(@list) - $error)." factoids");
427 if ($message =~ /^jump(\s+(\S+))?$/i) {
428 return unless (&hasFlag("n"));
436 if ($2 =~ /^(\S+)(:(\d+))?$/) {
440 &msg($who,"invalid format.");
444 &status("jumping servers... $server...");
445 $conn->quit("jumping to $server");
447 if (&irc($server,$port) == 0) {
453 if ($message =~ /^reload$/i) {
454 return unless (&hasFlag("n"));
456 &status("USER reload $who");
457 &pSReply("reloading...");
459 &pSReply("reloaded.");
465 if ($message =~ /^reset$/i) {
466 return unless (&hasFlag("n"));
468 &msg($who,"resetting...");
470 foreach ( keys %channels, keys %chanconf ) {
472 next if (grep /^\Q$c\E$/i, @done);
479 &DEBUG("before clearircvars");
481 &DEBUG("before joinnextchan");
483 &DEBUG("after joinnextchan");
485 &status("USER reset $who");
486 &msg($who,"reset complete");
492 if ($message =~ /^rehash$/) {
493 return unless (&hasFlag("n"));
495 &msg($who,"rehashing...");
497 &status("USER rehash $who");
498 &msg($who,"rehashed");
504 ##### USER//CHAN SPECIFIC CONFIGURATION COMMANDS
507 if ($message =~ /^chaninfo(\s+(.*))?$/) {
508 my @args = split /[\s\t]+/, $2; # hrm.
510 if (scalar @args != 1) {
515 if (!exists $chanconf{$args[0]}) {
516 &pSReply("no such channel $args[0]");
520 &pSReply("showing channel conf.");
521 foreach (sort keys %{ $chanconf{$args[0]} }) {
522 &pSReply("$chan: $_ => $chanconf{$args[0]}{$_}");
524 &pSReply("End of chaninfo.");
530 if ($message =~ /^(chanset|\+chan)(\s+(.*?))?$/) {
535 if (!defined $args) {
541 while ($args =~ s/^($mask{chan})\s*//) {
542 push(@chans, lc($1));
545 if (!scalar @chans) {
546 push(@chans, "_default");
550 my($what,$val) = split /[\s\t]+/, $args, 2;
552 ### TODO: "cannot set values without +m".
553 return unless (&hasFlag("n"));
556 if (defined $what and $what !~ /^[-+]/ and !defined $val and $no_chan) {
557 &pSReply("Showing $what values on all channels...");
560 foreach (keys %chanconf) {
562 if (defined $chanconf{$_}{$what}) {
563 $val = $chanconf{$_}{$what};
570 foreach (keys %vals) {
571 &pSReply(" $what = $_(" . scalar(keys %{$vals{$_}}) . "): ".join(' ', keys %{ $vals{$_} } ) );
574 &pSReply("End of list.");
579 ### TODO: move to UserDCC again.
580 if ($cmd eq "chanset" and !defined $what) {
581 &DEBUG("showing channel conf.");
583 foreach $chan (@chans) {
584 if ($chan eq '_default') {
585 &pSReply("Default channel settings");
587 &pSReply("chan: $chan (see _default also)");
591 foreach (sort keys %{ $chanconf{$chan} }) {
592 my $newstr = join(', ', @items);
593 ### TODO: make length use channel line limit?
594 if (length $newstr > 370) {
599 push(@items, "$_ => $chanconf{$chan}{$_}");
601 &pSReply(" $str") if (@items);
606 $cache{confvars}{$what} = $val;
610 &chanSet($cmd, $_, $what, $val);
616 if ($message =~ /^(chanunset|\-chan)(\s+(.*))?$/) {
617 return unless (&hasFlag("n"));
621 if (!defined $args) {
628 if ($args =~ s/^(\-)?($mask{chan})\s*//) {
630 $delete = ($1) ? 1 : 0;
632 &VERB("no chan arg; setting to default.",2);
637 if (!exists $chanconf{$chan}) {
638 &pSReply("no such channel $chan");
644 if (!&getChanConf($args,$chan)) {
645 &pSReply("$args does not exist for $chan");
649 my @chans = &ChanConfList($args);
650 &DEBUG("scalar chans => ".scalar(@chans) );
651 if (scalar @chans == 1 and $chans[0] eq "_default" and !$no_chan) {
652 &psReply("ok, $args was set only for _default; unsetting for _defaul but setting for other chans.");
654 my $val = $chanconf{$_}{_default};
655 foreach (keys %chanconf) {
656 $chanconf{$_}{$args} = $val;
658 delete $chanconf{_default}{$args};
659 $cache{confvars}{$args} = 0;
665 if ($no_chan and !exists($chanconf{_default}{$args})) {
666 &pSReply("ok, $args for _default does not exist, removing from all chans.");
668 foreach (keys %chanconf) {
669 next unless (exists $chanconf{$_}{$args});
670 &DEBUG("delete chanconf{$_}{$args};");
671 delete $chanconf{$_}{$args};
673 $cache{confvars}{$args} = 0;
679 &pSReply("Unsetting channel ($chan) option $args. (was $chanconf{$chan}{$args})");
680 delete $chanconf{$chan}{$args};
686 &pSReply("Deleting channel $chan for sure!");
687 $utime_chanfile = time();
691 &pSReply("Leaving $chan...");
693 delete $chanconf{$chan};
695 &pSReply("Prefix channel with '-' to delete for sure.");
701 if ($message =~ /^newpass(\s+(.*))?$/) {
702 my(@args) = split /[\s\t]+/, $2 || '';
704 if (scalar @args != 1) {
709 my $u = &getUser($who);
710 my $crypt = &mkcrypt($args[0]);
712 &pSReply("Set your passwd to '$crypt'");
713 $users{$u}{PASS} = $crypt;
715 $utime_userfile = time();
721 if ($message =~ /^chpass(\s+(.*))?$/) {
722 my(@args) = split /[\s\t]+/, $2 || '';
729 if (!&IsUser($args[0])) {
730 &pSReply("user $args[0] is not valid.");
734 my $u = &getUser($args[0]);
736 &pSReply("Internal error, u = NULL.");
740 if (scalar @args == 1) { # del pass.
741 if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
742 &pSReply("cannot remove passwd of others.");
746 if (!exists $users{$u}{PASS}) {
747 &pSReply("$u does not have pass set anyway.");
751 &pSReply("Deleted pass from $u.");
753 $utime_userfile = time();
756 delete $users{$u}{PASS};
761 my $crypt = &mkcrypt($args[1]);
762 &pSReply("Set $u's passwd to '$crypt'");
763 $users{$u}{PASS} = $crypt;
765 $utime_userfile = time();
771 if ($message =~ /^chattr(\s+(.*))?$/) {
772 my(@args) = split /[\s\t]+/, $2 || '';
781 if ($args[0] =~ /^$mask{nick}$/i) { # <nick>
782 $user = &getUser($args[0]);
785 $user = &getUser($who);
786 &DEBUG("user $who... nope.") unless (defined $user);
787 $user = &getUser($verifyUser);
791 if (!defined $user) {
792 &pSReply("user does not exist.");
796 my $flags = $users{$user}{FLAGS};
797 if (!defined $chflag) {
798 &pSReply("Flags for $user: $flags");
802 &DEBUG("who => $who");
803 &DEBUG("verifyUser => $verifyUser");
804 if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
805 &pSReply("cannto change attributes of others.");
811 foreach (split //, $chflag) {
812 if ($_ eq "+") { $state = 1; next; }
813 if ($_ eq "-") { $state = 0; next; }
815 if (!defined $state) {
816 &pSReply("no initial + or - was found in attr.");
821 next if ($flags =~ /\Q$_\E/);
824 if (&IsParam("owner")
825 and $param{owner} =~ /^\Q$user\E$/i
826 and $flags =~ /[nmo]/
828 &pSReply("not removing flag $_ for $user.");
831 next unless ($flags =~ s/\Q$_\E//);
838 $utime_userfile = time();
840 &pSReply("Current flags: $flags");
841 $users{$user}{FLAGS} = $flags;
843 &pSReply("No flags changed: $flags");
849 if ($message =~ /^chnick(\s+(.*))?$/) {
850 my(@args) = split /[\s\t]+/, $2 || '';
852 if ($who eq "_default") {
853 &WARN("$who or verifyuser tried to run chnick.");
857 if (!scalar @args or scalar @args > 2) {
862 if (scalar @args == 1) { # 1
863 $user = &getUser($who);
864 &DEBUG("nope, not $who.") unless (defined $user);
865 $user ||= &getUser($verifyUser);
868 $user = &getUser($args[0]);
872 if (!defined $user) {
873 &pSReply("user $who or $args[0] does not exist.");
877 if ($user =~ /^\Q$chnick\E$/i) {
878 &pSReply("user == chnick. why should I do that?");
882 if (&getUser($chnick)) {
883 &pSReply("user $chnick is already used!");
887 if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
888 &pSReply("cannto change nick of others.");
889 return "REPLY" if ($who eq "_default");
893 foreach (keys %{ $users{$user} }) {
894 $users{$chnick}{$_} = $users{$user}{$_};
895 delete $users{$user}{$_};
897 undef $users{$user}; # ???
899 $utime_userfile = time();
902 &pSReply("Changed '$user' to '$chnick' successfully.");
907 if ($message =~ /^([-+])host(\s+(.*))?$/) {
909 my(@args) = split /[\s\t]+/, $3 || '';
910 my $state = ($1 eq "+") ? 1 : 0;
917 if ($who eq "_default") {
918 &WARN("$who or verifyuser tried to run $cmd.");
923 if ($args[0] =~ /^$mask{nick}$/i) { # <nick>
924 return unless (&hasFlag("n"));
925 $user = &getUser($args[0]);
928 # FIXME: who or verifyUser. (don't remember why)
929 $user = &getUser($who);
933 if (!defined $user) {
934 &pSReply("user $user does not exist.");
938 if (!defined $mask) {
939 &pSReply("Hostmasks for $user: " . join(" ", keys %{$users{$user}{HOSTS}}));
943 if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
944 &pSReply("cannto change masks of others.");
948 if ($mask !~ /^$mask{nuh}$/) {
949 &pSReply("error: mask ($mask) is not a real hostmask.");
953 my $count = scalar keys %{ $users{$user}{HOSTS} };
956 if (exists $users{$user}{HOSTS}{$mask}) {
957 &pSReply("mask $mask already exists.");
961 ### TODO: override support.
962 $users{$user}{HOSTS}{$mask} = 1;
964 &pSReply("Added $mask to list of masks.");
968 if (!exists $users{$user}{HOSTS}{$mask}) {
969 &pSReply("mask $mask does not exist.");
973 ### TODO: wildcard support. ?
974 delete $users{$user}{HOSTS}{$mask};
976 if (scalar keys %{ $users{$user}{HOSTS} } != $count) {
977 &pSReply("Removed $mask from list of masks.");
979 &pSReply("error: could not find $mask in list of masks.");
984 $utime_userfile = time();
990 if ($message =~ /^([-+])ban(\s+(.*))?$/) {
993 my(@args) = split /[\s\t]+/, $3 || '';
994 my $state = ($1 eq "+") ? 1 : 0;
1001 my($mask,$chan,$time,$reason);
1003 if ($flatarg =~ s/^($mask{nuh})\s*//) {
1006 &DEBUG("arg does not contain nuh mask?");
1009 if ($flatarg =~ s/^($mask{chan})\s*//) {
1012 $chan = "*"; # _default instead?
1015 if ($state == 0) { # delete.
1016 my @c = &banDel($mask);
1023 &pSReply("Removed $mask from chans: @c");
1025 &pSReply("$mask was not found in ban list.");
1036 if ($flatarg =~ s/^(\d+)\s*//) {
1038 &DEBUG("time = $time.");
1040 &pSReply("error: time cannot be negatime?");
1047 if ($flatarg =~ s/^(.*)$//) { # need length?
1051 if (!&IsFlag("n") and $who !~ /^\Q$verifyUser\E$/i) {
1052 &pSReply("cannto change masks of others.");
1056 if ($mask !~ /^$mask{nuh}$/) {
1057 &pSReply("error: mask ($mask) is not a real hostmask.");
1061 if ( &banAdd($mask,$chan,$time,$reason) == 2) {
1062 &pSReply("ban already exists; overwriting.");
1064 &pSReply("Added $mask for $chan (time => $time, reason => $reason)");
1069 if ($message =~ /^whois(\s+(.*))?$/) {
1072 if (!defined $arg) {
1077 my $user = &getUser($arg);
1078 if (!defined $user) {
1079 &pSReply("whois: user $user does not exist.");
1083 ### TODO: better (eggdrop-like) output.
1084 &pSReply("user: $user");
1085 foreach (keys %{ $users{$user} }) {
1086 my $ref = ref $users{$user}{$_};
1088 if ($ref eq "HASH") {
1090 ### DOES NOT WORK???
1091 foreach (keys %{ $users{$user}{$type} }) {
1092 &pSReply(" $type => $_");
1097 &pSReply(" $_ => $users{$user}{$_}");
1099 &pSReply("End of USER whois.");
1104 if ($message =~ /^bans(\s+(.*))?$/) {
1108 if ($arg ne "_default" and !&validChan($arg) ) {
1109 &pSReply("error: chan $chan is invalid.");
1114 if (!scalar keys %bans) {
1115 &pSReply("Ban list is empty.");
1120 &pSReply(" mask: expire, time-added, count, who-by, reason");
1121 foreach $c (keys %bans) {
1122 next unless (!defined $arg or $arg =~ /^\Q$c\E$/i);
1125 foreach (keys %{ $bans{$c} }) {
1126 my $val = $bans{$c}{$_};
1128 if (ref $val eq "ARRAY") {
1129 my @array = @{ $val };
1130 &pSReply(" $_: @array");
1132 &DEBUG("unknown ban: $val");
1136 &pSReply("END of bans.");
1141 if ($message =~ /^banlist(\s+(.*))?$/) {
1144 if (defined $arg and $arg !~ /^$mask{chan}$/) {
1145 &pSReply("error: chan $chan is invalid.");
1149 &DEBUG("bans for global or arg => $arg.");
1150 foreach (keys %bans) { #CHANGE!!!
1151 &DEBUG(" $_ => $bans{$_}.");
1154 &DEBUG("End of bans.");
1155 &pSReply("END of bans.");
1160 if ($message =~ /^save$/) {
1161 return unless (&hasFlag("o"));
1165 &pSReply("saved user and chan files");
1171 $message =~ s/^addignore/+ignore/;
1172 $message =~ s/^(del|un)ignore/-ignore/;
1175 if ($message =~ /^(\+|\-)ignore(\s+(.*))?$/i) {
1176 return unless (&hasFlag("o"));
1177 my $state = ($1 eq "+") ? 1 : 0;
1178 my $str = $1."ignore";
1186 my($mask,$chan,$time,$comment);
1189 if ($args =~ s/^($mask{nuh})\s*//) {
1192 &ERROR("no NUH mask?");
1196 if (!$state) { # delignore.
1197 if ( &ignoreDel($mask) ) {
1198 &pSReply("ok, deleted ignores for $mask.");
1200 &pSReply("could not find $mask in ignore list.");
1210 if ($args =~ s/^($mask{chan}|\*)\s*//) {
1217 if ($args =~ s/^(\d+)\s*//) {
1218 $time = $1; # time is in minutes
1227 $comment = "added by $who";
1230 if ( &ignoreAdd($mask, $chan, $time, $comment) > 1) {
1231 &pSReply("FIXME: $mask already in ignore list; written over anyway.");
1233 &pSReply("added $mask to ignore list.");
1239 if ($message =~ /^ignore(\s+(.*))?$/) {
1243 if ($arg !~ /^$mask{chan}$/) {
1244 &pSReply("error: chan $chan is invalid.");
1248 if (!&validChan($arg)) {
1249 &pSReply("error: chan $arg is invalid.");
1253 &pSReply("Showing bans for $arg only.");
1256 if (!scalar keys %ignore) {
1257 &pSReply("Ignore list is empty.");
1261 ### TODO: proper (eggdrop-like) formatting.
1263 &pSReply(" mask: expire, time-added, who, comment");
1264 foreach $c (keys %ignore) {
1265 next unless (!defined $arg or $arg =~ /^\Q$c\E$/i);
1268 foreach (keys %{ $ignore{$c} }) {
1269 my $ref = ref $ignore{$c}{$_};
1270 if ($ref eq "ARRAY") {
1271 my @array = @{ $ignore{$c}{$_} };
1272 &pSReply(" $_: @array");
1274 &DEBUG("unknown ignore line?");
1278 &pSReply("END of ignore.");
1284 if ($message =~ /^(\+|\-|add|del)user(\s+(.*))?$/i) {
1286 my $strstr = $1."user";
1287 my @args = split /\s+/, $3 || '';
1289 my $state = ($str =~ /^(\+|add)$/) ? 1 : 0;
1291 if (!scalar @args) {
1297 if (scalar @args != 2) {
1298 &pSReply(".+host requires hostmask argument.");
1301 } elsif (scalar @args != 1) {
1302 &pSReply("too many arguments.");
1306 if ($state) { # adduser.
1307 if (scalar @args == 1) {
1308 $args[1] = &getHostMask($args[0]);
1309 &pSReply("Attemping to guess $args[0]'s hostmask...");
1311 # crude hack... crappy Net::IRC
1312 $conn->schedule(5, sub {
1313 # hopefully this is right.
1314 my $nick = (keys %{ $cache{nuhInfo} })[0];
1315 if (!defined $nick) {
1316 &pSReply("couldn't get nuhinfo... adding user without a hostmask.");
1321 my $mask = &makeHostMask( $cache{nuhInfo}{$nick}{NUH} );
1323 if ( &userAdd($nick, $mask) ) { # success.
1324 &pSReply("Added $nick with flags $users{$nick}{FLAGS}");
1325 my @hosts = keys %{ $users{$nick}{HOSTS} };
1326 &pSReply("hosts: @hosts");
1332 &DEBUG("args => @args");
1333 if ( &userAdd(@args) ) { # success.
1334 &pSReply("Added $args[0] with flags $users{$args[0]}{FLAGS}");
1335 my @hosts = keys %{ $users{$args[0]}{HOSTS} };
1336 &pSReply("hosts: @hosts");
1339 &pSReply("User $args[0] already exists");
1344 if ( &userDel($args[0]) ) { # success.
1345 &pSReply("Deleted $args[0] successfully.");
1348 &pSReply("User $args[0] does not exist.");
1355 if ($message =~ /^sched$/) {
1360 foreach (keys %sched) {
1361 next unless (exists $sched{$_}{TIME});
1362 $time{ $sched{$_}{TIME}-time() }{$_} = 1;
1365 next unless (exists $sched{$_}{RUNNING});
1370 foreach (sort { $a <=> $b } keys %time) {
1371 my $str = join(", ", sort keys %{ $time{$_} });
1372 &DEBUG("time => $_, str => $str");
1373 push(@time, "$str (".&Time2String($_).")");
1376 &pSReply( &formListReply(0, "Schedulers: ", @time ) );
1377 &pSReply( &formListReply(0, "Scheds to run: ", sort @list ) );
1378 &pSReply( &formListReply(0, "Scheds running(should not happen?) ", sort @run ) );
1383 # quite a cool hack: reply in DCC CHAT.
1384 $msgType = "chat" if (exists $dcc{'CHAT'}{$who});
1387 $done++ if &parseCmdHook("main", $message);
1388 $done++ if &parseCmdHook("extra", $message);
1389 $done++ unless (&Modules());
1392 &DEBUG("running non DCC CHAT command inside DCC CHAT!");