+ if(array_key_exists("bots", $this->botdb) && is_array($this->botdb["bots"])) {
+ foreach($this->botdb["bots"] as $name => $botfile) {
+ $this->loadBot($name, $botfile);
+ }
+ } else {
+ $this->botdb["bots"] = array();
+ }
+ }
+
+ public function unloadBots() {
+ foreach($this->loadedBots as $name => $bot) {
+ $this->unloadBot($name, false);
+ }
+ }
+
+ public function save() {
+ $this->saxdb->setSection("BotLoader", $this->botdb);
+ $this->saxdb->writeDB("php_p10.db");
+ }
+
+ public function autosave() {
+ foreach($this->loadedBots as $name => $bot) {
+ if($bot->getDBSection()) {
+ $db = $bot->writeDB();
+ $this->saxdb->setSection($bot->getDBSection(),$db);
+ }
+ }
+ $this->save();
+ timer(60*10, array($this, "autosave"), array());
+ }
+
+ public function loop() {
+ foreach($this->loadedBots as $name => $bot) {
+ $bot->loop();
+ }
+ }
+
+ private function loadBot($name, $botfile) {
+ if(array_key_exists(strtolower($name), $this->loadedBots)) return false;
+ //load bot
+ $bot = $this->loadClass($botfile, $name);
+ if(!$bot) return false;
+ $bot->load($this->uplink);
+ $this->loadedBots[strtolower($name)] = $bot;
+ if(!array_key_exists($name, $this->botdb["bots"])) {
+ $this->botdb["bots"][$name] = $botfile;
+ }
+ return true;
+ }
+
+ private function unloadBot($name, $delete = true) {
+ if(!(array_key_exists(strtolower($name), $this->loadedBots))) return false;
+ //unload bot
+ $bot = $this->loadedBots[strtolower($name)];
+ if($bot->getDBSection()) {
+ $db = $bot->writeDB();
+ $this->saxdb->setSection($bot->getDBSection(),$db);
+ }
+ ModCMD::unbindBot($bot);
+ $bot->unload(false);
+ unset($this->loadedBots[strtolower($name)]);
+ if(array_key_exists($name, $this->botdb["bots"]) && $delete) {
+ unset($this->botdb["bots"][$name]);
+ }
+ return true;
+ }