3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
23 * IRC background connection manager for IRC-using queue handlers,
24 * allowing them to send outgoing messages on the right connection.
26 * Input is handled during socket select loop, keepalive pings during idle.
27 * Any incoming messages will be handled.
29 * In a multi-site queuedaemon.php run, one connection will be instantiated
30 * for each site being handled by the current process that has IRC enabled.
33 class IrcManager extends ImManager {
37 * Initialize connection to server.
39 * @return boolean true on success
41 public function start($master) {
42 if (parent::start($master)) {
51 * Return any open sockets that the run loop should listen
54 * @return array Array of socket resources
56 public function getSockets() {
59 return $this->conn->getSockets();
66 * Process IRC events that have come in over the wire.
68 * @param resource $socket
71 public function handleInput($socket) {
72 common_log(LOG_DEBUG, 'Servicing the IRC queue.');
73 $this->stats('irc_process');
74 $this->conn->receive();
82 public function connect() {
84 $this->conn = new Phergie_ExtendedBot;
86 $port = empty($this->plugin->port) ? 6667 : $this->plugin->port;
87 $password = empty($this->plugin->password) ? '' : $this->plugin->password;
88 $transport = empty($this->plugin->transporttype) ? 'tcp' : $this->plugin->transporttype;
89 $encoding = empty($this->plugin->encoding) ? 'UTF8' : $this->plugin->encoding;
90 $nickservpassword = empty($this->plugin->nickservpassword) ? '' : $this->plugin->nickservpassword;
91 $channels = empty($this->plugin->channels) ? array() : $this->plugin->channels;
93 $config = new Phergie_Config;
96 'connections' => array(
98 'host' => $this->plugin->host,
100 'username' => $this->plugin->username,
101 'realname' => $this->plugin->realname,
102 'nick' => $this->plugin->nick,
103 'password' => $password,
104 'transport' => $transport,
105 'encoding' => $encoding
109 'driver' => 'statusnet',
111 'processor' => 'statusnet',
117 'Statusnet_Callback',
120 'plugins.autoload' => true,
122 'ui.enabled' => true,
124 'nickserv.password' => $nickservpassword,
125 'autojoin.channels' => $channels,
126 'statusnet_callback.callback' => array($this, 'handle_irc_message')
130 $this->conn->setConfig($config);
131 $this->conn->connect();
137 * Called via a callback when a message is received
139 * Passes it back to the queuing system
141 * @param array $data Data
144 public function handle_irc_message($data) {
145 $this->plugin->enqueue_incoming_raw($data);
150 * Send a message using the daemon
152 * @param $data Message
153 * @return boolean true on success
155 public function send_raw_message($data) {
160 $this->conn->send($data[0], $data[1]);