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+(.*?))?$/) {
467 if (!defined $args) {
473 if ($args =~ s/^($mask{chan})\s*//) {
475 &DEBUG("chan => $chan.");
477 &DEBUG("no chan arg; setting to default.");
481 my($what,$val) = split /[\s\t]+/, $args, 2;
483 ### TODO: "cannot set values without +m".
484 return unless (&hasFlag("m"));
486 if ($cmd eq "+chan") {
487 &DEBUG("setting _time_added...");
488 $chanconf{$chan}{_time_added} = time();
490 &pSReply("Joining $chan...");
496 if (!exists $chanconf{$chan}) {
497 &pSReply("no such channel $chan");
502 if ($what =~ /^\+(\S+)/) {
503 my $was = $chanconf{$chan}{$1};
504 $was = ($was) ? "; was '$was'" : "";
505 &pSReply("Setting $1 for $chan to '1'$was.");
507 $chanconf{$chan}{$1} = 1;
510 } elsif ($what =~ /^\-(\S+)/) {
511 my $was = $chanconf{$chan}{$1};
512 $was = ($was) ? "; was '$was'" : "";
513 &pSReply("Setting $1 for $chan to '0'$was.");
515 $chanconf{$chan}{$1} = 0;
518 } elsif (defined $val) {
519 my $was = $chanconf{$chan}{$what};
520 $was = ($was) ? "; was '$was'" : "";
521 &pSReply("Setting $what for $chan to '$val'$was.");
523 $chanconf{$chan}{$what} = $val;
526 } elsif (defined $what) {
527 &pSReply("$what for $chan is '$chanconf{$chan}{$what}'");
531 $utime_chanfile = time();
536 if ($cmd eq "chanset" and !defined $what) {
537 &DEBUG("showing channel conf.");
539 foreach $chan ($chan, "_default") {
540 &pSReply("chan: $chan");
541 ### TODO: merge 2 or 3 per line.
542 foreach (sort keys %{ $chanconf{$chan} }) {
543 &pSReply(" $_ => $chanconf{$chan}{$_}");
553 if ($message =~ /^(chanunset|\-chan)(\s+(.*))?$/) {
554 return unless (&hasFlag("m"));
557 if (!defined $args) {
564 if ($args =~ s/^(\-)?($mask{chan})\s*//) {
566 $delete = ($1) ? 1 : 0;
567 &DEBUG("chan => $chan.");
569 &DEBUG("no chan arg; setting to default.");
573 if (!exists $chanconf{$chan}) {
574 &pSReply("no such channel $chan");
579 if (&getChanConf($args,$chan)) {
580 &pSReply("Unsetting channel ($chan) option $args. (was $chanconf{$chan}{$args})");
581 undef $chanconf{$chan}{$args};
584 &pSReply("$args does not exist for $chan");
591 &pSReply("Deleting channel $chan for sure!");
592 $utime_chanfile = time();
596 &pSReply("Leaving $chan...");
598 delete $chanconf{$chan};
600 &pSReply("Prefix channel with '-' to delete for sure.");
607 if ($message =~ /^chpass(\s+(.*))?$/) {
608 my(@args) = split /[\s\t]+/, $2 || '';
615 if (!&IsUser($args[0])) {
616 &pSReply("user $args[0] is not valid.");
620 my $u = &getUser($who);
622 if (scalar @args == 1) { # del pass.
623 if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
624 &pSReply("cannto remove passwd of others.");
628 if (!exists $users{$u}{PASS}) {
629 &pSReply("$u does not have pass set anyway.");
633 &pSReply("Deleted pass from $u.");
635 $utime_userfile = time();
638 delete $users{$u}{PASS};
643 my $salt = join '',('.','/',0..9,'A'..'Z','a'..'z')[rand 64, rand 64];
644 my $crypt = crypt($args[1], $salt);
645 &pSReply("Set $u's passwd to '$crypt'");
646 $users{$u}{PASS} = $crypt;
648 $utime_userfile = time();
654 if ($message =~ /^chattr(\s+(.*))?$/) {
655 my(@args) = split /[\s\t]+/, $2 || '';
663 if ($args[0] =~ /^$mask{nick}$/i) { # <nick>
664 $user = &getUser($args[0]);
667 $user = &getUser($who);
668 &DEBUG("user $who... nope.") unless (defined $user);
669 $user = &getUser($verifyUser);
673 if (!defined $user) {
674 &pSReply("user $user does not exist.");
678 my $flags = $users{$user}{FLAGS};
679 if (!defined $chflag) {
680 &pSReply("Flags for $user: $flags");
684 &DEBUG("who => $who");
685 &DEBUG("verifyUser => $verifyUser");
686 if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
687 &pSReply("cannto change attributes of others.");
693 foreach (split //, $chflag) {
694 if ($_ eq "+") { $state = 1; next; }
695 if ($_ eq "-") { $state = 0; next; }
697 if (!defined $state) {
698 &pSReply("no initial + or - was found in attr.");
703 next if ($flags =~ /\Q$_\E/);
706 if (&IsParam("owner")
707 and $param{owner} =~ /^\Q$user\E$/i
708 and $flags =~ /[nmo]/
710 &pSReply("not removing flag $_ for $user.");
713 next unless ($flags =~ s/\Q$_\E//);
720 $utime_userfile = time();
722 &pSReply("Current flags: $flags");
723 $users{$user}{FLAGS} = $flags;
725 &pSReply("No flags changed: $flags");
731 if ($message =~ /^chnick(\s+(.*))?$/) {
732 my(@args) = split /[\s\t]+/, $2 || '';
734 if ($who eq "_default") {
735 &WARN("$who or verifyuser tried to run chnick.");
739 if (!scalar @args or scalar @args > 2) {
744 if (scalar @args == 1) { # 1
745 $user = &getUser($who);
746 &DEBUG("nope, not $who.") unless (defined $user);
747 $user ||= &getUser($verifyUser);
750 $user = &getUser($args[0]);
754 if (!defined $user) {
755 &pSReply("user $who or $args[0] does not exist.");
759 if ($user =~ /^\Q$chnick\E$/i) {
760 &pSReply("user == chnick. why should I do that?");
764 if (&getUser($chnick)) {
765 &pSReply("user $chnick is already used!");
769 if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
770 &pSReply("cannto change nick of others.");
771 return "REPLY" if ($who eq "_default");
775 foreach (keys %{ $users{$user} }) {
776 $users{$chnick}{$_} = $users{$user}{$_};
777 delete $users{$user}{$_};
779 undef $users{$user}; # ???
781 $utime_userfile = time();
784 &pSReply("Changed '$user' to '$chnick' successfully.");
789 if ($message =~ /^([-+])host(\s+(.*))?$/) {
791 my(@args) = split /[\s\t]+/, $3 || '';
792 my $state = ($1 eq "+") ? 1 : 0;
799 if ($who eq "_default") {
800 &WARN("$who or verifyuser tried to run $cmd.");
805 if ($args[0] =~ /^$mask{nick}$/i) { # <nick>
806 return unless (&hasFlag("m"));
807 $user = &getUser($args[0]);
810 # who or verifyUser. FIXME!!!
811 $user = &getUser($who);
815 if (!defined $user) {
816 &pSReply("user $user does not exist.");
820 if (!defined $mask) {
822 &pSReply("Hostmasks for $user: $users{$user}{HOSTS}");
827 if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
828 &pSReply("cannto change masks of others.");
832 if ($mask !~ /^$mask{nuh}$/) {
833 &pSReply("error: mask ($mask) is not a real hostmask.");
837 my $count = scalar keys %{ $users{$user}{HOSTS} };
840 if (exists $users{$user}{HOSTS}{$mask}) {
841 &pSReply("mask $mask already exists.");
845 ### TODO: override support.
846 $users{$user}{HOSTS}{$mask} = 1;
848 &pSReply("Added $mask to list of masks.");
852 if (!exists $users{$user}{HOSTS}{$mask}) {
853 &pSReply("mask $mask does not exist.");
857 ### TODO: wildcard support. ?
858 delete $users{$user}{HOSTS}{$mask};
860 if (scalar keys %{ $users{$user}{HOSTS} } != $count) {
861 &pSReply("Removed $mask from list of masks.");
863 &pSReply("error: could not find $mask in list of masks.");
868 $utime_userfile = time();
874 if ($message =~ /^([-+])ban(\s+(.*))?$/) {
877 my(@args) = split /[\s\t]+/, $3 || '';
878 my $state = ($1 eq "+") ? 1 : 0;
885 my($mask,$chan,$time,$reason);
887 if ($flatarg =~ s/^($mask{nuh})\s*//) {
890 &DEBUG("arg does not contain nuh mask?");
893 if ($flatarg =~ s/^($mask{chan})\s*//) {
896 $chan = "*"; # _default instead?
899 if ($state == 0) { # delete.
900 my $c = join(' ', &banDel($mask) );
903 &pSReply("Removed $mask from chans: $c");
905 &pSReply("$mask was not found in ban list.");
916 if ($flatarg =~ s/^(\d+)\s*//) {
918 &DEBUG("time = $time.");
920 &pSReply("error: time cannot be negatime?");
927 if ($flatarg =~ s/^(.*)$//) { # need length?
931 if (!&IsFlag("m") and $who !~ /^\Q$verifyUser\E$/i) {
932 &pSReply("cannto change masks of others.");
936 if ($mask !~ /^$mask{nuh}$/) {
937 &pSReply("error: mask ($mask) is not a real hostmask.");
941 if ( &banAdd($mask,$chan,$time,$reason) == 2) {
942 &pSReply("ban already exists; overwriting.");
944 &pSReply("Added $mask for $chan (time => $time, reason => $reason)");
949 if ($message =~ /^whois(\s+(.*))?$/) {
957 my $user = &getUser($arg);
958 if (!defined $user) {
959 &pSReply("whois: user $user does not exist.");
963 ### TODO: better (eggdrop-like) output.
964 &pSReply("user: $user");
965 foreach (keys %{ $users{$user} }) {
966 my $ref = ref $users{$user}{$_};
968 if ($ref eq "HASH") {
971 foreach (keys %{ $users{$user}{$type} }) {
972 &pSReply(" $type => $_");
977 &pSReply(" $_ => $users{$user}{$_}");
979 &pSReply("End of USER whois.");
984 if ($message =~ /^bans(\s+(.*))?$/) {
988 if ($arg ne "_default" and !&validChan($arg) ) {
989 &pSReply("error: chan $chan is invalid.");
994 if (!scalar keys %bans) {
995 &pSReply("Ban list is empty.");
1000 &pSReply(" expire, count, who-by, time-added, reason");
1001 foreach $c (keys %bans) {
1002 next unless (!defined $arg or $arg =~ /^\Q$c\E$/i);
1005 foreach (keys %{ $bans{$c} }) {
1006 my $val = $bans{$c}{$_};
1008 if (ref $val eq "ARRAY") {
1009 my @array = @{ $val };
1010 &pSReply(" @array");
1012 &DEBUG("unknown ban: $val");
1016 &pSReply("END of bans.");
1021 if ($message =~ /^banlist(\s+(.*))?$/) {
1024 if (defined $arg and $arg !~ /^$mask_chan$/) {
1025 &pSReply("error: chan $chan is invalid.");
1029 &DEBUG("bans for global or arg => $arg.");
1030 foreach (keys %bans) { #CHANGE!!!
1031 &DEBUG(" $_ => $bans{$_}.");
1034 &DEBUG("End of bans.");
1035 &pSReply("END of bans.");
1040 if ($message =~ /^save$/) {
1041 return unless (&hasFlag("o"));
1050 $message =~ s/^addignore/+ignore/;
1051 $message =~ s/^(del|un)ignore/-ignore/;
1054 if ($message =~ /^(\+|\-)ignore(\s+(.*))?$/i) {
1055 return unless (&hasFlag("o"));
1056 my $state = ($1 eq "+") ? 1 : 0;
1057 my $str = $1."ignore";
1065 my($mask,$chan,$time,$comment);
1068 if ($args =~ s/^($mask{nuh})\s*//) {
1071 &ERROR("no NUH mask?");
1075 if (!$state) { # delignore.
1076 if ( &ignoreDel($mask) ) {
1077 &pSReply("ok, deleted X ignores.");
1079 &pSReply("could not find $mask in ignore list.");
1089 if ($args =~ s/^($mask{chan}|\*)\s*//) {
1096 if ($args =~ s/^(\d+)\s*//) {
1106 $comment = "added by $who";
1109 if ( &ignoreAdd($mask, $chan, $time, $comment) > 1) {
1110 &pSReply("warn: $mask already in ignore list; written over anyway. FIXME");
1112 &pSReply("added $mask to ignore list.");
1118 if ($message =~ /^ignore(\s+(.*))?$/) {
1122 if ($arg !~ /^$mask{chan}$/) {
1123 &pSReply("error: chan $chan is invalid.");
1127 if (!&validChan($arg)) {
1128 &pSReply("error: chan $arg is invalid.");
1132 &pSReply("Showing bans for $arg only.");
1135 if (!scalar keys %ignore) {
1136 &pSReply("Ignore list is empty.");
1140 ### TODO: proper (eggdrop-like) formatting.
1142 &pSReply(" expire, count, who, added, comment");
1143 foreach $c (keys %ignore) {
1144 next unless (!defined $arg or $arg =~ /^\Q$c\E$/i);
1147 foreach (keys %{ $ignore{$c} }) {
1148 my $ref = ref $ignore{$c}{$_};
1149 if ($ref eq "ARRAY") {
1150 my @array = @{ $ignore{$c}{$_} };
1151 &pSReply(" $_: @array");
1153 &DEBUG("unknown ignore line?");
1157 &pSReply("END of ignore.");
1163 if ($message =~ /^(\+|\-|add|del)user(\s+(.*))?$/i) {
1165 my $strstr = $1."user";
1166 my @args = split /\s+/, $3 || '';
1168 my $state = ($str =~ /^(\+|add)$/) ? 1 : 0;
1170 if (!scalar @args) {
1176 if (scalar @args != 2) {
1177 &pSReply(".+host requires hostmask argument.");
1180 } elsif (scalar @args != 1) {
1181 &pSReply("too many arguments.");
1185 if ($state) { # adduser.
1186 if (scalar @args == 1) {
1187 $args[1] = &getHostMask($args[0]);
1188 if (!defined $args[1]) {
1189 &ERROR("could not get hostmask?");
1194 if ( &userAdd(@args) ) { # success.
1195 &pSReply("Added $args[0]...");
1198 &pSReply("User $args[0] already exists");
1203 if ( &userDel($args[0]) ) { # success.
1204 &pSReply("Deleted $args[0] successfully.");
1207 &pSReply("User $args[0] does not exist.");
1214 if ($message =~ /^sched$/) {
1217 foreach (keys %sched) {
1218 next unless (exists $sched{$_}{TIME});
1221 next unless (exists $sched{$_}{RUNNING});
1225 &pSReply( &formListReply(0,"Scheds to run: ", sort @list ) );
1226 &pSReply( &formListReply(0, "Scheds running(should not happen?) ", sort @run ) );