2 /********************************* PHP-P10 ******************************
3 * P10 uplink class by pk910 (c)2011 pk910 *
4 ************************************************************************
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. *
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. *
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. *
21 ************************************************************************
23 * Bots/ModManager.class.php
25 * module manager bot...
29 class {$_NAME} extends Bot {
32 private $cache = array(
37 public function load($uplink, $old = false) {
38 $this->uplink = $uplink;
43 $host = "fd00::C0CA:C01A:ADD5:11FE"; //coca cola adds life maybe someone undestands it :D
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);
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");
61 public function unload($rehash = false) {
65 $this->uplink->delUser($this->ipv6, "Bye.");
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]);
77 private function botOppedOnChannel($channel) {
78 $privs = $channel->getUserPrivs($this->ipv6);
79 return ($privs & P10_Channel::USERPRIV_OPED);
82 public function recive_join($user, $channel, $isBurst) {
83 if(!$this->botOppedOnChannel($channel)) return false;
84 $ipv6 = '/^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))(|\/[0-9]{1,3})$/';
85 if(preg_match($ipv6, $user->getIP())) {
86 $this->uplink->mode($this->ipv6, $channel, "+ov ".$user->getNumeric()." ".$user->getNumeric());
88 $this->uplink->mode($this->ipv6, $channel, "+v ".$user->getNumeric());
92 public function recive_mode($user, $channel, $modes) {
93 if($user->getModes()->hasMode('o') || !$this->botOppedOnChannel($channel)) return false;
94 if(array_key_exists($user->getNumeric(), $this->cache[0]) && $this->cache[0][$user->getNumeric()]['time'] > time()) {
95 $this->uplink->kick($this->ipv6, $user, $channel, "you're not allowed to change modes in this channel!");
97 $this->uplink->notice($this->ipv6, $user, "you're not allowed to change modes in this channel!");
98 $this->cache[0][$user->getNumeric()] = time() + 600;
100 $mode = explode(" ",$modes);
104 for($i=0;$i<strlen($mode[0]);$i++) {
105 switch ($mode[0][$i]) {
114 $modes = implode(" ",$mode);
115 $this->uplink->mode($this->ipv6, $channel, $modes);
118 public function recive_kick($user, $target, $channel, $modes) {
119 if($user->getModes()->hasMode('o') || !$this->botOppedOnChannel($channel)) return false;
120 if(array_key_exists($user->getNumeric(), $this->cache[1]) && $this->cache[1][$user->getNumeric()]['time'] > time()) {
121 $this->uplink->delUser($user, "You have been warned not to kick users from this Channel!");
123 $this->uplink->kick($this->ipv6, $user, $channel, "you're not allowed to kick users from this channel!");
124 $this->cache[1][$user->getNumeric()] = time() + 600;
128 public function recive_quit($user, $reason) {
129 if($user === $this->ipv6) {
130 $this->load($this->uplink);
132 for($i = 0; $i < 2; $i++) {
133 if(array_key_exists($user->getNumeric(), $this->cache[$i])) {
134 unset($this->cache[$i][$user->getNumeric()]);