added saxdb & continued BotLoader
[PHP-P10.git] / BotLoader / BotLoader.class.php
1 <?php
2 /********************************* PHP-P10 ******************************
3  *    P10 uplink class by pk910   (c)2011 pk910                         *
4  ************************************************************************
5  *                          Version 2 (OOP)                             *
6  *                                                                      *
7  * PHP-P10 is free software; you can redistribute it and/or modify      *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or    *
10  * (at your option) any later version.                                  *
11  *                                                                      *
12  * This program is distributed in the hope that it will be useful,      *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
15  * GNU General Public License for more details.                         *
16  *                                                                      *
17  * You should have received a copy of the GNU General Public License    *
18  * along with PHP-P10; if not, write to the Free Software Foundation,   *
19  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.       *
20  *                                                                      *
21  ************************************************************************
22  * 
23  *  BotLoader/BotLoader.class.php
24  *
25  * This class loades / rehashs or unloads all Bots.
26  *
27  */
28 require_once("Bot.class.php");
29 require_once("saxdb.class.php");
30
31 class BotLoader {
32         private $uplink;
33         private $saxdb;
34         private $botdb;
35         private $loadedBots = array();
36         
37         public function __construct($uplink) {
38                 $this->uplink = $uplink;
39                 $this->saxdb = new saxdb();
40                 $this->saxdb->loadDB("php_p10.db");
41                 $this->botdb = $this->saxdb->getSection("BotLoader");
42         }
43         
44         public function loadBots() {
45                 if(array_key_exists("bots", $this->botdb) && is_array($this->botdb["bots"])) {
46                         foreach($this->botdb["bots"] as $name => $botfile) {
47                                 $this->loadBot($name, $botfile);
48                         }
49                 } else {
50                         $this->botdb["bots"] = array();
51                 }
52         }
53         
54         private function loadBot($name, $botfile) {
55                 if(array_key_exists($name, $this->loadedBots)) return;
56                 //load bot
57                 if(!array_key_exists($name, $this->botdb["bots"])) {
58                         $this->botdb["bots"][$name] = $botfile;
59                 }
60         }
61         
62 }
63
64 ?>