7 public $Plist = array();
12 private $core_commands;
14 // Constructeur de la classe
15 public function __construct($server, $port, $channel, $name, $myip, $mydomain) {
16 // Récupération d'une connexion unique
17 IRCConn
::Init($server, $port, $channel, $name, $myip, $mydomain);
18 $this->IRCConn
= IRCConn
::GetInstance();
19 // On charge le plugin de base indispensable
20 require_once('./sources/plug_base-class.inc.php');
21 $this->Plist
['plug_base'] = new plug_base();
23 self
::register_command('core','!shownick');
24 self
::register_command('core','!nick');
27 public function run() {
29 $this->msg
= $this->IRCConn
->get();
33 if (preg_match('`^:(.*?)!.*?@.*? PRIVMSG ('.IRCConn
::$myBotName.'|'.IRCConn
::$channel.") :(.*)\r`",$this->msg
,$T)) {
40 } elseif (preg_match('`^:(.*?)!.*?@.*? NOTICE '.IRCConn
::$myBotName." :(.*)\r`",$this->msg
,$T)) {
44 'to' => IRCConn
::$myBotName,
50 switch ($msg['type']) {
52 if ($msg['message'][0] == chr(001)) { // ctcp
53 list($cmd,$query) = explode(chr(032),$msg['message']);
54 $cmd = str_replace(chr(001), "",$msg['message']);
57 $this->IRCConn
->notice($msg['from'],chr(001).'PING VERSION TIME USERINFO CLIENTINFO'.chr(001));
60 $this->IRCConn
->notice($msg['from'],chr(001).'RPGBot version '.IRCConn
::$botVersion.' - PHP '.phpversion().' -- par Tornald et Bloodshed'.chr(001));
63 $this->IRCConn
->notice($msg['from'],chr(001).'RPGBot'.chr(001));
66 $this->IRCConn
->notice($msg['from'],chr(001).date('Y-m-d H:i:s').chr(001));
69 $this->IRCConn
->notice($msg['from'],chr(001)."PING ".$query.chr(001));
73 if ($to == IRCConn
::$myBotName) {
74 if (preg_match('^connect ([^ ]+) ([^ ]+)',$msg['message'],$m)) {
75 if ($m[1] == 'admin' && $m[2] == 'mypass') {
76 $this->IRCConn
->notice($msg['from'],'Vous êtes bien authentifié comme administrateur.');
78 $this->IRCConn
->notice($msg['from'],'Erreur dans votre login et / ou mot de passe.');
82 if ($msg['message'][0] == '!') {
83 $pos_space = strpos($msg['message'],' ');
84 if ($pos_space !== false) {
85 $command = substr($msg['message'],0,$pos_space);
86 $query = substr($msg['message'],$pos_space+
1);
88 $command = $msg['message'];
101 foreach ($this->plugins
['_run'] as $plugin => $methods) {
102 foreach ($methods as $method) {
103 $this->plugins
[$plugin]->$method($msg);
109 public function AddPlug($Pname) {
110 if ( !array_key_exists ( $Pname, $this->Plist
) ) {
111 $this->Plist
[$Pname] = new $Pname($this);
115 public function load_plugin($pname) {
116 if ( !array_key_exists ( $pname, $this->plugins
) ) {
117 if ( is_readable('./plugins/'.$class.'-plugin.inc.php') ) {
118 require_once './plugins/'.$class.'-plugin.inc.php';
119 $this->plugins
[$pname] = new $pname($this);
120 self
::plugin_register_cmd($pname, $this->plugins
[$pname]->commands_list());
122 trigger_error ("Class '$class' not found",E_USER_ERROR
);
127 public function unload_plugin($plugin_name) {
128 if ( array_key_exists ( $plugin_name, $this->plugins
) ) {
129 unset( $this->plugins
[$plugin_name] );
133 protected function plugin_register_cmd($plugin,$commands) {
134 foreach ($commands as $method => $accepted_args) {
135 if (!method_exists($this->plugins
[$plugin],$method) ||
!is_callable(array($this->plugins
[$plugin],$method))) {
136 trigger_error("ERROR : method '$plugin:$method' in the commands list is not callable.\n",E_USER_WARNING
);
138 self
::add_command($plugin,$method,$accepted_args);
143 public function UnloadPlug($Pname) {
144 if ( array_key_exists ( $Pname, $this->Plist
) ) {
145 unset( $this->Plist
[$Pname] );
149 private function add_command($plugin,$method_to_add,$accepted_args=0) {
150 if (isset($this->commands
[$plugin])) {
151 foreach ($this->commands
[$plugin] as $method) {
152 if (isset($method[$method_to_add]))
157 $this->commands
[$plugin][] = array(
158 'method'=>$method_to_add,
159 'accepted_args'=>$accepted_args,
164 private function remove_command($plugin,$method_to_remove, $accepted_args = 0) {
165 if (isset($this->commands
[$plugin])) {
166 if ($method_to_remove != '_all_method') {
167 foreach($this->commands
[$plugin] as $method) {
168 if ($method['method'] != $method_to_remove)
169 $new_method_list[] = $method;
172 $this->commands
[$plugin] = $new_method_list;
174 unset($this->commands
[$plugin]);
182 public function __construct($main);
183 public function start($IRCtxt);
184 public function help();