added own IPAddr Class and rewrote the IP Address parser & builder
[PHP-P10.git] / Bots / IPv6.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 $ipv6;
32         private $cache = array(
33                                                 0 => array(),
34                                                 1 => array()
35                                         );
36         
37         public function load($uplink, $old = false) {
38                 $this->uplink = $uplink;
39                 if(!$old) {
40                         $nick = "IPv6";
41                         $ident = "ipv6";
42                         $ip = "0::0";
43                         $host = "fd00::C0CA:C01A:ADD5:11FE"; //coca cola adds life   maybe someone undestands it :D
44                         $realname = "IPv6";
45                         $modes = "ioknISD";
46                         $this->ipv6 = $this->uplink->addUser($nick,$ident,$host,$ip,$modes,$realname);
47                         if(is_a($this->ipv6, "P10_User")) {
48                                 $this->uplink->join($this->ipv6, "#IPv6", (P10_Channel::USERPRIV_OPED | P10_Channel::USERPRIV_VOICE));
49                                 $this->uplink->join($this->ipv6, "#dev", P10_Channel::USERPRIV_VOICE);
50                         }
51                 } else {
52                         $this->ipv6 = $old;
53                 }
54                 
55                 ModCMD::bind($this, BIND_JOIN, "recive_join");
56                 ModCMD::bind($this, BIND_CHANMODE, "recive_mode");
57                 ModCMD::bind($this, BIND_KICK, "recive_kick");
58                 ModCMD::bind($this, BIND_QUIT, "recive_quit");
59         }
60         
61         public function unload($rehash = false) {
62                 if($rehash) {
63                         return $this->ipv6;
64                 } else {
65                         $this->uplink->delUser($this->ipv6, "Bye.");
66                 }
67         }
68         
69         public function loop() {
70                 for($i = 0; $i < 2; $i++) {
71                         foreach($this->cache[$i] as $id => $cache) {
72                                 if($cache < time()) unset($this->cache[$i][$id]);
73                         }
74                 }
75         }
76         
77         private function botOppedOnChannel($channel) {
78                 $privs = $channel->getUserPrivs($this->ipv6);
79                 return ($privs & P10_Channel::USERPRIV_OPED);
80         }
81         
82         public function recive_join($user, $channel, $isBurst) {
83                 if(!$this->botOppedOnChannel($channel)) return false;
84                 if($user->getIP()->isIPv6()) {
85                         $this->uplink->mode($this->ipv6, $channel, "+ov ".$user->getNumeric()." ".$user->getNumeric());
86                 } else {
87                         $this->uplink->mode($this->ipv6, $channel, "+v ".$user->getNumeric());
88                 }
89         }
90         
91         public function recive_mode($user, $channel, $modes) {
92                 if($user->getModes()->hasMode('o') || !$this->botOppedOnChannel($channel)) return false;
93                 if(array_key_exists($user->getNumeric(), $this->cache[0]) && $this->cache[0][$user->getNumeric()]['time'] > time()) {
94                         $this->uplink->kick($this->ipv6, $user, $channel, "you're not allowed to change modes in this channel!");
95                 } else {
96                         $this->uplink->notice($this->ipv6, $user, "you're not allowed to change modes in this channel!");
97                         $this->cache[0][$user->getNumeric()] = time() + 600;
98                 }
99                 $mode = explode(" ",$modes);
100                 $modestr="";
101                 $params="";
102                 $p=0;
103                 for($i=0;$i<strlen($mode[0]);$i++) {
104                         switch ($mode[0][$i]) {
105                                 case "+":
106                                         $mode[0][$i] = "-";
107                                         break;
108                                 case "-":
109                                         $mode[0][$i] = "+";
110                                         break;
111                         }
112                 }
113                 $modes = implode(" ",$mode);
114                 $this->uplink->mode($this->ipv6, $channel, $modes);
115         }
116         
117         public function recive_kick($user, $target, $channel, $modes) {
118                 if($user->getModes()->hasMode('o') || !$this->botOppedOnChannel($channel)) return false;
119                 if(array_key_exists($user->getNumeric(), $this->cache[1]) && $this->cache[1][$user->getNumeric()]['time'] > time()) {
120                         $this->uplink->delUser($user, "You have been warned not to kick users from this Channel!");
121                 } else {
122                         $this->uplink->kick($this->ipv6, $user, $channel, "you're not allowed to kick users from this channel!");
123                         $this->cache[1][$user->getNumeric()] = time() + 600;
124                 }
125         }
126         
127         public function recive_quit($user, $reason) {
128                 if($user === $this->ipv6) {
129                         $this->load($this->uplink);
130                 }
131                 for($i = 0; $i < 2; $i++) {
132                         if(array_key_exists($user->getNumeric(), $this->cache[$i])) {
133                                 unset($this->cache[$i][$user->getNumeric()]);
134                         }
135                 }
136         }
137 }
138
139 ?>