#####
sub readUserFile {
- if (!open IN,"$bot_misc_dir/blootbot.users") {
+ my $f = "$bot_misc_dir/blootbot.users";
+
+ if ( -f $f and -f "$f~") {
+ my $s1 = -s $f;
+ my $s2 = -s "$f~";
+
+ if ($s2 > $s1*3) {
+ &DEBUG("rUF: backup file bigger than current file. FIXME");
+ }
+ }
+
+ if (!open IN, $f) {
&ERROR("cannot read userfile.");
&closeLog();
exit 1;
}
sub writeUserFile {
+ if (!scalar keys %users) {
+ &DEBUG("wUF: nothing to write.");
+ return;
+ }
+
if (!open OUT,">$bot_misc_dir/blootbot.users") {
&ERROR("cannot write to userfile.");
return;
#####
sub readChanFile {
- if (!open IN,"$bot_misc_dir/blootbot.chan") {
+ my $f = "$bot_misc_dir/blootbot.chan";
+ if ( -f $f and -f "$f~") {
+ my $s1 = -s $f;
+ my $s2 = -s "$f~";
+
+ if ($s2 > $s1*3) {
+ &DEBUG("rCF: backup file bigger than current file. FIXME");
+ }
+ }
+
+ if (!open IN, $f) {
&ERROR("cannot erad chanfile.");
return;
}
$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;
}
}
+ delete $cache{negative};
+
&status("CHANFILE: Loaded: ".(scalar(keys %chanconf)-1)." chans");
}
sub writeChanFile {
+ if (!scalar keys %chanconf) {
+ &DEBUG("wCF: nothing to write.");
+ return;
+ }
+
if (!open OUT,">$bot_misc_dir/blootbot.chan") {
&ERROR("cannot write chanfile.");
return;
}
}
- &DEBUG("chans => ".scalar(keys %chanconf)." - 1");
foreach (keys %opts) {
+ next unless ($opts{$_} > 1);
&DEBUG(" opts{$_} => $opts{$_}");
}
my ($user,$m);
if ($userHandle = $dcc{'CHATvrfy'}{$who}) {
- &DEBUG("vUser: cached auth for $who.");
+ &VERB("vUser: cached auth for $who.",2);
return $userHandle;
}
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));
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++;
}
}
+sub chanSet {
+ my($cmd, $chan, $what, $val) = @_;
+
+ if ($cmd eq "+chan") {
+ if (exists $chanconf{$chan}) {
+ &pSReply("chan $chan already exists.");
+ return;
+ }
+ $chanconf{$chan}{_time_added} = time();
+ $chanconf{$what}{autojoin} = 1;
+
+ &pSReply("Joining $chan...");
+ &joinchan($chan);
+
+ return;
+ }
+
+ if (!exists $chanconf{$chan}) {
+ &pSReply("no such channel $chan");
+ return;
+ }
+
+ my $update = 0;
+
+ ### ".chanset +blah"
+ ### ".chanset +blah 10" -- error.
+ if (defined $what and $what =~ s/^([+-])(\S+)/$2/) {
+ my $state = ($1 eq "+") ? 1 : 0;
+ my $was = $chanconf{$chan}{$what};
+
+ if ($state) { # add/set.
+ if (defined $was and $was eq "1") {
+ &pSReply("setting $what for $chan already 1.");
+ return;
+ }
+
+ $was = ($was) ? "; was '$was'" : "";
+ $val = 1;
+
+ } 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;
+ }
+
+ $was = ($was) ? "; was '$was'" : "";
+ $val = 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++;
+
+ ### ".chanset blah testing"
+ } elsif (defined $val) {
+ my $was = $chanconf{$chan}{$what};
+ if (defined $was and $was eq $val) {
+ &pSReply("setting $what for $chan already '$val'.");
+ return;
+ }
+ $was = ($was) ? "; was '$was'" : "";
+ &pSReply("Setting $what for $chan to '$val'$was.");
+
+ $chanconf{$chan}{$what} = $val;
+
+ $update++;
+
+ ### ".chanset"
+ ### ".chanset blah"
+ } else { # read only.
+ if (!defined $what) {
+ &WARN("chanset/DC: what == undefine.");
+ return;
+ }
+
+ if (exists $chanconf{$chan}{$what}) {
+ &pSReply("$what for $chan is '$chanconf{$chan}{$what}'");
+ } else {
+ &pSReply("$what for $chan is not set.");
+ }
+ }
+
+ if ($update) {
+ $utime_chanfile = time();
+ $ucount_chanfile++;
+ }
+
+ return;
+}
+
my @regFlagsChan = (
"autojoin",
"freshmeat",
### TODO: finish off this list.
);
-my @regFlagsUser = ("mno"); # todo...
+my @regFlagsUser = (
+ "m", # master
+ "n", # owner
+ "o", # op
+); # todo...
1;