#####
sub readUserFile {
- if (!open IN,"$bot_misc_dir/blootbot.users") {
+ my $f = "$bot_misc_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) {
+ &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{$_}");
}
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++;
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;
- }
+ ### ".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};
- $was = ($was) ? "; was '$was'" : "";
- &pSReply("Setting $what for $chan to '1'$was.");
+ if ($state) { # add/set.
+ if (defined $was and $was eq "1") {
+ &pSReply("setting $what for $chan already 1.");
+ return;
+ }
- $chanconf{$chan}{$what} = 1;
+ $was = ($was) ? "; was '$was'" : "";
+ $val = 1;
- $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;
- }
+ } 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;
- }
+ if ($was eq "0") {
+ &pSReply("setting $what for $chan already 0.");
+ return;
+ }
- $was = ($was) ? "; was '$was'" : "";
- &pSReply("Setting $what for $chan to '0'$was.");
+ $was = ($was) ? "; was '$was'" : "";
+ $val = 0;
+ }
- $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++;
+
+ ### ".chanset blah testing"
} elsif (defined $val) {
my $was = $chanconf{$chan}{$what};
if (defined $was and $was eq $val) {
$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 {
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}{$_}");
- }
-
- &pSReply(" $str") if (@items);
- }
-
- return;
}
return;
### TODO: finish off this list.
);
-my @regFlagsUser = ("mno"); # todo...
+my @regFlagsUser = (
+ "m", # master
+ "n", # owner
+ "o", # op
+); # todo...
1;
+
+#####
+# Userflags
+# +r - ability to remove factoids
+# +t - ability to teach factoids
+# +m - ability to modify factoids
+# +n - bot owner
+# +o - authorised user of bot (like +m on eggdrop)
+#####