added IPv6.class.php
authorpk910 <philipp@zoelle1.de>
Thu, 28 Jul 2011 04:01:08 +0000 (06:01 +0200)
committerpk910 <philipp@zoelle1.de>
Thu, 28 Jul 2011 04:01:08 +0000 (06:01 +0200)
Bots/IPv6.class.php [new file with mode: 0644]

diff --git a/Bots/IPv6.class.php b/Bots/IPv6.class.php
new file mode 100644 (file)
index 0000000..36c6989
--- /dev/null
@@ -0,0 +1,146 @@
+<?php
+/********************************* PHP-P10 ******************************
+ *    P10 uplink class by pk910   (c)2011 pk910                         *
+ ************************************************************************
+ *                          Version 2 (OOP)                             *
+ *                                                                      *
+ * PHP-P10 is free software; you can redistribute it and/or modify      *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or    *
+ * (at your option) any later version.                                  *
+ *                                                                      *
+ * This program is distributed in the hope that it will be useful,      *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
+ * GNU General Public License for more details.                         *
+ *                                                                      *
+ * You should have received a copy of the GNU General Public License    *
+ * along with PHP-P10; if not, write to the Free Software Foundation,   *
+ * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.       *
+ *                                                                      *
+ ************************************************************************
+ * 
+ *  Bots/ModManager.class.php
+ *
+ * module manager bot...
+ *
+ */
+
+class {$_NAME} extends Bot {
+       private $uplink;
+       private $ipv6;
+       private $cache = array(
+                                               0 => array(),
+                                               1 => array()
+                                       );
+       
+       public function load($uplink, $old = false) {
+               $this->uplink = $uplink;
+               if(!$old) {
+                       $nick = "IPv6";
+                       $ident = "ipv6";
+                       $ip = "fd00::C0CA:C01A:ADD5:11FE"; //coca cola adds life   maybe someone undestands it :D
+                       $host = $ip;
+                       $realname = "IPv6";
+                       $modes = "ioknISD";
+                       $this->ipv6 = $this->uplink->addUser($nick,$ident,$host,$ip,$modes,$realname);
+                       if(is_a($this->ipv6, "P10_User")) {
+                               $this->uplink->join($this->ipv6, "#IPv6", (P10_Channel::USERPRIV_OPED | P10_Channel::USERPRIV_VOICE));
+                               $this->uplink->join($this->ipv6, "#dev", P10_Channel::USERPRIV_VOICE);
+                       }
+               } else {
+                       $this->ipv6 = $old;
+               }
+               
+               ModCMD::bind($this, BIND_JOIN, "recive_join");
+               ModCMD::bind($this, BIND_MODE, "recive_mode");
+               ModCMD::bind($this, BIND_KICK, "recive_kick");
+               ModCMD::bind($this, BIND_QUIT, "recive_quit");
+       }
+       
+       public function unload($rehash = false) {
+               if($rehash) {
+                       return $this->ipv6;
+               } else {
+                       $this->uplink->delUser($this->ipv6, "Bye.");
+               }
+       }
+       
+       public function loop() {
+               for($i = 0; $i < 2; $i++) {
+                       foreach($this->cache[$i] as $id => $cache) {
+                               if($cache < time()) unset($this->cache[$i][$id]);
+                       }
+               }
+       }
+       
+       private function botOppedOnChannel($channel) {
+               $privs = $channel->getUserPrivs($this->ipv6);
+               return ($privs & P10_Channel::USERPRIV_OPED);
+       }
+       
+       public function receive_join($user, $channel) {
+               if(!$this->botOppedOnChannel($channel)) return false;
+               $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})$/';
+               if(preg_match($ipv6, $user->getIP())) {
+                       $privs = $channel->getUserPrivs($user);
+                       $privs |= (P10_Channel::USERPRIV_OPED | P10_Channel::USERPRIV_VOICE);
+                       $channel->setUserPrivs($user, $privs);
+                       $this->uplink->mode($this->ipv6, $channel, "+ov ".$user->getNumeric()." ".$user->getNumeric());
+               } else {
+                       $privs = $channel->getUserPrivs($user);
+                       $privs |= (P10_Channel::USERPRIV_VOICE);
+                       $channel->setUserPrivs($user, $privs);
+                       $this->uplink->mode($this->ipv6, $channel, "+v ".$user->getNumeric());
+               }
+       }
+       
+       public function recive_mode($user, $channel, $modes) {
+               if($user->getModes()->hasMode('o') || !$this->botOppedOnChannel($channel)) return false;
+               if(array_key_exists($user->getNumeric(), $this->cache[0]) && $this->cache[0][$user->getNumeric()]['time'] > time()) {
+                       $this->uplink->kick($this->ipv6, $user, $channel, "you're not allowed to change modes in this channel!");
+               } else {
+                       $this->uplink->notice($this->ipv6, $user, "you're not allowed to change modes in this channel!");
+                       $this->cache[0][$user->getNumeric()] = time() + 600;
+               }
+               $mode = explode(" ",$modes);
+               $modestr="";
+               $params="";
+               $p=0;
+               for($i=0;$i<strlen($mode[0]);$i++) {
+                       switch ($mode[0][$i]) {
+                               case "+":
+                                       $mode[0][$i] = "-";
+                                       break;
+                               case "-":
+                                       $mode[0][$i] = "+";
+                                       break;
+                       }
+               }
+               $modes = implode(" ",$mode);
+               $this->uplink->mode($this->ipv6, $channel, $modes);
+       }
+       
+       public function recive_kick($user, $target, $channel, $modes) {
+               if($user->getModes()->hasMode('o') || !$this->botOppedOnChannel($channel)) return false;
+               if(array_key_exists($user->getNumeric(), $this->cache[1]) && $this->cache[1][$user->getNumeric()]['time'] > time()) {
+                       $this->uplink->delUser($user, "You have been warned not to kick users from this Channel!");
+               } else {
+                       $this->uplink->kick($this->ipv6, $user, $channel, "you're not allowed to kick users from this channel!");
+                       $this->cache[1][$user->getNumeric()] = time() + 600;
+               }
+       }
+       
+       public function recive_quit($user, $reason) {
+               if($user === $this->ipv6) {
+                       $this->load($this->uplink);
+               }
+               for($i = 0; $i < 2; $i++) {
+                       if(array_key_exists($user->getNumeric(), $this->cache[$i])) {
+                               unset($this->cache[$i][$user->getNumeric()]);
+                       }
+               }
+       }
+}
+
+?>
\ No newline at end of file