]> git.donarmstrong.com Git - infobot.git/blobdiff - src/core.pl
- add 'days' to created_time output.
[infobot.git] / src / core.pl
index 567852c96683233dc8f9e6634543662e77df45e9..5b233981a60348f1a8081b99172e4a355afad1fd 100644 (file)
@@ -26,6 +26,7 @@ use vars qw(@joinchan @ircServers @wingateBad @wingateNow @wingateCache
 use vars qw(%count %netsplit %netsplitservers %flood %dcc %orig
            %nuh %talkWho %seen %floodwarn %param %dbh %ircPort %userList
            %jointime %topic %joinverb %moduleAge %last %time %mask %file
+           %forked %pid %fork
 );
 
 # Signals.
@@ -45,8 +46,8 @@ $wingaterun   = time();
 $firsttime     = 1;
 
 ### CHANGE TO STATIC.
-$bot_version = "blootbot 1.0.0 (20000725) -- $^O";
-$noreply        = "NOREPLY";
+$bot_version = "blootbot cvs (20001212) -- $^O";
+$noreply       = "NOREPLY";
 
 ##########
 ### misc commands.
@@ -60,6 +61,8 @@ sub doExit {
     } elsif ($bot_pid == $$) { # parent.
        &status("parent caught SIG$sig (pid $$).") if (defined $sig);
 
+       &status("--- Start of quit.");
+
        my $type;
        &closeDCC();
        &closePID();
@@ -71,6 +74,7 @@ sub doExit {
        &dumpallvars()  if (&IsParam("dumpvarsAtExit"));
        &closeLog();
        &closeSQLDebug()        if (&IsParam("SQLDebug"));
+       &status("--- QUIT.");
     } else {                                   # child.
        &status("child caught SIG$sig (pid $$).");
     }
@@ -85,7 +89,7 @@ sub doWarn {
        &WARN("PERL: $_");
     }
 
-    $SIG{__WARN__} = 'doWarn';
+    $SIG{__WARN__} = 'doWarn'; # ???
 }
 
 # Usage: &IsParam($param);
@@ -147,8 +151,9 @@ sub showProc {
 sub setup {
     &showProc(" (\&openLog before)");
     &openLog();                # write, append.
+    &status("--- Started logging.");
 
-    foreach ("debian","Temp") {
+    foreach ("debian") {
        my $dir = "$bot_base_dir/$_/";
        next if ( -d $dir);
        &status("Making dir $_");
@@ -160,6 +165,13 @@ sub setup {
     &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"));
@@ -167,19 +179,39 @@ sub setup {
 
     &status("Setup: ". &countKeys("factoids") ." factoids.");
 
+    $param{tempDir} =~ s#\~/#$ENV{HOME}/#;
+
     &status("Initial memory usage: $memusage kB");
 }
 
 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 ($param{tempDir} =~ s#\~/#$ENV{HOME}/#) {
+       &status("Fixing up tempDir.");
+    }
+
+    if ($param{tempDir} =~ /~/) {
+       &ERROR("parameter tempDir still contains tilde.");
+       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";
@@ -201,6 +233,8 @@ sub startup {
 
 sub shutdown {
     # reverse order of &setup().
+    &DEBUG("shutdown called.");
+
     &closeDB();
     &closeSHM($shm);   # aswell. TODO: use this in &doExit?
     &closeLog();
@@ -209,8 +243,12 @@ sub shutdown {
 sub restart {
     my ($sig) = @_;
 
+    &DEBUG(" forked => ".scalar(keys %forked) );
+    &DEBUG(" fork   => ".scalar(keys %fork) );
+    &DEBUG(" pid    => ".scalar(keys %pid) );
+
     if ($$ == $bot_pid) {
-       &status("$sig called.");
+       &status("--- $sig called.");
 
        ### crappy bug in Net::IRC?
        if (!$conn->connected and time - $msgtime > 900) {
@@ -225,7 +263,7 @@ sub restart {
        &reloadAllModules() if (&IsParam("DEBUG"));
        &setup();
 
-       &status("End of $sig.");
+       &status("--- End of $sig.");
     } else {
        &status("$sig called; ignoring restart.");
     }