9 * This source file is subject to the new BSD license that is bundled
10 * with this package in the file LICENSE.
11 * It is also available through the world-wide-web at this URL:
12 * http://phergie.org/license
15 * @package Phergie_Plugin_AltNick
16 * @author Phergie Development Team <team@phergie.org>
17 * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
18 * @license http://phergie.org/license New BSD License
19 * @link http://pear.phergie.org/package/Phergie_Plugin_AltNick
23 * Handles switching to alternate nicks in cases where the primary nick is
24 * not available for use.
27 * @package Phergie_Plugin_AltNick
28 * @author Phergie Development Team <team@phergie.org>
29 * @license http://phergie.org/license New BSD License
30 * @link http://pear.phergie.org/package/Phergie_Plugin_AltNick
33 class Phergie_Plugin_AltNick extends Phergie_Plugin_Abstract
36 * Iterator for the alternate nick list
43 * Initializes instance variables.
47 public function onConnect()
49 if ($this->config['altnick.nicks']) {
50 if (is_string($this->config['altnick.nicks'])) {
51 $this->config['altnick.nicks']
52 = array($this->config['altnick.nicks']);
54 $this->iterator = new ArrayIterator($this->config['altnick.nicks']);
59 * Switches to alternate nicks as needed when nick collisions occur.
63 public function onResponse()
65 // If no alternate nick list was found, return
66 if (empty($this->iterator)) {
70 // If the response event indicates that the nick set is in use...
71 $code = $this->getEvent()->getCode();
72 if ($code == Phergie_Event_Response::ERR_NICKNAMEINUSE) {
74 // Attempt to move to the next nick in the alternate nick list
75 $this->iterator->next();
77 // If another nick is available...
78 if ($this->iterator->valid()) {
80 // Switch to the new nick
81 $altNick = $this->iterator->current();
82 $this->doNick($altNick);
84 // Update the connection to reflect the nick change
85 $this->getConnection()->setNick($altNick);
88 // If no other nicks are available...
90 // Terminate the connection
91 $this->doQuit('All specified alternate nicks are in use');