d7a4c80e58f11c740d8291cd593829bcc9952f6b
[PHP-P10.git] / Bots / MCBot.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/MCBot.class.php
21  *
22  * MCBot bot...
23  *
24  */
25
26 class {$_NAME} extends Bot {
27         private $uplink;
28         private $mcbot;
29         
30         public function load($uplink, $old = false) {
31                 $this->uplink = $uplink;
32                 if(!$old) {
33                         $nick = "MCBot";
34                         $ident = "mcbot";
35                         $ip = "0::0";
36                         $host = "Services.WebGamesNet.net";
37                         $realname = "MineCraft Bot";
38                         $modes = "ioknISD";
39                         $this->mcbot = $this->uplink->addUser($nick,$ident,$host,$ip,$modes,$realname);
40                         if(is_a($this->mcbot, "P10_User")) {
41                                 $this->uplink->join($this->mcbot, "#MineCraft", (P10_Channel::USERPRIV_OPED | P10_Channel::USERPRIV_VOICE));
42                                 $this->uplink->join($this->mcbot, "#dev", P10_Channel::USERPRIV_VOICE);
43                         }
44                 } else {
45                         $this->mcbot = $old;
46                 }
47                 
48                 ModCMD::bind($this, BIND_JOIN, "recive_join");
49                 ModCMD::bind($this, BIND_QUIT, "recive_quit");
50         }
51         
52         public function unload($rehash = false) {
53                 if($rehash) {
54                         return $this->mcbot;
55                 } else {
56                         $this->uplink->delUser($this->mcbot, "Bye.");
57                 }
58         }
59         
60         private function botOppedOnChannel($channel) {
61                 $privs = $channel->getUserPrivs($this->mcbot);
62                 return ($privs & P10_Channel::USERPRIV_OPED);
63         }
64         
65         public function recive_join($user, $channel, $isBurst) {
66                 if(!$this->botOppedOnChannel($channel)) return false;
67                 if(preg_match("#(.*).spoof.minecraft.WebGamesNet#i",$user->getHost())) {
68                         $this->uplink->mode($this->mcbot, $channel, "+v ".$user->getNumeric());
69                 }
70         }
71         
72         public function recive_quit($user, $reason) {
73                 if($user === $this->mcbot) {
74                         $this->load($this->uplink);
75                 }
76         }
77 }
78
79 ?>