From 34baaf63f2b3a7ddc200aa12b1eebcef4fcc4b6a Mon Sep 17 00:00:00 2001 From: pk910 Date: Wed, 10 Aug 2011 07:29:42 +0200 Subject: [PATCH] fixed Bot database handling --- BotLoader/Bot.class.php | 10 +++++++++- BotLoader/BotLoader.class.php | 27 +++++++-------------------- BotLoader/saxdb.class.php | 5 ++++- Bots/PulseBot.class.php | 2 +- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/BotLoader/Bot.class.php b/BotLoader/Bot.class.php index b617193..303163d 100644 --- a/BotLoader/Bot.class.php +++ b/BotLoader/Bot.class.php @@ -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 diff --git a/BotLoader/BotLoader.class.php b/BotLoader/BotLoader.class.php index b13be36..a9082d7 100644 --- a/BotLoader/BotLoader.class.php +++ b/BotLoader/BotLoader.class.php @@ -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)); } diff --git a/BotLoader/saxdb.class.php b/BotLoader/saxdb.class.php index 1c43168..a76760a 100644 --- a/BotLoader/saxdb.class.php +++ b/BotLoader/saxdb.class.php @@ -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 .= "{"; diff --git a/Bots/PulseBot.class.php b/Bots/PulseBot.class.php index de2345a..20ef93e 100644 --- a/Bots/PulseBot.class.php +++ b/Bots/PulseBot.class.php @@ -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; -- 2.20.1