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 * ModCMD/ModCMD.class.php
25 * shares the incoming events to all bot's that request them.
27 ************************************************************************
31 require_once("Binding.class.php");
34 define("BIND_NEWSERVER", $bindid++);
35 define("BIND_SQUIT", $bindid++);
36 define("BIND_CONNECT", $bindid++);
37 define("BIND_NICK", $bindid++);
38 define("BIND_USERMODE", $bindid++);
39 define("BIND_QUIT", $bindid++);
40 define("BIND_JOIN", $bindid++);
41 define("BIND_PART", $bindid++);
42 define("BIND_KICK", $bindid++);
43 define("BIND_AWAY", $bindid++);
44 define("BIND_CHANMODE", $bindid++);
45 define("BIND_CHANMSG", $bindid++);
46 define("BIND_PRIVMSG", $bindid++);
47 define("BIND_CHANNOTICE", $bindid++);
48 define("BIND_PRIVNOTICE", $bindid++);
49 define("BIND_CTCP", $bindid++);
50 define("BIND_CTCPREPLY", $bindid++);
51 define("BIND_PREPARSE", $bindid++);
52 define("BIND_UNKNOWNCMD", $bindid++);
55 class ModCMD implements EventHandler {
56 private static $eventHandler = null;
57 private static $bindings = array();
59 public static function getEventHandler() {
60 if(self::$eventHandler == null) {
61 self::$eventHandler = new ModCMD();
63 return self::$eventHandler;
66 public static function bind($bot, $type, $method) {
67 if(is_a($bot, "Bot") && method_exists($bot, $method)) {
68 if(array_key_exists($type, self::$bindings)) {
69 foreach(self::$bindings[$type] as $binding) {
70 if($binding->match($bot, $method))
74 self::$bindings[$type] = array();
75 self::$bindings[$type][] = new Binding($bot, $method);
79 public static function unbind($bot, $type, $method) {
80 if(is_a($bot, "Bot")) {
81 if(array_key_exists($type, self::$bindings)) {
82 foreach(self::$bindings[$type] as $id => $binding) {
83 if($binding->match($bot, $method)) {
84 unset(self::$bindings[$type][$id]);
92 public static function unbindBot($bot) {
93 if(is_a($bot, "Bot")) {
94 foreach(self::$bindings as $type => $bindings) {
95 foreach($bindings as $id => $binding) {
96 if($binding->match($bot, null)) {
97 unset(self::$bindings[$type][$id]);
104 /********************************************************************************************
106 ********************************************************************************************/
108 private function event($type, $parameters) {
109 if(array_key_exists($type, self::$bindings)) {
110 foreach(self::$bindings[$type] as $binding) {
111 $binding->trigger($parameters);
116 public function event_newserver($server, $isBurst) {
117 $this->event(BIND_NEWSERVER, array($server, $isBurst));
120 public function event_squit($server){
121 $this->event(BIND_SQUIT, array($server));
124 public function event_connect($user, $isBurst) {
125 $this->event(BIND_CONNECT, array($user, $isBurst));
128 public function event_nick($user, $newNick) {
129 $this->event(BIND_NICK, array($user, $newNick));
132 public function event_usermode($user, $modes) {
133 $this->event(BIND_USERMODE, array($user, $modes));
136 public function event_quit($user, $reason) {
137 $this->event(BIND_QUIT, array($user, $reason));
140 public function event_join($user, $channel, $isBurst) {
141 $this->event(BIND_JOIN, array($user, $channel, $isBurst));
144 public function event_part($user, $channel, $reason) {
145 $this->event(BIND_PART, array($user, $channel, $reason));
148 public function event_kick($user, $target, $channel, $reason) {
149 $this->event(BIND_KICK, array($user, $target, $channel, $reason));
152 public function event_chanmode($user, $channel, $modes) {
153 $this->event(BIND_CHANMODE, array($user, $channel, $modes));
156 public function event_chanmessage($user, $channel, $message) {
157 $this->event(BIND_CHANMSG, array($user, $channel, $message));
160 public function event_channotice($user, $channel, $message) {
161 $this->event(BIND_CHANNOTICE, array($user, $channel, $message));
164 public function event_privmessage($user, $target, $message) {
165 $this->event(BIND_PRIVMSG, array($user, $target, $message));
168 public function event_privnotice($user, $target, $message) {
169 $this->event(BIND_PRIVNOTICE, array($user, $target, $message));
172 public function event_preparse($from, $command, $arguments) {
173 $this->event(BIND_PREPARSE, array($from, $command, $arguments));
176 public function event_unknown_cmd($from, $command, $arguments) {
177 $this->event(BIND_UNKNOWNCMD, array($from, $command, $arguments));
180 public function event_chanctcp($user, $channel, $command, $text) {
181 $this->event(BIND_CTCP, array($user, $channel, $command, $text, true));
184 public function event_chanctcpreply($user, $target, $command, $text) {
185 $this->event(BIND_CTCPREPLY, array($user, $channel, $command, $text, true));
188 public function event_privctcp($user, $target, $command, $text) {
189 $this->event(BIND_CTCP, array($user, $channel, $command, $text, false));
192 public function event_privctcpreply($user, $target, $command, $text) {
193 $this->event(BIND_CTCPREPLY, array($user, $channel, $command, $text, false));
196 public function event_away($user, $away) {
197 $this->event(BIND_AWAY, array($user, $away));