changed file headers & added AUTHORS file
[PHP-P10.git] / Bots / ModManager.class.php
1 <?php
2 /******************************* PHP-P10 v2 *****************************
3  * Copyright (C) 2011  Philipp Kreil (pk910)                            *
4  *                                                                      *
5  * This program is free software: you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation, either version 3 of the License, or    *
8  * (at your option) any later version.                                  *
9  *                                                                      * 
10  * This program is distributed in the hope that it will be useful,      *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
13  * GNU General Public License for more details.                         *
14  *                                                                      *
15  * You should have received a copy of the GNU General Public License    *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  *                                                                      *
18  ************************************************************************
19  * 
20  *  Bots/ModManager.class.php
21  *
22  * module manager bot...
23  *
24  */
25
26 class {$_NAME} extends Bot {
27         private $uplink;
28         private $modman;
29         
30         public function load($uplink, $old = false) {
31                 $this->uplink = $uplink;
32                 if(!$old) {
33                         $nick = "ModuleMan";
34                         $ident = "modman";
35                         $host = "Services.WebGamesNet.net";
36                         $ip = "0::0";
37                         $realname = "Module Manager";
38                         $modes = "ioknISD";
39                         $this->modman = $this->uplink->addUser($nick,$ident,$host,$ip,$modes,$realname);
40                         if(is_a($this->modman, "P10_User")) {
41                                 $this->uplink->join($this->modman, "#opers", (P10_Channel::USERPRIV_OPED | P10_Channel::USERPRIV_VOICE));
42                                 $this->uplink->join($this->modman, "#dev", P10_Channel::USERPRIV_VOICE);
43                         }
44                 } else {
45                         $this->modman = $old;
46                 }
47                 
48                 ModCMD::bind($this, BIND_CHANMSG, "recive_privmsg");
49                 ModCMD::bind($this, BIND_QUIT, "recive_quit");
50         }
51         
52         public function unload($rehash = false) {
53                 if($rehash) {
54                         return $this->modman;
55                 } else {
56                         $this->uplink->delUser($this->modman, "Bye.");
57                 }
58         }
59         
60         function recive_privmsg($user, $channel, $message) {
61                 if(!$user->getModes()->hasMode('o')) return 0;
62                 $exp=explode(" ",$message);
63                 switch (strtolower($exp[0])) {
64                         case "~loadmod":
65                                 if(BotLoader::load($exp[1],$exp[2])) {
66                                         $this->uplink->privmsg($this->modman, $channel, "done.");
67                                 } else {
68                                         $this->uplink->privmsg($this->modman, $channel, "error.");
69                                 }
70                                 break;
71                         case "~unloadmod":
72                                 if(BotLoader::unload($exp[1])) {
73                                         $this->uplink->privmsg($this->modman, $channel, "done.");
74                                 } else {
75                                         $this->uplink->privmsg($this->modman, $channel, "error.");
76                                 }
77                                 break;
78                         case "~rehash":
79                                 if(BotLoader::rehash($exp[1])) {
80                                         $this->uplink->privmsg($this->modman, $channel, "done.");
81                                 } else {
82                                         $this->uplink->privmsg($this->modman, $channel, "error.");
83                                 }
84                                 break;
85                         case "~list":
86                                 foreach(BotLoader::listBots() as $name => $bot) {
87                                         $this->uplink->privmsg($this->modman, $channel, $name);
88                                 }
89                                 break;
90                         case "~debug":
91                                 $exp=explode(" ",$message,2);
92                                 ob_start();
93                                 $ret = eval($exp[1]);
94                                 $out = ob_get_contents();
95                                 ob_end_clean();
96                                 $lines = explode("\n",$out);
97                                 for($i=0;$i<count($lines);$i++) {
98                                         if($lines[$i]!="") {
99                                                 $this->uplink->privmsg($this->modman, $channel, $lines[$i]);
100                                         }
101                                 }
102                                 $lines = explode("\n",$ret);
103                                 for($i=0;$i<count($lines);$i++) {
104                                         if($lines[$i]!="") {
105                                                 $this->uplink->privmsg($this->modman, $channel, $lines[$i]);
106                                         }
107                                 }
108                                 break;
109                 }
110         }
111         
112         function recive_quit($user, $reason) {
113                 if($user === $this->modman) {
114                         $this->load($this->uplink);
115                 }
116         }
117 }
118
119 ?>