fixed Bot database handling
authorpk910 <philipp@zoelle1.de>
Wed, 10 Aug 2011 05:29:42 +0000 (07:29 +0200)
committerpk910 <philipp@zoelle1.de>
Wed, 10 Aug 2011 05:29:42 +0000 (07:29 +0200)
BotLoader/Bot.class.php
BotLoader/BotLoader.class.php
BotLoader/saxdb.class.php
Bots/PulseBot.class.php

index b617193cfac36a748d9b2b4aee7a88e597c0d5ac..303163d40d8832b5add7fc5344dc0d078a022468 100644 (file)
@@ -24,6 +24,7 @@
  */
 
 class Bot {
+       private $db_section = NULL;
        
        public function load($uplink, $oldDatas = null) {
        
@@ -44,7 +45,14 @@ class Bot {
        public function readDB($value) {
        
        }
-
+       
+       public function getDBSection() {
+               return $this->db_section;
+       }
+       
+       public function setDBSection($section) {
+               $this->db_section = $section;
+       }
 }
 
 ?>
\ No newline at end of file
index b13be3657aa2f1676c67283700524d8771edc3d1..a9082d7c55b9ef07d061e0ee38aae514580125ab 100644 (file)
@@ -67,9 +67,9 @@ class BotLoader {
        
        public function autosave() {
                foreach($this->loadedBots as $name => $bot) {
-                       if(array_key_exists(strtolower($name), $this->botDatabases)) {
+                       if($bot->getDBSection()) {
                                $db = $bot->writeDB();
-                               $this->saxdb->setSection($this->botDatabases[strtolower($name)],$db);
+                               $this->saxdb->setSection($bot->getDBSection(),$db);
                        }
                }
                $this->save();
@@ -99,10 +99,9 @@ class BotLoader {
                if(!(array_key_exists(strtolower($name), $this->loadedBots))) return false;
                //unload bot
                $bot = $this->loadedBots[strtolower($name)];
-               if(array_key_exists(strtolower($name), $this->botDatabases)) {
+               if($bot->getDBSection()) {
                        $db = $bot->writeDB();
-                       $this->saxdb->setSection($this->botDatabases[strtolower($name)],$db);
-                       unset($this->botDatabases[strtolower($name)]);
+                       $this->saxdb->setSection($bot->getDBSection(),$db);
                }
                ModCMD::unbindBot($bot);
                $bot->unload(false);
@@ -125,10 +124,9 @@ class BotLoader {
                if(!$botfile) break;
                //rehash bot
                $bot = $this->loadedBots[strtolower($name)];
-               if(array_key_exists(strtolower($name), $this->botDatabases)) {
+               if($bot->getDBSection()) {
                        $db = $bot->writeDB();
-                       $this->saxdb->setSection($this->botDatabases[strtolower($name)],$db);
-                       unset($this->botDatabases[strtolower($name)]);
+                       $this->saxdb->setSection($bot->getDBSection(),$db);
                }
                ModCMD::unbindBot($bot);
                $data = $bot->unload(true);
@@ -147,18 +145,7 @@ class BotLoader {
        
        private function addDBsection($bot, $section) {
                if(!is_a($bot, "Bot")) return false;
-               $name = null;
-               foreach($this->loadedBots as $botname => $cbot) {
-                       if($cbot === $bot) {
-                               $name = $botname;
-                               break;
-                       }
-               }
-               if($name == null) return false;
-               if(array_key_exists(strtolower($name), $this->botDatabases)) {
-                       return false;
-               }
-               $this->botDatabases[strtolower($name)] = $section;
+               $bot->setDBSection($section);
                $bot->readDB($this->saxdb->getSection($section));
        }
        
index 1c431688536b69e118a91806b52052e4b1355466..a76760a387517a5b7e59b06666eb628ce1d6ecb5 100644 (file)
@@ -152,7 +152,10 @@ class saxdb {
        private function serializeDB($db) {
                $dbstring = "";
                foreach($db as $name => $value) {
-                       if(!is_array($value) && !is_string($value) && !is_numeric($value)) continue;
+                       if(!is_array($value) && !is_string($value) && !is_numeric($value)) {
+                               echo"invalid type ".gettype($value)."\n";
+                               continue;
+                       }
                        $dbstring .= "\"".str_replace("\"","\\\"", $name)."\"";
                        if(is_array($value)) {
                                $dbstring .= "{";
index de2345ada65894b8f53ef1dbed81d9878d4283d3..20ef93ef2465e2552006b01866b600fb06ef32de 100644 (file)
@@ -145,7 +145,7 @@ class {$_NAME} extends Bot {
                                        if(!array_key_exists("users", $this->db)) {
                                                $this->db['users'] = array();
                                        }
-                                       $this->db['users'][$auth] = $pulseUser->MemberName;
+                                       $this->db['users'][$auth] = strval($pulseUser->MemberName);
                                        $this->uplink->notice($this->pulsebot, $user, "WhatPulse user '".$pulseUserName."' added (Keys: ".number_format(floatval($pulseUser->MemberKeys),0,',','.').", Clicks: ".number_format(floatval($pulseUser->MemberClicks),0,',','.').").");
                                }
                                break;