2 /******************************* PHP-P10 v2 *****************************
3 * Copyright (C) 2011 Philipp Kreil (pk910) *
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. *
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. *
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/>. *
18 ************************************************************************
26 class {$_NAME} extends Bot {
29 private $cache = array(
34 public function load($uplink, $old = false) {
35 $this->uplink = $uplink;
39 $ip = "fd00::c0ca:c01a:add5:11fe"; //coca cola adds life maybe someone undestands it :D
43 $this->ipv6 = $this->uplink->addUser($nick,$ident,$host,$ip,$modes,$realname);
44 if(is_a($this->ipv6, "P10_User")) {
45 $this->uplink->join($this->ipv6, "#IPv6", (P10_Channel::USERPRIV_OPED | P10_Channel::USERPRIV_VOICE));
46 $this->uplink->join($this->ipv6, "#dev", P10_Channel::USERPRIV_VOICE);
52 ModCMD::bind($this, BIND_JOIN, "recive_join");
53 ModCMD::bind($this, BIND_CHANMODE, "recive_mode");
54 ModCMD::bind($this, BIND_KICK, "recive_kick");
55 ModCMD::bind($this, BIND_QUIT, "recive_quit");
58 public function unload($rehash = false) {
62 $this->uplink->delUser($this->ipv6, "Bye.");
66 public function loop() {
67 for($i = 0; $i < 2; $i++) {
68 foreach($this->cache[$i] as $id => $cache) {
69 if($cache < time()) unset($this->cache[$i][$id]);
74 private function botOppedOnChannel($channel) {
75 $privs = $channel->getUserPrivs($this->ipv6);
76 return ($privs & P10_Channel::USERPRIV_OPED);
79 public function recive_join($user, $channel, $isBurst) {
80 if(!$this->botOppedOnChannel($channel)) return false;
81 if($user->getIP()->isIPv6()) {
82 $this->uplink->mode($this->ipv6, $channel, "+ov ".$user->getNumeric()." ".$user->getNumeric());
84 $this->uplink->mode($this->ipv6, $channel, "+v ".$user->getNumeric());
88 public function recive_mode($user, $channel, $modes) {
89 if($user->getModes()->hasMode('o') || !$this->botOppedOnChannel($channel)) return false;
90 if(array_key_exists($user->getNumeric(), $this->cache[0]) && $this->cache[0][$user->getNumeric()]['time'] > time()) {
91 $this->uplink->kick($this->ipv6, $user, $channel, "you're not allowed to change modes in this channel!");
93 $this->uplink->notice($this->ipv6, $user, "you're not allowed to change modes in this channel!");
94 $this->cache[0][$user->getNumeric()] = time() + 600;
96 $mode = explode(" ",$modes);
100 for($i=0;$i<strlen($mode[0]);$i++) {
101 switch ($mode[0][$i]) {
110 $modes = implode(" ",$mode);
111 $this->uplink->mode($this->ipv6, $channel, $modes);
114 public function recive_kick($user, $target, $channel, $modes) {
115 if($user->getModes()->hasMode('o') || !$this->botOppedOnChannel($channel)) return false;
116 if(array_key_exists($user->getNumeric(), $this->cache[1]) && $this->cache[1][$user->getNumeric()]['time'] > time()) {
117 $this->uplink->delUser($user, "You have been warned not to kick users from this Channel!");
119 $this->uplink->kick($this->ipv6, $user, $channel, "you're not allowed to kick users from this channel!");
120 $this->cache[1][$user->getNumeric()] = time() + 600;
124 public function recive_quit($user, $reason) {
125 if($user === $this->ipv6) {
126 $this->load($this->uplink);
128 for($i = 0; $i < 2; $i++) {
129 if(array_key_exists($user->getNumeric(), $this->cache[$i])) {
130 unset($this->cache[$i][$user->getNumeric()]);