# NOTE: Merged from User.pl
#
-if (&IsParam("useStrict")) { use strict; }
+#use strict;
#####
##### USERFILE CONFIGURATION READER/WRITER
#####
sub readUserFile {
- my $f = "$bot_misc_dir/blootbot.users";
+ my $f = "$bot_state_dir/blootbot.users";
if (! -f $f) {
&DEBUG("userfile not found; new fresh run detected.");
}
if (!open IN, $f) {
- &ERROR("cannot read userfile.");
+ &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;
return;
}
- if (!open OUT,">$bot_misc_dir/blootbot.users") {
- &ERROR("cannot write to userfile.");
+ if (!open OUT,">$bot_state_dir/blootbot.users") {
+ &ERROR("Cannot write userfile ($bot_state_dir/blootbot.users): $!");
return;
}
$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 {
- my $f = "$bot_misc_dir/blootbot.chan";
+ my $f = "$bot_state_dir/blootbot.chan";
if ( -f $f and -f "$f~") {
my $s1 = -s $f;
my $s2 = -s "$f~";
}
if (!open IN, $f) {
- &ERROR("cannot erad chanfile.");
+ &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;
### 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}{$_};
return;
}
- if (!open OUT,">$bot_misc_dir/blootbot.chan") {
- &ERROR("cannot write chanfile.");
+ if (!open OUT,">$bot_state_dir/blootbot.chan") {
+ &ERROR("Cannot write chanfile ($bot_state_dir/blootbot.chan): $!");
return;
}
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};
}
}
foreach (keys %opts) {
- next unless ($opts{$_} > 1);
+ next unless ($opts{$_} > 2);
&DEBUG(" opts{$_} => $opts{$_}");
}
" chans) at $time");
if (defined $msgType and $msgType =~ /^chat$/) {
- &performStrictReply("--- Writing chan file...");
+ &pSReply("--- Writing chan file...");
}
}
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;
}
}
$ignore{$chan}{$mask} = [$expire, time(), $who, $comment];
+ # todo: improve this.
+ &status("ignore: Added $mask for $chan to expire $expire, by $who, for $comment");
+
if ($exist) {
$utime_userfile = time();
$ucount_userfile++;
return;
}
+sub rehashConfVars {
+ # this is an attempt to fix where an option is loaded but the module
+ # has 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}{$_};
+ }
+
+ if (/^uptime$/ and $i) {
+ &loadMyModule("uptime");
+ delete $cache{confvars}{$_};
+ }
+
+ if (/^rootwarn$/i and $i) {
+ &loadMyModule($_);
+ delete $cache{confvars}{$_};
+ }
+ }
+
+ &DEBUG("end of rehashConfVars");
+
+ delete $cache{confvars};
+}
+
my @regFlagsChan = (
"autojoin",
"freshmeat",