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 if($user->getIP()->isIPv6()) {
85 $this->uplink->mode($this->ipv6, $channel, "+ov ".$user->getNumeric()." ".$user->getNumeric());
87 $this->uplink->mode($this->ipv6, $channel, "+v ".$user->getNumeric());
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!");
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;
99 $mode = explode(" ",$modes);
103 for($i=0;$i<strlen($mode[0]);$i++) {
104 switch ($mode[0][$i]) {
113 $modes = implode(" ",$mode);
114 $this->uplink->mode($this->ipv6, $channel, $modes);
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!");
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;
127 public function recive_quit($user, $reason) {
128 if($user === $this->ipv6) {
129 $this->load($this->uplink);
131 for($i = 0; $i < 2; $i++) {
132 if(array_key_exists($user->getNumeric(), $this->cache[$i])) {
133 unset($this->cache[$i][$user->getNumeric()]);