# NOTE: Merged from User.pl
#
-if (&IsParam("useStrict")) { use strict; }
+use strict;
+
+use vars qw(%chanconf %cache %bans %channels %nuh %users %ignore
+ %talkWho %dcc %mask);
+use vars qw($utime_userfile $ucount_userfile $utime_chanfile $who
+ $ucount_chanfile $userHandle $chan $msgType $talkchannel
+ $ident $bot_state_dir $talkWho $flag_quit $wtime_userfile
+ $wcount_userfile $wtime_chanfile $nuh $message);
#####
##### USERFILE CONFIGURATION READER/WRITER
#####
sub readUserFile {
- if (!open IN,"$bot_misc_dir/blootbot.users") {
- &ERROR("cannot read userfile.");
+ my $f = "$bot_state_dir/blootbot.users";
+
+ if (! -f $f) {
+ &DEBUG("userfile not found; new fresh run detected.");
+ return;
+ }
+
+ if ( -f $f and -f "$f~") {
+ my $s1 = -s $f;
+ my $s2 = -s "$f~";
+
+ if ($s2 > $s1*3) {
+ &FIXME("rUF: backup file bigger than current file.");
+ }
+ }
+
+ if (!open IN, $f) {
+ &ERROR("Cannot read userfile ($f): $!");
&closeLog();
exit 1;
}
undef %users; # clear on reload.
undef %bans; # reset.
- undef %ingore; # reset.
+ undef %ignore; # reset.
my $ver = <IN>;
if ($ver !~ /^#v1/) {
next;
}
+ if (!defined $nick) {
+ &WARN("DynaConfig: invalid line: $_");
+ next;
+ }
+
# nice little hack.
if ($what eq "HOSTS") {
$users{$nick}{$what}{$val} = 1;
}
sub writeUserFile {
- if (!open OUT,">$bot_misc_dir/blootbot.users") {
- &ERROR("cannot write to userfile.");
+ if (!scalar keys %users) {
+ &DEBUG("wUF: nothing to write.");
+ return;
+ }
+
+ if (!open OUT,">$bot_state_dir/blootbot.users") {
+ &ERROR("Cannot write userfile ($bot_state_dir/blootbot.users): $!");
return;
}
- my $time = scalar(localtime);
+ my $time = scalar(gmtime);
print OUT "#v1: blootbot -- $ident -- written $time\n\n";
$wtime_userfile = time();
&status("--- Saved USERFILE ($cusers users; $cbans bans; $cignore ignore) at $time");
if (defined $msgType and $msgType =~ /^chat$/) {
- &performStrictReply("--- Writing user file...");
+ &pSReply("--- Writing user file...");
}
}
#####
sub readChanFile {
- if (!open IN,"$bot_misc_dir/blootbot.chan") {
- &ERROR("cannot erad chanfile.");
+ my $f = "$bot_state_dir/blootbot.chan";
+ if ( -f $f and -f "$f~") {
+ my $s1 = -s $f;
+ my $s2 = -s "$f~";
+
+ if ($s2 > $s1*3) {
+ &FIXME("rCF: backup file bigger than current file.");
+ }
+ }
+
+ if (!open IN, $f) {
+ &ERROR("Cannot read chanfile ($f): $!");
return;
}
while (<IN>) {
chop;
- next if /^$/;
+ next if /^\s*$/;
+ next if /^\// or /^\;/; # / or ; are comment lines.
if (/^(\S+)\s*$/) {
$chan = $1;
$chanconf{$chan}{$1} = 1;
} elsif (/^[\s\t]+\-(\S+)$/) { # bool, false.
- $chanconf{$chan}{$1} = 0;
+ &DEBUG("deprecated support of negative options.") unless ($cache{negative});
+ # although this is supported in run-time configuration.
+ $cache{negative} = 1;
+# $chanconf{$chan}{$1} = 0;
} elsif (/^[\s\t]+(\S+)[\ss\t]+(.*)$/) {# what = val.
$chanconf{$chan}{$1} = $2;
### TODO: check against valid params.
foreach $chan (keys %chanconf) {
foreach (keys %{ $chanconf{$chan} }) {
- next unless (/^[+-]/);
+ next unless /^[+-]/;
+
&WARN("invalid param: chanconf{$chan}{$_}; removing.");
delete $chanconf{$chan}{$_};
undef $chanconf{$chan}{$_};
}
}
+ delete $cache{negative};
+
&status("CHANFILE: Loaded: ".(scalar(keys %chanconf)-1)." chans");
}
sub writeChanFile {
- if (!open OUT,">$bot_misc_dir/blootbot.chan") {
- &ERROR("cannot write chanfile.");
+ if (!scalar keys %chanconf) {
+ &DEBUG("wCF: nothing to write.");
return;
}
- my $time = scalar(localtime);
+ if (!open OUT,">$bot_state_dir/blootbot.chan") {
+ &ERROR("Cannot write chanfile ($bot_state_dir/blootbot.chan): $!");
+ return;
+ }
+
+ my $time = scalar(gmtime);
print OUT "#v1: blootbot -- $ident -- written $time\n\n";
if ($flag_quit) {
next if ($chan eq "_default");
next unless (exists $chanconf{$chan}{$opt});
next unless ($val eq $chanconf{$chan}{$opt});
+
push(@chans,$chan);
delete $chanconf{$chan}{$opt};
}
}
}
- &DEBUG("chans => ".scalar(keys %chanconf)." - 1");
foreach (keys %opts) {
+ next unless ($opts{$_} > 2);
&DEBUG(" opts{$_} => $opts{$_}");
}
" chans) at $time");
if (defined $msgType and $msgType =~ /^chat$/) {
- &performStrictReply("--- Writing chan file...");
+ &pSReply("--- Writing chan file...");
}
}
##### USER COMMANDS.
#####
+# todo: support multiple flags.
sub IsFlag {
my $flags = shift;
my ($ret, $f, $o) = "";
sub verifyUser {
my ($nick, $lnuh) = @_;
- my ($user,$m);
+ my ($user, $m);
if ($userHandle = $dcc{'CHATvrfy'}{$who}) {
&VERB("vUser: cached auth for $who.",2);
foreach $user (keys %users) {
next if ($user eq "_default");
- foreach $m (keys %{$users{$user}{HOSTS}}) {
+ foreach $m (keys %{ $users{$user}{HOSTS} }) {
$m =~ s/\?/./g;
$m =~ s/\*/.*?/g;
$m =~ s/([\@\(\)\[\]])/\\$1/g;
return 0 unless ($plain ne "" and $encrypted ne "");
# MD5 // DES. Bobby Billingsley++.
- my $salt = substr($encrypted, 0, 2);
- if ($encrypted =~ /^\$\d\$(\w\w)\$/) {
+ my $salt;
+ if ($encrypted =~ /^(\S{2})/ and length $encrypted == 13) {
$salt = $1;
+ } elsif ($encrypted =~ /^\$\d\$(\w\w)\$/) {
+ $salt = $1;
+ } else {
+ &DEBUG("unknown salt from $encrypted.");
+ return 0;
}
return ($encrypted eq crypt($plain, $salt));
return 1;
} else {
&status("DCC CHAT: <$who> $message -- not enough flags.");
- &performStrictReply("error: you do not have enough flags for that. ($flag required)");
+ &pSReply("error: you do not have enough flags for that. ($flag required)");
return 0;
}
}
+# expire is time in minutes
sub ignoreAdd {
my($mask,$chan,$expire,$comment) = @_;
my $count ||= 0;
if ($expire > 0) {
- $expire = $expire*60 + time();
+ $expire = ($expire*60) + time();
} else {
$expire = 0;
}
$ignore{$chan}{$mask} = [$expire, time(), $who, $comment];
+ # todo: improve this.
+ if ($expire == 0) {
+ &status("ignore: Added $mask for $chan to NEVER expire, by $who, for $comment");
+ } else {
+ &status("ignore: Added $mask for $chan to expire $expire mins, by $who, for $comment");
+ }
+
if ($exist) {
$utime_userfile = time();
$ucount_userfile++;
$utime_userfile = time();
$ucount_userfile++;
- $users{$nick}{HOSTS}{$mask} = 1;
+ if (defined $mask and $mask !~ /^\s*$/) {
+ &DEBUG("userAdd: mask => $mask");
+ $users{$nick}{HOSTS}{$mask} = 1;
+ }
+
$users{$nick}{FLAGS} ||= $users{_default}{FLAGS};
return 1;
exists $bans{'*'}{$mask});
$bans{$chan}{$mask} = [$expire, time(), 0, $who, $reason];
+ my @chans = ($chan eq "*") ? keys %channels : $chan;
+ my $m = $mask;
+ $m =~ s/\?/\\./g;
+ $m =~ s/\*/\\S*/g;
+ foreach (@chans) {
+ my $chan = $_;
+ foreach (keys %{ $channels{$chan}{''} }) {
+ next unless (exists $nuh{lc $_});
+ next unless ($nuh{lc $_} =~ /^$m$/i);
+ &FIXME("nuh{$_} =~ /$m/");
+ }
+ }
+
if ($exist == 1) {
$utime_userfile = time();
$ucount_userfile++;
return;
}
$chanconf{$chan}{_time_added} = time();
- $chanconf{$what}{autojoin} = 1;
+ $chanconf{$chan}{autojoin} = 1;
&pSReply("Joining $chan...");
&joinchan($chan);
my $update = 0;
- if (defined $what and $what =~ s/^\+(\S+)/$1/) {
- my $was = $chanconf{$chan}{$1};
- if (defined $was and $was eq "1") {
- &pSReply("setting $what for $chan already 1.");
- return;
- }
+ if (defined $what and $what =~ s/^([+-])(\S+)/$2/) {
+ ### ".chanset +blah"
+ ### ".chanset +blah 10" -- error.
- $was = ($was) ? "; was '$was'" : "";
- &pSReply("Setting $what for $chan to '1'$was.");
+ my $state = ($1 eq "+") ? 1 : 0;
+ my $was = $chanconf{$chan}{$what};
- $chanconf{$chan}{$what} = 1;
+ if ($state) { # add/set.
+ if (defined $was and $was eq "1") {
+ &pSReply("setting $what for $chan already 1.");
+ return;
+ }
- $update++;
- } elsif (defined $what and $what =~ s/^\-(\S+)/$1/) {
- my $was = $chanconf{$chan}{$1};
- # hrm...
- if (!defined $was) {
- &pSReply("setting $what for $chan is not set.");
- return;
- }
+ $val = 1;
- if ($was eq "0") {
- &pSReply("setting $what for $chan already 0.");
- return;
+ } else { # delete/unset.
+ if (!defined $was) {
+ &pSReply("setting $what for $chan is not set.");
+ return;
+ }
+
+ if ($was eq "0") {
+ &pSReply("setting $what for $chan already 0.");
+ return;
+ }
+
+ $val = 0;
}
+ # alter for cosmetic (print out) reasons only.
$was = ($was) ? "; was '$was'" : "";
- &pSReply("Setting $what for $chan to '0'$was.");
- $chanconf{$chan}{$what} = 0;
+ if ($val eq "0") {
+ &pSReply("Unsetting $what for $chan$was.");
+ delete $chanconf{$chan}{$what};
+ } else {
+ &pSReply("Setting $what for $chan to '$val'$was.");
+ $chanconf{$chan}{$what} = $val;
+ }
$update++;
+
} elsif (defined $val) {
+ ### ".chanset blah testing"
+
my $was = $chanconf{$chan}{$what};
if (defined $was and $was eq $val) {
&pSReply("setting $what for $chan already '$val'.");
$chanconf{$chan}{$what} = $val;
$update++;
+
} else { # read only.
+ ### ".chanset"
+ ### ".chanset blah"
+
+ if (!defined $what) {
+ &WARN("chanset/DC: what == undefine.");
+ return;
+ }
+
if (exists $chanconf{$chan}{$what}) {
&pSReply("$what for $chan is '$chanconf{$chan}{$what}'");
} else {
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.
- my @items;
- my $str = "";
- foreach (sort keys %{ $chanconf{$chan} }) {
- my $newstr = join(', ', @items);
- if (length $newstr > 60) {
- &pSReply(" $str");
- @items = ();
- }
- $str = $newstr;
- push(@items, "$_ => $chanconf{$chan}{$_}");
- }
+ return;
+}
- &pSReply(" $str") if (@items);
+sub rehashConfVars {
+ # this is an attempt to fix where an option is enabled but the module
+ # has been not loaded. it also can be used for other things.
+
+ foreach (keys %{ $cache{confvars} }) {
+ my $i = $cache{confvars}{$_};
+ &DEBUG("rehashConfVars: _ => $_");
+
+ if (/^news$/ and $i) {
+ &loadMyModule("news");
+ delete $cache{confvars}{$_};
}
- return;
+ if (/^uptime$/ and $i) {
+ &loadMyModule("uptime");
+ delete $cache{confvars}{$_};
+ }
+
+ if (/^rootwarn$/i and $i) {
+ &loadMyModule($_);
+ delete $cache{confvars}{$_};
+ }
}
- return;
+ &DEBUG("end of rehashConfVars");
+
+ delete $cache{confvars};
}
+# registered flags... not used yet.
my @regFlagsChan = (
"autojoin",
- "freshmeat",
"limitcheckInterval",
"limitcheckPlus",
"allowConv",
### TODO: finish off this list.
);
-my @regFlagsUser = ("mno"); # todo...
+my @regFlagsUser = (
+ "m", # modify factoid. (includes renaming)
+ "r", # remove factoid.
+ "t", # teach/add factoid.
+ "a", # ask/request factoid.
+ "n", # bot owner
+ # can "reload"
+ "o", # master of bot (automatic +amrt)
+ # can search on factoid strings shorter than 2 chars
+ # can tell bot to join new channels
+ # can [un]lock factoids
+ "O", # dynamic ops (as on channel). (automatic +o)
+ "A", # bot administration over /msg
+ # default is only via DCC CHAT
+ "T", # add topics.
+);
1;