]> git.donarmstrong.com Git - infobot.git/blobdiff - src/DynaConfig.pl
- added top3 irctextcounter stats
[infobot.git] / src / DynaConfig.pl
index 398781d55197d23ea324a06ff86a7234951e1697..9fa01ddd57fe6ca88eb9ad7a21c1a081c28b4600 100644 (file)
@@ -13,7 +13,23 @@ if (&IsParam("useStrict")) { use strict; }
 #####
 
 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;
@@ -96,6 +112,11 @@ sub readUserFile {
 }
 
 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;
@@ -200,7 +221,17 @@ sub writeUserFile {
 #####
 
 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;
     }
@@ -225,7 +256,10 @@ sub readChanFile {
            $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;
@@ -247,10 +281,17 @@ sub readChanFile {
        }
     }
 
+    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;
@@ -302,8 +343,8 @@ sub writeChanFile {
            }
        }
 
-       &DEBUG("chans => ".scalar(keys %chanconf)." - 1");
        foreach (keys %opts) {
+           next unless ($opts{$_} > 1);
            &DEBUG("  opts{$_} => $opts{$_}");
        }
 
@@ -381,7 +422,7 @@ sub verifyUser {
     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;
@@ -422,9 +463,14 @@ sub ckpasswd {
     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));
@@ -542,6 +588,19 @@ sub banAdd {
                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++;
@@ -658,8 +717,14 @@ sub chanSet {
            $val        = 0;
        }
 
-       $chanconf{$chan}{$what} = $val;
-       &pSReply("Setting $what for $chan to '$val'$was.");
+       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"
@@ -709,6 +774,19 @@ my @regFlagsChan = (
 ### 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)
+#####