fixed Client.class.php (block timeouts) and some other bugs
[PHP-P10.git] / Bots / ModManager.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  *  Bots/ModManager.class.php
24  *
25  * module manager bot...
26  *
27  */
28
29 class {$_NAME} extends Bot {
30         private $uplink;
31         private $modman;
32         
33         public function load($uplink, $old = false) {
34                 $this->uplink = $uplink;
35                 if(!$old) {
36                         $nick = "ModuleMan";
37                         $ident = "modman";
38                         $host = "Services.WebGamesNet.net";
39                         $ip = "0::0";
40                         $realname = "Module Manager";
41                         $modes = "ioknISD";
42                         $this->modman = $this->uplink->addUser($nick,$ident,$host,$ip,$modes,$realname);
43                         if(is_a($this->modman, "P10_User")) {
44                                 $this->uplink->join($this->modman, "#opers", (P10_Channel::USERPRIV_OPED | P10_Channel::USERPRIV_VOICE));
45                                 $this->uplink->join($this->modman, "#dev", P10_Channel::USERPRIV_VOICE);
46                         }
47                 } else {
48                         $this->modman = $old;
49                 }
50                 
51                 ModCMD::bind($this, BIND_CHANMSG, "recive_privmsg");
52                 ModCMD::bind($this, BIND_QUIT, "recive_quit");
53         }
54         
55         public function unload($rehash = false) {
56                 if($rehash) {
57                         return $this->modman;
58                 } else {
59                         $this->uplink->delUser($this->modman, "Bye.");
60                 }
61         }
62         
63         function recive_privmsg($user, $channel, $message) {
64                 if(!$user->getModes()->hasMode('o')) return 0;
65                 $exp=explode(" ",$message);
66                 switch (strtolower($exp[0])) {
67                         case "~loadmod":
68                                 if(BotLoader::load($exp[1],$exp[2])) {
69                                         $this->uplink->privmsg($this->modman, $channel, "done.");
70                                 } else {
71                                         $this->uplink->privmsg($this->modman, $channel, "error.");
72                                 }
73                                 break;
74                         case "~unloadmod":
75                                 if(BotLoader::unload($exp[1])) {
76                                         $this->uplink->privmsg($this->modman, $channel, "done.");
77                                 } else {
78                                         $this->uplink->privmsg($this->modman, $channel, "error.");
79                                 }
80                                 break;
81                         case "~rehash":
82                                 if(BotLoader::rehash($exp[1])) {
83                                         $this->uplink->privmsg($this->modman, $channel, "done.");
84                                 } else {
85                                         $this->uplink->privmsg($this->modman, $channel, "error.");
86                                 }
87                                 break;
88                         case "~list":
89                                 foreach(BotLoader::listBots() as $name => $bot) {
90                                         $this->uplink->privmsg($this->modman, $channel, $name);
91                                 }
92                                 break;
93                         case "~debug":
94                                 $exp=explode(" ",$message,2);
95                                 ob_start();
96                                 $ret = eval($exp[1]);
97                                 $out = ob_get_contents();
98                                 ob_end_clean();
99                                 $lines = explode("\n",$out);
100                                 for($i=0;$i<count($lines);$i++) {
101                                         if($lines[$i]!="") {
102                                                 $this->uplink->privmsg($this->modman, $channel, $lines[$i]);
103                                         }
104                                 }
105                                 $lines = explode("\n",$ret);
106                                 for($i=0;$i<count($lines);$i++) {
107                                         if($lines[$i]!="") {
108                                                 $this->uplink->privmsg($this->modman, $channel, $lines[$i]);
109                                         }
110                                 }
111                                 break;
112                 }
113         }
114         
115         function recive_quit($user, $reason) {
116                 if($user === $this->modman) {
117                         $this->load($this->uplink);
118                 }
119         }
120 }
121
122 ?>