2 # UserDCC.pl: User Commands, DCC CHAT.
4 # Version: v0.2 (20010119)
5 # Created: 20000707 (from UserExtra.pl)
8 if (&IsParam("useStrict")) { use strict; }
16 if ($message =~ /^(exit|quit)$/i) {
17 # do ircII clients support remote close? if so, cool!
18 &status("userDCC: quit called. FIXME");
26 if ($message =~ /^who$/) {
27 my $count = scalar(keys %{$dcc{'CHAT'}});
28 my $dccCHAT = $message;
30 &pSReply("Start of who ($count users).");
31 foreach (keys %{$dcc{'CHAT'}}) {
34 &pSReply("End of who.");
39 ### for those users with enough flags.
42 if ($message =~ /^4op(\s+($mask{chan}))?$/i) {
43 return unless (&hasFlag("o"));
52 if (!$channels{$chan}{'o'}{$ident}) {
53 &msg($who, "i don't have ops on $chan to do that.");
57 # on non-4mode(<4) servers, this may be exploited.
58 if ($channels{$chan}{'o'}{$who}) {
59 rawout("MODE $chan -o+o-o+o". (" $who" x 4));
61 rawout("MODE $chan +o-o+o-o". (" $who" x 4));
68 if ($message =~ /^backlog(\s+(.*))?$/i) {
69 return unless (&hasFlag("o"));
70 return unless (&hasParam("backlog"));
72 my $max = $param{'backlog'};
77 } elsif ($num !~ /^\d+/) {
78 &msg($who, "error: argument is not positive integer.");
80 } elsif ($num > $max or $num < 0) {
81 &msg($who, "error: argument is out of range (max $max).");
85 &msg($who, "Start of backlog...");
87 sleep 1 if ($_ % 4 == 0 and $_ != 0);
88 $conn->privmsg($who, "[".($_+1)."]: $backlog[$max-$num+$_]");
90 &msg($who, "End of backlog.");
96 if ($message =~ /^dumpvars$/i) {
97 return unless (&hasFlag("o"));
98 return unless (&IsParam("dumpvars"));
100 &status("Dumping all variables...");
107 if ($message =~ /^kick(\s+(\S+)(\s+(\S+))?)?/) {
108 return unless (&hasFlag("o"));
109 my ($nick,$chan) = (lc $2,lc $4);
116 if (&validChan($chan) == 0) {
117 &msg($who,"error: invalid channel \002$chan\002");
121 if (&IsNickInChan($nick,$chan) == 0) {
122 &msg($who,"$nick is not in $chan.");
132 if ($message =~ /^mode(\s+(.*))?$/) {
133 return unless (&hasFlag("m"));
134 my ($chan,$mode) = split /\s+/,$2,2;
141 if (&validChan($chan) == 0) {
142 &msg($who,"error: invalid channel \002$chan\002");
146 if (!$channels{$chan}{o}{$ident}) {
147 &msg($who,"error: don't have ops on \002$chan\002");
157 if ($message =~ /^part(\s+(\S+))?$/i) {
158 return unless (&hasFlag("o"));
161 if ($jchan !~ /^$mask{chan}$/) {
162 &msg($who, "error, invalid chan.");
167 if (!&validChan($jchan)) {
168 &msg($who, "error, I'm not on that chan.");
172 &msg($jchan, "Leaving. (courtesy of $who).");
177 # lobotomy. sometimes we want the bot to be _QUIET_.
178 if ($message =~ /^(lobotomy|bequiet)$/i) {
179 return unless (&hasFlag("o"));
182 &performReply("i'm already lobotomized");
184 &performReply("i have been lobotomized");
192 if ($message =~ /^(unlobotomy|benoisy)$/i) {
193 return unless (&hasFlag("o"));
195 &performReply("i have been unlobotomized, woohoo");
198 &performReply("i'm not lobotomized");
204 if ($message =~ /^op(\s+(.*))?$/i) {
205 return unless (&hasFlag("o"));
210 if ($opee =~ /^(\S+)\s+(\S+)$/) {
213 if (!&validChan($2)) {
214 &msg($who,"error: invalid chan ($2).");
218 &msg($who,"error: invalid params.");
222 @chans = keys %channels;
228 next unless (&IsNickInChan($opee,$_));
230 if ($channels{$_}{'o'}{$opee}) {
231 &status("op: $opee already has ops on $_");
236 &status("opping $opee on $_ at ${who}'s request");
237 &pSReply("opping $opee on $_");
242 &status("op: opped on all possible channels.");
244 &DEBUG("found => '$found'.");
245 &DEBUG("op => '$op'.");
252 if ($message =~ /^deop(\s+(.*))?$/i) {
253 return unless (&hasFlag("o"));
258 if ($opee =~ /^(\S+)\s+(\S+)$/) {
261 if (!&validChan($2)) {
262 &msg($who,"error: invalid chan ($2).");
266 &msg($who,"error: invalid params.");
270 @chans = keys %channels;
276 next unless (&IsNickInChan($opee,$_));
278 if (!exists $channels{$_}{'o'}{$opee}) {
279 &status("deop: $opee already has no ops on $_");
284 &status("deopping $opee on $_ at ${who}'s request");
289 &status("deop: deopped on all possible channels.");
291 &DEBUG("deop: found => '$found'.");
292 &DEBUG("deop: op => '$op'.");
299 if ($message =~ s/^say\s+(\S+)\s+(.*)//) {
300 return unless (&hasFlag("o"));
301 my ($chan,$msg) = (lc $1, $2);
302 &DEBUG("chan => '$1', msg => '$msg'.");
304 if (&validChan($chan)) {
307 &msg($who,"i'm not on \002$1\002, sorry.");
313 if ($message =~ /^die$/) {
314 return unless (&hasFlag("n"));
318 &status("Dying by $who\'s request");
322 # global factoid substitution.
323 if ($message =~ m|^s([/,#])(.+?)\1(.*?)\1;?\s*$|) {
324 my ($delim,$op,$np) = ($1, $2, $3);
325 return unless (&hasFlag("n"));
326 ### TODO: support flags to do full-on global.
329 if ($np =~ /$delim/) {
330 &performReply("looks like you used the delimiter too many times. You may want to use a different delimiter, like ':' or '#'.");
334 ### TODO: fix up $op to support mysql/pgsql/dbm(perl)
335 ### TODO: => add db/sql specific function to fix this.
336 my @list = &searchTable("factoids", "factoid_key",
337 "factoid_value", $op);
340 &performReply("Expression didn't match anything.");
344 if (scalar @list > 100) {
345 &performReply("regex found more than 100 matches... not doing.");
349 &status("gsubst: going to alter ".scalar(@list)." factoids.");
350 &performReply("going to alter ".scalar(@list)." factoids.");
356 next if (&IsLocked($faqtoid) == 1);
357 my $result = &getFactoid($faqtoid);
359 &DEBUG("was($faqtoid) => '$was'.");
362 # we could support global local (once off).
363 if ($result =~ s/\Q$op/$np/gi) {
364 if (length $result > $param{'maxDataSize'}) {
365 &performReply("that's too long (or was long)");
368 &setFactInfo($faqtoid, "factoid_value", $result);
369 &status("update: '$faqtoid' =is=> '$result'; was '$was'");
371 &WARN("subst: that's weird... thought we found the string ($op) in '$faqtoid'.");
377 &ERROR("Some warnings/errors?");
380 &performReply("Ok... did s/$op/$np/ for ".
381 (scalar(@list) - $error)." factoids");
387 if ($message =~ /^jump(\s+(\S+))?$/i) {
388 return unless (&hasFlag("n"));
396 if ($2 =~ /^(\S+)(:(\d+))?$/) {
400 &msg($who,"invalid format.");
404 &status("jumping servers... $server...");
405 &rawout("QUIT :jumping to $server");
407 if (&irc($server,$port) == 0) {
413 if ($message =~ /^reload$/i) {
414 return unless (&hasFlag("n"));
416 &status("USER reload $who");
417 &pSReply("reloading...");
419 &pSReply("reloaded.");
425 if ($message =~ /^rehash$/) {
426 return unless (&hasFlag("n"));
428 &msg($who,"rehashing...");
430 &status("USER rehash $who");
431 &msg($who,"rehashed");
437 ##### USER//CHAN SPECIFIC CONFIGURATION COMMANDS
440 if ($message =~ /^chaninfo(\s+(.*))?$/) {
441 my @args = split /[\s\t]+/, $2; # hrm.
443 if (scalar @args != 1) {
448 if (!exists $chanconf{$args[0]}) {
449 &pSReply("no such channel $args[0]");
453 &pSReply("showing channel conf.");
454 foreach (sort keys %{ $chanconf{$args[0]} }) {
455 &pSReply("$chan: $_ => $chanconf{$args[0]}{$_}");
457 &pSReply("End of chaninfo.");
463 if ($message =~ /^(chanset|\+chan)(\s+(.*?))?$/) {
468 if (!defined $args) {
474 while ($args =~ s/^($mask{chan})\s*//) {
478 if (!scalar @chans) {
479 push(@chans, "_default");
483 my($what,$val) = split /[\s\t]+/, $args, 2;
485 ### TODO: "cannot set values without +m".
486 return unless (&hasFlag("m"));
489 if (defined $what and $what !~ /^[-+]/ and !defined $val and $no_chan) {
490 &pSReply("Showing $what values on all channels...");
493 foreach (keys %chanconf) {
494 my $val = $chanconf{$_}{$what} || "NOT-SET";
498 foreach (keys %vals) {
499 &pSReply(" $what = $_: ".join(' ', keys %{ $vals{$_} } ) );
502 &pSReply("End of list.");
508 &chanSet($cmd, $_, $what, $val);
514 if ($message =~ /^(chanunset|\-chan)(\s+(.*))?$/) {
515 return unless (&hasFlag("m"));
519 if (!defined $args) {
526 if ($args =~ s/^(\-)?($mask{chan})\s*//) {
528 $delete = ($1) ? 1 : 0;
529 &DEBUG("chan => $chan.");
531 &VERB("no chan arg; setting to default.",2);
536 if (!exists $chanconf{$chan}) {
537 &pSReply("no such channel $chan");
543 if (!&getChanConf($args,$chan)) {
544 &pSReply("$args does not exist for $chan");
548 my @chans = &ChanConfList($args);
549 &DEBUG("scalar chans => ".scalar(@chans) );
550 if (scalar @chans == 1 and $chans[0] eq "_default" and !$no_chan) {
551 &psReply("ok, $args was set only for _default; unsetting for _defaul but setting for other chans.");
553 my $val = $chanconf{$_}{_default};
554 foreach (keys %chanconf) {
555 $chanconf{$_}{$args} = $val;
557 delete $chanconf{_default}{$args};
562 if ($no_chan and !exists($chanconf{_default}{$args})) {
563 &pSReply("ok, $args for _default does not exist, removing from all chans.");
565 foreach (keys %chanconf) {
566 next unless (exists $chanconf{$_}{$args});
567 &DEBUG("delete chanconf{$_}{$args};");
568 delete $chanconf{$_}{$args};
574 &pSReply("Unsetting channel ($chan) option $args. (was $chanconf{$chan}{$args})");
575 delete $chanconf{$chan}{$args};
581 &pSReply("Deleting channel $chan for sure!");
582 $utime_chanfile = time();
586 &pSReply("Leaving $chan...");
588 delete $chanconf{$chan};
590 &pSReply("Prefix channel with '-' to delete for sure.");
597 if ($message =~ /^chpass(\s+(.*))?$/) {
598 my(@args) = split /[\s\t]+/, $2 || '';
605 if (!&IsUser($args[0])) {
606 &pSReply("user $args[0] is not valid.");
610 my $u = &getUser($who);
612 if (scalar @args == 1) { # del pass.
613 if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
614 &pSReply("cannto remove passwd of others.");
618 if (!exists $users{$u}{PASS}) {
619 &pSReply("$u does not have pass set anyway.");
623 &pSReply("Deleted pass from $u.");
625 $utime_userfile = time();
628 delete $users{$u}{PASS};
633 my $salt = join '',('.','/',0..9,'A'..'Z','a'..'z')[rand 64, rand 64];
634 my $crypt = crypt($args[1], $salt);
635 &pSReply("Set $u's passwd to '$crypt'");
636 $users{$u}{PASS} = $crypt;
638 $utime_userfile = time();
644 if ($message =~ /^chattr(\s+(.*))?$/) {
645 my(@args) = split /[\s\t]+/, $2 || '';
653 if ($args[0] =~ /^$mask{nick}$/i) { # <nick>
654 $user = &getUser($args[0]);
657 $user = &getUser($who);
658 &DEBUG("user $who... nope.") unless (defined $user);
659 $user = &getUser($verifyUser);
663 if (!defined $user) {
664 &pSReply("user $user does not exist.");
668 my $flags = $users{$user}{FLAGS};
669 if (!defined $chflag) {
670 &pSReply("Flags for $user: $flags");
674 &DEBUG("who => $who");
675 &DEBUG("verifyUser => $verifyUser");
676 if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
677 &pSReply("cannto change attributes of others.");
683 foreach (split //, $chflag) {
684 if ($_ eq "+") { $state = 1; next; }
685 if ($_ eq "-") { $state = 0; next; }
687 if (!defined $state) {
688 &pSReply("no initial + or - was found in attr.");
693 next if ($flags =~ /\Q$_\E/);
696 if (&IsParam("owner")
697 and $param{owner} =~ /^\Q$user\E$/i
698 and $flags =~ /[nmo]/
700 &pSReply("not removing flag $_ for $user.");
703 next unless ($flags =~ s/\Q$_\E//);
710 $utime_userfile = time();
712 &pSReply("Current flags: $flags");
713 $users{$user}{FLAGS} = $flags;
715 &pSReply("No flags changed: $flags");
721 if ($message =~ /^chnick(\s+(.*))?$/) {
722 my(@args) = split /[\s\t]+/, $2 || '';
724 if ($who eq "_default") {
725 &WARN("$who or verifyuser tried to run chnick.");
729 if (!scalar @args or scalar @args > 2) {
734 if (scalar @args == 1) { # 1
735 $user = &getUser($who);
736 &DEBUG("nope, not $who.") unless (defined $user);
737 $user ||= &getUser($verifyUser);
740 $user = &getUser($args[0]);
744 if (!defined $user) {
745 &pSReply("user $who or $args[0] does not exist.");
749 if ($user =~ /^\Q$chnick\E$/i) {
750 &pSReply("user == chnick. why should I do that?");
754 if (&getUser($chnick)) {
755 &pSReply("user $chnick is already used!");
759 if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
760 &pSReply("cannto change nick of others.");
761 return "REPLY" if ($who eq "_default");
765 foreach (keys %{ $users{$user} }) {
766 $users{$chnick}{$_} = $users{$user}{$_};
767 delete $users{$user}{$_};
769 undef $users{$user}; # ???
771 $utime_userfile = time();
774 &pSReply("Changed '$user' to '$chnick' successfully.");
779 if ($message =~ /^([-+])host(\s+(.*))?$/) {
781 my(@args) = split /[\s\t]+/, $3 || '';
782 my $state = ($1 eq "+") ? 1 : 0;
789 if ($who eq "_default") {
790 &WARN("$who or verifyuser tried to run $cmd.");
795 if ($args[0] =~ /^$mask{nick}$/i) { # <nick>
796 return unless (&hasFlag("m"));
797 $user = &getUser($args[0]);
800 # who or verifyUser. FIXME!!!
801 $user = &getUser($who);
805 if (!defined $user) {
806 &pSReply("user $user does not exist.");
810 if (!defined $mask) {
812 &pSReply("Hostmasks for $user: $users{$user}{HOSTS}");
817 if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
818 &pSReply("cannto change masks of others.");
822 if ($mask !~ /^$mask{nuh}$/) {
823 &pSReply("error: mask ($mask) is not a real hostmask.");
827 my $count = scalar keys %{ $users{$user}{HOSTS} };
830 if (exists $users{$user}{HOSTS}{$mask}) {
831 &pSReply("mask $mask already exists.");
835 ### TODO: override support.
836 $users{$user}{HOSTS}{$mask} = 1;
838 &pSReply("Added $mask to list of masks.");
842 if (!exists $users{$user}{HOSTS}{$mask}) {
843 &pSReply("mask $mask does not exist.");
847 ### TODO: wildcard support. ?
848 delete $users{$user}{HOSTS}{$mask};
850 if (scalar keys %{ $users{$user}{HOSTS} } != $count) {
851 &pSReply("Removed $mask from list of masks.");
853 &pSReply("error: could not find $mask in list of masks.");
858 $utime_userfile = time();
864 if ($message =~ /^([-+])ban(\s+(.*))?$/) {
867 my(@args) = split /[\s\t]+/, $3 || '';
868 my $state = ($1 eq "+") ? 1 : 0;
875 my($mask,$chan,$time,$reason);
877 if ($flatarg =~ s/^($mask{nuh})\s*//) {
880 &DEBUG("arg does not contain nuh mask?");
883 if ($flatarg =~ s/^($mask{chan})\s*//) {
886 $chan = "*"; # _default instead?
889 if ($state == 0) { # delete.
890 my $c = join(' ', &banDel($mask) );
893 &pSReply("Removed $mask from chans: $c");
895 &pSReply("$mask was not found in ban list.");
906 if ($flatarg =~ s/^(\d+)\s*//) {
908 &DEBUG("time = $time.");
910 &pSReply("error: time cannot be negatime?");
917 if ($flatarg =~ s/^(.*)$//) { # need length?
921 if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
922 &pSReply("cannto change masks of others.");
926 if ($mask !~ /^$mask{nuh}$/) {
927 &pSReply("error: mask ($mask) is not a real hostmask.");
931 if ( &banAdd($mask,$chan,$time,$reason) == 2) {
932 &pSReply("ban already exists; overwriting.");
934 &pSReply("Added $mask for $chan (time => $time, reason => $reason)");
939 if ($message =~ /^whois(\s+(.*))?$/) {
947 my $user = &getUser($arg);
948 if (!defined $user) {
949 &pSReply("whois: user $user does not exist.");
953 ### TODO: better (eggdrop-like) output.
954 &pSReply("user: $user");
955 foreach (keys %{ $users{$user} }) {
956 my $ref = ref $users{$user}{$_};
958 if ($ref eq "HASH") {
961 foreach (keys %{ $users{$user}{$type} }) {
962 &pSReply(" $type => $_");
967 &pSReply(" $_ => $users{$user}{$_}");
969 &pSReply("End of USER whois.");
974 if ($message =~ /^bans(\s+(.*))?$/) {
978 if ($arg ne "_default" and !&validChan($arg) ) {
979 &pSReply("error: chan $chan is invalid.");
984 if (!scalar keys %bans) {
985 &pSReply("Ban list is empty.");
990 &pSReply(" mask: expire, time-added, count, who-by, reason");
991 foreach $c (keys %bans) {
992 next unless (!defined $arg or $arg =~ /^\Q$c\E$/i);
995 foreach (keys %{ $bans{$c} }) {
996 my $val = $bans{$c}{$_};
998 if (ref $val eq "ARRAY") {
999 my @array = @{ $val };
1000 &pSReply(" $_: @array");
1002 &DEBUG("unknown ban: $val");
1006 &pSReply("END of bans.");
1011 if ($message =~ /^banlist(\s+(.*))?$/) {
1014 if (defined $arg and $arg !~ /^$mask_chan$/) {
1015 &pSReply("error: chan $chan is invalid.");
1019 &DEBUG("bans for global or arg => $arg.");
1020 foreach (keys %bans) { #CHANGE!!!
1021 &DEBUG(" $_ => $bans{$_}.");
1024 &DEBUG("End of bans.");
1025 &pSReply("END of bans.");
1030 if ($message =~ /^save$/) {
1031 return unless (&hasFlag("o"));
1040 $message =~ s/^addignore/+ignore/;
1041 $message =~ s/^(del|un)ignore/-ignore/;
1044 if ($message =~ /^(\+|\-)ignore(\s+(.*))?$/i) {
1045 return unless (&hasFlag("o"));
1046 my $state = ($1 eq "+") ? 1 : 0;
1047 my $str = $1."ignore";
1055 my($mask,$chan,$time,$comment);
1058 if ($args =~ s/^($mask{nuh})\s*//) {
1061 &ERROR("no NUH mask?");
1065 if (!$state) { # delignore.
1066 if ( &ignoreDel($mask) ) {
1067 &pSReply("ok, deleted X ignores.");
1069 &pSReply("could not find $mask in ignore list.");
1079 if ($args =~ s/^($mask{chan}|\*)\s*//) {
1086 if ($args =~ s/^(\d+)\s*//) {
1096 $comment = "added by $who";
1099 if ( &ignoreAdd($mask, $chan, $time, $comment) > 1) {
1100 &pSReply("warn: $mask already in ignore list; written over anyway. FIXME");
1102 &pSReply("added $mask to ignore list.");
1108 if ($message =~ /^ignore(\s+(.*))?$/) {
1112 if ($arg !~ /^$mask{chan}$/) {
1113 &pSReply("error: chan $chan is invalid.");
1117 if (!&validChan($arg)) {
1118 &pSReply("error: chan $arg is invalid.");
1122 &pSReply("Showing bans for $arg only.");
1125 if (!scalar keys %ignore) {
1126 &pSReply("Ignore list is empty.");
1130 ### TODO: proper (eggdrop-like) formatting.
1132 &pSReply(" mask: expire, time-added, who, comment");
1133 foreach $c (keys %ignore) {
1134 next unless (!defined $arg or $arg =~ /^\Q$c\E$/i);
1137 foreach (keys %{ $ignore{$c} }) {
1138 my $ref = ref $ignore{$c}{$_};
1139 if ($ref eq "ARRAY") {
1140 my @array = @{ $ignore{$c}{$_} };
1141 &pSReply(" $_: @array");
1143 &DEBUG("unknown ignore line?");
1147 &pSReply("END of ignore.");
1153 if ($message =~ /^(\+|\-|add|del)user(\s+(.*))?$/i) {
1155 my $strstr = $1."user";
1156 my @args = split /\s+/, $3 || '';
1158 my $state = ($str =~ /^(\+|add)$/) ? 1 : 0;
1160 if (!scalar @args) {
1166 if (scalar @args != 2) {
1167 &pSReply(".+host requires hostmask argument.");
1170 } elsif (scalar @args != 1) {
1171 &pSReply("too many arguments.");
1175 if ($state) { # adduser.
1176 if (scalar @args == 1) {
1177 $args[1] = &getHostMask($args[0]);
1178 if (!defined $args[1]) {
1179 &ERROR("could not get hostmask?");
1184 if ( &userAdd(@args) ) { # success.
1185 &pSReply("Added $args[0]...");
1188 &pSReply("User $args[0] already exists");
1193 if ( &userDel($args[0]) ) { # success.
1194 &pSReply("Deleted $args[0] successfully.");
1197 &pSReply("User $args[0] does not exist.");
1204 if ($message =~ /^sched$/) {
1209 foreach (keys %sched) {
1210 next unless (exists $sched{$_}{TIME});
1211 $time{ $sched{$_}{TIME}-time() }{$_} = 1;
1214 next unless (exists $sched{$_}{RUNNING});
1219 foreach (sort { $a <=> $b } keys %time) {
1220 my $str = join(", ", sort keys %{ $time{$_} });
1221 push(@time, "$str (".&Time2String($_).")");
1224 &pSReply( &formListReply(0, "Schedulers: ", sort @time ) );
1225 &pSReply( &formListReply(0, "Scheds to run: ", sort @list ) );
1226 &pSReply( &formListReply(0, "Scheds running(should not happen?) ", sort @run ) );