]> git.donarmstrong.com Git - infobot.git/commitdiff
- support multiple bots on one host.
authordms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 22 Aug 2003 11:32:11 +0000 (11:32 +0000)
committerdms <dms@c11ca15a-4712-0410-83d8-924469b57eb5>
Fri, 22 Aug 2003 11:32:11 +0000 (11:32 +0000)
  seems to work with one bot on the machine.
  requested by timriker.

git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk/blootbot@814 c11ca15a-4712-0410-83d8-924469b57eb5

src/Shm.pl

index 5ab3d186501a89807fff7662fa83aa049adb5b92..ae7e84283317b71b658b5c2d7e10d31e6f5acfbe 100644 (file)
@@ -64,22 +64,29 @@ sub shmWrite {
 
     return if (&IsParam("noSHM"));
 
-    # NULL hack.
-    ### TODO: create shmClear to deal with this.
-    if ($str !~ /^$/) {
-       my $read = &shmRead($key);
-       $read =~ s/\0+//g;
-
-       if ($str eq "") {
-           $str = time().": ";         # time stamping, null.
-       } elsif ($read eq "") {
-           $str = time().": ";         # timestamping.
-       } else {
-           $str = $read ."||". $str;
+    if (length($str) > $size) {
+       &status("ERROR: length(str) (..)>$size...");
+       return;
+    }
+
+    if (length($str) == 0) {
+       # does $size overwrite the whole lot?
+       # if not, set to 2000.
+       if (!shmwrite($key, '', $position, $size)) {
+           &ERROR("shmWrite: failed: $!");
        }
+       return;
     }
 
-    if (!shmwrite($key,$str,$position,$size)) {
+    my $read = &shmRead($key);
+    $read =~ s/\0+//g;
+    if ($read eq "") {
+       $str = sprintf("%s:%d:%d: ", $param{ircNick}, $bot_pid, time());
+    } else {
+       $str = $read ."||". $str;
+    }
+
+    if (!shmwrite($key, '', $position, $size)) {
        &ERROR("shmWrite: failed: $!");
     }
 }
@@ -227,8 +234,14 @@ sub shmFlush {
     my $time;
     my $shmmsg = &shmRead($shm);
     $shmmsg =~ s/\0//g;         # remove padded \0's.
-    if ($shmmsg =~ s/^(\d+): //) {
-       $time   = $1;
+    return if (length($shmmsg) == 0);
+    if ($shmmsg =~ s/^(\S+):(\d+):(\d+): //) {
+       my $n   = $1;
+       my $pid = $2;
+       $time   = $3;
+    } else {
+       &status("warn: shmmsg='$shmmsg'.");
+       return;
     }
 
     foreach (split '\|\|', $shmmsg) {