author | Dan |
Mon, 05 Jan 2009 22:29:36 -0500 | |
changeset 44 | 73f74d395f95 |
parent 40 | 1855846cbdab |
child 51 | 508400fc5282 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
||
3 |
/** |
|
4 |
* PHP IRC Client library |
|
5 |
* Copyright (C) 2008 Dan Fuhry. All rights reserved. |
|
6 |
*/ |
|
7 |
||
8 |
/** |
|
9 |
* Version number |
|
10 |
* @const string |
|
11 |
*/ |
|
12 |
||
13 |
define('REQUEST_IRC_VERSION', '0.1'); |
|
14 |
||
15 |
/** |
|
16 |
* The base class for an IRC session. |
|
17 |
*/ |
|
18 |
||
19 |
class Request_IRC |
|
20 |
{ |
|
21 |
||
22 |
/** |
|
23 |
* Hostname |
|
24 |
* @var string |
|
25 |
*/ |
|
26 |
||
27 |
private $host = ''; |
|
28 |
||
29 |
/** |
|
30 |
* Port number |
|
31 |
* @var int |
|
32 |
*/ |
|
33 |
||
34 |
private $port = 6667; |
|
35 |
||
36 |
/** |
|
37 |
* The socket for the connection. |
|
38 |
* @var resource |
|
39 |
*/ |
|
40 |
||
41 |
public $sock = false; |
|
42 |
||
43 |
/** |
|
44 |
* Channel objects, associative array |
|
45 |
* @var array |
|
46 |
*/ |
|
47 |
||
48 |
public $channels = array(); |
|
49 |
||
50 |
/** |
|
51 |
* The function called when a private message is received. |
|
52 |
* @var string |
|
53 |
*/ |
|
54 |
||
55 |
private $privmsg_handler = false; |
|
56 |
||
57 |
/** |
|
30 | 58 |
* The function called when a timeout is suspected. |
59 |
* @var string |
|
60 |
*/ |
|
61 |
||
62 |
private $timeout_warning_handler = false; |
|
63 |
||
64 |
/** |
|
65 |
* The function called when a timeout is confirmed. |
|
66 |
* @var string |
|
67 |
*/ |
|
68 |
||
69 |
private $timeout_error_handler = false; |
|
70 |
||
71 |
/** |
|
0 | 72 |
* Switch to track if quitted or not. Helps avoid quitting the connection twice thus causing write errors. |
73 |
* @var bool |
|
74 |
* @access private |
|
75 |
*/ |
|
76 |
||
77 |
protected $quitted = false; |
|
78 |
||
79 |
/** |
|
80 |
* The nickname we're connected as. Not modified once connected. |
|
81 |
* @var string |
|
82 |
*/ |
|
83 |
||
84 |
public $nick = ''; |
|
85 |
||
86 |
/** |
|
87 |
* The username we're connected as. Not modified once connected. |
|
88 |
* @var string |
|
89 |
*/ |
|
90 |
||
91 |
public $user = ''; |
|
92 |
||
93 |
/** |
|
94 |
* Constructor. |
|
95 |
* @param string Hostname |
|
96 |
* @param int Port number, defaults to 6667 |
|
97 |
*/ |
|
98 |
||
99 |
public function __construct($host, $port = 6667) |
|
100 |
{ |
|
101 |
// Check hostname |
|
102 |
if ( !preg_match('/^(([a-z0-9-]+\.)*?)([a-z0-9-]+)$/', $host) ) |
|
103 |
die(__CLASS__ . ': Invalid hostname'); |
|
104 |
$this->host = $host; |
|
105 |
||
106 |
// Check port |
|
107 |
if ( is_int($port) && $port >= 1 && $port <= 65535 ) |
|
108 |
$this->port = $port; |
|
109 |
else |
|
110 |
die(__CLASS__ . ': Invalid port'); |
|
111 |
} |
|
112 |
||
113 |
/** |
|
114 |
* Sets parameters and opens the connection. |
|
115 |
* @param string Nick |
|
116 |
* @param string User |
|
117 |
* @param string Real name |
|
118 |
* @param string NickServ password |
|
119 |
* @param int Flags, defaults to 0. |
|
120 |
*/ |
|
121 |
||
30 | 122 |
public function connect($nick, $username, $realname, $pass = false, $flags = 0) |
0 | 123 |
{ |
124 |
// Init connection |
|
125 |
$this->sock = fsockopen($this->host, $this->port); |
|
126 |
if ( !$this->sock ) |
|
127 |
throw new Exception('Could not make socket connection to host.'); |
|
128 |
||
8 | 129 |
stream_set_timeout($this->sock, 1); |
0 | 130 |
|
131 |
// Send nick and username |
|
132 |
$this->put("NICK $nick\r\n"); |
|
133 |
$this->put("USER $username 0 * :$realname\r\n"); |
|
134 |
||
38 | 135 |
$need_deghost = false; |
136 |
||
8 | 137 |
// wait for a mode +i or end of the motd |
138 |
while ( true ) |
|
0 | 139 |
{ |
8 | 140 |
$msg = $this->get(); |
141 |
if ( empty($msg) ) |
|
142 |
continue; |
|
38 | 143 |
if ( strstr($msg, "433") ) |
144 |
{ |
|
145 |
// nick already in use - try to ghost |
|
146 |
$this->change_nick("{$nick}|de-ghosting"); |
|
147 |
$need_deghost = true; |
|
148 |
} |
|
8 | 149 |
if ( ( strstr($msg, 'MODE') && strstr($msg, '+i') ) || strstr(strtolower($msg), 'end of /motd') ) |
0 | 150 |
{ |
8 | 151 |
break; |
0 | 152 |
} |
8 | 153 |
if ( preg_match('/^PING :(.+?)$/', $msg, $match) ) |
154 |
{ |
|
155 |
$this->put("PONG :{$match[1]}\r\n"); |
|
156 |
} |
|
0 | 157 |
} |
158 |
||
38 | 159 |
if ( $need_deghost ) |
160 |
{ |
|
161 |
$this->privmsg('NickServ', "GHOST $nick $pass"); |
|
162 |
while ( $msg = $this->get(10) ) |
|
163 |
{ |
|
164 |
if ( stristr($msg, 'nickserv') && stristr($msg, 'ghost') ) |
|
165 |
break; |
|
166 |
} |
|
167 |
$this->change_nick($nick); |
|
168 |
} |
|
169 |
||
8 | 170 |
// identify to nickserv |
30 | 171 |
if ( $pass ) |
172 |
$this->privmsg('NickServ', "IDENTIFY $pass"); |
|
8 | 173 |
|
0 | 174 |
$this->nick = $nick; |
175 |
$this->user = $username; |
|
30 | 176 |
$this->quitted = false; |
0 | 177 |
} |
178 |
||
179 |
/** |
|
180 |
* Writes some data to the socket, abstracted for debugging purposes. |
|
181 |
* @param string Message to send, this should include a CRLF. |
|
182 |
*/ |
|
183 |
||
184 |
public function put($message) |
|
185 |
{ |
|
186 |
if ( !$this->sock ) |
|
187 |
{ |
|
188 |
if ( defined('LIBIRC_DEBUG') ) |
|
189 |
echo ">>> WRITE FAILED: $message"; |
|
190 |
return false; |
|
191 |
} |
|
192 |
if ( defined('LIBIRC_DEBUG') ) |
|
193 |
echo ">>> $message"; |
|
194 |
fwrite($this->sock, $message); |
|
195 |
} |
|
196 |
||
197 |
/** |
|
198 |
* Reads from the socket... |
|
199 |
* @return string |
|
200 |
*/ |
|
201 |
||
30 | 202 |
public function get($timeout = 1) |
0 | 203 |
{ |
204 |
if ( !$this->sock ) |
|
205 |
{ |
|
206 |
if ( defined('LIBIRC_DEBUG') ) |
|
207 |
echo "<<< READ FAILED\n"; |
|
208 |
return false; |
|
209 |
} |
|
30 | 210 |
if ( ($c = stream_select($r = array($this->sock), $w = null, $e = null, $timeout)) !== false ) |
211 |
{ |
|
212 |
if ( $c > 0 ) |
|
213 |
{ |
|
214 |
$out = fgets($this->sock, 4096); |
|
215 |
if ( defined('LIBIRC_DEBUG') ) |
|
216 |
if ( !empty($out) ) |
|
217 |
echo "<<< $out"; |
|
218 |
return $out; |
|
219 |
} |
|
220 |
} |
|
221 |
return false; |
|
0 | 222 |
} |
223 |
||
224 |
/** |
|
225 |
* Sends a message to a nick or channel. |
|
226 |
* @param string Nick or channel |
|
227 |
* @param string Message |
|
228 |
*/ |
|
229 |
||
230 |
public function privmsg($nick, $message) |
|
231 |
{ |
|
232 |
$message = str_replace("\r\n", "\n", $message); |
|
233 |
$message = explode("\n", $message); |
|
234 |
foreach ( $message as $line ) |
|
235 |
{ |
|
32 | 236 |
$line = $this->filter_message($line); |
0 | 237 |
$this->put("PRIVMSG $nick :$line\r\n"); |
238 |
} |
|
239 |
} |
|
240 |
||
241 |
/** |
|
40 | 242 |
* Sends a notice. |
243 |
* @param string Nick or channel |
|
244 |
* @param string Message |
|
245 |
*/ |
|
246 |
||
247 |
public function notice($nick, $message) |
|
248 |
{ |
|
249 |
$message = str_replace("\r\n", "\n", $message); |
|
250 |
$message = explode("\n", $message); |
|
251 |
foreach ( $message as $line ) |
|
252 |
{ |
|
253 |
$line = $this->filter_message($line); |
|
254 |
$this->put("NOTICE $nick :$line\r\n"); |
|
255 |
} |
|
256 |
} |
|
257 |
||
258 |
/** |
|
33 | 259 |
* Parse bold (<b>...</b>) tags and color tags in a text into IRC speak, and process /me commands. Colors are <cyan>...</cyan>, specify background with <fg:bg>...</fgcolor:bgcolor>. Valid colors are white, black, navy, green, red, maroon, purple, orange, yellow, lime, teal, aqua, cyan, blue, pink, grey, and silver |
32 | 260 |
* @param string Text to filter |
261 |
* @return string |
|
262 |
*/ |
|
263 |
||
264 |
function filter_message($text) |
|
265 |
{ |
|
266 |
$text = preg_replace('#<b>(.*?)</b>#is', "\x02$1\x02", $text); |
|
267 |
if ( preg_match('#^/me #i', $text) ) |
|
268 |
{ |
|
269 |
$text = "\x01ACTION " . preg_replace('#^/me #i', '', $text) . "\x01"; |
|
270 |
} |
|
271 |
$supportedcolors = array('white', 'black', 'navy', 'green', 'red', 'maroon', 'purple', 'orange', 'yellow', 'lime', 'teal', 'cyan', 'blue', 'pink', 'grey', 'silver'); |
|
272 |
$colors = implode('|', $supportedcolors); |
|
273 |
$supportedcolors = array_flip($supportedcolors); |
|
274 |
preg_match_all("#<((?:$colors)(?::(?:$colors))?)>(.*?)</\\1>#is", $text, $matches); |
|
275 |
foreach ( $matches[0] as $i => $match ) |
|
276 |
{ |
|
277 |
preg_match("#<(?:($colors)(?::($colors))?)>#i", $match, $colordata); |
|
278 |
$fgcolor = $supportedcolors[$colordata[1]]; |
|
279 |
$bgcolor = $colordata[1] ? $supportedcolors[$colordata[2]] : ''; |
|
280 |
$fgcolor = ( $fgcolor < 10 ) ? "0$fgcolor" : "$fgcolor"; |
|
281 |
if ( is_int($bgcolor) ) |
|
282 |
$bgcolor = ( $bgcolor < 10 ) ? ",0$bgcolor" : ",$bgcolor"; |
|
283 |
$text = str_replace($match, "\x03{$fgcolor}{$bgcolor}{$matches[2][$i]}\x03", $text); |
|
284 |
} |
|
285 |
||
286 |
return $text; |
|
287 |
} |
|
288 |
||
289 |
/** |
|
0 | 290 |
* The main event loop. |
291 |
*/ |
|
292 |
||
293 |
public function event_loop() |
|
294 |
{ |
|
30 | 295 |
$timeout = 180; |
296 |
$timeout_warn = false; |
|
297 |
while ( true ) |
|
0 | 298 |
{ |
30 | 299 |
$data = $this->get($timeout); |
300 |
$data_trim = $data ? trim($data) : false; |
|
301 |
if ( empty($data_trim) ) |
|
302 |
{ |
|
303 |
if ( $timeout_warn ) |
|
304 |
{ |
|
305 |
// timeout confirmed :-/ |
|
306 |
if ( $this->timeout_error_handler ) |
|
307 |
{ |
|
308 |
$result = @call_user_func($this->timeout_error_handler, $this); |
|
309 |
if ( $result == 'BREAK' ) |
|
310 |
break; |
|
311 |
} |
|
312 |
$timeout = 180; |
|
313 |
$timeout_warn = false; |
|
314 |
continue; |
|
315 |
} |
|
316 |
// timeout suspected |
|
317 |
if ( $this->timeout_warning_handler ) |
|
318 |
{ |
|
319 |
$result = @call_user_func($this->timeout_warning_handler, $this); |
|
320 |
if ( $result == 'BREAK' ) |
|
321 |
break; |
|
322 |
} |
|
323 |
// ping the server |
|
324 |
$this->put("PING :{$this->nick}\r\n"); |
|
325 |
// set timeout lower to make reconnecting work as fast as possible |
|
326 |
$timeout = 10; |
|
327 |
$timeout_warn = true; |
|
328 |
continue; |
|
329 |
} |
|
0 | 330 |
$match = self::parse_message($data_trim); |
331 |
if ( preg_match('/^PING :(.+?)$/', $data_trim, $pmatch) ) |
|
332 |
{ |
|
333 |
$this->put("PONG :{$pmatch[1]}\r\n"); |
|
8 | 334 |
eval(eb_fetch_hook('event_ping')); |
0 | 335 |
} |
30 | 336 |
else if ( preg_match('/^:((?:[a-z0-9-]+\.)*[a-z0-9-]+) PONG \\1 :' . preg_quote($this->nick) .'/', $data_trim) ) |
337 |
{ |
|
338 |
$timeout = 180; |
|
339 |
$timeout_warn = false; |
|
340 |
} |
|
0 | 341 |
else if ( $match ) |
342 |
{ |
|
38 | 343 |
if ( $match['action'] == 'KILL' ) |
344 |
{ |
|
345 |
// be ethical here and die |
|
346 |
return 'killed'; |
|
347 |
} |
|
0 | 348 |
// Received PRIVMSG or other mainstream action |
8 | 349 |
if ( $match['action'] == 'JOIN' || $match['action'] == 'PART' ) |
0 | 350 |
$channel =& $match['message']; |
351 |
else |
|
352 |
$channel =& $match['target']; |
|
353 |
||
354 |
if ( !preg_match('/^[#!&\+]/', $channel) ) |
|
355 |
{ |
|
356 |
// Private message from user |
|
357 |
$result = $this->handle_privmsg($data); |
|
8 | 358 |
@stream_set_timeout($this->sock, 0xFFFFFFFE); |
0 | 359 |
} |
360 |
else if ( isset($this->channels[strtolower($channel)]) ) |
|
361 |
{ |
|
362 |
// Message into channel |
|
363 |
$chan =& $this->channels[strtolower($channel)]; |
|
364 |
$func = $chan->get_handler(); |
|
365 |
$result = @call_user_func($func, $data, $chan); |
|
8 | 366 |
@stream_set_timeout($this->sock, 0xFFFFFFFE); |
0 | 367 |
} |
368 |
if ( $result == 'BREAK' ) |
|
369 |
{ |
|
370 |
break; |
|
371 |
} |
|
372 |
} |
|
373 |
} |
|
374 |
} |
|
375 |
||
376 |
/** |
|
377 |
* Processor for when a private message is received. |
|
378 |
* @access private |
|
379 |
*/ |
|
380 |
||
381 |
private function handle_privmsg($message) |
|
382 |
{ |
|
383 |
$message = self::parse_message($message); |
|
21 | 384 |
$message['message'] = preg_replace('/^(.+?):/', '', $message['message']); |
0 | 385 |
$ph = $this->privmsg_handler; |
386 |
if ( @function_exists($ph) ) |
|
387 |
return @call_user_func($ph, $message); |
|
388 |
} |
|
389 |
||
390 |
/** |
|
391 |
* Changes the function called upon receipt of a private message. |
|
392 |
* @param string Function to call, will be passed a parsed message. |
|
393 |
*/ |
|
394 |
||
395 |
function set_privmsg_handler($func) |
|
396 |
{ |
|
397 |
if ( !function_exists($func) ) |
|
398 |
return false; |
|
399 |
$this->privmsg_handler = $func; |
|
400 |
return true; |
|
401 |
} |
|
402 |
||
403 |
/** |
|
30 | 404 |
* Changes the functions called when IRC connection timeouts occur. |
405 |
* @param string Function to call when a warning (no traffic within 3 minutes) occurs. If false, nothing will be called. |
|
406 |
* @param string Function to call if a ping timeout occurs. If false, nothing will be called. |
|
407 |
*/ |
|
408 |
||
409 |
function set_timeout_handlers($warn_func, $error_func) |
|
410 |
{ |
|
411 |
$this->timeout_warning_handler = false; |
|
412 |
$this->timeout_error_handler = false; |
|
413 |
if ( function_exists($warn_func) ) |
|
414 |
{ |
|
415 |
$this->timeout_warning_handler = $warn_func; |
|
416 |
} |
|
417 |
if ( function_exists($error_func) ) |
|
418 |
{ |
|
419 |
$this->timeout_error_handler = $error_func; |
|
420 |
} |
|
421 |
return true; |
|
422 |
} |
|
423 |
||
424 |
/** |
|
0 | 425 |
* Parses a message line. |
426 |
* @param string Message text |
|
427 |
* @return array Associative with keys: nick, user, host, action, target, message |
|
428 |
*/ |
|
429 |
||
430 |
public static function parse_message($message) |
|
431 |
{ |
|
432 |
// Indices: 12 3 4 5 67 8 |
|
433 |
$mc = preg_match('/^:(([^ ]+)!([^ ]+)@([^ ]+)) ([A-Z]+) (([#!&\+]*[A-z0-9_-]+) )?:?(.*?)$/', $message, $match); |
|
434 |
if ( !$mc ) |
|
435 |
{ |
|
436 |
return false; |
|
437 |
} |
|
438 |
// Indices: 0 1 2 3 4 5 6 7 8 |
|
439 |
list( , , $nick, $user, $host, $action, , $target, $message) = $match; |
|
440 |
return array( |
|
441 |
'nick' => $nick, |
|
442 |
'user' => $user, |
|
443 |
'host' => $host, |
|
444 |
'action' => $action, |
|
445 |
'target' => $target, |
|
446 |
'message' => trim($message) |
|
447 |
); |
|
448 |
} |
|
449 |
||
450 |
/** |
|
451 |
* Joins a channel, and returns a Request_IRC_Channel object. |
|
452 |
* @param string Channel name (remember # prefix) |
|
453 |
* @param string Event handler function, will be called with param 0 = socket output and param 1 = channel object |
|
454 |
* @return object |
|
455 |
*/ |
|
456 |
||
457 |
function join($channel, $handler) |
|
458 |
{ |
|
459 |
$chan = new Request_IRC_Channel(strtolower($channel), $handler, $this); |
|
460 |
$this->channels[strtolower($channel)] = $chan; |
|
461 |
return $chan; |
|
462 |
} |
|
463 |
||
464 |
/** |
|
30 | 465 |
* Changes the current nick. |
466 |
* @param string New nick. |
|
467 |
* @param string Password to authenticate to NickServ if needed. |
|
468 |
*/ |
|
469 |
||
470 |
public function change_nick($nick, $pass = false) |
|
471 |
{ |
|
472 |
$this->put("NICK $nick\r\n"); |
|
473 |
$this->nick = $nick; |
|
474 |
if ( $pass ) |
|
475 |
{ |
|
476 |
while ( $data = $this->get(3) ) |
|
477 |
{ |
|
478 |
if ( strstr($data, 'NickServ') ) |
|
479 |
{ |
|
480 |
$this->privmsg('NickServ', "IDENTIFY $pass"); |
|
481 |
break; |
|
482 |
} |
|
483 |
} |
|
484 |
} |
|
485 |
} |
|
486 |
||
487 |
/** |
|
0 | 488 |
* Closes the connection and quits. |
489 |
* @param string Optional part message |
|
490 |
*/ |
|
491 |
||
492 |
public function close($partmsg = false) |
|
493 |
{ |
|
494 |
if ( $this->quitted ) |
|
495 |
return true; |
|
496 |
||
497 |
$this->quitted = true; |
|
498 |
// Part all channels |
|
499 |
if ( !$partmsg ) |
|
31
d75124700259
Timeout recovery should avoid getting the bot throttled now :)
Dan
parents:
30
diff
changeset
|
500 |
$partmsg = 'Closing connection (no reason given)'; |
0 | 501 |
|
502 |
foreach ( $this->channels as $channel ) |
|
503 |
{ |
|
504 |
$channel->part($partmsg); |
|
505 |
} |
|
506 |
||
507 |
$this->put("QUIT\r\n"); |
|
508 |
||
30 | 509 |
while ( $msg = $this->get(1) ) |
0 | 510 |
{ |
511 |
// Do nothing. |
|
512 |
} |
|
513 |
||
514 |
fclose($this->sock); |
|
515 |
} |
|
516 |
||
517 |
} |
|
518 |
||
519 |
/** |
|
520 |
* Wrapper for channels. |
|
521 |
*/ |
|
522 |
||
523 |
class Request_IRC_Channel extends Request_IRC |
|
524 |
{ |
|
525 |
||
526 |
/** |
|
527 |
* The name of the channel |
|
528 |
* @var string |
|
529 |
*/ |
|
530 |
||
531 |
private $channel_name = ''; |
|
532 |
||
533 |
/** |
|
534 |
* The event handler function. |
|
535 |
* @var string |
|
536 |
*/ |
|
537 |
||
538 |
private $handler = ''; |
|
539 |
||
540 |
/** |
|
541 |
* The parent connection. |
|
542 |
* @var object |
|
543 |
*/ |
|
544 |
||
545 |
public $parent = false; |
|
546 |
||
547 |
/** |
|
548 |
* Whether the channel has been parted or not, used to kill the destructor. |
|
549 |
* @var bool |
|
550 |
*/ |
|
551 |
||
552 |
protected $parted = false; |
|
553 |
||
554 |
/** |
|
555 |
* Constructor. |
|
556 |
* @param string Channel name |
|
557 |
* @param string Handler function |
|
558 |
* @param object IRC connection (Request_IRC object) |
|
559 |
*/ |
|
560 |
||
561 |
function __construct($channel, $handler, $parent) |
|
562 |
{ |
|
563 |
$this->parent = $parent; |
|
564 |
$this->parent->put("JOIN $channel\r\n"); |
|
8 | 565 |
// stream_set_timeout($this->parent->sock, 3); |
566 |
// while ( $msg = $this->parent->get() ) |
|
567 |
// { |
|
568 |
// // Do nothing |
|
569 |
// } |
|
0 | 570 |
$this->channel_name = $channel; |
571 |
$this->handler = $handler; |
|
8 | 572 |
eval(eb_fetch_hook('event_self_join')); |
0 | 573 |
} |
574 |
||
575 |
/** |
|
576 |
* Returns the channel name |
|
577 |
* @return string |
|
578 |
*/ |
|
579 |
||
580 |
function get_channel_name() |
|
581 |
{ |
|
582 |
return $this->channel_name; |
|
583 |
} |
|
584 |
||
585 |
/** |
|
586 |
* Returns the handler function |
|
587 |
* @return string |
|
588 |
*/ |
|
589 |
||
590 |
function get_handler() |
|
591 |
{ |
|
592 |
return $this->handler; |
|
593 |
} |
|
594 |
||
595 |
/** |
|
596 |
* Sends a message. |
|
597 |
* @param string message |
|
598 |
* @param bool If true, will fire a message event when the message is sent. |
|
599 |
*/ |
|
600 |
||
601 |
function msg($msg, $fire_event = false) |
|
602 |
{ |
|
603 |
$this->parent->privmsg($this->channel_name, $msg); |
|
604 |
if ( $fire_event ) |
|
605 |
{ |
|
606 |
$func = $this->get_handler(); |
|
607 |
// format: :nick!user@host PRIVMSG #channel :msg. |
|
608 |
$lines = explode("\n", $msg); |
|
609 |
foreach ( $lines as $line ) |
|
610 |
{ |
|
611 |
$data = ":{$this->parent->nick}!{$this->parent->user}@localhost PRIVMSG {$this->channel_name} :$line"; |
|
612 |
$result = @call_user_func($func, $data, $this); |
|
613 |
stream_set_timeout($this->parent->sock, 0xFFFFFFFE); |
|
614 |
} |
|
615 |
} |
|
616 |
} |
|
617 |
||
618 |
/** |
|
619 |
* Destructor, automatically parts the channel. |
|
620 |
*/ |
|
621 |
||
622 |
function __destruct() |
|
623 |
{ |
|
624 |
if ( !$this->parted ) |
|
625 |
$this->part('IRC bot powered by PHP/' . PHP_VERSION . ' libirc/' . REQUEST_IRC_VERSION); |
|
626 |
} |
|
627 |
||
628 |
/** |
|
629 |
* Parts the channel. |
|
630 |
* @param string Optional message |
|
631 |
*/ |
|
632 |
||
633 |
function part($msg = '') |
|
634 |
{ |
|
635 |
$this->parent->put("PART {$this->channel_name} :$msg\r\n"); |
|
636 |
$this->parted = true; |
|
637 |
unset($this->parent->channels[$this->channel_name]); |
|
638 |
} |
|
639 |
||
640 |
} |
|
641 |
||
642 |
?> |