]> git.donarmstrong.com Git - infobot.git/blobdiff - src/core.pl
tempdir fix
[infobot.git] / src / core.pl
index 5f5d8138f1a75c0f8c323e5f829633667615504b..4faff2fb4ec8f32587f4dc41aeed5c4070bea8a6 100644 (file)
@@ -10,7 +10,7 @@ use strict;
 # dynamic scalar. MUST BE REDUCED IN SIZE!!!
 ### TODO: reorder.
 use vars qw(
-       $answer $correction_plausible $loggingstatus $talkchannel
+       $answer $correction_plausible $talkchannel
        $statcount $memusage $user $memusageOld $bot_version $dbh
        $shm $host $msg $bot_misc_dir $bot_pid $bot_base_dir $noreply
        $bot_src_dir $conn $irc $learnok $nick $ident $no_syscall
@@ -45,8 +45,8 @@ $wingaterun   = time();
 $firsttime     = 1;
 
 ### CHANGE TO STATIC.
-$bot_version = "blootbot 1.0.0 (20000725) -- $^O";
-$noreply        = "NOREPLY";
+$bot_version = "blootbot 1.0.3 (20000930) -- $^O";
+$noreply       = "NOREPLY";
 
 ##########
 ### misc commands.
@@ -70,6 +70,7 @@ sub doExit {
        &closeSHM($shm);
        &dumpallvars()  if (&IsParam("dumpvarsAtExit"));
        &closeLog();
+       &closeSQLDebug()        if (&IsParam("SQLDebug"));
     } else {                                   # child.
        &status("child caught SIG$sig (pid $$).");
     }
@@ -115,15 +116,22 @@ sub showProc {
        if (defined $memusageOld and &IsParam("DEBUG")) {
            # it's always going to be increase.
            my $delta = $memusage - $memusageOld;
-           if ($delta > 500) {
-               &status("MEM:$prefix increased by $delta kB. (total: $memusage kB)");
+           my $str;
+           if ($delta == 0) {
+               return;
+           } elsif ($delta > 500) {
+               $str = "MEM:$prefix increased by $delta kB. (total: $memusage kB)";
            } elsif ($delta > 0) {
-               &status("MEM:$prefix increased by $delta kB.");
-           } elsif ($delta < 0) {
+               $str = "MEM:$prefix increased by $delta kB";
+           } else {    # delta < 0.
                $delta = -$delta;
                # never knew RSS could decrease, probably Size can't?
-               &status("MEM:$prefix decreased by $delta kB. YES YES YES");
+               $str = "MEM:$prefix decreased by $delta kB. YES YES YES";
            }
+
+           &status($str);
+           &DCCBroadcast($str) if (&whatInterface() =~ /IRC/ &&
+               grep(/Irc.pl/, keys %moduleAge));
        }
        $memusageOld = $memusage;
     } else {
@@ -140,13 +148,28 @@ sub setup {
     &showProc(" (\&openLog before)");
     &openLog();                # write, append.
 
+    foreach ("debian") {
+       my $dir = "$bot_base_dir/$_/";
+       next if ( -d $dir);
+       &status("Making dir $_");
+       mkdir $dir, 0755;
+    }
+
     # read.
     &loadIgnore($bot_misc_dir.         "/blootbot.ignore");
     &loadLang($bot_misc_dir.           "/blootbot.lang");
     &loadIRCServers($bot_misc_dir.     "/ircII.servers");
     &loadUsers($bot_misc_dir.          "/blootbot.users");
+    if (&IsParam("WIP")) {
+       require "src/UserFile.pl";
+       &NEWloadUsers($bot_misc_dir."/blootbot.users_NEW");
+       &closePID();
+       &closeLog();
+       exit 0;
+    }
 
     $shm = &openSHM();
+    &openSQLDebug()    if (&IsParam("SQLDebug"));
     &openDB($param{'DBName'}, $param{'SQLUser'}, $param{'SQLPass'});
 
     &status("Setup: ". &countKeys("factoids") ." factoids.");
@@ -157,13 +180,22 @@ sub setup {
 sub setupConfig {
     $param{'VERBOSITY'} = 1;
     &loadConfig($bot_misc_dir."/blootbot.config");
+    if (&IsParam("WIP")) {
+       require "src/Config.pl";
+       &NEWloadConfig();
+    }
 
-    foreach ("ircNick", "ircUser", "ircName", "DBType") {
+    foreach ("ircNick", "ircUser", "ircName", "DBType", "tempDir") {
        next if &IsParam($_);
        &ERROR("Parameter $_ has not been defined.");
        exit 1;
     }
 
+    if (! -d $param{tempDir}) {
+       &status("making $param{tempDir}...");
+       system("mkdir $param{tempDir}");
+    }
+
     # static scalar variables.
     $file{utm} = "$bot_base_dir/$param{'ircUser'}.uptime";
     $file{PID} = "$bot_base_dir/$param{'ircUser'}.pid";
@@ -194,7 +226,7 @@ sub restart {
     my ($sig) = @_;
 
     if ($$ == $bot_pid) {
-       &status("$sig called.");
+       &status("--- $sig called.");
 
        ### crappy bug in Net::IRC?
        if (!$conn->connected and time - $msgtime > 900) {
@@ -206,10 +238,10 @@ sub restart {
 
        &shutdown();
        &loadConfig($bot_misc_dir."/blootbot.config");
-       &reloadModules() if (&IsParam("DEBUG"));
+       &reloadAllModules() if (&IsParam("DEBUG"));
        &setup();
 
-       &status("End of $sig.");
+       &status("--- End of $sig.");
     } else {
        &status("$sig called; ignoring restart.");
     }